 |
\r\n\r\n\r\nHello, 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... \r\nI builded a sslstream to authenticate but it got an exception said "a call to SSPI failed see inner exception" \r\nI don\'t know how to connect APNS correctly, and when I enter to the method SelectLocalCertificate, the certificate is empty. \r\nHow do I get the certificate and why it call SSPI failed....  \r\nThe parameter \'acceptableIssuers() is null in the function SelectLocalCertificate, does anyone know what is the problem? \r\n \r\nThank you \r\nBest regards, \r\n \r\n Code: \r\n Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load\r\nTry\r\n Dim ssl As String = "ssl://gateway.push.apple.com:2195"\r\n \'Create a TCP/IP client socket\r\n Dim client2 As New TcpClient\r\n client2.Connect("gateway.push.apple.com", 2195)\r\n Dim b As Boolean = client2.Connected\r\n Dim sslStream2 As New SslStream(client2.GetStream, False, New RemoteCertificateValidationCallback(AddressOf ValidateServerCertificate), New LocalCertificateSelectionCallback(AddressOf SelectLocalCertificate))\r\nsslStream2.AuthenticateAsClient(ssl)\r\nCatch ex As AuthenticationException\r\n Throw New AuthenticationException(ex.ToString())\r\n Catch ex As Exception\r\n End Try\r\n End Sub\r\n\r\nPublic Shared Function SelectLocalCertificate(ByVal sender As Object, _\r\n ByVal targetHost As String, _\r\n ByVal localCertificates As X509CertificateCollection, _\r\n ByVal remoteCertificate As X509Certificate, _\r\n ByVal acceptableIssuers() As String) As X509Certificate\r\n Console.WriteLine("Client is selecting a local certificate.")\r\n\r\n If acceptableIssuers IsNot Nothing AndAlso acceptableIssuers.Length > 0 AndAlso localCertificates IsNot Nothing AndAlso localCertificates.Count > 0 Then\r\n \'use the first certificate that is from an acceptable issuer.\r\n For Each certificate As X509Certificate In localCertificates\r\n Dim issuer As String = certificate.Issuer\r\n If Array.IndexOf(acceptableIssuers, issuer) <> -1 Then\r\n Return certificate\r\n End If\r\n Next certificate\r\n End If\r\n If localCertificates IsNot Nothing AndAlso localCertificates.Count > 0 Then\r\n Return localCertificates(0)\r\n End If\r\n\r\n Return Nothing\r\n End Function\r\n \r\n \r\n\r\n | \r\n \r\n \r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n Last edited by terry7545; 09-21-2011 at 02:13 AM.\r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n \r\n \r\n \r\n \r\n \r\n  \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n \r\n\r\n | \r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n';
// next/previous post info
pn[1386667] = "1386667,1386667";
pn[0] = ",1386667";
// cached usernames
pu[0] = guestphrase;
pu[224690] = "terry7545";
// -->

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.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Threaded Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|