public static X509CertificateImpl InitFromCertificate(X509CertificateImpl impl)
        {
            if (impl == null)
            {
                return(null);
            }

            var copy = impl.Clone();

            if (copy != null)
            {
                return(copy);
            }

            var data = impl.GetRawCertData();

            if (data == null)
            {
                return(null);
            }

            var x509 = new MX.X509Certificate(data);

            return(new X509CertificateImplMono(x509));
        }
示例#2
0
 internal static void ThrowIfContextInvalid(X509CertificateImpl impl)
 {
     if (!IsValid(impl))
     {
         throw GetInvalidContextException();
     }
 }
 public X509Certificate(byte[] data)
 {
     if (data != null && data.Length != 0)
     {
         impl = X509Helper.Import(data);
     }
 }
 public void Add(X509CertificateImpl impl, bool takeOwnership)
 {
     if (!takeOwnership)
     {
         impl = impl.Clone();
     }
     list.Add(impl);
 }
示例#5
0
        public X509Certificate(IntPtr handle)
        {
            if (handle == IntPtr.Zero)
            {
                throw new ArgumentException("Invalid handle.");
            }

            impl = X509Helper.InitFromHandle(handle);
        }
示例#6
0
        public X509CertificateMono(X509CertificateMono cert)
        {
            if (cert == null)
            {
                throw new ArgumentNullException("cert");
            }

            impl = X509Helper.InitFromCertificate(cert);
        }
示例#7
0
 public X509Certificate(byte[] data)
 {
     if (data != null && data.Length != 0)
     {
         // For compat reasons, this constructor treats passing a null or empty data set as the same as calling the nullary constructor.
         using (var safePasswordHandle = new SafePasswordHandle((string)null))
             impl = X509Helper.Import(data, safePasswordHandle, X509KeyStorageFlags.DefaultKeySet);
     }
 }
示例#8
0
		internal static void ExportAsPEM (X509CertificateImpl impl, Stream stream, bool includeHumanReadableForm)
		{
#if SECURITY_DEP
			using (var x509 = GetNativeInstance (impl))
				ExportAsPEM (x509, stream, includeHumanReadableForm);
#else
			throw new NotSupportedException ();
#endif
		}
示例#9
0
		internal static long GetSubjectNameHash (X509CertificateImpl impl)
		{
#if SECURITY_DEP
			using (var x509 = GetNativeInstance (impl))
				return GetSubjectNameHash (x509);
#else
			throw new NotSupportedException ();
#endif
		}
示例#10
0
        internal X509Certificate(X509CertificateImpl impl)
        {
            if (impl == null)
            {
                throw new ArgumentNullException("impl");
            }

            this.impl = X509Helper.InitFromCertificate(impl);
        }
        internal static long GetSubjectNameHash(X509CertificateImpl impl)
        {
#if SECURITY_DEP
            using (var x509 = GetNativeInstance(impl))
                return(GetSubjectNameHash(x509));
#else
            throw new NotSupportedException();
#endif
        }
        internal static void ExportAsPEM(X509CertificateImpl impl, Stream stream, bool includeHumanReadableForm)
        {
#if SECURITY_DEP
            using (var x509 = GetNativeInstance(impl))
                ExportAsPEM(x509, stream, includeHumanReadableForm);
#else
            throw new NotSupportedException();
#endif
        }
示例#13
0
        public X509Certificate(X509Certificate cert)
        {
            if (cert == null)
            {
                throw new ArgumentNullException(nameof(cert));
            }

            impl = X509Helper.InitFromCertificate(cert);
        }
示例#14
0
        public X509Certificate(System.Security.Cryptography.X509Certificates.X509Certificate cert)
        {
            if (cert == null)
            {
                throw new ArgumentNullException("cert");
            }

            impl      = X509Helper.InitFromCertificate(cert);
            hideDates = false;
        }
示例#15
0
        void MustFallback()
        {
            ThrowIfContextInvalid();
            if (fallback != null)
            {
                return;
            }
            var mxCert = new MX.X509Certificate(GetRawCertData());

            fallback = new X509CertificateImplMono(mxCert);
        }
		public override bool Equals (X509CertificateImpl other, out bool result)
		{
			var otherAppleImpl = other as X509CertificateImplApple;
			if (otherAppleImpl != null && otherAppleImpl.handle == handle) {
				result = true;
				return true;
			}

			result = false;
			return false;
		}
示例#17
0
        public X509Certificate(byte[] rawData, SecureString password, X509KeyStorageFlags keyStorageFlags)
        {
            if (rawData == null || rawData.Length == 0)
            {
                throw new ArgumentException(SR.Arg_EmptyOrNullArray, nameof(rawData));
            }

            ValidateKeyStorageFlags(keyStorageFlags);

            using (var safePasswordHandle = new SafePasswordHandle(password))
                impl = X509Helper.Import(rawData, safePasswordHandle, keyStorageFlags);
        }
