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


Java SSLSocket.setEnabledProtocols方法代码示例

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


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

示例1: doClientSide

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
void doClientSide() throws Exception {

        /*
         * Wait for server to get started.
         */
        while (!serverReady) {
            Thread.sleep(50);
        }

        SSLSocketFactory sslsf =
            (SSLSocketFactory) SSLSocketFactory.getDefault();
        SSLSocket sslSocket = (SSLSocket)
            sslsf.createSocket("localhost", serverPort);

        // enable TLSv1.1 only
        sslSocket.setEnabledProtocols(new String[] {"TLSv1.1"});

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

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

        sslSocket.close();
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:EmptyCertificateAuthorities.java

示例2: accept

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
@Override
public Socket accept() throws IOException {
    final SSLSocketFactory sslSocketFactory =
            context == null ?
                getDefaultSSLSocketFactory() : context.getSocketFactory();
    Socket socket = super.accept();
    SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(
            socket, socket.getInetAddress().getHostName(),
            socket.getPort(), true);
    sslSocket.setUseClientMode(false);
    if (enabledCipherSuites != null) {
        sslSocket.setEnabledCipherSuites(enabledCipherSuites);
    }
    if (enabledProtocols != null) {
        sslSocket.setEnabledProtocols(enabledProtocols);
    }
    sslSocket.setNeedClientAuth(needClientAuth);
    return sslSocket;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:ConnectorBootstrap.java

示例3: allEnabledTlsVersions

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
@Test public void allEnabledTlsVersions() throws Exception {
  ConnectionSpec tlsSpec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
      .allEnabledTlsVersions()
      .build();
  assertNull(tlsSpec.tlsVersions());

  SSLSocket sslSocket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
  sslSocket.setEnabledProtocols(new String[] {
      TlsVersion.SSL_3_0.javaName(),
      TlsVersion.TLS_1_1.javaName()
  });

  tlsSpec.apply(sslSocket, false);
  assertEquals(Arrays.asList(TlsVersion.SSL_3_0.javaName(), TlsVersion.TLS_1_1.javaName()),
      Arrays.asList(sslSocket.getEnabledProtocols()));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:ConnectionSpecTest.java

示例4: createServerSocket

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
/**
 * <p>Creates a server socket that accepts SSL connections
 * configured according to this factory's SSL socket configuration
 * parameters.</p>
 */
public ServerSocket createServerSocket(int port) throws IOException {
    final SSLSocketFactory sslSocketFactory =
            context == null ?
                getDefaultSSLSocketFactory() : context.getSocketFactory();
    return new ServerSocket(port) {
        public Socket accept() throws IOException {
            Socket socket = super.accept();
            SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(
                    socket, socket.getInetAddress().getHostName(),
                    socket.getPort(), true);
            sslSocket.setUseClientMode(false);
            if (enabledCipherSuites != null) {
                sslSocket.setEnabledCipherSuites(enabledCipherSuites);
            }
            if (enabledProtocols != null) {
                sslSocket.setEnabledProtocols(enabledProtocols);
            }
            sslSocket.setNeedClientAuth(needClientAuth);
            return sslSocket;
        }
    };
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:28,代码来源:SslRMIServerSocketFactory.java

示例5: createSSLSocket

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
private static TSocket createSSLSocket(SSLSocketFactory factory, String host,
                                       int port, int timeout, List<String> excludeProtocols)
    throws FlumeException {
  try {
    SSLSocket socket = (SSLSocket) factory.createSocket(host, port);
    socket.setSoTimeout(timeout);

    List<String> enabledProtocols = new ArrayList<String>();
    for (String protocol : socket.getEnabledProtocols()) {
      if (!excludeProtocols.contains(protocol)) {
        enabledProtocols.add(protocol);
      }
    }
    socket.setEnabledProtocols(enabledProtocols.toArray(new String[0]));
    return new TSocket(socket);
  } catch (Exception e) {
    throw new FlumeException("Could not connect to " + host + " on port " + port, e);
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:20,代码来源:ThriftRpcClient.java

示例6: tls_missingRequiredCipher

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
@Test public void tls_missingRequiredCipher() throws Exception {
  ConnectionSpec tlsSpec = new ConnectionSpec.Builder(true)
      .cipherSuites(CipherSuite.TLS_RSA_WITH_RC4_128_MD5)
      .tlsVersions(TlsVersion.TLS_1_2)
      .supportsTlsExtensions(false)
      .build();

  SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
  socket.setEnabledProtocols(new String[] {
      TlsVersion.TLS_1_2.javaName,
      TlsVersion.TLS_1_1.javaName,
  });

  socket.setEnabledCipherSuites(new String[] {
      CipherSuite.TLS_RSA_WITH_RC4_128_SHA.javaName,
      CipherSuite.TLS_RSA_WITH_RC4_128_MD5.javaName,
  });
  assertTrue(tlsSpec.isCompatible(socket));

  socket.setEnabledCipherSuites(new String[] {
      CipherSuite.TLS_RSA_WITH_RC4_128_SHA.javaName,
  });
  assertFalse(tlsSpec.isCompatible(socket));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:ConnectionSpecTest.java

示例7: apply

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
void apply(SSLSocket sslSocket, boolean isFallback) {
    ConnectionSpec specToApply = supportedSpec(sslSocket, isFallback);
    if (specToApply.tlsVersions != null) {
        sslSocket.setEnabledProtocols(specToApply.tlsVersions);
    }
    if (specToApply.cipherSuites != null) {
        sslSocket.setEnabledCipherSuites(specToApply.cipherSuites);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:10,代码来源:ConnectionSpec.java

示例8: tls_defaultCiphers_noFallbackIndicator

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
@Test public void tls_defaultCiphers_noFallbackIndicator() throws Exception {
  ConnectionSpec tlsSpec = new ConnectionSpec.Builder(true)
      .tlsVersions(TlsVersion.TLS_1_2)
      .supportsTlsExtensions(false)
      .build();

  SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
  socket.setEnabledCipherSuites(new String[] {
      CipherSuite.TLS_RSA_WITH_RC4_128_MD5.javaName,
      CipherSuite.TLS_RSA_WITH_RC4_128_SHA.javaName,
  });
  socket.setEnabledProtocols(new String[] {
      TlsVersion.TLS_1_2.javaName,
      TlsVersion.TLS_1_1.javaName,
  });

  assertTrue(tlsSpec.isCompatible(socket));
  tlsSpec.apply(socket, false /* isFallback */);

  assertEquals(set(TlsVersion.TLS_1_2.javaName), set(socket.getEnabledProtocols()));

  Set<String> expectedCipherSet =
      set(
          CipherSuite.TLS_RSA_WITH_RC4_128_MD5.javaName,
          CipherSuite.TLS_RSA_WITH_RC4_128_SHA.javaName);
  assertEquals(expectedCipherSet, expectedCipherSet);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:28,代码来源:ConnectionSpecTest.java

示例9: tls_defaultCiphers_withFallbackIndicator

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
@Test public void tls_defaultCiphers_withFallbackIndicator() throws Exception {
  ConnectionSpec tlsSpec = new ConnectionSpec.Builder(true)
      .tlsVersions(TlsVersion.TLS_1_2)
      .supportsTlsExtensions(false)
      .build();

  SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
  socket.setEnabledCipherSuites(new String[] {
      CipherSuite.TLS_RSA_WITH_RC4_128_MD5.javaName,
      CipherSuite.TLS_RSA_WITH_RC4_128_SHA.javaName,
  });
  socket.setEnabledProtocols(new String[] {
      TlsVersion.TLS_1_2.javaName,
      TlsVersion.TLS_1_1.javaName,
  });

  assertTrue(tlsSpec.isCompatible(socket));
  tlsSpec.apply(socket, true /* isFallback */);

  assertEquals(set(TlsVersion.TLS_1_2.javaName), set(socket.getEnabledProtocols()));

  Set<String> expectedCipherSet =
      set(
          CipherSuite.TLS_RSA_WITH_RC4_128_MD5.javaName,
          CipherSuite.TLS_RSA_WITH_RC4_128_SHA.javaName);
  if (Arrays.asList(socket.getSupportedCipherSuites()).contains("TLS_FALLBACK_SCSV")) {
    expectedCipherSet.add("TLS_FALLBACK_SCSV");
  }
  assertEquals(expectedCipherSet, expectedCipherSet);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:31,代码来源:ConnectionSpecTest.java

示例10: tls_explicitCiphers

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
@Test public void tls_explicitCiphers() throws Exception {
  ConnectionSpec tlsSpec = new ConnectionSpec.Builder(true)
      .cipherSuites(CipherSuite.TLS_RSA_WITH_RC4_128_MD5)
      .tlsVersions(TlsVersion.TLS_1_2)
      .supportsTlsExtensions(false)
      .build();

  SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
  socket.setEnabledCipherSuites(new String[] {
      CipherSuite.TLS_RSA_WITH_RC4_128_MD5.javaName,
      CipherSuite.TLS_RSA_WITH_RC4_128_SHA.javaName,
  });
  socket.setEnabledProtocols(new String[] {
      TlsVersion.TLS_1_2.javaName,
      TlsVersion.TLS_1_1.javaName,
  });

  assertTrue(tlsSpec.isCompatible(socket));
  tlsSpec.apply(socket, true /* isFallback */);

  assertEquals(set(TlsVersion.TLS_1_2.javaName), set(socket.getEnabledProtocols()));

  Set<String> expectedCipherSet = set(CipherSuite.TLS_RSA_WITH_RC4_128_MD5.javaName);
  if (Arrays.asList(socket.getSupportedCipherSuites()).contains("TLS_FALLBACK_SCSV")) {
    expectedCipherSet.add("TLS_FALLBACK_SCSV");
  }
  assertEquals(expectedCipherSet, expectedCipherSet);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:ConnectionSpecTest.java

示例11: _openDataConnection_

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
/**
 * Returns a socket of the data connection.
 * Wrapped as an {@link javax.net.ssl.SSLSocket}, which carries out handshake processing.
 * @param command The textual representation of the FTP command to send.
 * @param arg The arguments to the FTP command.
 * If this parameter is set to null, then the command is sent with
 * no arguments.
 * @return corresponding to the established data connection.
 * Null is returned if an FTP protocol error is reported at any point
 * during the establishment and initialization of the connection.
 * @throws java.io.IOException If there is any problem with the connection.
 * @see org.apache.commons.net.ftp.FTPClient#_openDataConnection_(int, String)
 * @since 3.2
 */
@Override
protected Socket _openDataConnection_(String command, String arg)
        throws IOException {
    Socket socket = super._openDataConnection_(command, arg);
    _prepareDataSocket_(socket);
    if (socket instanceof SSLSocket) {
        SSLSocket sslSocket = (SSLSocket)socket;

        sslSocket.setUseClientMode(isClientMode);
        sslSocket.setEnableSessionCreation(isCreation);

        // server mode
        if (!isClientMode) {
            sslSocket.setNeedClientAuth(isNeedClientAuth);
            sslSocket.setWantClientAuth(isWantClientAuth);
        }
        if (suites != null) {
            sslSocket.setEnabledCipherSuites(suites);
        }
        if (protocols != null) {
            sslSocket.setEnabledProtocols(protocols);
        }
        sslSocket.startHandshake();
    }

    return socket;
}
 
开发者ID:archos-sa,项目名称:aos-FileCoreLibrary,代码行数:42,代码来源:FTPSClient.java

示例12: createSocket

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
@Override
public Socket createSocket(String host, int port) throws IOException {
    SSLSocket s = (SSLSocket) delegate.createSocket(host, port);
    s.setEnabledProtocols(new String[]{tag});
    return s;
}
 
开发者ID:rafaeltoledo,项目名称:android-security,代码行数:7,代码来源:Tls12SslSocketFactory.java

示例13: doClientSide

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
void doClientSide() throws Exception {

        /*
         * Wait for server to get started.
         */
        while (!serverReady) {
            Thread.sleep(50);
        }

        SSLSocketFactory sslsf =
            (SSLSocketFactory) SSLSocketFactory.getDefault();
        SSLSocket sslSocket = (SSLSocket)
            sslsf.createSocket("localhost", serverPort);

        // enable TLSv1.1 only
        sslSocket.setEnabledProtocols(new String[] {"TLSv1.1"});

        // enable a exportable block cipher
        sslSocket.setEnabledCipherSuites(
            new String[] {"SSL_RSA_EXPORT_WITH_DES40_CBC_SHA"});

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

        boolean interrupted = false;
        try {
            sslOS.write('B');
            sslOS.flush();
            sslIS.read();
        } catch (SSLException ssle) {
            // get the expected exception
            interrupted = true;
        } finally {
            sslSocket.close();
        }

        if (!interrupted) {
            throw new SSLHandshakeException(
                "A weak cipher suite is negotiated, " +
                "TLSv1.1 must not negotiate the exportable cipher suites.");
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:43,代码来源:ExportableBlockCipher.java

示例14: wrapSocket

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
private SSLSocket wrapSocket(SSLSocket socket) {
  socket.setEnabledProtocols(protos);
  socket.setEnabledCipherSuites(ciphers);
  return socket;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:6,代码来源:SSLSocketFactoryExt.java

示例15: createSocket

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
@Override
public Socket createSocket(InetAddress inetAddress, int i) throws IOException {
  SSLSocket sc = (SSLSocket) socketFactory.createSocket(inetAddress, i);
  sc.setEnabledProtocols(protocols);
  return sc;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:7,代码来源:TestHTTPSource.java


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