本文整理汇总了Java中javax.net.ssl.SSLServerSocket类的典型用法代码示例。如果您正苦于以下问题:Java SSLServerSocket类的具体用法?Java SSLServerSocket怎么用?Java SSLServerSocket使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SSLServerSocket类属于javax.net.ssl包,在下文中一共展示了SSLServerSocket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import javax.net.ssl.SSLServerSocket; //导入依赖的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: createServerTransport
import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
private static TServerSocket createServerTransport(boolean secure)
throws TTransportException
{
if (!secure) {
return new TServerSocket(0);
}
try {
SSLContext serverSslContext = ClientTestUtils.getServerSslContext();
SSLServerSocket serverSocket = (SSLServerSocket) serverSslContext.getServerSocketFactory().createServerSocket(0);
return new TServerSocket(serverSocket);
}
catch (Exception e) {
throw new TTransportException("Error initializing secure socket", e);
}
}
示例3: getSSLServerTransport
import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
private TServerTransport getSSLServerTransport() {
try {
TServerTransport transport;
TSSLTransportFactory.TSSLTransportParameters params =
new TSSLTransportFactory.TSSLTransportParameters();
params.setKeyStore(keystore, keystorePassword, getkeyManagerAlgorithm(), keystoreType);
transport = TSSLTransportFactory.getServerSocket(
port, 120000, InetAddress.getByName(bindAddress), params);
ServerSocket serverSock = ((TServerSocket) transport).getServerSocket();
if (serverSock instanceof SSLServerSocket) {
SSLServerSocket sslServerSock = (SSLServerSocket) serverSock;
List<String> enabledProtocols = new ArrayList<String>();
for (String protocol : sslServerSock.getEnabledProtocols()) {
if (!excludeProtocols.contains(protocol)) {
enabledProtocols.add(protocol);
}
}
sslServerSock.setEnabledProtocols(enabledProtocols.toArray(new String[0]));
}
return transport;
} catch (Throwable throwable) {
throw new FlumeException("Cannot start Thrift source.", throwable);
}
}
示例4: initServerSocket
import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
/**
* Configures the given SSL server socket with the requested cipher suites,
* protocol versions, and need for client authentication
*/
private void initServerSocket(ServerSocket ssocket) {
SSLServerSocket socket = (SSLServerSocket) ssocket;
if (enabledCiphers != null) {
socket.setEnabledCipherSuites(enabledCiphers);
}
String requestedProtocols = (String) attributes.get("protocols");
setEnabledProtocols(socket, getEnabledProtocols(socket,
requestedProtocols));
// we don't know if client auth is needed -
// after parsing the request we may re-handshake
configureClientAuth(socket);
}
示例5: finishServerSocket
import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
/**
* Configure the SSLServerSocket based on this SocketCreator's settings.
*/
private void finishServerSocket(SSLServerSocket serverSocket) throws IOException {
serverSocket.setUseClientMode(false);
if (this.sslConfig.isRequireAuth()) {
// serverSocket.setWantClientAuth( true );
serverSocket.setNeedClientAuth(true);
}
serverSocket.setEnableSessionCreation(true);
// restrict protocols
String[] protocols = this.sslConfig.getProtocolsAsStringArray();
if (!"any".equalsIgnoreCase(protocols[0])) {
serverSocket.setEnabledProtocols(protocols);
}
// restrict ciphers
String[] ciphers = this.sslConfig.getCiphersAsStringArray();
if (!"any".equalsIgnoreCase(ciphers[0])) {
serverSocket.setEnabledCipherSuites(ciphers);
}
}
示例6: createServerSocket
import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
/**
* Create a server socket listening on the given port.
*
* @param port The target listening port.
* @param backlog The desired backlog value.
*
* @return An appropriate server socket for this connection.
* @exception IOException
* @exception ConnectException
*/
public ServerSocket createServerSocket(int port, int backlog) throws IOException {
try {
// if no protection is required, just create a plain socket.
if ((NoProtection.value & requires) == NoProtection.value) {
if (log.isDebugEnabled()) log.debug("Created plain server socket for port " + port);
return new ServerSocket(port, backlog);
}
else {
// SSL is required. Create one from the SSLServerFactory retrieved from the config. This will
// require additional QOS configuration after creation.
SSLServerSocket serverSocket = (SSLServerSocket)getServerSocketFactory().createServerSocket(port, backlog);
configureServerSocket(serverSocket);
return serverSocket;
}
} catch (IOException ex) {
log.error("Exception creating a server socket for port " + port, ex);
throw ex;
}
}
示例7: configureServerSocket
import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
/**
* Set the server socket configuration to our required
* QOS values.
*
* A small experiment shows that setting either (want, need) parameter to either true or false sets the
* other parameter to false.
*
* @param serverSocket
* The newly created SSLServerSocket.
*
* @throws IOException if server socket can't be configured
*/
private void configureServerSocket(SSLServerSocket serverSocket) throws IOException {
// set the authentication value and cipher suite info.
serverSocket.setEnabledCipherSuites(cipherSuites);
if (clientAuthRequired) {
serverSocket.setNeedClientAuth(true);
} else if (clientAuthSupported) {
serverSocket.setWantClientAuth(true);
} else {
serverSocket.setNeedClientAuth(false); //could set want with the same effect
}
serverSocket.setSoTimeout(SOCKET_TIMEOUT_MS);
if (log.isDebugEnabled()) {
log.debug("Created SSL server socket on port " + serverSocket.getLocalPort());
log.debug(" client authentication " + (clientAuthSupported ? "SUPPORTED" : "UNSUPPORTED"));
log.debug(" client authentication " + (clientAuthRequired ? "REQUIRED" : "OPTIONAL"));
log.debug(" cipher suites:");
for (int i = 0; i < cipherSuites.length; i++) {
log.debug(" " + cipherSuites[i]);
}
}
}
示例8: printInfo
import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
public static void printInfo(SSLServerSocket socket) {
System.out.println();
System.out.println("--- SSL ServerSocket Info ---");
System.out.print("SupportedProtocols : ");
printStringArray(socket.getSupportedProtocols());
System.out.print("SupportedCipherSuites : ");
printStringArray(socket.getSupportedCipherSuites());
System.out.print("EnabledProtocols : ");
printStringArray(socket.getEnabledProtocols());
System.out.print("EnabledCipherSuites : ");
String[] supportedCipherSuites = socket.getEnabledCipherSuites();
Arrays.sort(supportedCipherSuites);
printStringArray(supportedCipherSuites);
System.out.println("NeedClientAuth : "
+ socket.getNeedClientAuth());
System.out.println("WantClientAuth : "
+ socket.getWantClientAuth());
System.out.println("-----------------------");
}
示例9: JSSEServer
import javax.net.ssl.SSLServerSocket; //导入依赖的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);
}
示例10: start
import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
public void start() throws IOException {
if (this.status.compareAndSet(Status.READY, Status.ACTIVE)) {
this.serverSocket = this.serverSocketFactory.createServerSocket(
this.port, this.socketConfig.getBacklogSize(), this.ifAddress);
this.serverSocket.setReuseAddress(this.socketConfig.isSoReuseAddress());
if (this.socketConfig.getRcvBufSize() > 0) {
this.serverSocket.setReceiveBufferSize(this.socketConfig.getRcvBufSize());
}
if (this.sslSetupHandler != null && this.serverSocket instanceof SSLServerSocket) {
this.sslSetupHandler.initialize((SSLServerSocket) this.serverSocket);
}
this.requestListener = new RequestListener(
this.socketConfig,
this.serverSocket,
this.httpService,
this.connectionFactory,
this.exceptionLogger,
this.workerExecutorService);
this.listenerExecutorService.execute(this.requestListener);
}
}
示例11: initSecure
import javax.net.ssl.SSLServerSocket; //导入依赖的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;
}
示例12: doServerSide
import javax.net.ssl.SSLServerSocket; //导入依赖的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();
}
}
示例13: doServerSide
import javax.net.ssl.SSLServerSocket; //导入依赖的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();
}
示例14: doServerSide
import javax.net.ssl.SSLServerSocket; //导入依赖的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();
}
示例15: JSSEServer
import javax.net.ssl.SSLServerSocket; //导入依赖的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);
}