示例#18
0
        public override bool Equals(X509CertificateImpl other, out bool result)
        {
            var otherAppleImpl = other as X509CertificateImplApple;

            if (otherAppleImpl != null && otherAppleImpl.handle == handle)
            {
                result = true;
                return(true);
            }

            result = false;
            return(false);
        }
示例#19
0
 protected override void Dispose(bool disposing)
 {
     if (handle != IntPtr.Zero)
     {
         CFHelpers.CFRelease(handle);
         handle = IntPtr.Zero;
     }
     if (fallback != null)
     {
         fallback.Dispose();
         fallback = null;
     }
 }
示例#20
0
		public static X509CertificateImpl InitFromCertificate (X509CertificateImpl impl)
		{
			ThrowIfContextInvalid (impl);
			var copy = impl.Clone ();
			if (copy != null)
				return copy;

			var data = impl.GetRawCertData ();
			if (data == null)
				return null;

			var x509 = new MX.X509Certificate (data);
			return new X509CertificateImplMono (x509);
		}
示例#21
0
        public X509Certificate(string fileName, SecureString password, X509KeyStorageFlags keyStorageFlags) : this()
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            ValidateKeyStorageFlags(keyStorageFlags);

            var rawData = File.ReadAllBytes(fileName);

            using (var safePasswordHandle = new SafePasswordHandle(password))
                impl = X509Helper.Import(rawData, safePasswordHandle, keyStorageFlags);
        }
        static MonoBtlsX509 GetNativeInstance(X509CertificateImpl impl)
        {
            ThrowIfContextInvalid(impl);
            var btlsImpl = impl as X509CertificateImplBtls;

            if (btlsImpl != null)
            {
                return(btlsImpl.X509.Copy());
            }
            else
            {
                return(MonoBtlsX509.LoadFromData(impl.GetRawCertData(), MonoBtlsX509Format.DER));
            }
        }
示例#23
0
        public virtual void Reset()
        {
            if (impl != null)
            {
                impl.Dispose();
                impl = null;
            }

            lazyCertHash               = null;
            lazyIssuer                 = null;
            lazySubject                = null;
            lazySerialNumber           = null;
            lazyKeyAlgorithm           = null;
            lazyKeyAlgorithmParameters = null;
            lazyPublicKey              = null;
            lazyNotBefore              = DateTime.MinValue;
            lazyNotAfter               = DateTime.MinValue;
        }
示例#24
0
        // public methods

        public virtual bool Equals(System.Security.Cryptography.X509Certificates.X509Certificate other)
        {
            if (other == null)
            {
                return(false);
            }
            else
            {
                if (!X509Helper.IsValid(other.impl))
                {
                    if (!X509Helper.IsValid(impl))
                    {
                        return(true);
                    }
                    throw new CryptographicException(Locale.GetText("Certificate instance is empty."));
                }

                return(X509CertificateImpl.Equals(impl, other.impl));
            }
        }
示例#25
0
        public static bool Equals(X509CertificateImpl first, X509CertificateImpl second)
        {
            if (!IsValid(first) || !IsValid(second))
            {
                return(false);
            }

            bool result;

            if (first.Equals(second, out result))
            {
                return(result);
            }

            var firstRaw  = first.RawData;
            var secondRaw = second.RawData;

            if (firstRaw == null)
            {
                return(secondRaw == null);
            }
            else if (secondRaw == null)
            {
                return(false);
            }

            if (firstRaw.Length != secondRaw.Length)
            {
                return(false);
            }

            for (int i = 0; i < firstRaw.Length; i++)
            {
                if (firstRaw [i] != secondRaw [i])
                {
                    return(false);
                }
            }

            return(true);
        }
		protected override void Dispose (bool disposing)
		{
			if (handle != IntPtr.Zero){
				CFHelpers.CFRelease (handle);
				handle = IntPtr.Zero;
			}
			if (fallback != null) {
				fallback.Dispose ();
				fallback = null;
			}
		}
		public override bool Equals (X509CertificateImpl other, out bool result)
		{
			// Use default implementation
			result = false;
			return false;
		}
示例#28
0
 public static byte[] Export(X509CertificateImpl impl, X509ContentType contentType, SafePasswordHandle password)
 {
     ThrowIfContextInvalid(impl);
     return(impl.Export(contentType, password));
 }
示例#29
0
		public override bool Equals (X509CertificateImpl other, out bool result)
		{
			var otherBoringImpl = other as X509CertificateImplBtls;
			if (otherBoringImpl == null) {
				result = false;
				return false;
			}

			result = MonoBtlsX509.Compare (X509, otherBoringImpl.X509) == 0;
			return true;
		}
