List of usage examples for javax.net.ssl SSLServerSocketFactory createServerSocket
@Override public ServerSocket createServerSocket(int port) throws IOException
From source file:org.jgentleframework.integration.remoting.rmi.customsocket.SSLSocket_RMIServerSocketFactory.java
public ServerSocket createServerSocket(int port) { try {/*www. ja v a 2s.c o m*/ java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); SSLServerSocketFactory socketFactory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); SSLServerSocket returnValue = (SSLServerSocket) socketFactory.createServerSocket(port); returnValue.setEnabledCipherSuites(Ciphers); returnValue.setNeedClientAuth(false); return returnValue; } catch (Exception ignored) { if (log.isFatalEnabled()) { log.fatal("Could not create SSL Socket !! ", ignored); } } return null; }
From source file:org.jgentleframework.utils.network.sockets.SSLSocketTools.java
/** * Creates the server socket./*from w ww . j a v a2s .c o m*/ * * @param port * the port * @param cipherSuites * the cipher suites * @return the sSL server socket */ public SSLServerSocket createServerSocket(int port, SSLCipherSuites[] cipherSuites) { SSLServerSocket returnValue = null; try { java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); SSLServerSocketFactory socketFactory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); returnValue = (SSLServerSocket) socketFactory.createServerSocket(port); String[] CIPHERS = new String[cipherSuites.length]; for (int i = 0; i < cipherSuites.length; i++) { CIPHERS[i] = cipherSuites[i].name(); } returnValue.setEnabledCipherSuites(CIPHERS); returnValue.setEnableSessionCreation(true); return returnValue; } catch (IOException e) { if (log.isFatalEnabled()) { log.fatal("Could not create SSL server socket !!", e); } } return returnValue; }
From source file:org.opennms.netmgt.provision.server.SSLServer.java
/** * <p>init</p>//from www.j ava2 s .c om * * @throws java.lang.Exception if any. */ @Override public void init() throws Exception { super.init(); KeyManagerFactory kmf = KeyManagerFactory.getInstance(getKeyManagerAlgorithm(), getKeyManagerProvider()); KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); char[] password = getPassword().toCharArray(); java.io.FileInputStream fis = null; try { fis = new java.io.FileInputStream(getPathToKeyStore()); ks.load(fis, password); } finally { if (fis != null) { fis.close(); } } kmf.init(ks, password); KeyManager[] km = kmf.getKeyManagers(); SSLContext sslContext = SSLContext.getInstance(getSslContextProtocol()); sslContext.init(km, null, new SecureRandom()); SSLServerSocketFactory serverFactory = sslContext.getServerSocketFactory(); setServerSocket(serverFactory.createServerSocket(getPort())); onInit(); }
From source file:org.wso2.carbon.databridge.receiver.binary.BinaryDataReceiver.java
private void startSecureTransmission() throws IOException, DataBridgeException { ServerConfiguration serverConfig = ServerConfiguration.getInstance(); String keyStore = serverConfig.getFirstProperty("Security.KeyStore.Location"); if (keyStore == null) { keyStore = System.getProperty("Security.KeyStore.Location"); if (keyStore == null) { throw new DataBridgeException( "Cannot start agent server, not valid Security.KeyStore.Location is null"); }/*ww w .j a v a 2 s. c o m*/ } String keyStorePassword = serverConfig.getFirstProperty("Security.KeyStore.Password"); if (keyStorePassword == null) { keyStorePassword = System.getProperty("Security.KeyStore.Password"); if (keyStorePassword == null) { throw new DataBridgeException( "Cannot start agent server, not valid Security.KeyStore.Password is null "); } } System.setProperty("javax.net.ssl.keyStore", keyStore); System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword); SSLServerSocketFactory sslserversocketfactory = (SSLServerSocketFactory) SSLServerSocketFactory .getDefault(); SSLServerSocket sslserversocket = (SSLServerSocket) sslserversocketfactory .createServerSocket(binaryDataReceiverConfiguration.getSSLPort()); sslserversocket.setEnabledCipherSuites(sslserversocket.getSupportedCipherSuites()); for (int i = 0; i < binaryDataReceiverConfiguration.getSizeOfSSLThreadPool(); i++) { sslReceiverExecutorService.execute(new BinaryTransportReceiver(sslserversocket)); } log.info("Started Binary SSL Transport on port : " + binaryDataReceiverConfiguration.getSSLPort()); }
From source file:org.wso2.carbon.databridge.receiver.binary.internal.BinaryDataReceiver.java
private void startSecureTransmission() throws IOException, DataBridgeException { String keyStore = dataBridgeReceiverService.getInitialConfig().getKeyStoreLocation(); if (keyStore == null) { ServerConfiguration serverConfig = ServerConfiguration.getInstance(); keyStore = serverConfig.getFirstProperty("Security.KeyStore.Location"); if (keyStore == null) { keyStore = System.getProperty("Security.KeyStore.Location"); if (keyStore == null) { throw new DataBridgeException( "Cannot start binary agent server, not valid Security.KeyStore.Location is null"); }/*from ww w .j a va2 s. c o m*/ } } String keyStorePassword = dataBridgeReceiverService.getInitialConfig().getKeyStorePassword(); if (keyStorePassword == null) { ServerConfiguration serverConfig = ServerConfiguration.getInstance(); keyStorePassword = serverConfig.getFirstProperty("Security.KeyStore.Password"); if (keyStorePassword == null) { keyStorePassword = System.getProperty("Security.KeyStore.Password"); if (keyStorePassword == null) { throw new DataBridgeException( "Cannot start binary agent server, not valid Security.KeyStore.Password is null "); } } } System.setProperty("javax.net.ssl.keyStore", keyStore); System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword); SSLServerSocketFactory sslserversocketfactory = (SSLServerSocketFactory) SSLServerSocketFactory .getDefault(); SSLServerSocket sslserversocket = (SSLServerSocket) sslserversocketfactory .createServerSocket(binaryDataReceiverConfiguration.getSSLPort()); String sslProtocols = binaryDataReceiverConfiguration.getSslProtocols(); if (sslProtocols != null && sslProtocols.length() != 0) { String[] sslProtocolsArray = sslProtocols.split(","); sslserversocket.setEnabledProtocols(sslProtocolsArray); } String ciphers = binaryDataReceiverConfiguration.getCiphers(); if (ciphers != null && ciphers.length() != 0) { String[] ciphersArray = ciphers.split(","); sslserversocket.setEnabledCipherSuites(ciphersArray); } else { sslserversocket.setEnabledCipherSuites(sslserversocket.getSupportedCipherSuites()); } Thread thread = new Thread(new BinarySecureEventServerAcceptor(sslserversocket)); thread.start(); log.info("Started Binary SSL Transport on port : " + binaryDataReceiverConfiguration.getSSLPort()); }
From source file:test.integ.be.fedict.commons.eid.client.SSLTest.java
@Test public void testMutualSSL() throws Exception { Security.addProvider(new BeIDProvider()); final KeyPair serverKeyPair = generateKeyPair(); final PrivateKey serverPrivateKey = serverKeyPair.getPrivate(); final DateTime notBefore = new DateTime(); final DateTime notAfter = notBefore.plusDays(1); final X509Certificate serverCertificate = generateCACertificate(serverKeyPair, "CN=Test", notBefore, notAfter);/*w w w . ja v a2 s . c o m*/ final KeyManager keyManager = new ServerTestX509KeyManager(serverPrivateKey, serverCertificate); final TrustManager trustManager = new ServerTestX509TrustManager(); final SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(new KeyManager[] { keyManager }, new TrustManager[] { trustManager }, new SecureRandom()); final SSLServerSocketFactory sslServerSocketFactory = sslContext.getServerSocketFactory(); final int serverPort = 8443; final SSLServerSocket sslServerSocket = (SSLServerSocket) sslServerSocketFactory .createServerSocket(serverPort); sslServerSocket.setNeedClientAuth(true); final TestRunnable testRunnable = new TestRunnable(serverPort); final Thread thread = new Thread(testRunnable); thread.start(); SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept(); LOG.debug("server accepted"); InputStream inputStream = sslSocket.getInputStream(); int result = inputStream.read(); LOG.debug("result: " + result); assertEquals(12, result); SSLSession sslSession = sslSocket.getSession(); sslSession.invalidate(); sslSocket = (SSLSocket) sslServerSocket.accept(); inputStream = sslSocket.getInputStream(); result = inputStream.read(); LOG.debug("result: " + result); assertEquals(34, result); }