public GcmXmppConnection (GcmXmppConfiguration configuration) { authCompletion = new TaskCompletionSource<bool> (); notifications = new Dictionary<string,CompletableNotification> (); Configuration = configuration; certificates = new X509CertificateCollection (); // Add local/machine certificate stores to our collection if requested //if (Configuration.AddLocalAndMachineCertificateStores) { var store = new X509Store (StoreLocation.LocalMachine); certificates.AddRange (store.Certificates); store = new X509Store (StoreLocation.CurrentUser); certificates.AddRange (store.Certificates); //} // Add optionally specified additional certs into our collection // if (Configuration.AdditionalCertificates != null) { // foreach (var addlCert in Configuration.AdditionalCertificates) // certificates.Add (addlCert); // } // Finally, add the main private cert for authenticating to our collection // if (certificate != null) // certificates.Add (certificate); }
public ApplePushChannel(ApplePushChannelSettings channelSettings) { cancelToken = cancelTokenSrc.Token; appleSettings = channelSettings; certificate = this.appleSettings.Certificate; certificates = new X509CertificateCollection(); if (appleSettings.AddLocalAndMachineCertificateStores) { var store = new X509Store(StoreLocation.LocalMachine); certificates.AddRange(store.Certificates); store = new X509Store(StoreLocation.CurrentUser); certificates.AddRange(store.Certificates); } certificates.Add(certificate); if (this.appleSettings.AdditionalCertificates != null) foreach (var addlCert in this.appleSettings.AdditionalCertificates) certificates.Add(addlCert); timerCleanup = new Timer(state => Cleanup(), null, TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(1000)); }
public ApplePushChannel(ApplePushChannelSettings channelSettings, PushServiceSettings serviceSettings = null) : base(channelSettings, serviceSettings) { this.appleSettings = channelSettings; certificate = this.appleSettings.Certificate; certificates = new X509CertificateCollection(); if (appleSettings.AddLocalAndMachineCertificateStores) { var store = new X509Store(StoreLocation.LocalMachine); certificates.AddRange(store.Certificates); store = new X509Store(StoreLocation.CurrentUser); certificates.AddRange(store.Certificates); } certificates.Add(certificate); if (this.appleSettings.AdditionalCertificates != null) foreach (var addlCert in this.appleSettings.AdditionalCertificates) certificates.Add(addlCert); //Start our cleanup task taskCleanup = new Task(() => Cleanup(), TaskCreationOptions.LongRunning); taskCleanup.ContinueWith((t) => { var ex = t.Exception; }, TaskContinuationOptions.OnlyOnFaulted); taskCleanup.Start(); }
private void ConfigureCertificates() { _certificate = _appleSettings.Certificate; _certificates = new X509CertificateCollection(); if (_appleSettings.AddLocalAndMachineCertificateStores) { var store = new X509Store(StoreLocation.LocalMachine); _certificates.AddRange(store.Certificates); store = new X509Store(StoreLocation.CurrentUser); _certificates.AddRange(store.Certificates); } _certificates.Add(_certificate); if (_appleSettings.AdditionalCertificates != null) { foreach (var additionalCertificate in _appleSettings.AdditionalCertificates) { _certificates.Add(additionalCertificate); } } }
public ApnsConnection(ApnsConfiguration configuration) { id = ++ID; if (id >= int.MaxValue) ID = 0; Configuration = configuration; certificate = Configuration.Certificate; certificates = new X509CertificateCollection(); // Add local/machine certificate stores to our collection if requested if (Configuration.AddLocalAndMachineCertificateStores) { var store = new X509Store(StoreLocation.LocalMachine); certificates.AddRange(store.Certificates); store = new X509Store(StoreLocation.CurrentUser); certificates.AddRange(store.Certificates); } // Add optionally specified additional certs into our collection if (Configuration.AdditionalCertificates != null) { foreach (var addlCert in Configuration.AdditionalCertificates) certificates.Add(addlCert); } // Finally, add the main private cert for authenticating to our collection if (certificate != null) certificates.Add(certificate); timerBatchWait = new Timer(new TimerCallback(async state => { await batchSendSemaphore.WaitAsync(); try { await SendBatch().ConfigureAwait(false); } finally { batchSendSemaphore.Release(); } }), null, Timeout.Infinite, Timeout.Infinite); }
public ApnsHttp2Connection (ApnsHttp2Configuration configuration) { id = ++ID; if (id >= int.MaxValue) ID = 0; Configuration = configuration; certificate = Configuration.Certificate; certificates = new X509CertificateCollection (); // Add local/machine certificate stores to our collection if requested if (Configuration.AddLocalAndMachineCertificateStores) { var store = new X509Store (StoreLocation.LocalMachine); certificates.AddRange (store.Certificates); store = new X509Store (StoreLocation.CurrentUser); certificates.AddRange (store.Certificates); } // Add optionally specified additional certs into our collection if (Configuration.AdditionalCertificates != null) { foreach (var addlCert in Configuration.AdditionalCertificates) certificates.Add (addlCert); } // Finally, add the main private cert for authenticating to our collection if (certificate != null) certificates.Add (certificate); var http2Settings = new HttpTwo.Http2ConnectionSettings ( Configuration.Host, (uint)Configuration.Port, true, certificates); http2 = new HttpTwo.Http2Client (http2Settings); }
public ApplePushChannel(ApplePushChannelSettings channelSettings) { cancelToken = cancelTokenSrc.Token; appleSettings = channelSettings; certificate = this.appleSettings.Certificate; certificates = new X509CertificateCollection(); if (appleSettings.AddLocalAndMachineCertificateStores) { var store = new X509Store(StoreLocation.LocalMachine); certificates.AddRange(store.Certificates); store = new X509Store(StoreLocation.CurrentUser); certificates.AddRange(store.Certificates); } certificates.Add(certificate); if (this.appleSettings.AdditionalCertificates != null) foreach (var addlCert in this.appleSettings.AdditionalCertificates) certificates.Add(addlCert); timerCleanup = new Timer(state => Cleanup(), null, TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(1000)); if (channelSettings.IdleConnectionResetTimeout.HasValue) { this.IdleConnectionResetTimer.Interval = channelSettings.IdleConnectionResetTimeout.Value.TotalMilliseconds; this.IdleConnectionResetTimer.AutoReset = false; this.IdleConnectionResetTimer.Elapsed += (sender, e) => { disconnect(); }; } }
public void open() { try { X509Store store = new X509Store(StoreLocation.LocalMachine); store.Open(OpenFlags.ReadOnly); X509CertificateCollection certificates = new X509CertificateCollection(); certificates.AddRange(store.Certificates); client = new TcpClient(); client.Connect("gateway.sandbox.push.apple.com", 2195); LocalCertificateSelectionCallback localCallBack = new LocalCertificateSelectionCallback(APNSLocalCert.SelectLocalCertificate); stream = new SslStream(client.GetStream(), false, (sender, cert, chain, sslPolicyErrors) => true, localCallBack); stream.AuthenticateAsClient("gateway.sandbox.push.apple.com", certificates, System.Security.Authentication.SslProtocols.Tls, false); } catch (Exception ex) { Console.Write(ex.Message); } }
/// <summary> /// Retrieve client SSL certificates. Dependent on connection string /// settings we use either file or store based certificates. /// </summary> private X509CertificateCollection GetClientCertificates() { X509CertificateCollection certs = new X509CertificateCollection(); // Check for file-based certificate if (Settings.CertificateFile != null) { if (!Version.isAtLeast(5, 1, 0)) throw new MySqlException(Properties.Resources.FileBasedCertificateNotSupported); X509Certificate2 clientCert = new X509Certificate2(Settings.CertificateFile, Settings.CertificatePassword); certs.Add(clientCert); return certs; } if (Settings.CertificateStoreLocation == MySqlCertificateStoreLocation.None) return certs; StoreLocation location = (Settings.CertificateStoreLocation == MySqlCertificateStoreLocation.CurrentUser) ? StoreLocation.CurrentUser : StoreLocation.LocalMachine; // Check for store-based certificate X509Store store = new X509Store(StoreName.My, location); store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly); if (Settings.CertificateThumbprint == null) { // Return all certificates from the store. certs.AddRange(store.Certificates); return certs; } // Find certificate with given thumbprint certs.AddRange(store.Certificates.Find(X509FindType.FindByThumbprint, Settings.CertificateThumbprint, true)); if (certs.Count == 0) { throw new MySqlException("Certificate with Thumbprint " + Settings.CertificateThumbprint + " not found"); } return certs; }
public void CopyTo_TooSmall () { X509Certificate[] array = new X509Certificate [1]; X509CertificateCollection c = new X509CertificateCollection (); c.AddRange (range); c.CopyTo (array, 0); }
public void AddRange_CollectionNull () { X509CertificateCollection coll = null; X509CertificateCollection c = new X509CertificateCollection (); c.AddRange (coll); }
public void AddRange_Collection () { X509CertificateCollection coll = new X509CertificateCollection (range); X509CertificateCollection c = new X509CertificateCollection (); c.AddRange (c); Assert.AreEqual (0, c.Count, "Self(none)"); c.AddRange (coll); Assert.AreEqual (2, c.Count, "Range(a+b)"); c.AddRange (coll); Assert.AreEqual (4, c.Count, "Duplicate(a+b)"); c.Add (x509c); Assert.AreEqual (5, c.Count, "New(c)"); // This leads to an infinite loop until the runtime throws an OutOfMemoryException //c.AddRange (c); //Assert.AreEqual (10, c.Count, "Self(double)"); }
public void AddRange_ArrayNull () { X509Certificate[] array = null; X509CertificateCollection c = new X509CertificateCollection (); c.AddRange (array); }
public void AddRange_Array () { X509CertificateCollection c = new X509CertificateCollection (); c.AddRange (range); Assert.AreEqual (2, c.Count, "Range(a+b)"); c.AddRange (range); Assert.AreEqual (4, c.Count, "Duplicate(a+b)"); c.Add (x509c); Assert.AreEqual (5, c.Count, "New(c)"); }
public void AddRange_Array () { X509CertificateCollection c = new X509CertificateCollection (); c.AddRange (range); AssertEquals ("Range(a+b)", 2, c.Count); c.AddRange (range); AssertEquals ("Duplicate(a+b)", 4, c.Count); c.Add (x509c); AssertEquals ("New(c)", 5, c.Count); }