示例#30
0
		internal X509Certificate (X509CertificateImpl impl)
		{
			if (impl == null)
				throw new ArgumentNullException ("impl");

			this.impl = X509Helper.InitFromCertificate (impl);
		}
示例#31
0
 public static bool IsValid(X509CertificateImpl impl)
 {
     return(impl != null && impl.IsValid);
 }
示例#32
0
		internal static void ThrowIfContextInvalid (X509CertificateImpl impl)
		{
			if (!IsValid (impl))
				throw GetInvalidContextException ();
		}
示例#33
0
		internal void ImportHandle (X509CertificateImpl impl)
		{
			Reset ();
			this.impl = impl;
		}
示例#34
0
		internal static void ThrowIfContextInvalid (X509CertificateImpl impl)
		{
			X509Helper.ThrowIfContextInvalid (impl);
		}
示例#35
0
		public static bool IsValid (X509CertificateImpl impl)
		{
			return impl != null && impl.IsValid;
		}
示例#36
0
		public static bool Equals (X509CertificateImpl first, X509CertificateImpl second)
		{
			if (!IsValid (first) || !IsValid (second))
				return false;

			bool result;
			if (first.Equals (second, out result))
				return result;

			var firstRaw = first.GetRawCertData ();
			var secondRaw = second.GetRawCertData ();

			if (firstRaw == null)
				return secondRaw == null;
			else if (secondRaw == null)
				return false;

			if (firstRaw.Length != secondRaw.Length)
				return false;

			for (int i = 0; i < firstRaw.Length; i++) {
				if (firstRaw [i] != secondRaw [i])
					return false;
			}

			return true;
		}
示例#37
0
		public static byte[] Export (X509CertificateImpl impl, X509ContentType contentType, byte[] password)
		{
			ThrowIfContextInvalid (impl);
			return impl.Export (contentType, password);
		}
 static X509Certificate GetNativeInstance(X509CertificateImpl impl)
 {
     throw new PlatformNotSupportedException();
 }
示例#39
0
 public virtual void Import(byte[] rawData, SecureString password, X509KeyStorageFlags keyStorageFlags)
 {
     using (var safePasswordHandle = new SafePasswordHandle(password))
         impl = X509Helper.Import(rawData, safePasswordHandle, keyStorageFlags);
 }
示例#40
0
		public X509Certificate (IntPtr handle) 
		{
			if (handle == IntPtr.Zero)
				throw new ArgumentException ("Invalid handle.");

			impl = X509Helper.InitFromHandle (handle);
		}
示例#41
0
 public virtual void Import(string fileName, SecureString password, X509KeyStorageFlags keyStorageFlags)
 {
     byte[] rawData = File.ReadAllBytes(fileName);
     using (var safePasswordHandle = new SafePasswordHandle(password))
         impl = X509Helper.Import(rawData, safePasswordHandle, keyStorageFlags);
 }
示例#42
0
		public X509Certificate (System.Security.Cryptography.X509Certificates.X509Certificate cert) 
		{
			if (cert == null)
				throw new ArgumentNullException ("cert");

			X509Helper.ThrowIfContextInvalid (cert.impl);

			impl = X509Helper.InitFromCertificate (cert.impl);
			hideDates = false;
		}
示例#43
0
 internal void ImportHandle(X509CertificateImpl impl)
 {
     Reset();
     this.impl = impl;
 }
示例#44
0
 public override bool Equals(X509CertificateImpl other, out bool result)
 {
     // Use default implementation
     result = false;
     return(false);
 }
示例#45
0
 public static X509CertificateImpl InitFromCertificate(X509CertificateImpl impl)
 {
     return(impl?.Clone());
 }
		void MustFallback ()
		{
			ThrowIfContextInvalid ();
			if (fallback != null)
				return;
			var mxCert = new MX.X509Certificate (GetRawCertData ());
			fallback = new X509CertificateImplMono (mxCert);
		}
示例#47
0
		static X509Certificate GetNativeInstance (X509CertificateImpl impl)
		{
			throw new PlatformNotSupportedException ();
		}
示例#48
0
 internal X509Certificate(X509CertificateImpl impl)
 {
     Debug.Assert(impl != null);
     this.impl = X509Helper.InitFromCertificate(impl);
 }
		public void Add (X509CertificateImpl impl, bool takeOwnership)
		{
			if (!takeOwnership)
				impl = impl.Clone ();
			list.Add (impl);
		}
示例#50
0
		static MonoBtlsX509 GetNativeInstance (X509CertificateImpl impl)
		{
			ThrowIfContextInvalid (impl);
			var btlsImpl = impl as X509CertificateImplBtls;
			if (btlsImpl != null)
				return btlsImpl.X509.Copy ();
			else
				return MonoBtlsX509.LoadFromData (impl.GetRawCertData (), MonoBtlsX509Format.DER);
		}