\r\n\r\n
Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET Communications > Some problems of SSLStream


\r\n \r\n
 
 
Thread Tools Display Modes

\r\n\r\n\r\n
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...
\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 Last edited by terry7545; 09-21-2011 at 03: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 Reply With Quote\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"; // -->
Prev Previous Post   Next Post Next
  #1  
Old 09-21-2011, 01:57 AM
terry7545 terry7545 is offline
Newcomer
 
Join Date: Sep 2011
Posts: 1
Default 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 03:13 AM.
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->