当前位置: 首页>>代码示例>>Java>>正文


Java SSLContext.getServerSocketFactory方法代码示例

本文整理汇总了Java中javax.net.ssl.SSLContext.getServerSocketFactory方法的典型用法代码示例。如果您正苦于以下问题:Java SSLContext.getServerSocketFactory方法的具体用法?Java SSLContext.getServerSocketFactory怎么用?Java SSLContext.getServerSocketFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.net.ssl.SSLContext的用法示例。


在下文中一共展示了SSLContext.getServerSocketFactory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSSLServerSF

import javax.net.ssl.SSLContext; //导入方法依赖的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();
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:EmptyCertificateAuthorities.java

示例2: makeSSLSocketFactory

import javax.net.ssl.SSLContext; //导入方法依赖的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;
}
 
开发者ID:johndavidbustard,项目名称:RoughWorld,代码行数:18,代码来源:WebInterfaceSSL.java

示例3: JSSEServer

import javax.net.ssl.SSLContext; //导入方法依赖的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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:JSSEServer.java

示例4: JSSEServer

import javax.net.ssl.SSLContext; //导入方法依赖的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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:JSSEServer.java

示例5: makeSSLSocketFactory

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
/**
 * Creates an SSLSocketFactory for HTTPS. Pass a loaded KeyStore and an
 * array of loaded KeyManagers. These objects must properly
 * loaded/initialized by the caller.
 */
public static SSLServerSocketFactory makeSSLSocketFactory(KeyStore loadedKeyStore, KeyManager[] keyManagers) throws IOException {
    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) {
        throw new IOException(e.getMessage());
    }
    return res;
}
 
开发者ID:xm0625,项目名称:VBrowser-Android,代码行数:19,代码来源:NanoHTTPD.java

示例6: SslNetworkLayer

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
public SslNetworkLayer(
		SipStackImpl sipStack,
        String trustStoreFile,
        String keyStoreFile,
        char[] keyStorePassword,
        char[] trustStorePassword,
        String keyStoreType, String trustStoreType) throws GeneralSecurityException, FileNotFoundException, IOException
{
    SSLContext sslContext;
    sslContext = SSLContext.getInstance("TLS");
    String algorithm = KeyManagerFactory.getDefaultAlgorithm();
    TrustManagerFactory tmFactory = TrustManagerFactory.getInstance(algorithm);
    KeyManagerFactory kmFactory = KeyManagerFactory.getInstance(algorithm);
    SecureRandom secureRandom   = new SecureRandom();
    secureRandom.nextInt();
    KeyStore keyStore = KeyStore.getInstance(
         keyStoreType != null ? keyStoreType : KeyStore.getDefaultType());
    KeyStore trustStore = KeyStore.getInstance(
    		trustStoreType != null ? trustStoreType : KeyStore.getDefaultType());
    keyStore.load(new FileInputStream(keyStoreFile), keyStorePassword);
    trustStore.load(new FileInputStream(trustStoreFile), trustStorePassword);
    tmFactory.init(trustStore);
    kmFactory.init(keyStore, keyStorePassword);
    if(sipStack.getClientAuth() == ClientAuthType.DisabledAll) {
    	if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
            logger.logDebug(
                    "ClientAuth " + sipStack.getClientAuth()  +  " bypassing all cert validations");
        }
    	sslContext.init(null, trustAllCerts, secureRandom);
    } else {
    	if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
            logger.logDebug(
                    "ClientAuth " + sipStack.getClientAuth());
        }
    	sslContext.init(kmFactory.getKeyManagers(), tmFactory.getTrustManagers(), secureRandom);
    }
    sslServerSocketFactory = sslContext.getServerSocketFactory();        
    sslSocketFactory = sslContext.getSocketFactory();
}
 
开发者ID:YunlongYang,项目名称:LightSIP,代码行数:40,代码来源:SslNetworkLayer.java

