我正在尝试与.NET SslStream进行安全的重新协商,但我不确定如何实现它,或者它是否可能.我的目标是使用服务器的相同证书更新共享密钥.
我使用OpenSSL设置了一个服务器:
s_server -accept 443 -key privkey.pem
Run Code Online (Sandbox Code Playgroud)
这是我的客户端代码:
public static void RunClient()
{
TcpClient client = new TcpClient("localhost", 443);
Console.WriteLine("Client connected.");
SslStream sslStream = new SslStream(innerStream: client.GetStream(), leaveInnerStreamOpen: true, userCertificateValidationCallback: (a,b,c,d) => true, userCertificateSelectionCallback: null);
sslStream.AuthenticateAsClient("localhost");
byte[] message = Encoding.UTF8.GetBytes("Hello from the client.");
sslStream.Write(message);
sslStream.Dispose();
// if code below is commented, there's no error.
sslStream = new SslStream(innerStream: client.GetStream(), leaveInnerStreamOpen: true, userCertificateValidationCallback: (a, b, c, d) => true, userCertificateSelectionCallback: null);
message = Encoding.UTF8.GetBytes("Hello from the client again, renegotiated.");
sslStream.AuthenticateAsClient("localhost"); …Run Code Online (Sandbox Code Playgroud)