Azure / DotNetty

DotNetty project – a port of netty, event-driven asynchronous network application framework
Other
4.09k stars 977 forks source link

netty SslHandler和dotnetty TlsHandler不适配 #628

Closed 110jiangnan closed 2 months ago

110jiangnan commented 2 months ago

这是netty

private ChannelHandler createSslHandler() { try { InputStream jksInputStream = FileUtil.getInputStream("classpath:/test.jks"); SSLContext serverContext = SSLContext.getInstance("TLS"); final KeyStore ks = KeyStore.getInstance("JKS");

        ks.load(jksInputStream, "123456".toCharArray());
        final KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmf.init(ks, "123456".toCharArray());
        TrustManager[] trustManagers = null;

        serverContext.init(kmf.getKeyManagers(), trustManagers, null);

        SSLEngine sslEngine = serverContext.createSSLEngine();
        sslEngine.setUseClientMode(false);
        sslEngine.setNeedClientAuth(false);

        return new SslHandler(sslEngine);
    } catch (Exception e) {
        log.error("create SSL handler failed", e);
        e.printStackTrace();
    }
    return null;
}

public IChannelHandler createSslHandler() { // return TlsHandler.Server(new X509Certificate2("E:\game\test\ConsoleApp4\proxy\Ztest\yang.pfx", "123456")); byte[] readAllBytes = File.ReadAllBytes("E:\game\test\ConsoleApp4\proxy\Ztest\yang.pfx"); var cert = new X509Certificate2("E:\game\test\ConsoleApp4\proxy\Ztest\yang.pfx", "123456"); var targetHost = cert.GetNameInfo(X509NameType.DnsFromAlternativeName, false); // TlsHandler tlsHandler = new TlsHandler(new ClientTlsSettings(targetHost, new List() { cert }));

    // TlsHandler.Client()
    TlsHandler tlsHandler = new TlsHandler(
        stream => {
            return
                new SslStream(stream, true,
                    (sender, certificate, chain, errors) => { return true; });
        },
        new ClientTlsSettings(targetHost));

    return new TlsHandler(stream => new SslStream(stream, true, 
            (sender, certificate, chain, errors) => {
                Console.WriteLine(sender);
                return true;
            }),
        new ClientTlsSettings(targetHost));
}

上面代码调试不通 能否给一个netty SslHandler和dotnetty TlsHandler 调试成功的例子

110jiangnan commented 2 months ago

已解决,版本问题