X509CertificateImplBtls (X509CertificateImplBtls other)
		{
			disallowFallback = other.disallowFallback;
			x509 = other.x509 != null ? other.x509.Copy () : null;
			privateKey = other.privateKey != null ? other.privateKey.Copy () : null;
			if (other.intermediateCerts != null)
				intermediateCerts = other.intermediateCerts.Clone ();
		}
Example #2
0
		X509CertificateImplBtls (X509CertificateImplBtls other)
		{
			disallowFallback = other.disallowFallback;
			x509 = other.x509 != null ? other.x509.Copy () : null;
			nativePrivateKey = other.nativePrivateKey != null ? other.nativePrivateKey.Copy () : null;
			fallback = other.fallback != null ? (X509Certificate2Impl)other.fallback.Clone () : null;
			if (other.intermediateCerts != null)
				intermediateCerts = other.intermediateCerts.Clone ();
		}
        X509CertificateImplBtls(X509CertificateImplBtls other)
        {
            x509 = other.x509 != null?other.x509.Copy() : null;

            nativePrivateKey = other.nativePrivateKey != null?other.nativePrivateKey.Copy() : null;

            if (other.intermediateCerts != null)
            {
                intermediateCerts = other.intermediateCerts.Clone();
            }
        }
Example #4
0
		public MonoBtlsKey GetPrivateKey ()
		{
			if (!HasPrivateKey)
				throw new InvalidOperationException ();
			if (privateKey == null) {
				var handle = mono_btls_pkcs12_get_private_key (Handle.DangerousGetHandle ());
				CheckError (handle != IntPtr.Zero);
				privateKey = new MonoBtlsKey (new MonoBtlsKey.BoringKeyHandle (handle));
			}
			return privateKey;
		}
Example #5
0
        X509CertificateImplBtls(X509CertificateImplBtls other)
        {
            disallowFallback = other.disallowFallback;
            x509             = other.x509 != null?other.x509.Copy() : null;

            privateKey = other.privateKey != null?other.privateKey.Copy() : null;

            if (other.intermediateCerts != null)
            {
                intermediateCerts = other.intermediateCerts.Clone();
            }
        }
Example #6
0
        public void SetPrivateKey(MonoBtlsKey key)
        {
            CheckThrow();

            var ret = mono_btls_ssl_use_private_key(
                Handle.DangerousGetHandle(),
                key.Handle.DangerousGetHandle());

            if (ret <= 0)
            {
                throw ThrowError();
            }
        }
Example #7
0
        X509CertificateImplBtls(X509CertificateImplBtls other)
        {
            disallowFallback = other.disallowFallback;
            x509             = other.x509 != null?other.x509.Copy() : null;

            nativePrivateKey = other.nativePrivateKey != null?other.nativePrivateKey.Copy() : null;

            fallback = other.fallback != null ? (X509Certificate2Impl)other.fallback.Clone() : null;
            if (other.intermediateCerts != null)
            {
                intermediateCerts = other.intermediateCerts.Clone();
            }
        }
Example #8
0
        public static MonoBtlsKey CreateFromRSAPrivateKey(System.Security.Cryptography.RSA privateKey)
        {
            var keyData = MX.PKCS8.PrivateKeyInfo.Encode(privateKey);
            var key     = new MonoBtlsKey(new BoringKeyHandle(mono_btls_key_new()));

            var ret = mono_btls_key_assign_rsa_private_key(key.Handle.DangerousGetHandle(), keyData, keyData.Length);

            if (ret == 0)
            {
                throw new MonoBtlsException("Assigning private key failed.");
            }

            return(key);
        }
 public override void Reset()
 {
     if (x509 != null)
     {
         x509.Dispose();
         x509 = null;
     }
     if (nativePrivateKey != null)
     {
         nativePrivateKey.Dispose();
         nativePrivateKey = null;
     }
     publicKey         = null;
     intermediateCerts = null;
 }
        void ImportPkcs12(byte[] data, SafePasswordHandle password)
        {
            using (var pkcs12 = new MonoBtlsPkcs12()) {
                if (password == null || password.IsInvalid)
                {
                    try {
                        // Support both unencrypted PKCS#12..
                        pkcs12.Import(data, null);
                    } catch {
                        // ..and PKCS#12 encrypted with an empty password
                        using (var empty = new SafePasswordHandle(string.Empty))
                            pkcs12.Import(data, empty);
                    }
                }
                else
                {
                    pkcs12.Import(data, password);
                }

                x509 = pkcs12.GetCertificate(0);
                if (pkcs12.HasPrivateKey)
                {
                    nativePrivateKey = pkcs12.GetPrivateKey();
                }
                if (pkcs12.Count > 1)
                {
                    intermediateCerts = new X509CertificateImplCollection();
                    for (int i = 0; i < pkcs12.Count; i++)
                    {
                        using (var ic = pkcs12.GetCertificate(i)) {
                            if (MonoBtlsX509.Compare(ic, x509) == 0)
                            {
                                continue;
                            }
                            var impl = new X509CertificateImplBtls(ic);
                            intermediateCerts.Add(impl, true);
                        }
                    }
                }
            }
        }
