/** * Creates a socket factory given a keystore. * * @param keyStore keystore containing a certificate and private key for * used in creating a secured socket. * @return a socket factory for use in creating a secured socket. * @throws NoSuchAlgorithmException when TLS 1.2 is not available. * @throws UnrecoverableKeyException when the private key cannot be * recovered. Ususally a bad keystore password. * @throws KeyStoreException when keystore cannot be created. * @throws KeyManagementException when SSL context cannot be created by key * manager. */ public static SSLSocketFactory getSocketFactoryWithKeyStore(KeyStore keyStore) throws NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, KeyManagementException { SSLContext context = SSLContext.getInstance("TLSv1.2"); KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory .getDefaultAlgorithm()); kmf.init(keyStore, AWSIotKeystoreHelper.AWS_IOT_INTERNAL_KEYSTORE_PASSWORD.toCharArray()); KeyManager[] km = kmf.getKeyManagers(); context.init(km, null, new SecureRandom()); return new AWSIotTLSSocketFactory(context.getSocketFactory()); } }
@Override public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException { return enableTLSOnSocket(sslSocketFactory.createSocket(address, port, localAddress, localPort)); }
@Override public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException { return enableTLSOnSocket(sslSocketFactory.createSocket(s, host, port, autoClose)); }
/** * Creates a socket factory given a keystore. * * @param keyStore keystore containing a certificate and private key for * used in creating a secured socket. * @return a socket factory for use in creating a secured socket. * @throws NoSuchAlgorithmException when TLS 1.2 is not available. * @throws UnrecoverableKeyException when the private key cannot be * recovered. Ususally a bad keystore password. * @throws KeyStoreException when keystore cannot be created. * @throws KeyManagementException when SSL context cannot be created by key * manager. */ public static SSLSocketFactory getSocketFactoryWithKeyStore(KeyStore keyStore) throws NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, KeyManagementException { SSLContext context = SSLContext.getInstance("TLSv1.2"); KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory .getDefaultAlgorithm()); kmf.init(keyStore, AWSIotKeystoreHelper.AWS_IOT_INTERNAL_KEYSTORE_PASSWORD.toCharArray()); KeyManager[] km = kmf.getKeyManagers(); context.init(km, null, new SecureRandom()); return new AWSIotTLSSocketFactory(context.getSocketFactory()); } }
@Override public Socket createSocket(String host, int port) throws IOException { return enableTLSOnSocket(sslSocketFactory.createSocket(host, port)); }
@Override public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException { return enableTLSOnSocket(sslSocketFactory.createSocket(host, port, localHost, localPort)); }
@Override public Socket createSocket() throws IOException { return enableTLSOnSocket(sslSocketFactory.createSocket()); }
@Override public Socket createSocket(InetAddress host, int port) throws IOException { return enableTLSOnSocket(sslSocketFactory.createSocket(host, port)); }
@Override public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException { return enableTLSOnSocket(sslSocketFactory.createSocket(address, port, localAddress, localPort)); }
@Override public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException { return enableTLSOnSocket(sslSocketFactory.createSocket(s, host, port, autoClose)); }
@Override public Socket createSocket(String host, int port) throws IOException { return enableTLSOnSocket(sslSocketFactory.createSocket(host, port)); }
@Override public Socket createSocket(InetAddress host, int port) throws IOException { return enableTLSOnSocket(sslSocketFactory.createSocket(host, port)); }
@Override public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException { return enableTLSOnSocket(sslSocketFactory.createSocket(host, port, localHost, localPort)); }
@Override public Socket createSocket() throws IOException { return enableTLSOnSocket(sslSocketFactory.createSocket()); }