RhasspyIntentLauncher/RhasspyIntentLauncher/src/com/jens/rhasspy/intentlauncher/MySSLSocketFactory.java

129 lines
3.5 KiB
Java

package com.jens.rhasspy.intentlauncher;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import javax.net.SocketFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManagerFactory;
//import org.bouncycastle.jce.provider.BouncyCastleProvider;
public class MySSLSocketFactory extends SSLSocketFactory
{
// private static SSLSocketFactory sf;
private static SSLContext context = null;
public MySSLSocketFactory() throws KeyManagementException, KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException
{
init();
}
private static void init() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException, CertificateException, IOException
{
// Security.addProvider(new BouncyCastleProvider());
KeyStore keyStore = KeyStore.getInstance("BKS");
InputStream is = new FileInputStream(new File("keystore.ks"));
char[] keystorePass="insecure".toCharArray();
keyStore.load(is,keystorePass);
TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
tmf.init(keyStore);
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, tmf.getTrustManagers(), null);
// sf = ctx.getSocketFactory();
final SSLContext context = SSLContext.getInstance("SSL");
context.init(null, tmf.getTrustManagers(), new SecureRandom());
}
@Override
public Socket createSocket(Socket arg0, String arg1, int arg2, boolean arg3) throws IOException
{
return null;
}
@Override
public String[] getDefaultCipherSuites()
{
return null;
}
@Override
public String[] getSupportedCipherSuites()
{
return null;
}
@Override
public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
{
return null;
}
@Override
public Socket createSocket(InetAddress arg0, int arg1) throws IOException
{
return null;
}
@Override
public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException
{
return null;
}
@Override
public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
{
return null;
}
public static SocketFactory getDefault()
{
if(context == null)
{
try
{
init();
}
catch (KeyManagementException e)
{
Miscellaneous.logEvent(Miscellaneous.getStackTraceAsString(e), 1);
}
catch (KeyStoreException e)
{
Miscellaneous.logEvent(Miscellaneous.getStackTraceAsString(e), 1);
}
catch (NoSuchAlgorithmException e)
{
Miscellaneous.logEvent(Miscellaneous.getStackTraceAsString(e), 1);
}
catch (CertificateException e)
{
Miscellaneous.logEvent(Miscellaneous.getStackTraceAsString(e), 1);
}
catch (IOException e)
{
Miscellaneous.logEvent(Miscellaneous.getStackTraceAsString(e), 1);
}
}
return context.getSocketFactory();
}
/* delegate SSLSocketFactory public methods to sf */
// ssf.setHostnameVerifier(MySSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
}