@@ -0,0 +1,2243 @@
+package org.webmessage.util;%0D%0A%0D%0Aimport java.io.InputStream;%0D%0Aimport java.security.KeyStore;%0D%0Aimport java.security.Security;%0D%0A%0D%0Aimport javax.net.ssl.KeyManagerFactory;%0D%0Aimport javax.net.ssl.SSLContext;%0D%0Aimport javax.net.ssl.TrustManager;%0D%0Aimport javax.net.ssl.TrustManagerFactory;%0D%0A%0D%0Aimport org.webmessage.exception.WebMessageException;%0D%0A/**%0D%0A * This code was forked from %0D%0A * %3Ca href=%22https://github.com/joewalnes/webbit%22%3Ewebbit%3C/a%3E and modified.%0D%0A */%0D%0Apublic class SslContextFactory %7B%0D%0A%09private static final String PROTOCOL = %22TLS%22;%0D%0A%09private KeyStore keyStore;%0D%0A%09%0D%0A%09private SslContextFactory(InputStream keyStore,char%5B%5D storePass)%0D%0A%09%09%09throws WebMessageException%7B%0D%0A        try %7B%0D%0A        %09this.keyStore = KeyStore.getInstance(KeyStore.getDefaultType());%0D%0A%09%09%09this.keyStore.load(keyStore, storePass);%0D%0A%09%09%7D catch (Exception e) %7B%0D%0A%09%09%09throw new WebMessageException(e);%0D%0A%09%09%7D %0D%0A%09%7D%0D%0A%09%0D%0A%09public static SslContextFactory getInstance(InputStream keyStore,String storePass)%0D%0A%09%09%09throws WebMessageException%7B%0D%0A%09%09return new SslContextFactory(keyStore,storePass.toCharArray());%0D%0A%09%7D%0D%0A%09%0D%0A%09public SSLContext getServerContext(String pass) throws WebMessageException%7B%0D%0A        try %7B%0D%0A            String algorithm = Security.getProperty(%22ssl.KeyManagerFactory.algorithm%22);%0D%0A            if (algorithm == null)%7B%0D%0A            %09algorithm = %22SunX509%22;%0D%0A            %7D%0D%0A            KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);%0D%0A            kmf.init(this.keyStore, pass.toCharArray());%0D%0A%0D%0A            SSLContext sslContext = SSLContext.getInstance(PROTOCOL);%0D%0A            sslContext.init(kmf.getKeyManagers(), null, null);%0D%0A            return sslContext;%0D%0A        %7D catch (Exception e) %7B%0D%0A            throw new WebMessageException(e);%0D%0A        %0D%0A        %7D%0D%0A%09%7D%0D%0A%09%0D%0A%09public SSLContext getClientContext() throws Exception%7B%0D%0A%09%09try %7B%0D%0A%09        SSLContext sslContext = SSLContext.getInstance(PROTOCOL);%0D%0A%09        TrustManagerFactory tmf = TrustManagerFactory.getInstance(%22SunX509%22, %22SunJSSE%22);%0D%0A%09        tmf.init(this.keyStore);%0D%0A%09        TrustManager%5B%5D trustManagers = tmf.getTrustManagers();%0D%0A%09        sslContext.init(null, trustManagers, null);%0D%0A%09        return sslContext;%0D%0A%09%09%7D catch (Exception e) %7B%0D%0A%09%09%09throw new WebMessageException(e);%0D%0A%09%09%7D %0D%0A%0D%0A%09%7D%0D%0A%7D%0D%0A

add SslContextFactory