javax.net.ssl.SSLEngine.setEnabledCipherSuites()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(227)

本文整理了Java中javax.net.ssl.SSLEngine.setEnabledCipherSuites()方法的一些代码示例,展示了SSLEngine.setEnabledCipherSuites()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SSLEngine.setEnabledCipherSuites()方法的具体详情如下:
包路径:javax.net.ssl.SSLEngine
类名称:SSLEngine
方法名:setEnabledCipherSuites

SSLEngine.setEnabledCipherSuites介绍

[英]Sets the SSL cipher suite names that should be enabled in this engine instance. Only cipher suites listed by getSupportedCipherSuites()are allowed.
[中]设置应在此引擎实例中启用的SSL密码套件名称。只允许使用GetSupportedCipherSuite()列出的密码套件。

代码示例

代码示例来源:origin: TooTallNate/Java-WebSocket

  1. @Override
  2. public ByteChannel wrapChannel(SocketChannel channel, SelectionKey key) throws IOException {
  3. SSLEngine e = sslcontext.createSSLEngine();
  4. if (enabledProtocols != null) {
  5. e.setEnabledProtocols(enabledProtocols);
  6. }
  7. if (enabledCiphersuites != null) {
  8. e.setEnabledCipherSuites(enabledCiphersuites);
  9. }
  10. e.setUseClientMode(false);
  11. return new SSLSocketChannel2(channel, e, exec, key);
  12. }

代码示例来源:origin: TooTallNate/Java-WebSocket

  1. @Override
  2. public ByteChannel wrapChannel( SocketChannel channel, SelectionKey key ) throws IOException {
  3. SSLEngine e = sslcontext.createSSLEngine();
  4. /*
  5. * See https://github.com/TooTallNate/Java-WebSocket/issues/466
  6. *
  7. * We remove TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 from the enabled ciphers since it is just available when you patch your java installation directly.
  8. * E.g. firefox requests this cipher and this causes some dcs/instable connections
  9. */
  10. List<String> ciphers = new ArrayList<String>( Arrays.asList(e.getEnabledCipherSuites()));
  11. ciphers.remove("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256");
  12. e.setEnabledCipherSuites( ciphers.toArray( new String[ciphers.size()] ) );
  13. e.setUseClientMode( false );
  14. return new SSLSocketChannel2( channel, e, exec, key );
  15. }

代码示例来源:origin: igniterealtime/Openfire

  1. /**
  2. * A utility method that implements the shared functionality of getClientModeSSLEngine and getServerModeSSLEngine.
  3. *
  4. * This method is used to initialize and pre-configure an instance of SSLEngine for a particular connection type.
  5. * The returned value lacks further configuration. In most cases, developers will want to use getClientModeSSLEngine
  6. * or getServerModeSSLEngine instead of this method.
  7. *
  8. * @return A new pre-configured SSLEngine instance (never null).
  9. */
  10. private SSLEngine createSSLEngine() throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException
  11. {
  12. final SSLContext sslContext = getSSLContext();
  13. final SSLEngine sslEngine = sslContext.createSSLEngine();
  14. // Configure protocol support.
  15. final Set<String> protocols = configuration.getEncryptionProtocols();
  16. if ( !protocols.isEmpty() )
  17. {
  18. // When an explicit list of enabled protocols is defined, use only those (otherwise, an implementation-specific default will be used).
  19. sslEngine.setEnabledProtocols( protocols.toArray( new String[ protocols.size() ] ) );
  20. }
  21. // Configure cipher suite support.
  22. final Set<String> cipherSuites = configuration.getEncryptionCipherSuites();
  23. if ( !cipherSuites.isEmpty() )
  24. {
  25. // When an explicit list of enabled protocols is defined, use only those (otherwise, an implementation-specific default will be used)..
  26. sslEngine.setEnabledCipherSuites( cipherSuites.toArray( new String[ cipherSuites.size() ] ) );
  27. }
  28. return sslEngine;
  29. }

