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

Thread Tools Display Modes
Old 09-21-2011, 12:57 AM
terry7545 terry7545 is offline
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,
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            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))
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.
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


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.
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
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..