@@ -0,0 +1,3053 @@
+// Copyright 2014, Kevin Ko %3Ckevin@faveset.com%3E%0A%0Apackage com.faveset.khttp.ssl;%0A%0Aimport java.io.FileInputStream;%0Aimport java.io.FileOutputStream;%0Aimport java.io.InputStream;%0Aimport java.io.IOException;%0Aimport java.io.OutputStream;%0Aimport java.security.GeneralSecurityException;%0Aimport java.security.KeyStore;%0Aimport java.security.KeyStoreException;%0Aimport java.security.cert.Certificate;%0A%0A/**%0A * This manages a keystore in JKS format.%0A */%0Apublic class KeyStoreBuilder %7B%0A    private static String sKeyStoreType = %22JKS%22;%0A%0A    private KeyStore mKeyStore;%0A%0A    private String mPassword;%0A%0A    /**%0A     * @param password can be null if no password is desired%0A     *%0A     * @throws KeyStoreException on error.%0A     */%0A    public static KeyStoreBuilder create(String password)%0A            throws IOException, KeyStoreException %7B%0A        KeyStore keyStore = KeyStore.getInstance(sKeyStoreType);%0A%0A        char%5B%5D passChars = null;%0A        if (password != null) %7B%0A            passChars = password.toCharArray();%0A        %7D%0A%0A        try %7B%0A            keyStore.load(null, passChars);%0A        %7D catch (GeneralSecurityException e) %7B%0A            throw new KeyStoreException(e);%0A        %7D%0A        return new KeyStoreBuilder(keyStore, password);%0A    %7D%0A%0A    public static KeyStoreBuilder open(String filename, String password)%0A            throws IOException, KeyStoreException %7B%0A        FileInputStream input = new FileInputStream(filename);%0A        return open(input, password);%0A    %7D%0A%0A    public static KeyStoreBuilder open(InputStream input, String password)%0A            throws IOException, KeyStoreException %7B%0A        KeyStore keyStore = KeyStore.getInstance(sKeyStoreType);%0A%0A        char%5B%5D passChars = null;%0A        if (password != null) %7B%0A            passChars = password.toCharArray();%0A        %7D%0A%0A        try %7B%0A            keyStore.load(input, passChars);%0A        %7D catch (GeneralSecurityException e) %7B%0A            throw new KeyStoreException(e);%0A        %7D%0A%0A        return new KeyStoreBuilder(keyStore, password);%0A    %7D%0A%0A    private KeyStoreBuilder(KeyStore keyStore, String password) %7B%0A        mKeyStore = keyStore;%0A        mPassword = password;%0A    %7D%0A%0A    public void build(String outFilename) throws IOException, KeyStoreException %7B%0A        FileOutputStream out = new FileOutputStream(outFilename);%0A        build(out);%0A    %7D%0A%0A    public void build(OutputStream out) throws IOException, KeyStoreException %7B%0A        char%5B%5D passChars = null;%0A        if (mPassword != null) %7B%0A            passChars = mPassword.toCharArray();%0A        %7D%0A%0A        try %7B%0A            mKeyStore.store(out, passChars);%0A        %7D catch (GeneralSecurityException e) %7B%0A            throw new KeyStoreException(e);%0A        %7D%0A    %7D%0A%0A    public KeyStoreBuilder setCertificate(String alias, Certificate cert) throws KeyStoreException %7B%0A        mKeyStore.setCertificateEntry(alias, cert);%0A        return this;%0A    %7D%0A%0A    /**%0A     * @param password set to null for no password%0A     */%0A    public KeyStoreBuilder setPassword(String password) %7B%0A        mPassword = password;%0A        return this;%0A    %7D%0A%7D%0A

Add KeyStoreBuilder helper.