Extremely Serious

Month: December 2019

Generating SSH Key Pair

  1. Execute the following command:
    ssh-keygen -t ed25519
  2. Distribute the public key using the following syntax:
    ssh-copy-id -i ~/.ssh/id_ed25519.pub <USER>@<HOST>
    Token Description
    USER A valid user on the host computer.
    HOST The host that has an active ssh service.

    If ssh-copy-id command doesn't work, you can directly append the content of the id_ed25519.pub file to the ~/.ssh/authorized_keys file (i.e. create this file if it doesn't exists) of the target <USER> on the target <HOST>.

Creating an Email Alias

Create a new alias for postfix service by updating the following file:

/etc/aliases

Each entry in the file must have the following syntax:

<ALIAS>: <USER1>[[, <USER2>], <USERn>]
Token Description
ALIAS The desired email alias.
USER1, USER2, USERn USER1 is required and the rest are optional. Each user must be delimited by a comma.

The target user of the alias must be a valid user of the system with a home directory.

Example:

postmaster: root

After updating the file, you must execute the following command:

sudo newaliases

Using Embedded Derby in Java 9 with Gradle

  1. Add the following dependencies to your build.gradle file:
    compile group: 'org.apache.derby', name: 'derby', version: '10.15.1.3'
    compile group: 'org.apache.derby', name: 'derbyshared', version: '10.15.1.3'
  2. Add the following entries to your module-info.java file:
    requires org.apache.derby.engine;
    requires org.apache.derby.commons;
    requires java.sql;
    
  3. In your Java class, you can create a connection like the following:
    final String DATABASE_NAME = "sample_table";
    String connectionURL = String.format("jdbc:derby:%s;create=true", DATABASE_NAME);
    connection = DriverManager.getConnection(connectionURL);
    
  4. Do your needed database operations with the connection (e.g. create table, execute a query, or call a stored procedure.).
  5. When your done using the connection, close the connection and shutdown the Derby engine like the following:
    connection.close();
    
    boolean gotSQLExc = false;
    try {
        //shutdown all databases and the Derby engine
        DriverManager.getConnection("jdbc:derby:;shutdown=true");
    } catch (SQLException se)  {
        if ( se.getSQLState().equals("XJ015") ) {
            gotSQLExc = true;
        }
    }
    if (!gotSQLExc) {
        System.out.println("Database did not shut down normally");
    }

    A clean shutdown always throws SQL exception XJ015, which can be ignored.

Using Values as the Record Source for Select Statement

Values can become a valid record source for select statement if the values has table alias and column names as follows:

SELECT dummy_table.* 
FROM (VALUES ('record1'),
	 ('record2'),
	 ('record3'),
	 ('record4'),
	 ('record5'),
	 ('record6'),
	 ('record7'),
	 ('record8'),
	 ('record9')) dummy_table (column1)

From the preceding select statement, the dummy_table is the table alias and the column name is column1.

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 --send-key <EMAIL_ADDRESS>

Use the email address you've used from generating the key.

Alternative way of Publishing your Public Key

  1. Generate an ASCII-armored PGP key using the following command:
    gpg --armor --export <EMAIL_ADDRESS>

    Use the email address you've used from generating the key.

    The preceding command is exporting your public key in ascii format.

  2. Copy and paste the generated public ID to the following address: http://hkps.pool.sks-keyservers.net/#submit
  3. Click the Submit this key to the keyserver! button.

Validating your Published Public Key

  1. You can validate the upload public key by placing your <EMAIL_ADDRESS> as a Search String from the following address: http://hkps.pool.sks-keyservers.net/#extract.

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

  2. Click the Do 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/