本文整理匯總了Java中javax.net.ssl.SSLServerSocketFactory.createServerSocket方法的典型用法代碼示例。如果您正苦於以下問題:Java SSLServerSocketFactory.createServerSocket方法的具體用法?Java SSLServerSocketFactory.createServerSocket怎麽用?Java SSLServerSocketFactory.createServerSocket使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.net.ssl.SSLServerSocketFactory
的用法示例。
在下文中一共展示了SSLServerSocketFactory.createServerSocket方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
示例2: 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);
}
示例3: 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();
}
}
示例4: 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();
}
}
示例5: 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();
}
示例6: 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();
}
示例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: newSslServerSocket
import javax.net.ssl.SSLServerSocketFactory; //導入方法依賴的package包/類
public SSLServerSocket newSslServerSocket(String host,int port,int backlog) throws IOException {
SSLServerSocketFactory factory = sslContext.getServerSocketFactory();
SSLServerSocket socket =
(SSLServerSocket) (host==null ?
factory.createServerSocket(port, backlog):
factory.createServerSocket(port, backlog, InetAddress.getByName(host)));
if (sslConfig.getWantClientAuth())
socket.setWantClientAuth(sslConfig.getWantClientAuth());
if (sslConfig.getNeedClientAuth())
socket.setNeedClientAuth(sslConfig.getNeedClientAuth());
socket.setEnabledCipherSuites(selectCipherSuites(socket.getEnabledCipherSuites(),
socket.getSupportedCipherSuites()));
socket.setEnabledProtocols(selectProtocols(socket.getEnabledProtocols(),socket.getSupportedProtocols()));
return socket;
}
示例9: start
import javax.net.ssl.SSLServerSocketFactory; //導入方法依賴的package包/類
/**
* Starts this test server.
*/
public void start() throws Exception {
Asserts.check(servicedSocket == null, "Already running");
final ServerSocket ssock;
if (sslcontext != null) {
final SSLServerSocketFactory sf = sslcontext.getServerSocketFactory();
final SSLServerSocket sslsock = (SSLServerSocket) sf.createServerSocket();
if (forceSSLAuth) {
sslsock.setNeedClientAuth(true);
} else {
sslsock.setWantClientAuth(true);
}
ssock = sslsock;
} else {
ssock = new ServerSocket();
}
ssock.setReuseAddress(true); // probably pointless for port '0'
ssock.bind(TEST_SERVER_ADDR);
servicedSocket = ssock;
listenerThread = new ListenerThread();
listenerThread.setDaemon(false);
listenerThread.start();
}
示例10: createServer
import javax.net.ssl.SSLServerSocketFactory; //導入方法依賴的package包/類
private static GfxdTSSLServerSocket createServer(
SSLServerSocketFactory factory, InetSocketAddress bindAddress,
SocketParameters params) throws TTransportException {
try {
SSLServerSocket serverSocket = (SSLServerSocket)factory
.createServerSocket(bindAddress.getPort(), 100,
bindAddress.getAddress());
if (params != null) {
if (params.getSSLEnabledProtocols() != null) {
serverSocket.setEnabledProtocols(params.getSSLEnabledProtocols());
}
if (params.getSSLCipherSuites() != null) {
serverSocket.setEnabledCipherSuites(params.getSSLCipherSuites());
}
serverSocket.setNeedClientAuth(params.getSSLClientAuth());
}
return new GfxdTSSLServerSocket(serverSocket, bindAddress, params);
} catch (Exception e) {
throw new TTransportException(TTransportException.NOT_OPEN,
"Could not bind to host:port " + bindAddress.toString(), e);
}
}
示例11: start
import javax.net.ssl.SSLServerSocketFactory; //導入方法依賴的package包/類
/**
* Starts this test server.
*/
public void start() throws Exception {
if (servicedSocket != null) {
throw new IllegalStateException(this.toString() + " already running");
}
ServerSocket ssock;
if (sslcontext != null) {
SSLServerSocketFactory sf = sslcontext.getServerSocketFactory();
ssock = sf.createServerSocket();
} else {
ssock = new ServerSocket();
}
ssock.setReuseAddress(true); // probably pointless for port '0'
ssock.bind(TEST_SERVER_ADDR);
servicedSocket = ssock;
listenerThread = new ListenerThread();
listenerThread.setDaemon(false);
listenerThread.start();
}
示例12: BlockingServletEngine
import javax.net.ssl.SSLServerSocketFactory; //導入方法依賴的package包/類
BlockingServletEngine(FilterChain dispatcher, ServletEngineConfiguration config)
throws InterruptedException, IOException {
this.config = config;
if (config.isSecure()) {
SSLServerSocketFactory factory = (SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
SSLServerSocket sslServerSocket = (SSLServerSocket)factory.createServerSocket(config.getPort());
sslServerSocket.setEnabledCipherSuites(config.getEnabledCipherSuites());
serverSocket = sslServerSocket;
} else {
serverSocket = new ServerSocket(config.getPort());
}
int nthreads = config.getMaxThreads();
queue = new DispatchQueueImpl(nthreads);
handler = new HttpRequestHandlerAdapter(dispatcher);
socketHandler = new HttpSocketHandler(handler);
for (int i = 0; i < nthreads; ++i) {
queue.addRunnable(new AcceptSocketAndHandleRequest(socketHandler, serverSocket));
}
}
示例13: main
import javax.net.ssl.SSLServerSocketFactory; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
// try {
SSLServerSocketFactory ssf =
(SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
SSLServerSocket ss = (SSLServerSocket)ssf.createServerSocket();
String[] protocols = ss.getSupportedProtocols();
for (int i = 0; i < protocols.length; i++) {
// try {
if (protocols[i].equals("SSLv2Hello")) {
continue;
}
SSLContext sslc = SSLContext.getInstance(protocols[i]);
SSLSessionContext sslsc = sslc.getServerSessionContext();
System.out.println("Protocol: " + protocols[i]);
sslsc.setSessionTimeout(Integer.MAX_VALUE);
int newtime = sslsc.getSessionTimeout();
if (newtime != Integer.MAX_VALUE) {
throw new Exception ("Expected timeout: " +
Integer.MAX_VALUE + ", got instead: " +
newtime);
}
// } catch (Exception e) {
// }
}
// } catch (Exception e) {
// System.out.println(e);
// }
System.out.println("Finished");
}
示例14: init
import javax.net.ssl.SSLServerSocketFactory; //導入方法依賴的package包/類
static SSLEchoServer init(String cipherSuiteFilter,
String sniPattern) throws NoSuchAlgorithmException, IOException {
SSLContext context = SSLContext.getDefault();
SSLServerSocketFactory ssf =
(SSLServerSocketFactory) context.getServerSocketFactory();
SSLServerSocket ssocket =
(SSLServerSocket) ssf.createServerSocket(0);
// specify enabled cipher suites
if (cipherSuiteFilter != null) {
String[] ciphersuites = UnboundSSLUtils.filterStringArray(
ssf.getSupportedCipherSuites(), cipherSuiteFilter);
System.out.println("Server: enabled cipher suites: "
+ Arrays.toString(ciphersuites));
ssocket.setEnabledCipherSuites(ciphersuites);
}
// specify SNI matcher pattern
if (sniPattern != null) {
System.out.println("Server: set SNI matcher: " + sniPattern);
SNIMatcher matcher = SNIHostName.createSNIMatcher(sniPattern);
List<SNIMatcher> matchers = new ArrayList<>();
matchers.add(matcher);
SSLParameters params = ssocket.getSSLParameters();
params.setSNIMatchers(matchers);
ssocket.setSSLParameters(params);
}
return new SSLEchoServer(ssocket);
}
示例15: init
import javax.net.ssl.SSLServerSocketFactory; //導入方法依賴的package包/類
static SSLServer init(String[] ciphersuites)
throws IOException {
SSLServerSocketFactory ssf = (SSLServerSocketFactory)
SSLServerSocketFactory.getDefault();
SSLServerSocket ssocket = (SSLServerSocket)
ssf.createServerSocket(0);
if (ciphersuites != null) {
System.out.println("Server: enable cipher suites: "
+ java.util.Arrays.toString(ciphersuites));
ssocket.setEnabledCipherSuites(ciphersuites);
}
return new SSLServer(ssocket);
}