Ejemplo n.º 1
0
 X509Certificate2ImplMono(X509Certificate2ImplMono other)
 {
     _cert = other._cert;
     if (other.intermediateCerts != null)
     {
         intermediateCerts = other.intermediateCerts.Clone();
     }
 }
Ejemplo n.º 2
0
		internal static X509Certificate2Impl Import (byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)
		{
			var provider = MonoTlsProviderFactory.GetProvider ();
			if (provider.HasNativeCertificates) {
				var impl = provider.GetNativeCertificate (rawData, password, keyStorageFlags);
				return impl;
			} else {
				var impl = new X509Certificate2ImplMono ();
				impl.Import (rawData, password, keyStorageFlags);
				return impl;
			}
		}
Ejemplo n.º 3
0
        internal static X509Certificate2Impl Import(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)
        {
            var provider = MonoTlsProviderFactory.GetProvider();

            if (provider.HasNativeCertificates)
            {
                var impl = provider.GetNativeCertificate(rawData, password, keyStorageFlags);
                return(impl);
            }
            else
            {
                var impl = new X509Certificate2ImplMono();
                impl.Import(rawData, password, keyStorageFlags);
                return(impl);
            }
        }
Ejemplo n.º 4
0
        internal static X509Certificate2Impl Import(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags, bool disableProvider = false)
        {
#if !FEATURE_NO_BSD_SOCKETS
            if (!disableProvider)
            {
                var provider = MonoTlsProviderFactory.GetProvider();
                if (provider.HasNativeCertificates)
                {
                    var impl = provider.GetNativeCertificate(rawData, password, keyStorageFlags);
                    return(impl);
                }
            }
#endif // FEATURE_NO_BSD_SOCKETS
            var impl2 = new X509Certificate2ImplMono();
            impl2.Import(rawData, password, keyStorageFlags);
            return(impl2);
        }
        internal static X509Certificate2Impl Import(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags, bool disableProvider = false)
        {
            if (rawData == null || rawData.Length == 0)
            {
                return(null);
            }

#if MONO_FEATURE_BTLS
            if (!disableProvider)
            {
                var provider = MonoTlsProviderFactory.GetProvider();
                if (provider.HasNativeCertificates)
                {
                    var impl = provider.GetNativeCertificate(rawData, password, keyStorageFlags);
                    return(impl);
                }
            }
#endif // MONO_FEATURE_BTLS
            var impl2 = new X509Certificate2ImplMono();
            impl2.Import(rawData, password, keyStorageFlags);
            return(impl2);
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
0
		X509Certificate2ImplMono (X509Certificate2ImplMono other)
		{
			_cert = other._cert;
			if (other.intermediateCerts != null)
				intermediateCerts = other.intermediateCerts.Clone ();
		}
Ejemplo n.º 8
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;
			}
		}
Ejemplo n.º 9
0
		internal static X509Certificate2Impl Import (byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags, bool disableProvider = false)
		{
#if !FEATURE_NO_BSD_SOCKETS
			if (!disableProvider) {
				var provider = MonoTlsProviderFactory.GetProvider ();
				if (provider.HasNativeCertificates) {
					var impl = provider.GetNativeCertificate (rawData, password, keyStorageFlags);
					return impl;
				}
			}
#endif // FEATURE_NO_BSD_SOCKETS
			var impl2 = new X509Certificate2ImplMono ();
			impl2.Import (rawData, password, keyStorageFlags);
			return impl2;
		}