@@ -0,0 +1,2955 @@
+// Copyright 2014, Kevin Ko %3Ckevin@faveset.com%3E%0A%0Apackage com.faveset.khttpserver;%0A%0Aimport java.io.IOException;%0Aimport java.io.FileOutputStream;%0Aimport java.security.KeyPair;%0Aimport java.security.KeyStoreException;%0Aimport java.security.cert.Certificate;%0Aimport java.security.cert.CertificateEncodingException;%0A%0Aimport com.faveset.flags.Flags;%0Aimport com.faveset.flags.BoolFlag;%0Aimport com.faveset.flags.StringFlag;%0Aimport com.faveset.khttp.ssl.CertificateBuilder;%0Aimport com.faveset.khttp.ssl.KeyStoreBuilder;%0A%0Apublic class SSLCertGen %7B%0A    private static StringFlag sAliasFlag =%0A        Flags.registerString(%22alias%22, %22%22, %22certificate alias%22);%0A%0A    private static StringFlag sOutputFlag =%0A        Flags.registerString(%22o%22, %22%22, %22output filename%22);%0A%0A    private static StringFlag sKeystoreFlag =%0A        Flags.registerString(%22keystore%22, %22%22, %22filename for the JKS keystore%22);%0A%0A    private static StringFlag sTruststoreFlag =%0A        Flags.registerString(%22truststore%22, %22%22,%0A                %22filename for the JKS truststore that will hold the certificate%22);%0A%0A    private static String getConsolePassword(String prompt) %7B%0A        System.out.print(prompt);%0A        String password = System.console().readLine();%0A        if (password.isEmpty()) %7B%0A            password = null;%0A        %7D%0A        return password;%0A    %7D%0A%0A    public static void main(String%5B%5D args)%0A            throws CertificateEncodingException, IOException, KeyStoreException %7B%0A        Flags.parse(args);%0A%0A        if (sOutputFlag.get().isEmpty()) %7B%0A            System.out.println(%22must specify output file%22);%0A            return;%0A        %7D%0A%0A        if (sKeystoreFlag.get().isEmpty()) %7B%0A            System.out.println(%22error: keystore file not specified%22);%0A            return;%0A        %7D%0A%0A        if (sTruststoreFlag.get().isEmpty()) %7B%0A            System.out.println(%22error: truststore file not specified%22);%0A            return;%0A        %7D%0A%0A        KeyPair keyPair = CertificateBuilder.makeKey();%0A%0A        // Build the certificate and truststore first so that we can use the self-signed certificate%0A        // for the keystore's certificate chain..%0A        CertificateBuilder builder = new CertificateBuilder();%0A        Certificate cert = builder.build(keyPair.getPrivate(), keyPair.getPublic());%0A%0A        String truststorePass = getConsolePassword(%22Truststore pass: %22);%0A        KeyStoreBuilder ksBuilder = KeyStoreBuilder.create(truststorePass);%0A        ksBuilder.setCertificate(sAliasFlag.get(), cert);%0A        ksBuilder.build(sTruststoreFlag.get());%0A%0A        // Build the keystore.%0A        String keystorePass = getConsolePassword(%22Keystore pass: %22);%0A        ksBuilder = KeyStoreBuilder.create(keystorePass);%0A        // We are generating a self-certified certificate, so the certificate chain is empty.%0A        Certificate%5B%5D certChain = new Certificate%5B%5D%7B cert %7D;%0A        ksBuilder.setPrivateKey(sAliasFlag.get(), keyPair.getPrivate(), certChain);%0A        ksBuilder.build(sKeystoreFlag.get());%0A    %7D%0A%7D%0A

Add simple testing tool for generating self-signed certificates.