代码示例来源:origin: apache/kafka

  1. private SSLEngine createSslEngine(SSLContext sslContext, String peerHost, int peerPort) {
  2. SSLEngine sslEngine = sslContext.createSSLEngine(peerHost, peerPort);
  3. if (cipherSuites != null) sslEngine.setEnabledCipherSuites(cipherSuites);
  4. if (enabledProtocols != null) sslEngine.setEnabledProtocols(enabledProtocols);
  5. // SSLParameters#setEndpointIdentificationAlgorithm enables endpoint validation
  6. // only in client mode. Hence, validation is enabled only for clients.
  7. if (mode == Mode.SERVER) {
  8. sslEngine.setUseClientMode(false);
  9. if (needClientAuth)
  10. sslEngine.setNeedClientAuth(needClientAuth);
  11. else
  12. sslEngine.setWantClientAuth(wantClientAuth);
  13. } else {
  14. sslEngine.setUseClientMode(true);
  15. SSLParameters sslParams = sslEngine.getSSLParameters();
  16. sslParams.setEndpointIdentificationAlgorithm(endpointIdentification);
  17. sslEngine.setSSLParameters(sslParams);
  18. }
  19. return sslEngine;
  20. }

代码示例来源:origin: robovm/robovm

  1. /**
  2. * Sets various SSL handshake parameters based on the SSLParameter
  3. * argument. Specifically, sets the SSLEngine's enabled cipher
  4. * suites if the parameter's cipher suites are non-null. Similarly
  5. * sets the enabled protocols. If the parameters specify the want
  6. * or need for client authentication, those requirements are set
  7. * on the SSLEngine, otherwise both are set to false.
  8. * @since 1.6
  9. */
  10. public void setSSLParameters(SSLParameters p) {
  11. String[] cipherSuites = p.getCipherSuites();
  12. if (cipherSuites != null) {
  13. setEnabledCipherSuites(cipherSuites);
  14. }
  15. String[] protocols = p.getProtocols();
  16. if (protocols != null) {
  17. setEnabledProtocols(protocols);
  18. }
  19. if (p.getNeedClientAuth()) {
  20. setNeedClientAuth(true);
  21. } else if (p.getWantClientAuth()) {
  22. setWantClientAuth(true);
  23. } else {
  24. setWantClientAuth(false);
  25. }
  26. }
  27. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. /**
  2. * Creates an SSL engine each time a connection is established.
  3. *
  4. * <p>
  5. *
  6. * <p>You might want to override this if you need to fine-tune the engine's configuration (for
  7. * example enabling hostname verification).
  8. *
  9. * @param channel the Netty channel for that connection.
  10. * @return the engine.
  11. */
  12. protected SSLEngine newSSLEngine(@SuppressWarnings("unused") SocketChannel channel) {
  13. SSLEngine engine = context.createSSLEngine();
  14. engine.setUseClientMode(true);
  15. if (cipherSuites != null) engine.setEnabledCipherSuites(cipherSuites);
  16. return engine;
  17. }

代码示例来源:origin: io.netty/netty

  1. @Override
  2. public final SSLEngine newEngine(String peerHost, int peerPort) {
  3. SSLEngine engine = context().createSSLEngine(peerHost, peerPort);
  4. engine.setEnabledCipherSuites(cipherSuites);
  5. engine.setEnabledProtocols(PROTOCOLS);
  6. engine.setUseClientMode(isClient());
  7. return wrapEngine(engine);
  8. }

