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

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

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

SSLEngine.setUseClientMode介绍

[英]Sets whether this engine should act in client (or server) mode when handshaking.
[中]设置握手时此引擎是否应在客户端(或服务器)模式下运行。

代码示例

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

  1. private SSLEngine createServerEngine() {
  2. SSLEngine engine = sslContext.createSSLEngine();
  3. engine.setUseClientMode(false);
  4. return engine;
  5. }

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

  1. private ChannelHandler createSslHandler(SSLContext sslContext, boolean needsClientAuth) {
  2. SSLEngine sslEngine = sslContext.createSSLEngine();
  3. sslEngine.setUseClientMode(false);
  4. if (needsClientAuth) {
  5. sslEngine.setNeedClientAuth(true);
  6. }
  7. return new SslHandler(sslEngine);
  8. }

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

  1. SSLEngine sslEngine = sslContext.createSSLEngine(_host, _port);
  2. sslEngine.setUseClientMode(true);
  3. sslEngine.setEnabledProtocols(SSLUtils.getSupportedProtocols(sslEngine.getEnabledProtocols()));
  4. sslEngine.beginHandshake();
  5. if (!Link.doHandshake(_clientConnection, sslEngine)) {

代码示例来源:origin: andsel/moquette

  1. private ChannelHandler createSslHandler(SocketChannel channel, SslContext sslContext, boolean needsClientAuth) {
  2. SSLEngine sslEngine = sslContext.newEngine(
  3. channel.alloc(),
  4. channel.remoteAddress().getHostString(),
  5. channel.remoteAddress().getPort());
  6. sslEngine.setUseClientMode(false);
  7. if (needsClientAuth) {
  8. sslEngine.setNeedClientAuth(true);
  9. }
  10. return new SslHandler(sslEngine);
  11. }
  12. }

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

  1. engine.setUseClientMode(true);
  2. engine.setEnabledCipherSuites(SSLSupport.parseCommaSeparatedListIntoArray(enabledCipherSuites));
  3. } catch (IllegalArgumentException e) {
  4. ActiveMQClientLogger.LOGGER.invalidCipherSuite(SSLSupport.parseArrayIntoCommandSeparatedList(engine.getSupportedCipherSuites()));
  5. engine.setEnabledProtocols(SSLSupport.parseCommaSeparatedListIntoArray(enabledProtocols));
  6. } catch (IllegalArgumentException e) {
  7. ActiveMQClientLogger.LOGGER.invalidProtocol(SSLSupport.parseArrayIntoCommandSeparatedList(engine.getSupportedProtocols()));
  8. engine.setEnabledProtocols(originalProtocols);

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

  1. private PeerChannel createPeerChannel(final SocketChannel channel, final String peerDescription) {
  2. if (sslContext == null) {
  3. logger.debug("No SSL Context is available so will not perform SSL Handshake with Peer {}", peerDescription);
  4. return new PeerChannel(channel, null, peerDescription);
  5. }
  6. logger.debug("Performing SSL Handshake with Peer {}", peerDescription);
  7. final SSLEngine sslEngine = sslContext.createSSLEngine();
  8. sslEngine.setUseClientMode(true);
  9. sslEngine.setNeedClientAuth(true);
  10. return new PeerChannel(channel, sslEngine, peerDescription);
  11. }

代码示例来源:origin: org.mongodb/mongo-java-driver

  1. private static SSLEngine defaultSSLEngineFactory(final SSLContext sslContext) {
  2. SSLEngine engine = sslContext.createSSLEngine();
  3. engine.setUseClientMode(true);
  4. return engine;
  5. }

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

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

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

  1. next.setUseClientMode(false);
  2. final int flagsVal = flags.get();
  3. if ((flagsVal & FL_WANT_C_AUTH) != 0) {
  4. next.setWantClientAuth(true);
  5. } else if ((flagsVal & FL_NEED_C_AUTH) != 0) {
  6. next.setNeedClientAuth(true);

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

  1. public SSLSocketChannel(final SSLContext sslContext, final String hostname, final int port, final InetAddress localAddress, final boolean client) throws IOException {
  2. this.socketAddress = new InetSocketAddress(hostname, port);
  3. this.channel = SocketChannel.open();
  4. if (localAddress != null) {
  5. final SocketAddress localSocketAddress = new InetSocketAddress(localAddress, 0);
  6. this.channel.bind(localSocketAddress);
  7. }
  8. this.hostname = hostname;
  9. this.port = port;
  10. this.engine = sslContext.createSSLEngine();
  11. this.engine.setUseClientMode(client);
  12. engine.setNeedClientAuth(true);
  13. streamInManager = new BufferStateManager(ByteBuffer.allocate(engine.getSession().getPacketBufferSize()));
  14. streamOutManager = new BufferStateManager(ByteBuffer.allocate(engine.getSession().getPacketBufferSize()));
  15. appDataManager = new BufferStateManager(ByteBuffer.allocate(engine.getSession().getApplicationBufferSize()));
  16. }

代码示例来源:origin: mrniko/netty-socketio

  1. /**
  2. * Adds the ssl handler
  3. *
  4. * @param pipeline - channel pipeline
  5. */
  6. protected void addSslHandler(ChannelPipeline pipeline) {
  7. if (sslContext != null) {
  8. SSLEngine engine = sslContext.createSSLEngine();
  9. engine.setUseClientMode(false);
  10. pipeline.addLast(SSL_HANDLER, new SslHandler(engine));
  11. }
  12. }

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

  1. /**
  2. * Creates a new SSL Engine that is configured to use server mode when handshaking.
  3. *
  4. * For Openfire, an engine is of this mode used for most purposes (as Openfire is a server by nature).
  5. *
  6. * @return A new, initialized SSLEngine instance (never null).
  7. */
  8. public SSLEngine createServerModeSSLEngine() throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException
  9. {
  10. final SSLEngine sslEngine = createSSLEngine( );
  11. sslEngine.setUseClientMode( false );
  12. switch ( configuration.getClientAuth() )
  13. {
  14. case needed:
  15. sslEngine.setNeedClientAuth( true );
  16. break;
  17. case wanted:
  18. sslEngine.setWantClientAuth( true );
  19. break;
  20. case disabled:
  21. sslEngine.setWantClientAuth( false );
  22. break;
  23. }
  24. return sslEngine;
  25. }

相关文章