java - Is there any way to use SSLContext with ServerSocketChannel? -
i have application need use serversocketchannel , socketchannel within, sslcontext gives me serversocketfactory gives serversocket , accepts connections in sockets.
any solutions? thanks
the 'basic' jsse .getsocketfactory , .getserversocketfactory indirectly create client-side sslsocket, or sslserversocket in turn creates server-side sslsocket, in either case subclasses socket (with added methods) , manages both ssl/tls protocol , network i/o in simple waited style simplest (most) applications.
to use channels, must instead create sslengine handles only ssl/tls protocol , not network (or other!) i/o. read , write socketchannel yourself, sending data sslengine has 'wrapped' , giving received data 'unwrap'.
for overview, see https://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/jsserefguide.html#sslengine has partial example code -- client; need modify changing setuseclientmode false , not using peer-identity hint. (ssl/tls client must (cache and) select saved session(s) server identity, server uses sessionid assigned , client remembered.)
then see javadoc (with unusually detailed introduction) sslengine class @ https://docs.oracle.com/javase/8/docs/api/javax/net/ssl/sslengine.html or in favorite jdk/ide.
or java sslengine example has links people have done examples, haven't looked @ them myself.
Comments
Post a Comment