Ron and Ella Wiki Page

Extremely Serious

Page 22 of 33

Using Detach ASCII Signature to Verify a File

Import Keys from Keyserver

Run the following command:

gpg --receive-keys <KEY_ID>

Showing the Fingerprints

Run the following command:

gpg --fingerprint <KEY_ID>

Verifying a File with ASCII Key

  1. Download the detach asc <ASC_FILE> file associated to the file.
  2. Download the signed file <SIGNED_FILE> file.
  3. Use the following command for verification:
    gpg --verify <ASC_FILE> <SIGNED_FILE>

Generating PGP Keys with Gpg4win

Pre-requisite

Generating Keys

    1. Run the following command:
      gpg --full-gen-key
    2. Type 1 and press enter for the following question:
      Please select what kind of key you want:
         (1) RSA and RSA (default)
         (2) DSA and Elgamal
         (3) DSA (sign only)
         (4) RSA (sign only)
      Your selection?
    3. Press enter for the following question:
      RSA keys may be between 1024 and 4096 bits long.
      What keysize do you want? (2048)
    4. Press enter for the following question:
      Please specify how long the key should be valid.
               0 = key does not expire
            <n>  = key expires in n days
            <n>w = key expires in n weeks
            <n>m = key expires in n months
            <n>y = key expires in n years
      Key is valid for? (0)
    5. Type y and press enter for the following question:
      Key does not expire at all
      Is this correct? (y/N)
    6. Fill in the Real name appropriately and press enter.
    7. Fill in the Email address appropriately and press enter.
    8. The Comment is optional but don't forget to press enter.
    9. Type o and press enter for the following question:
      Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit?
    10. Fill-in the passphrase appropriately.

The output will be ending with something like the following:

pub   rsa2048 2019-11-27 [SC]
      8C99E30527B112D1CB6D646FE86A4FE7189AADC9
uid                      Real Name <real_email@email.com>
sub   rsa2048 2019-11-27 [E]

The second line is the PGP key ID. Thus from the output above. The key id is:

8C99E30527B112D1CB6D646FE86A4FE7189AADC9

Exporting Your Private Key

The my-secret-key.pgp file generated by this command can be use for signing your binaries.

Run the following command:

gpg --export-secret-keys <KEY_ID> > my-secret-key.pgp

DO NOT SHARE THIS FILE OR COMMIT TO YOUR REPOSITORY.

Publishing Your Public Key

Run the following command:

gpg --keyserver hkp://keys.openpgp.org --send-keys <KEY_ID>

Validating your Published Public Key

  1. You can validate the upload public key by placing your <KEY_ID> as a Search String from the following address: https://keys.openpgp.org.

    This will only work if you submit your keys using the preceding section.

  2. Click the Search button.

Publishing to Maven Central with Gradle

Pre-requisites

  1. Create an account to sonatype.
  2. Request for a group id from sonatype by using Jira to create an issue.
  3. Generate PGP keys to be used for signing the binaries (e.g. jar file). For windows, you can follow the procedure here.
  4. Wait for the completion of the issue you've created from item 2.

Gradle Configuration

  1. Update your gradle.properties to include the following properties:
    nexusUsername=<SONATYPE_USERNAME>
    nexusPassword=<SONATYPE_PASSWORD>
    
    signing.keyId=<PGP_PUBLIC_KEY_ID>
    signing.password=<PGP_PASS_PHRASE>
    signing.secretKeyRingFile=<PGP_EXPORTED_PRIVATE_KEY>
    
  2. In your build.gradle file,  add the Gradle Sonatype Nexus Plugin like the following:
    plugins {
       id "java"
       id "com.bmuschko.nexus" version "2.3.1" // Gradle Sonatype Nexus Plugin
    }
  3. Add the following plugin configurations:
    modifyPom {
        project {
            name '<PROJECT_NAME>'
            description '<PROJECT_DESCRIPTION>'
            url '<PROJECT_WEBSITE>'
            inceptionYear '<PROJECT_INCEPTION_YEAR>'
    
            scm {
                url '<PROJECT_SCM_ADDRESS>'
                connection '<PROJECT_SCM_ADDRESS>'
                developerConnection '<PROJECT_SCM_ADDRESS>'
            }
    
            licenses {
                license {
                    name '<PROJECT_LICENSE_NAME>'
                    url '<PROJECT_LICENSE_ADDRESS>'
                    distribution 'repo'
                }
            }
    
            developers {
                developer {
                    id '<DEVELOPER_ID>'
                    name '<DEVELOPER_NAME>'
                    email '<DEVELOPER_EMAIL>'
                }
            }
        }
    }
    
    extraArchive {
        sources = true
        tests = true
        javadoc = true
    }
    
    nexus {
        sign = true
        repositoryUrl = '<SONATYPE_RELEASE_REPOSITORY>'
        snapshotRepositoryUrl = '<SONATYPE_SNAPSHOT_REPOSITORY>'
    }
  4. Add the Gradle Nexus Staging plugin like the following:
    plugins {
        id 'java'
        id "com.bmuschko.nexus" version "2.3.1" // Gradle Sonatype Nexux Plugin
        id "io.codearte.nexus-staging" version "0.21.1" // Gradle Nexus Staging Plugin
    }
  5. After adding the plugin save the build.gradle file.
  6. Get the staging profile ID by running the following command:
    gradlew getStagingProfile
  7. Add the following plugin configuration:
    nexusStaging {
        stagingProfileId = "<STAGING_PROFILE_ID>"
    }
  8. Save the build.gradle file again.

Uploading to Sonatype Repository

Run the following command:

gradlew publishToSonatype

Publishing to Maven Central

Run the following command:

