
09-21-2011, 12:57 AM
|
|
Newcomer
|
|
Join Date: Sep 2011
Posts: 1
|
|
Some problems of SSLStream
|
Hello, thanks for your pation to read my question, I want to build a web service to connect APNS(Apple push notification service) but have some problems...
I builded a sslstream to authenticate but it got an exception said "a call to SSPI failed see inner exception"
I don't know how to connect APNS correctly, and when I enter to the method SelectLocalCertificate, the certificate is empty.
How do I get the certificate and why it call SSPI failed.... 
The parameter 'acceptableIssuers() is null in the function SelectLocalCertificate, does anyone know what is the problem?
Thank you
Best regards,
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Dim ssl As String = "ssl://gateway.push.apple.com:2195"
'Create a TCP/IP client socket
Dim client2 As New TcpClient
client2.Connect("gateway.push.apple.com", 2195)
Dim b As Boolean = client2.Connected
Dim sslStream2 As New SslStream(client2.GetStream, False, New RemoteCertificateValidationCallback(AddressOf ValidateServerCertificate), New LocalCertificateSelectionCallback(AddressOf SelectLocalCertificate))
sslStream2.AuthenticateAsClient(ssl)
Catch ex As AuthenticationException
Throw New AuthenticationException(ex.ToString())
Catch ex As Exception
End Try
End Sub
Public Shared Function SelectLocalCertificate(ByVal sender As Object, _
ByVal targetHost As String, _
ByVal localCertificates As X509CertificateCollection, _
ByVal remoteCertificate As X509Certificate, _
ByVal acceptableIssuers() As String) As X509Certificate
Console.WriteLine("Client is selecting a local certificate.")
If acceptableIssuers IsNot Nothing AndAlso acceptableIssuers.Length > 0 AndAlso localCertificates IsNot Nothing AndAlso localCertificates.Count > 0 Then
'use the first certificate that is from an acceptable issuer.
For Each certificate As X509Certificate In localCertificates
Dim issuer As String = certificate.Issuer
If Array.IndexOf(acceptableIssuers, issuer) <> -1 Then
Return certificate
End If
Next certificate
End If
If localCertificates IsNot Nothing AndAlso localCertificates.Count > 0 Then
Return localCertificates(0)
End If
Return Nothing
End Function
|
Last edited by terry7545; 09-21-2011 at 02:13 AM.
|