本文整理匯總了Java中javax.net.ssl.SSLServerSocketFactory類的典型用法代碼示例。如果您正苦於以下問題:Java SSLServerSocketFactory類的具體用法?Java SSLServerSocketFactory怎麽用?Java SSLServerSocketFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SSLServerSocketFactory類屬於javax.net.ssl包,在下文中一共展示了SSLServerSocketFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import javax.net.ssl.SSLServerSocketFactory; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
// reserve the security properties
String reservedSSFacProvider =
Security.getProperty("ssl.ServerSocketFactory.provider");
try {
Security.setProperty("ssl.ServerSocketFactory.provider", "oops");
ServerSocketFactory ssocketFactory =
SSLServerSocketFactory.getDefault();
SSLServerSocket sslServerSocket =
(SSLServerSocket)ssocketFactory.createServerSocket();
} catch (Exception e) {
if (!(e.getCause() instanceof ClassNotFoundException)) {
throw e;
}
// get the expected exception
} finally {
// restore the security properties
if (reservedSSFacProvider == null) {
reservedSSFacProvider = "";
}
Security.setProperty("ssl.ServerSocketFactory.provider",
reservedSSFacProvider);
}
}
示例2: getSSLServerSF
import javax.net.ssl.SSLServerSocketFactory; //導入依賴的package包/類
private SSLServerSocketFactory getSSLServerSF() throws Exception {
char [] password =
System.getProperty("javax.net.ssl.keyStorePassword").toCharArray();
String keyFilename = System.getProperty("javax.net.ssl.keyStore");
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream(keyFilename), password);
KeyManagerFactory kmf = KeyManagerFactory.getInstance("NewSunX509");
kmf.init(ks, password);
KeyManager[] kms = kmf.getKeyManagers();
TrustManager[] tms = new MyX509TM[] {new MyX509TM()};
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(kms, tms, null);
return ctx.getServerSocketFactory();
}
示例3: makeSSLSocketFactory
import javax.net.ssl.SSLServerSocketFactory; //導入依賴的package包/類
/**
* Creates an SSLSocketFactory for HTTPS. Pass a KeyStore resource with your
* certificate and passphrase
*/
public static SSLServerSocketFactory makeSSLSocketFactory(String keyAndTrustStoreClasspathPath, char[] passphrase) throws IOException {
try {
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
InputStream keystoreStream = NanoHTTPD.class.getResourceAsStream(keyAndTrustStoreClasspathPath);
if (keystoreStream == null) {
throw new IOException("Unable to load keystore from classpath: " + keyAndTrustStoreClasspathPath);
}
keystore.load(keystoreStream, passphrase);
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keystore, passphrase);
return makeSSLSocketFactory(keystore, keyManagerFactory);
} catch (Exception e) {
throw new IOException(e.getMessage());
}
}
示例4: getServerSocketFactoryImpl
import javax.net.ssl.SSLServerSocketFactory; //導入依賴的package包/類
/**
* Retrieves the underlying javax.net.ssl.SSLServerSocketFactory.
*
* @throws Exception if there is a problem retrieving the
* underlying factory
* @return the underlying javax.net.ssl.SSLServerSocketFactory
*/
protected SSLServerSocketFactory getServerSocketFactoryImpl()
throws Exception {
Object factory;
synchronized (server_socket_factory_mutex) {
factory = serverSocketFactory;
if (factory == null) {
factory = SSLServerSocketFactory.getDefault();
serverSocketFactory = factory;
}
}
return (SSLServerSocketFactory) factory;
}
示例5: makeSSLSocketFactory
import javax.net.ssl.SSLServerSocketFactory; //導入依賴的package包/類
public static SSLServerSocketFactory makeSSLSocketFactory(KeyStore loadedKeyStore, KeyManager[] keyManagers)
{
SSLServerSocketFactory res = null;
try {
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(loadedKeyStore);
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(keyManagers, trustManagerFactory.getTrustManagers(), null);
res = ctx.getServerSocketFactory();
}
catch (Exception e)
{
System.out.println(e.toString());
//throw new IOException(e.getMessage());
}
return res;
}
示例6: main
import javax.net.ssl.SSLServerSocketFactory; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
System.setProperty("javax.net.ssl.keyStorePassword", "passphrase");
System.setProperty("javax.net.ssl.keyStore",
System.getProperty("test.src", "./") + "/../../ssl/etc/keystore");
SSLServerSocketFactory sslssf =
(SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
final ServerSocket server = sslssf.createServerSocket(0);
System.out.println(server.getLocalPort());
System.out.flush();
Thread t = new Thread() {
public void run() {
try {
Thread.sleep(30000);
server.close();
} catch (Exception e) {
;
}
throw new RuntimeException("Timeout");
}
};
t.setDaemon(true);
t.start();
((SSLSocket)server.accept()).startHandshake();
}
示例7: JSSEServer
import javax.net.ssl.SSLServerSocketFactory; //導入依賴的package包/類
JSSEServer(CipherTestUtils cipherTest, int serverPort,
String protocol, String cipherSuite) throws Exception {
super(cipherTest);
this.serverPort = serverPort;
SSLContext serverContext = SSLContext.getInstance("TLS");
serverContext.init(new KeyManager[]{cipherTest.getServerKeyManager()},
new TrustManager[]{cipherTest.getServerTrustManager()},
CipherTestUtils.secureRandom);
SSLServerSocketFactory factory =
(SSLServerSocketFactory)serverContext.getServerSocketFactory();
serverSocket =
(SSLServerSocket) factory.createServerSocket(serverPort);
serverSocket.setEnabledProtocols(protocol.split(","));
serverSocket.setEnabledCipherSuites(cipherSuite.split(","));
CipherTestUtils.printInfo(serverSocket);
}
示例8: main
import javax.net.ssl.SSLServerSocketFactory; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
ServerSocketFactory ssf = SSLServerSocketFactory.getDefault();
ServerSocket ss = ssf.createServerSocket(Integer.parseInt(args[0]));
System.out.println("Ready...");
SSLSimpleServer server = new SSLSimpleServer(ss);
new Thread(server).start();
try {
Thread.sleep(200 * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Stopping Server");
}
示例9: initSecure
import javax.net.ssl.SSLServerSocketFactory; //導入依賴的package包/類
final ServerSocket initSecure(int port) throws Exception {
ServerSocketFactory fac;
if (sslContext != null) {
fac = sslContext.getServerSocketFactory();
} else {
fac = SSLServerSocketFactory.getDefault();
}
SSLServerSocket se = (SSLServerSocket) fac.createServerSocket(port);
SSLParameters sslp = se.getSSLParameters();
sslp.setApplicationProtocols(new String[]{"h2"});
se.setSSLParameters(sslp);
se.setEnabledCipherSuites(se.getSupportedCipherSuites());
se.setEnabledProtocols(se.getSupportedProtocols());
// other initialisation here
return se;
}
示例10: run
import javax.net.ssl.SSLServerSocketFactory; //導入依賴的package包/類
@Override
public void run() {
System.setProperty("javax.net.ssl.keyStorePassword", "passphrase");
System.setProperty("javax.net.ssl.keyStore", "keystore");
SSLServerSocketFactory sslssf =
(SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
try (ServerSocket server = sslssf.createServerSocket(0)) {
this.serverPort = server.getLocalPort();
System.out.printf("%nServer started on: %s%n", getServerPort());
untilServerReady.countDown();
((SSLSocket)server.accept()).startHandshake();
} catch (Throwable e) {
e.printStackTrace(System.out);
untilServerReady.countDown();
}
}
示例11: doServerSide
import javax.net.ssl.SSLServerSocketFactory; //導入依賴的package包/類
void doServerSide() throws Exception {
SSLServerSocketFactory sslssf =
(SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
SSLServerSocket sslServerSocket =
(SSLServerSocket) sslssf.createServerSocket(serverPort);
serverPort = sslServerSocket.getLocalPort();
/*
* Signal Client, we're ready for his connect.
*/
serverReady = true;
while (serverReady) {
SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
// System.out.printf(" accept: %s%n", sslSocket);
InputStream sslIS = sslSocket.getInputStream();
OutputStream sslOS = sslSocket.getOutputStream();
sslIS.read();
sslOS.write(85);
sslOS.flush();
sslSocket.close();
}
}
示例12: doServerSide
import javax.net.ssl.SSLServerSocketFactory; //導入依賴的package包/類
void doServerSide() throws Exception {
SSLServerSocketFactory sslssf = getSSLServerSF();
SSLServerSocket sslServerSocket =
(SSLServerSocket) sslssf.createServerSocket(serverPort);
// require client authentication.
sslServerSocket.setNeedClientAuth(true);
serverPort = sslServerSocket.getLocalPort();
/*
* Signal Client, we're ready for his connect.
*/
serverReady = true;
SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
InputStream sslIS = sslSocket.getInputStream();
OutputStream sslOS = sslSocket.getOutputStream();
sslIS.read();
sslOS.write('A');
sslOS.flush();
sslSocket.close();
}
示例13: doServerSide
import javax.net.ssl.SSLServerSocketFactory; //導入依賴的package包/類
void doServerSide() throws Exception {
SSLServerSocketFactory sslssf =
(SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
SSLServerSocket sslServerSocket =
(SSLServerSocket) sslssf.createServerSocket(serverPort);
serverPort = sslServerSocket.getLocalPort();
/*
* Signal Client, we're ready for his connect.
*/
serverReady = true;
SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
InputStream sslIS = sslSocket.getInputStream();
OutputStream sslOS = sslSocket.getOutputStream();
sslIS.read();
sslOS.write('A');
sslOS.flush();
sslSocket.close();
}
示例14: JSSEServer
import javax.net.ssl.SSLServerSocketFactory; //導入依賴的package包/類
JSSEServer(CipherTestUtils cipherTest, int serverPort,
String protocol, String cipherSuite) throws Exception {
super(cipherTest);
SSLContext serverContext = SSLContext.getInstance("TLS");
serverContext.init(new KeyManager[]{cipherTest.getServerKeyManager()},
new TrustManager[]{cipherTest.getServerTrustManager()},
CipherTestUtils.secureRandom);
SSLServerSocketFactory factory =
(SSLServerSocketFactory)serverContext.getServerSocketFactory();
serverSocket =
(SSLServerSocket) factory.createServerSocket(serverPort);
serverSocket.setEnabledProtocols(protocol.split(","));
serverSocket.setEnabledCipherSuites(cipherSuite.split(","));
CipherTestUtils.printInfo(serverSocket);
}
示例15: createHttpService
import javax.net.ssl.SSLServerSocketFactory; //導入依賴的package包/類
@Override protected HttpServer createHttpService(HttpServer.Config config, Logger logger) {
return new TefHttpServer(config, logger) {
@Override protected ServerSocket createServerSocket(int port) throws IOException {
return "ssl".equals(System.getProperty("http-socket-type"))
? SSLServerSocketFactory.getDefault().createServerSocket(port)
: super.createServerSocket(port);
}
@Override protected HttpConnection newConnection(Socket socket) {
return new TefHttpConnection(this, socket) {
@Override protected boolean authenticate(HttpRequest request) {
return authenticateHttpRequest(request);
}
};
}
};
}