gradlew closeAndReleaseSonatypeStagingRepository

Errors in Publishing

If there are any errors after running the preceding command

  1. Sign in to the following address using your sonatype credentials: https://oss.sonatype.org/
  2. Click the Staging Repositories menu and investigate the error from there.
  3. Once the errors were identified and corrected locally, upload it again to sonatype repository before publishing it again.

Do this error correction process until all the errors were corrected.

Successful Publishing Validation

After around 10 minutes, navigate to your registered group id from sonatype, starting from the following address:

https://repo.maven.apache.org/maven2/

After around 2 hours, your artifact id may be searchable in maven central from the following address:

https://search.maven.org/

 

Writing and Reading Into and From a Text File in Gosu

Writing into a Text File in Gosu

To write into a text file in gosu we can use the FileWriter as follows:

using(var writer = new BufferedWriter(new FileWriter("<FILENAME>"))) {
  writer.write("<TEXT>")  // Writes a text to into a file.
  writer.flush() // Must be at the last.
}
Token Description
FILENAME The target filename to write into.
TEXT The text to write into the filename. You can write as many text as you like. Just don't forget the flush method at the end.

Reading from a Text File in Gosu

To read from a text file in gosu we can use the FileReader with Scanner as follows:

using (var scanner = new Scanner(new BufferedReader(new FileReader("<FILENAME>")))) {
  while(scanner.hasNext()) {
    print(scanner.nextLine()) //---Reads a line from the file.
  }
}
Token Description
FILENAME The target filename to read from.

Using Reduce Method to do AND and OR Testing

If the if conditions are becoming longer and complicated. It is possible to separate all the conditions to a list like the following:

var conditions : List<block() : Boolean>= {
  \-> {
    print("1")
    return true
  }, 
  \-> {
    print("2")
    return false
  }
}

The above example is just a simple illustration and not good for actual coding.

The following code snippet is for hunting at least one truth condition using reduce method to do OR logic testing.

if (conditions?.reduce(false, \ ___aggr, ___cond -> ___aggr || ___cond())) {
  print("I'm in")
}

Once a truth condition was identified it stops checking the rest and the if condition is evaluated to true.

The following code snippet is for checking all the conditions are true using the reduce method to do AND logic testing.

if (conditions?.reduce(true, \ ___aggr, ___cond -> ___aggr && ___cond())) {
  print("I'm in")
}

Once a false condition was identified it stops checking the rest and the if condition is evaluated to false.

Java Proxy Properties By Protocol

Common Protocols

Protocol proxyHost proxyPort nonProxyHosts proxyUser proxyPassword
http Y Y Y Y Y
https Y Y also use http.nonProxyHosts Y Y
ftp Y Y Y Y Y

For nonProxyHosts, a list of hosts that should be reached directly without the proxy. The list is separated by '|' (i.e. pipe symbol). The patterns may start or end with a '*' for wildcards.

If the protocol value is Y for a particular header, it means you can combine the protocol with the header (e.g. http is Y for proxyHost in the table, thus we can combine it as http.proxyHost) to form a single property.

SOCKS Protocol

Property Description
socksProxyHost The host of the SOCKS proxy server.
socksProxyPort The port (i.e. defaulting to 1080) where SOCKS proxy server is listening.
socksProxyVersion The version (i.e. defaulting to 5) of the SOCKS protocol supported by the server.
java.net.socks.username The username for authenticating to SOCKSv5 proxy server.
java.net.socks.password The password for authenticating to SOCKSv5 proxy server.

System Proxy

java.net.useSystemProxies set this property to true to use the system proxy.

Simple Example of Using Some of the Properties

java -Dhttp.proxyHost=localhost -Dhttp.proxyPort=808 ApplicationAccessingTheNet

Extracting GMail SMTP Certificate using OpenSSL

1a.) For TLS, use the following command:

openssl s_client -connect smtp.gmail.com:587 -starttls smtp

1b.) For SSL, use the following command:

openssl s_client -connect smtp.gmail.com:465

2.) Both  outputs of the preceding commands are long but you we are just interested in the entries that starts with:

-----BEGIN CERTIFICATE-----

and ends with:

-----END CERTIFICATE-----

3.) Copy that block of entries to a new file like smtp.gmail.com.pem.

This file is now the certificate file.

Listing the Entries of a Java Keystore

Use the following command to list the entries of a Java keystore:

The keytool is normally found in $JAVA_HOME/jre/bin (i.e. the $JAVA_HOME variable is where you’ve installed JDK).

keytool -list -v -keystore <KEYSTORE_FILE> -storepass <KEYSTORE_PASSWORD>

Include the -a <ALIAS> parameter to just display a single certificate.

Token Description
KEYSTORE_FILE The target key store file (e.g. cacerts found in $JAVA_HOME/jre/lib/security)
KEYSTORE_PASSWORD The password for accessing the keystore (i.e. the default is changeit)

Importing a Certificate to Java Keystore

Use the following command in importing a certificate to Java keystore:

The keytool is normally found in $JAVA_HOME/jre/bin (i.e. the $JAVA_HOME variable is where you've installed JDK).

keytool -importcert -alias <ALIAS> -v -keystore <KEYSTORE_FILE> -file <INPUT_FILE> -storepass <KEYSTORE_PASSWORD>
Token Description
ALIAS Alias name of the entry to process
KEYSTORE_FILE The target key store file (e.g. cacerts found in $JAVA_HOME/jre/lib/security)
INPUT_FILE Input file name (i.e. certificate file like cer, crt or pem)
KEYSTORE_PASSWORD The password for accessing the keystore (i.e. the default is changeit)

 

« Older posts Newer posts »