Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try
- {
- using (TcpClient client = new TcpClient())
- {
- try
- {
- client.Connect("gateway.sandbox.push.apple.com", 2195);
- Logging("TSSLProDi :Connected to Apple");
- }
- catch (Exception ex)
- {
- Logging("TSSLProDi :" + ex.Message + "-IE-" + ex.InnerException);
- }
- using (NetworkStream networkStream = client.GetStream())
- {
- Logging("TSSLProDi :Client connected.");
- X509Certificate clientCertificate = new X509Certificate(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory + @"startupcertname.pfx"), "mycertpassword");
- X509CertificateCollection clientCertificateCollection = new X509CertificateCollection(new X509Certificate[1] { clientCertificate });
- // Create an SSL stream that will close the client's stream.
- SslStream sslStream = new SslStream(
- client.GetStream(),
- false,
- new RemoteCertificateValidationCallback(validateServerCertificate),
- null
- );
- try
- {
- sslStream.AuthenticateAsClient("gateway.sandbox.push.apple.com", clientCertificateCollection, System.Security.Authentication.SslProtocols.Default, false);
- Logging("TSSLProDi :slStreamAuthenticated");
- }
- catch (AuthenticationException ex)
- {
- Logging("TSSLProDi :" + "Exception: " + ex.Message.ToString());
- if (ex.InnerException != null)
- {
- Logging("Inner exception: " + ex.InnerException.Message.ToString());
- }
- Logging("TSSLProDi :" + "Authentication failed - closing the connection.");
- client.Close();
- return;
- }
- }
- }
- }
- catch (Exception ex)
- {
- Logging("TSSLProCert :" + ex.Message + "-IE-" + ex.InnerException);
- }
- SslStream sslStream = new SslStream(client.GetStream(), false);
Add Comment
Please, Sign In to add comment