I wrote a SSL client application. It is communicating fine through SSL, but I noticed that the SSL communication takes anywhere from 15-20 seconds, where tcp is only about 3-5 seconds. Steping through my code I notice that when I am selecting the certificate and returning it, the code pauses for about 7-10 seconds after steping out of that function. Here is the function:
I'm calling this function when instantiating the SSL stream
This is using VS2005 and .NET 3.0. Is this normal, or is there something I can do to speed up the process?
Code:
Private Function SelectLocalCertificate(ByVal sender As Object, ByVal targetHost As String, ByVal localCertificate As X509CertificateCollection, ByVal remotecertficate As X509Certificate, ByVal acceptableIssuers() As String) As X509Certificate
If ((localCertificate Is Nothing) Or (localCertificate.Count = 0)) Then
Return Nothing
End If
Return localCertificate(0)
End Function
Code:
socketStream = New SslStream(socket.GetStream, False, New RemoteCertificateValidationCallback(AddressOf ValidateServerCertificate), New LocalCertificateSelectionCallback(AddressOf SelectLocalCertificate))