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 ();
		}
Esempio n. 2
0
 X509Certificate2ImplMono(X509Certificate2ImplMono other)
 {
     _cert = other._cert;
     if (other.intermediateCerts != null)
     {
         intermediateCerts = other.intermediateCerts.Clone();
     }
 }
 X509CertificateImplCollection(X509CertificateImplCollection other)
 {
     list = new List <X509CertificateImpl> ();
     foreach (var impl in other.list)
     {
         list.Add(impl.Clone());
     }
 }
Esempio n. 4
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 ();
		}
Esempio n. 5
0
 public override void Reset()
 {
     _cert      = null;
     _publicKey = null;
     if (intermediateCerts != null)
     {
         intermediateCerts.Dispose();
         intermediateCerts = null;
     }
 }
Esempio n. 6
0
 public override void Reset()
 {
     _cert               = null;
     _archived           = false;
     _extensions         = null;
     _publicKey          = null;
     issuer_name         = null;
     subject_name        = null;
     signature_algorithm = null;
     if (intermediateCerts != null)
     {
         intermediateCerts.Dispose();
         intermediateCerts = null;
     }
 }
Esempio n. 7
0
        MX.X509Certificate ImportPkcs12(byte[] rawData, string password)
        {
            MX.PKCS12 pfx = null;
            if (string.IsNullOrEmpty(password))
            {
                try {
                    // Support both unencrypted PKCS#12..
                    pfx = new MX.PKCS12(rawData, (string)null);
                } catch {
                    // ..and PKCS#12 encrypted with an empty password
                    pfx = new MX.PKCS12(rawData, string.Empty);
                }
            }
            else
            {
                pfx = new MX.PKCS12(rawData, password);
            }

            if (pfx.Certificates.Count == 0)
            {
                // no certificate was found
                return(null);
            }
            else if (pfx.Keys.Count == 0)
            {
                // no key were found - pick the first certificate
                return(pfx.Certificates [0]);
            }
            else
            {
                // find the certificate that match the first key
                MX.X509Certificate cert = null;
                var    keypair          = (pfx.Keys [0] as AsymmetricAlgorithm);
                string pubkey           = keypair.ToXmlString(false);
                foreach (var c in pfx.Certificates)
                {
                    if (((c.RSA != null) && (pubkey == c.RSA.ToXmlString(false))) ||
                        ((c.DSA != null) && (pubkey == c.DSA.ToXmlString(false))))
                    {
                        cert = c;
                        break;
                    }
                }
                if (cert == null)
                {
                    cert = pfx.Certificates [0];                     // no match, pick first certificate without keys
                }
                else
                {
                    cert.RSA = (keypair as RSA);
                    cert.DSA = (keypair as DSA);
                }
                if (pfx.Certificates.Count > 1)
                {
                    intermediateCerts = new X509CertificateImplCollection();
                    foreach (var c in pfx.Certificates)
                    {
                        if (c == cert)
                        {
                            continue;
                        }
                        var impl = new X509Certificate2ImplMono(c);
                        intermediateCerts.Add(impl, true);
                    }
                }
                return(cert);
            }
        }
Esempio n. 8
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 ();
		}
Esempio n. 9
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);
						}
					}
				}
			}
		}
Esempio n. 10
0
		X509Certificate2ImplMono (X509Certificate2ImplMono other)
		{
			_cert = other._cert;
			if (other.intermediateCerts != null)
				intermediateCerts = other.intermediateCerts.Clone ();
		}
Esempio n. 11
0
		public override void Reset () 
		{
			_cert = null;
			_archived = false;
			_extensions = null;
			_serial = null;
			_publicKey = null;
			issuer_name = null;
			subject_name = null;
			signature_algorithm = null;
			if (intermediateCerts != null) {
				intermediateCerts.Dispose ();
				intermediateCerts = null;
			}
		}
Esempio n. 12
0
		private MX.X509Certificate ImportPkcs12 (byte[] rawData, string password)
		{
			MX.PKCS12 pfx = null;
			if (string.IsNullOrEmpty (password)) {
				try {
					// Support both unencrypted PKCS#12..
					pfx = new MX.PKCS12 (rawData, (string)null);
				} catch {
					// ..and PKCS#12 encrypted with an empty password
					pfx = new MX.PKCS12 (rawData, string.Empty);
				}
			} else {
				pfx = new MX.PKCS12 (rawData, password);
			}

			if (pfx.Certificates.Count == 0) {
				// no certificate was found
				return null;
			} else if (pfx.Keys.Count == 0) {
				// no key were found - pick the first certificate
				return pfx.Certificates [0];
			} else {
				// find the certificate that match the first key
				MX.X509Certificate cert = null;
				var keypair = (pfx.Keys [0] as AsymmetricAlgorithm);
				string pubkey = keypair.ToXmlString (false);
				foreach (var c in pfx.Certificates) {
					if (((c.RSA != null) && (pubkey == c.RSA.ToXmlString (false))) ||
						((c.DSA != null) && (pubkey == c.DSA.ToXmlString (false)))) {
						cert = c;
						break;
					}
				}
				if (cert == null) {
					cert = pfx.Certificates [0]; // no match, pick first certificate without keys
				} else {
					cert.RSA = (keypair as RSA);
					cert.DSA = (keypair as DSA);
				}
				if (pfx.Certificates.Count > 1) {
					intermediateCerts = new X509CertificateImplCollection ();
					foreach (var c in pfx.Certificates) {
						if (c == cert)
							continue;
						var impl = new X509Certificate2ImplMono (c);
						intermediateCerts.Add (impl, true);
					}
				}
				return cert;
			}
		}
		X509CertificateImplCollection (X509CertificateImplCollection other)
		{
			list = new List<X509CertificateImpl> ();
			foreach (var impl in other.list)
				list.Add (impl.Clone ());
		}