5

I get the follwoing error "Authentication failed because the remote party has closed the transport stream"

after the ling code: stream.AuthenticateAsClient(this.appleSettings.Host, this.certificates, System.Security.Authentication.SslProtocols.Ssl3, false);

It poined to a valid p.12

void connect()
        {
            client = new TcpClient();

            //Notify we are connecting
            var eoc = this.OnConnecting;
            if (eoc != null)
                eoc(this.appleSettings.Host, this.appleSettings.Port);

            try
            {
                client.Connect(this.appleSettings.Host, this.appleSettings.Port);
            }
            catch (Exception ex)
            {
                throw new ConnectionFailureException("Connection to Host Failed", ex);
            }

            if (appleSettings.SkipSsl)
            {
                networkStream = client.GetStream();
            }
            else
            {
                stream = new SslStream(client.GetStream(), false,
                    new RemoteCertificateValidationCallback((sender, cert, chain, sslPolicyErrors) => { return true; }),
                    new LocalCertificateSelectionCallback((sender, targetHost, localCerts, remoteCert, acceptableIssuers) =>
                    {
                        return certificate;
                    }));

                try
                {
                    stream.AuthenticateAsClient(this.appleSettings.Host, this.certificates, System.Security.Authentication.SslProtocols.Ssl3, false);
                    //stream.AuthenticateAsClient(this.appleSettings.Host);
                }
                catch (System.Security.Authentication.AuthenticationException ex)
                {
                    throw new ConnectionFailureException("SSL Stream Failed to Authenticate as Client", ex);
                }

                if (!stream.IsMutuallyAuthenticated)
                    throw new ConnectionFailureException("SSL Stream Failed to Authenticate", null);

                if (!stream.CanWrite)
                    throw new ConnectionFailureException("SSL Stream is not Writable", null);

                networkStream = stream;
            }

            //Start reading from the stream asynchronously
            Reader();
        }

    }
Ortal Blumenfeld Lagziel
  • 2,017
  • 3
  • 19
  • 30

2 Answers2

4
stream.AuthenticateAsClient(this.appleSettings.Host, this.certificates, System.Security.Authentication.SslProtocols.Ssl3, false);

https://developer.apple.com/news/?id=10222014a

Apple push servers no longer supports SSL3. Try change this to .Default or .TLS and it should work.

KristofferArl
  • 701
  • 6
  • 6
1

I have used Moon API for .NET and change Protocol Ssl3 to Tls as Above and used .p12 file instead of .pem .p12 is generated using fallowing certificates.

$ openssl pkcs12 -export -in chatPushCert.pem -inkey chatPushKey.pem -certfile CertificateSigningRequest.certSigningRequest -name "apn_developer_identity" -out apn_developer_identity.p12

and every thing working very fine.

  • I downloaded the Moon Api too but alse there I get: Authentication failed because the remote party has closed the transport stream. Any idea? I used the Code Signing Certificate from the Apple server, is that the correct one'? – Nick Prozee Aug 27 '15 at 11:47
  • 1
    have you generated above certificates if yes then use this inside .Net developer process as moon API Guide line and change Protocol Ssl3 to Tls . – Dilip Ingole Patil Aug 27 '15 at 12:10
  • I extracted the p12 file from keychain on the apple server instead of using openssl – Nick Prozee Aug 27 '15 at 12:20
  • Its working indeed. Some upvotes for your help, Thanks. Final question, do you have any info on dinfing the device Token? Regards – Nick Prozee Aug 27 '15 at 12:28
  • 1
    actually you can't define any token for your device, apple server will assign device token to your device for that you have to place following code into your AppDelegate.m file. – Dilip Ingole Patil Aug 31 '15 at 05:53
  • 1
    - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken { NSLog(@"My token is: %@", deviceToken); NSString *token=[[NSUserDefaults standardUserDefaults] objectForKey:@"devicetoken"]; } – Dilip Ingole Patil Aug 31 '15 at 05:55
  • 1
    this function call if you have successfully resisted for push notification and you will receive your device token..and add notification permission code to 'same file in didfinishlosding function '.here i am unable to post code you can find by googling it. – Dilip Ingole Patil Aug 31 '15 at 05:58