SSL and SocketChannel

后端 未结 4 1395
猫巷女王i
猫巷女王i 2021-02-02 00:54

Ideally, I only need a simple SSLSocketChannel.

I already have a component that reads and writes message over ordinary SocketChannel, but for

相关标签:
4条回答
  • 2021-02-02 01:00

    Check out Restlet's implementation it may do what you need, and it's all about NIO.

    Restlet Engine Javadoc

    Specifically the HttpClientCall. SetProtocol(HTTPS) - getResponseEntityChannel returns a ReadableByteChannel (getEntityChannel returns a WriteableByteChannel)

    0 讨论(0)
  • 2021-02-02 01:14

    Not sure if this is what you're looking for, but may help... To create SSL/TLS enabled server sockets, I'm currently using code like the following (keystore.jks contains a self signed private/public key pair used for securing confirmation) - clients have a similar trust store which contains the signed certificate with the public key of that pair.

    A bit of googling around getting that configured should get you underway.

    String keyStorePath = "keystore.jks";
    String keyStorePassword = "password";
    
    KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    KeyStore keyStore = new KeyStore();
    keyStore.load(new FileInputStream(keyStorePath), keyStorePassword);
    keyManagerFactory.init(keyStore, keyStorePassword.toCharArray());
    
    sslContext = SSLContext.getInstance("TLS");
    sslContext.init(keyManagerFactory.getKeyManagers(), null, new SecureRandom());
    
    SSLContext sslContext = getServerSSLContext(namespace.getUuid());
    SSLServerSocketFactory serverSocketFactory = sslContext.getServerSocketFactory();
    
    // Create sockets as necessary
    
    0 讨论(0)
  • 2021-02-02 01:23

    Jetty has an NIO SSL implementation for their server: SslSelectorChannelConnector. You might want to peek at it for details on what its doing.

    There is also an old (but decent) article from O'Reilly that explains the details about NIO + SSL along with example code.

    0 讨论(0)
  • 2021-02-02 01:24

    TLS Channel is a simple library that does exactly that: wrapping a SSLContext (or SSLEngine) and exposing a ByteChannel interface, doing the heavy lifting internally.

    (Disclaimer: I am the library's main author).

    0 讨论(0)
提交回复
热议问题