代码示例来源:origin: apache/servicecomb-java-chassis

  1. public static SSLEngine createSSLEngine(SSLOption option, SSLCustom custom) {
  2. SSLContext context = createSSLContext(option, custom);
  3. SSLEngine engine =
  4. context.createSSLEngine();
  5. engine.setEnabledProtocols(option.getProtocols().split(","));
  6. String[] supported = engine.getSupportedCipherSuites();
  7. String[] eanbled = option.getCiphers().split(",");
  8. engine.setEnabledCipherSuites(getEnabledCiphers(supported, eanbled));
  9. engine.setNeedClientAuth(option.isAuthPeer());
  10. return engine;
  11. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. /**
  2. * Creates an SSL engine each time a connection is established.
  3. *
  4. * <p>You might want to override this if you need to fine-tune the engine's configuration (for
  5. * example enabling hostname verification).
  6. *
  7. * @param channel the Netty channel for that connection.
  8. * @param remoteEndpoint the remote endpoint we are connecting to.
  9. * @return the engine.
  10. * @since 3.2.0
  11. */
  12. protected SSLEngine newSSLEngine(
  13. @SuppressWarnings("unused") SocketChannel channel, InetSocketAddress remoteEndpoint) {
  14. SSLEngine engine =
  15. remoteEndpoint == null
  16. ? context.createSSLEngine()
  17. : context.createSSLEngine(remoteEndpoint.getHostName(), remoteEndpoint.getPort());
  18. engine.setUseClientMode(true);
  19. if (cipherSuites != null) engine.setEnabledCipherSuites(cipherSuites);
  20. return engine;
  21. }

代码示例来源:origin: io.netty/netty

  1. @Override
  2. public final SSLEngine newEngine() {
  3. SSLEngine engine = context().createSSLEngine();
  4. engine.setEnabledCipherSuites(cipherSuites);
  5. engine.setEnabledProtocols(PROTOCOLS);
  6. engine.setUseClientMode(isClient());
  7. return wrapEngine(engine);
  8. }

代码示例来源:origin: apache/servicecomb-java-chassis

  1. public static SSLEngine createSSLEngine(SSLOption option, SSLCustom custom, String peerHost, int peerPort) {
  2. SSLContext context = createSSLContext(option, custom);
  3. SSLEngine engine =
  4. context.createSSLEngine(peerHost, peerPort);
  5. engine.setEnabledProtocols(option.getProtocols().split(","));
  6. String[] supported = engine.getSupportedCipherSuites();
  7. String[] eanbled = option.getCiphers().split(",");
  8. engine.setEnabledCipherSuites(getEnabledCiphers(supported, eanbled));
  9. engine.setNeedClientAuth(option.isAuthPeer());
  10. return engine;
  11. }

代码示例来源:origin: Atmosphere/nettosphere

  1. @Override
  2. public void onPostCreate(SSLEngine e) {
  3. e.setEnabledCipherSuites(enabledCipherSuites);
  4. e.setUseClientMode(false);
  5. }
  6. };

代码示例来源:origin: apache/flume

  1. private Optional<SSLEngine> getSslEngine(boolean useClientMode) {
  2. return getSslContext().map(sslContext -> {
  3. SSLEngine sslEngine = sslContext.createSSLEngine();
  4. sslEngine.setUseClientMode(useClientMode);
  5. sslEngine.setEnabledProtocols(
  6. getFilteredProtocols(sslEngine.getEnabledProtocols()));
  7. sslEngine.setEnabledCipherSuites(
  8. getFilteredCipherSuites(sslEngine.getEnabledCipherSuites()));
  9. return sslEngine;
  10. });
  11. }