示例7: SecureWebServer

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
/**
 * WebServer constructor.
 */
public SecureWebServer(Context ctx) {
    try {
        // Get an SSL context using the TLS protocol
        SSLContext sslContext = SSLContext.getInstance("TLS");

        // Get a key manager factory using the default algorithm
        KeyManagerFactory kmf = KeyManagerFactory
                .getInstance(KeyManagerFactory.getDefaultAlgorithm());

        // Load the PKCS12 key chain
        KeyStore ks = KeyStore.getInstance("PKCS12");
        FileInputStream fis = ctx.getAssets()
                .openFd(KeyChainDemoActivity.PKCS12_FILENAME)
                .createInputStream();
        ks.load(fis, KeyChainDemoActivity.PKCS12_PASSWORD.toCharArray());
        kmf.init(ks, KeyChainDemoActivity.PKCS12_PASSWORD.toCharArray());

        // Initialize the SSL context
        sslContext.init(kmf.getKeyManagers(), null, null);

        // Create the SSL server socket factory
        sssf = sslContext.getServerSocketFactory();

    } catch (Exception e) {
        e.printStackTrace();
    }

    // Create the base64 image string used in the server response
    base64Image = createBase64Image(ctx);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:34,代码来源:SecureWebServer.java

示例8: init

import javax.net.ssl.SSLContext; //导入方法依赖的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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:31,代码来源:UnboundSSLUtils.java

示例9: getServerSocket

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
@Override
public ServerSocket getServerSocket() throws Exception {
    SSLContext sslContext = SslUtils.getSSLContext(trustStore);
    SSLServerSocketFactory serverSocketFactory = sslContext.getServerSocketFactory();
    SSLServerSocket serverSocket = (SSLServerSocket) serverSocketFactory.createServerSocket(port);
    serverSocket.setNeedClientAuth(true);
    return serverSocket;
}
 
开发者ID:RomascuAndrei,项目名称:BTNotifierAndroid,代码行数:9,代码来源:SslNetworkConnectionProvider.java

示例10: JSSEServer

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
public JSSEServer(SSLContext context, String constraint,
        boolean needClientAuth) throws Exception {
    TLSRestrictions.setConstraint("Server", constraint);

    SSLServerSocketFactory serverFactory = context.getServerSocketFactory();
    server = (SSLServerSocket) serverFactory.createServerSocket(0);
    server.setSoTimeout(TLSRestrictions.TIMEOUT);
    server.setNeedClientAuth(needClientAuth); // for dual authentication
    System.out.println("Server: port=" + getPort());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:JSSEServer.java

示例11: JSSEServer

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
JSSEServer(CipherTest cipherTest) throws Exception {
    super(cipherTest);
    SSLContext serverContext = SSLContext.getInstance("TLS");
    serverContext.init(
            new KeyManager[] { CipherTest.keyManager },
            new TrustManager[] { CipherTest.trustManager },
            CipherTest.secureRandom);

    SSLServerSocketFactory factory = (SSLServerSocketFactory)serverContext.getServerSocketFactory();
    serverSocket = (SSLServerSocket)factory.createServerSocket(0);
    serverSocket.setSoTimeout(CipherTest.TIMEOUT);
    CipherTest.serverPort = serverSocket.getLocalPort();
    serverSocket.setEnabledCipherSuites(factory.getSupportedCipherSuites());
    serverSocket.setWantClientAuth(true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:JSSEServer.java

示例12: doServerSide

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
void doServerSide() throws Exception {
    SSLContext context = generateSSLContext(false);
    SSLServerSocketFactory sslssf = context.getServerSocketFactory();
    SSLServerSocket sslServerSocket =
        (SSLServerSocket)sslssf.createServerSocket(serverPort);
    serverPort = sslServerSocket.getLocalPort();

    /*
     * Signal Client, we're ready for his connect.
     */
    serverReady = true;

    SSLSocket sslSocket = (SSLSocket)sslServerSocket.accept();
    try {
        sslSocket.setSoTimeout(5000);
        sslSocket.setSoLinger(true, 5);

        InputStream sslIS = sslSocket.getInputStream();
        OutputStream sslOS = sslSocket.getOutputStream();

        sslIS.read();
        sslOS.write('A');
        sslOS.flush();

        throw new Exception("EC curve secp224k1 should be disabled");
    } catch (SSLHandshakeException she) {
        // expected exception: no cipher suites in common
        System.out.println("Expected exception: " + she);
    } finally {
        sslSocket.close();
        sslServerSocket.close();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:ECCurvesconstraints.java

示例13: init

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
/**
 * Reads the keystore and initializes the SSL socket factory.
 */
void init() throws IOException {
	try {

		String clientAuthStr = endpoint.getClientAuth();
		if ("true".equalsIgnoreCase(clientAuthStr) || "yes".equalsIgnoreCase(clientAuthStr)) {
			requireClientAuth = true;
		} else if ("want".equalsIgnoreCase(clientAuthStr)) {
			wantClientAuth = true;
		}

		SSLContext context = createSSLContext();
		context.init(getKeyManagers(), getTrustManagers(), null);

		// Configure SSL session cache
		SSLSessionContext sessionContext = context.getServerSessionContext();
		if (sessionContext != null) {
			configureSessionContext(sessionContext);
		}

		// create proxy
		sslProxy = context.getServerSocketFactory();

		// Determine which cipher suites to enable
		enabledCiphers = getEnableableCiphers(context);
		enabledProtocols = getEnableableProtocols(context);

		allowUnsafeLegacyRenegotiation = "true".equals(endpoint.getAllowUnsafeLegacyRenegotiation());

		// Check the SSL config is OK
		checkConfig();

	} catch (Exception e) {
		if (e instanceof IOException)
			throw (IOException) e;
		throw new IOException(e.getMessage(), e);
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:41,代码来源:JSSESocketFactory.java

示例14: newSSLSocketFactory

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
public static SSLServerSocketFactory newSSLSocketFactory(final InputStream cert, final String password,
    final String ksType, final String ksAlgorithm) throws InvalidSSLConfig {
    final SSLContext context = newSSLContext(cert, password, ksType, ksAlgorithm);
    return context.getServerSocketFactory();
}
 
开发者ID:aerogear,项目名称:push-network-proxies,代码行数:6,代码来源:SSLHelper.java

示例15: init

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
/**
 * Reads the keystore and initializes the SSL socket factory.
 */
void init() throws IOException {
    try {

        String clientAuthStr = endpoint.getClientAuth();
        if("true".equalsIgnoreCase(clientAuthStr) ||
           "yes".equalsIgnoreCase(clientAuthStr)) {
            requireClientAuth = true;
        } else if("want".equalsIgnoreCase(clientAuthStr)) {
            wantClientAuth = true;
        }

        SSLContext context = createSSLContext();
        context.init(getKeyManagers(), getTrustManagers(), null);

        // Configure SSL session cache
        SSLSessionContext sessionContext =
            context.getServerSessionContext();
        if (sessionContext != null) {
            configureSessionContext(sessionContext);
        }

        // create proxy
        sslProxy = context.getServerSocketFactory();

        // Determine which cipher suites to enable
        enabledCiphers = getEnableableCiphers(context);
        enabledProtocols = getEnableableProtocols(context);

        allowUnsafeLegacyRenegotiation = "true".equals(
                endpoint.getAllowUnsafeLegacyRenegotiation());

        // Check the SSL config is OK
        checkConfig();

    } catch(Exception e) {
        if( e instanceof IOException )
            throw (IOException)e;
        throw new IOException(e.getMessage(), e);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:44,代码来源:JSSESocketFactory.java


注:本文中的javax.net.ssl.SSLContext.getServerSocketFactory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。