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

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

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

SSLEngine.setEnabledProtocols介绍

[英]Sets the protocol version names that should be enabled in this engine instance. Only protocols listed by getSupportedProtocols() are allowed.
[中]设置应在此引擎实例中启用的协议版本名称。只允许使用getSupportedProtocols()列出的协议。

代码示例

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

  1. /**
  2. * Apply engine modifications that will exist in any use-case of TLS
  3. *
  4. * @param sslEngine the ssl engine that will be used for the connections. Is mutated.
  5. * @return the updated sslEngine (should be the same as the original, but don't rely on that)
  6. */
  7. @Override
  8. public SSLEngine apply( SSLEngine sslEngine )
  9. {
  10. if ( tlsVersions != null )
  11. {
  12. sslEngine.setEnabledProtocols( tlsVersions );
  13. }
  14. sslEngine.setUseClientMode( isClient );
  15. return sslEngine;
  16. }
  17. }

代码示例来源: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: 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: org.apache.hadoop/hadoop-common

  1. /**
  2. * Returns a configured SSLEngine.
  3. *
  4. * @return the configured SSLEngine.
  5. * @throws GeneralSecurityException thrown if the SSL engine could not
  6. * be initialized.
  7. * @throws IOException thrown if and IO error occurred while loading
  8. * the server keystore.
  9. */
  10. public SSLEngine createSSLEngine()
  11. throws GeneralSecurityException, IOException {
  12. SSLEngine sslEngine = context.createSSLEngine();
  13. if (mode == Mode.CLIENT) {
  14. sslEngine.setUseClientMode(true);
  15. } else {
  16. sslEngine.setUseClientMode(false);
  17. sslEngine.setNeedClientAuth(requireClientCert);
  18. disableExcludedCiphers(sslEngine);
  19. }
  20. sslEngine.setEnabledProtocols(enabledProtocols);
  21. return sslEngine;
  22. }

代码示例来源: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) {
  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: igniterealtime/Openfire

  1. /**
  2. * Creates an SSL Engine that is configured to use client mode when handshaking.
  3. *
  4. * For Openfire, an engine of this mode is typically used when the server tries to connect to another server.
  5. *
  6. * These SSLEngines never send SSLV2 ClientHello messages.
  7. *
  8. * @return An initialized SSLEngine instance (never null).
  9. */
  10. public SSLEngine createClientModeSSLEngine() throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException
  11. {
  12. final SSLEngine sslEngine = createSSLEngine();
  13. sslEngine.setUseClientMode( true );
  14. final Set<String> protocols = new LinkedHashSet<>( Arrays.asList( sslEngine.getEnabledProtocols() ) );
  15. protocols.remove( "SSLv2Hello" );
  16. sslEngine.setEnabledProtocols( protocols.toArray( new String[ protocols.size() ] ) );
  17. return sslEngine;
  18. }

代码示例来源: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, 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: apache/cloudstack

  1. sslEngine.setUseClientMode(true);
  2. sslEngine.setEnabledProtocols(SSLUtils.getSupportedProtocols(sslEngine.getEnabledProtocols()));
  3. sslEngine.beginHandshake();
  4. if (!Link.doHandshake(_clientConnection, sslEngine)) {

代码示例来源: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: apache/cloudstack

  1. SSLContext sslContext = Link.initManagementSSLContext(caService);
  2. sslEngine = sslContext.createSSLEngine(ip, port);
  3. sslEngine.setUseClientMode(true);
  4. sslEngine.setEnabledProtocols(SSLUtils.getSupportedProtocols(sslEngine.getEnabledProtocols()));
  5. sslEngine.beginHandshake();
  6. if (!Link.doHandshake(ch1, sslEngine)) {

代码示例来源: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: apache/cloudstack

  1. try {
  2. sslEngine = Link.initServerSSLEngine(caService, socketChannel.getRemoteAddress().toString());
  3. sslEngine.setUseClientMode(false);
  4. sslEngine.setEnabledProtocols(SSLUtils.getSupportedProtocols(sslEngine.getEnabledProtocols()));
  5. final NioConnection nioConnection = this;
  6. _sslHandshakeExecutor.submit(new Runnable() {

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

  1. optionMap.get(Options.SSL_PEER_PORT, peerAddress.getPort())
  2. );
  3. engine.setUseClientMode(true);
  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. }

相关文章