代码示例来源:origin: sscarduzio/elasticsearch-readonlyrest-plugin

  1. public static boolean validateProtocolAndCiphers(SSLEngine eng, LoggerShim logger, BasicSettings basicSettings) {
  2. try {
  3. String[] defaultProtocols = eng.getEnabledProtocols();
  4. logger.info("ROR SSL: Available ciphers: " + Joiner.on(",").join(eng.getEnabledCipherSuites()));
  5. basicSettings.getAllowedSSLCiphers()
  6. .map(x -> x.toArray(new String[x.size()]))
  7. .ifPresent(p -> {
  8. eng.setEnabledCipherSuites(p);
  9. logger.info("ROR SSL: Restricting to ciphers: " + Joiner.on(",").join(eng.getEnabledCipherSuites()));
  10. });
  11. logger.info("ROR SSL: Available SSL protocols: " + Joiner.on(",").join(defaultProtocols));
  12. basicSettings.getAllowedSSLProtocols()
  13. .map(x -> x.toArray(new String[x.size()]))
  14. .ifPresent(p -> {
  15. eng.setEnabledProtocols(p);
  16. logger.info("ROR SSL: Restricting to SSL protocols: " + Joiner.on(",").join(eng.getEnabledProtocols()));
  17. });
  18. return true;
  19. } catch (Exception e) {
  20. logger.error("ROR SSL: cannot validate SSL protocols and ciphers! " + e.getClass().getSimpleName() + ": " + e.getMessage(), e);
  21. return false;
  22. }
  23. }

代码示例来源:origin: org.atmosphere/nettosphere

  1. @Override
  2. public void onPostCreate(SSLEngine e) {
  3. e.setEnabledCipherSuites(enabledCipherSuites);
  4. e.setUseClientMode(false);
  5. }
  6. };

代码示例来源:origin: eclipse-vertx/vert.x

  1. public void configureEngine(SSLEngine engine, String serverName) {
  2. if (enabledCipherSuites != null && !enabledCipherSuites.isEmpty()) {
  3. String[] toUse = enabledCipherSuites.toArray(new String[enabledCipherSuites.size()]);
  4. engine.setEnabledCipherSuites(toUse);
  5. engine.setUseClientMode(client);
  6. Set<String> protocols = new LinkedHashSet<>(enabledProtocols);
  7. protocols.retainAll(Arrays.asList(engine.getSupportedProtocols()));
  8. log.warn("no SSL/TLS protocols are enabled due to configuration restrictions");
  9. engine.setEnabledProtocols(protocols.toArray(new String[protocols.size()]));
  10. if (!client) {
  11. switch (getClientAuth()) {

代码示例来源:origin: org.wildfly.core/wildfly-domain-management

  1. private void setSslParams(final SSLEngine engine) {
  2. if (enabledCipherSuites.length > 0) {
  3. engine.setEnabledCipherSuites(enabledCipherSuites);
  4. }
  5. if (enabledProtocols.length > 0) {
  6. engine.setEnabledProtocols(enabledProtocols);
  7. }
  8. }

代码示例来源:origin: jsevellec/cassandra-unit

  1. protected final SslHandler createSslHandler()
  2. {
  3. SSLEngine sslEngine = sslContext.createSSLEngine();
  4. sslEngine.setUseClientMode(false);
  5. String[] suites = SSLFactory.filterCipherSuites(sslEngine.getSupportedCipherSuites(), encryptionOptions.cipher_suites);
  6. sslEngine.setEnabledCipherSuites(suites);
  7. sslEngine.setNeedClientAuth(encryptionOptions.require_client_auth);
  8. return new SslHandler(sslEngine);
  9. }
  10. }

代码示例来源:origin: wildfly/wildfly

  1. optionMap.get(Options.SSL_PEER_PORT, peerAddress.getPort())
  2. );
  3. engine.setUseClientMode(client);
  4. engine.setEnableSessionCreation(optionMap.get(Options.SSL_ENABLE_SESSION_CREATION, true));
  5. final Sequence<String> cipherSuites = optionMap.get(Options.SSL_ENABLED_CIPHER_SUITES);
  6. engine.setEnabledCipherSuites(finalList.toArray(new String[finalList.size()]));
  7. engine.setEnabledProtocols(finalList.toArray(new String[finalList.size()]));

代码示例来源:origin: wildfly/wildfly-core

  1. private void setSslParams(final SSLEngine engine) {
  2. if (enabledCipherSuites.length > 0) {
  3. engine.setEnabledCipherSuites(enabledCipherSuites);
  4. }
  5. if (enabledProtocols.length > 0) {
  6. engine.setEnabledProtocols(enabledProtocols);
  7. }
  8. }

相关文章