客户端:访问
1. https://host1.com/
2. https://host2.com/
服务器:有两个证书。
证书1.pfx CN=host1.com 和证书2.pfx CN=host2.com
使用wireshark
客户端访问https://host1.com/
1: C --> S SYN
2: C <-- S SYN,ACK
3: C --> S ACK
4: C --> S Client Hello (Contain Server名称:host1.com)
... 如何在 C#
5 中选择证书 1:C <-- S Server Hello, Certificate, Server Hello Done
客户端访问https://host2.com/
1: C --> S SYN
2: C <-- S SYN,ACK
3: C --> S ACK
4: C --> S Client Hello (包含服务器名称: host2.com)
... 如何在 C#
5 中选择 certificate2: c <-- S Server Hello, Certificate, Server Hello Done
SslStream sslStream = new SslStream(
clientStream,
false,
new RemoteCertificateValidationCallback(ValidateServerCertificate),
new LocalCertificateSelectionCallback(SelectLocalCertificate)
);
X509Certificate2 certificate = new X509Certificate2("certificates1.pfx");
sslStream.AuthenticateAsServer(certificate , false, SslProtocols.Tls | SslProtocols.Ssl3 | SslProtocols.Ssl2, true);
private X509Certificate SelectLocalCertificate(object sender, string targetHost, X509CertificateCollection localCertificates, X509Certificate remoteCertificate, string[] acceptableIssuers)
{
//In Debug, targetHost is empty string and remoteCertificate=null
//I can't return right Certificates
return null;
}
private bool ValidateServerCertificate( object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}