/// <summary> /// Replaces this entry of handler in the netty pipeline with the provided SslHandler and maintains the handler name /// </summary> /// <param name="sslHandler"> configured netty handler that enables TLS </param> private void ReplaceSelfWith(SslHandler sslHandler) { string myName = _pipeline.toMap().entrySet().Where(entry => this.Equals(entry.Value)).Select(DictionaryEntry.getKey).First().orElseThrow(() => new System.InvalidOperationException("This handler has no name")); _pipeline.replace(this, myName, sslHandler); _pipeline.addAfter(myName, "handshakeCompletionSslDetailsHandler", new HandshakeCompletionSslDetailsHandler(this)); }
/// <summary> /// Main event that is triggered for connections and swapping out SslHandler for this handler. channelActive and handlerAdded handlers are /// secondary boundary cases to this. /// </summary> /// <param name="ctx"> Context of the existing channel </param> /// <param name="remoteAddress"> the address used for initating a connection to a remote host (has type InetSocketAddress) </param> /// <param name="localAddress"> the local address that will be used for receiving responses from the remote host </param> /// <param name="promise"> the Channel promise to notify once the operation completes </param> /// <exception cref="Exception"> when there is an error of any sort </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void connect(io.netty.channel.ChannelHandlerContext ctx, java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress, io.netty.channel.ChannelPromise promise) throws Exception public override void Connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) { SslHandler sslHandler = CreateSslHandler(ctx, ( InetSocketAddress )remoteAddress); ReplaceSelfWith(sslHandler); ctx.connect(remoteAddress, localAddress, promise); }
private SocketHandler BuildSslSocketHandler() { X509Certificate2 x509Cert = new X509Certificate2(serverConfig.TlsConfig.Path, serverConfig.TlsConfig.Password); SslHandler handler = new SslHandler(serverConfig.Port, httpStreamMarshal, x509Cert); return(handler); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) throws Exception public override void HandlerAdded(ChannelHandlerContext ctx) { // Sometimes the connect event will have happened before adding, the channel will be active then if (ctx.channel().Active) { SslHandler sslHandler = CreateSslHandler(ctx, ( InetSocketAddress )ctx.channel().remoteAddress()); ReplaceSelfWith(sslHandler); sslHandler.handlerAdded(ctx); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: protected void initChannel(io.netty.channel.socket.SocketChannel ch) throws Exception protected internal override void initChannel(SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); SSLEngine sslEngine = _outerInstance.sslContext.newEngine(ch.alloc()); sslEngine.NeedClientAuth = true; SslHandler sslHandler = new SslHandler(sslEngine); pipeline.addLast(sslHandler); pipeline.addLast(new Responder()); }
public virtual int sceHttpsSetSslCallback(int sslID, TPointer sslCallback, int sslArg) { if (!isHttpsInit) { return(ERROR_HTTP_NOT_INIT); } SslHandler sslHandler = new SslHandler(this, sslID, sslCallback.Address, sslArg); sslHandlers[sslID] = sslHandler; return(0); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void userEventTriggered(io.netty.channel.ChannelHandlerContext ctx, Object evt) throws Exception public override void UserEventTriggered(ChannelHandlerContext ctx, object evt) { if (evt is SslHandshakeCompletionEvent) { SslHandshakeCompletionEvent sslHandshakeEvent = ( SslHandshakeCompletionEvent )evt; if (sslHandshakeEvent.cause() == null) { SslHandler sslHandler = ctx.pipeline().get(typeof(SslHandler)); string ciphers = sslHandler.engine().Session.CipherSuite; string protocols = sslHandler.engine().Session.Protocol; ctx.fireUserEventTriggered(new SslHandlerDetailsRegisteredEvent(ciphers, protocols)); } } ctx.fireUserEventTriggered(evt); }
private bool DetectSsl(ByteBuf buf) { return(_sslCtx != null && SslHandler.isEncrypted(buf)); }