private async Task <bool> OpenSslStreamAsync(string host, X509CertificateCollection certificates) { Logger.Info("Creating SSL connection."); ApnsStream = new SslStream(ApnsClient.GetStream(), false, ValidateServerCertificate, SelectLocalCertificate); try { await ApnsStream.AuthenticateAsClientAsync(host, certificates, System.Security.Authentication.SslProtocols.Tls12, false).ConfigureAwait(false); } catch (System.Security.Authentication.AuthenticationException ex) { Logger.Error(ex.Message); return(false); } if (!ApnsStream.IsMutuallyAuthenticated) { Logger.Error("SSL Stream Failed to Authenticate"); return(false); } if (!ApnsStream.CanWrite) { Logger.Error("SSL Stream is not Writable"); return(false); } return(true); }
public void Sending_NonVoip_Type_With_Voip_Cert_Fails() { var apns = ApnsClient.CreateUsingCert("voip.p12"); var push = ApplePush.CreateAlert(new ApplePushAlert("title", "body")).AddToken("token"); Assert.ThrowsAsync <InvalidOperationException>(async() => await apns.Send(push)); }
public IApnsClient CreateUsingJwt(ApnsJwtOptions options, bool useSandbox = false) { var client = ApnsClient.CreateUsingJwt(_httpClientFactory.CreateClient("dotAPNS"), options); if (useSandbox) { client.UseSandbox(); } return(client); }
public IApnsClient CreateUsingCert(string pathToCert, bool useSandbox = false) { var client = ApnsClient.CreateUsingCert(pathToCert); if (useSandbox) { client.UseSandbox(); } return(client); }
public IApnsClient CreateUsingCert(X509Certificate2 cert, bool useSandbox) { var client = ApnsClient.CreateUsingCert(cert); if (useSandbox) { client.UseSandbox(); } return(client); }
public IApnsClient CreateUsingJwt(ApnsJwtOptions options, bool useSandbox = false, bool disableServerCertValidation = false) { var httpClient = _httpClientFactory.CreateClient(disableServerCertValidation ? "dotAPNS_DisableCerverCertValidation" : "dotAPNS"); var client = ApnsClient.CreateUsingJwt(httpClient, options); if (useSandbox) { client.UseSandbox(); } return(client); }
public IApnsClient CreateUsingCert(X509Certificate2 cert, bool useSandbox, bool disableServerCertValidation = false) { var client = disableServerCertValidation ? CreateUsingCertWithNoServerCertValidation(cert) : ApnsClient.CreateUsingCert(cert); if (useSandbox) { client.UseSandbox(); } return(client); }
ApnsClient CreateUsingCertWithNoServerCertValidation(X509Certificate2 cert) { var handler = new HttpClientHandler { ClientCertificateOptions = ClientCertificateOption.Manual, ServerCertificateCustomValidationCallback = (a, b, c, d) => true }; handler.ClientCertificates.Add(cert); var httpClient = new HttpClient(handler); var client = ApnsClient.CreateUsingCustomHttpClient(httpClient, cert); return(client); }
IApnsClient BoostrapApnsClient(int statusCode = 200, string responseContent = "{}") { var httpHandler = new Mock <HttpMessageHandler>(MockBehavior.Strict); httpHandler.Protected() .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(new HttpResponseMessage() { StatusCode = (HttpStatusCode)statusCode, Content = new JsonContent(responseContent) }); var jwt = CreateStubJwt(); var client = ApnsClient.CreateUsingJwt(new HttpClient(httpHandler.Object), jwt); return(client); }
public void Disconnect() { try { ApnsClient.Dispose(); ApnsStream.Dispose(); ApnsStream = null; ApnsClient = null; _connected = false; Logger.Info("Disconnected."); } catch (Exception ex) { Logger.Error("An error occurred while disconnecting. - " + ex.Message); } }
public IApnsClient CreateUsingJwt(ApnsJwtOptions options) => ApnsClient.CreateUsingJwt(_httpClientFactory.CreateClient("dotAPNS"), options);
public IApnsClient CreateUsingCert(string pathToCert) => ApnsClient.CreateUsingCert(pathToCert);
public IApnsClient CreateUsingCert(X509Certificate2 cert) => ApnsClient.CreateUsingCert(cert);