Example #11
0
 public override void Reset()
 {
     if (x509 != null)
     {
         x509.Dispose();
         x509 = null;
     }
     if (nativePrivateKey != null)
     {
         nativePrivateKey = null;
     }
     subjectName       = null;
     issuerName        = null;
     archived          = false;
     publicKey         = null;
     intermediateCerts = null;
     if (fallback != null)
     {
         fallback.Reset();
     }
 }
		public MonoBtlsKey GetPrivateKey ()
		{
			if (!HasPrivateKey)
				throw new InvalidOperationException ();
			if (privateKey == null) {
				var handle = mono_btls_pkcs12_get_private_key (Handle.DangerousGetHandle ());
				CheckError (handle != IntPtr.Zero);
				privateKey = new MonoBtlsKey (new MonoBtlsKey.BoringKeyHandle (handle));
			}
			return privateKey;
		}
Example #13
0
		public void SetPrivateKey (MonoBtlsKey key)
		{
			CheckThrow ();

			var ret = mono_btls_ssl_use_private_key (
				Handle.DangerousGetHandle (),
				key.Handle.DangerousGetHandle ());
			if (ret <= 0)
				throw ThrowError ();
		}
Example #14
0
		public override void Reset ()
		{
			if (x509 != null) {
				x509.Dispose ();
				x509 = null;
			}
			if (nativePrivateKey != null) {
				nativePrivateKey = null;
			}
			subjectName = null;
			issuerName = null;
			archived = false;
			publicKey = null;
			intermediateCerts = null;
			if (fallback != null)
				fallback.Reset ();
		}
Example #15
0
		void ImportPkcs12 (byte[] data, string password)
		{
			using (var pkcs12 = new MonoBtlsPkcs12 ()) {
				if (string.IsNullOrEmpty (password)) {
					try {
						// Support both unencrypted PKCS#12..
						pkcs12.Import (data, null);
					} catch {
						// ..and PKCS#12 encrypted with an empty password
						pkcs12.Import (data, string.Empty);
					}
				} else {
					pkcs12.Import (data, password);
				}

				x509 = pkcs12.GetCertificate (0);
				if (pkcs12.HasPrivateKey)
					nativePrivateKey = pkcs12.GetPrivateKey ();
				if (pkcs12.Count > 1) {
					intermediateCerts = new X509CertificateImplCollection ();
					for (int i = 0; i < pkcs12.Count; i++) {
						using (var ic = pkcs12.GetCertificate (i)) {
							if (MonoBtlsX509.Compare (ic, x509) == 0)
								continue;
							var impl = new X509CertificateImplBtls (ic, true);
							intermediateCerts.Add (impl, true);
						}
					}
				}
			}
		}
Example #16
0
		public static MonoBtlsKey CreateFromRSAPrivateKey (System.Security.Cryptography.RSA privateKey)
		{
			var keyData = Mono.Security.Cryptography.PKCS8.PrivateKeyInfo.Encode (privateKey);
			var key = new MonoBtlsKey (new BoringKeyHandle (mono_btls_key_new ()));

			var ret = mono_btls_key_assign_rsa_private_key (key.Handle.DangerousGetHandle (), keyData, keyData.Length);
			if (ret == 0)
				throw new MonoBtlsException ("Assigning private key failed.");

			return key;
		}