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));
        }
Example #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);
 }
Example #5
0
        public X509Certificate(IntPtr handle)
        {
            if (handle == IntPtr.Zero)
            {
                throw new ArgumentException("Invalid handle.");
            }

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

            impl = X509Helper.InitFromCertificate(cert);
        }
Example #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);
     }
 }
Example #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
		}
Example #9
0
		internal static long GetSubjectNameHash (X509CertificateImpl impl)
		{
#if SECURITY_DEP
			using (var x509 = GetNativeInstance (impl))
				return GetSubjectNameHash (x509);
#else
			throw new NotSupportedException ();
#endif
		}
Example #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
        }
Example #13
0
        public X509Certificate(X509Certificate cert)
        {
            if (cert == null)
            {
                throw new ArgumentNullException(nameof(cert));
            }

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

            impl      = X509Helper.InitFromCertificate(cert);
            hideDates = false;
        }
Example #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;
		}
Example #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);
        }
Example #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);
        }
Example #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;
     }
 }
Example #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);
		}
Example #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));
            }
        }
Example #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;
        }
Example #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));
            }
        }
Example #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;
		}
Example #28
0
 public static byte[] Export(X509CertificateImpl impl, X509ContentType contentType, SafePasswordHandle password)
 {
     ThrowIfContextInvalid(impl);
     return(impl.Export(contentType, password));
 }
Example #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;
		}
Example #30
0
		internal X509Certificate (X509CertificateImpl impl)
		{
			if (impl == null)
				throw new ArgumentNullException ("impl");

			this.impl = X509Helper.InitFromCertificate (impl);
		}
Example #31
0
 public static bool IsValid(X509CertificateImpl impl)
 {
     return(impl != null && impl.IsValid);
 }
Example #32
0
		internal static void ThrowIfContextInvalid (X509CertificateImpl impl)
		{
			if (!IsValid (impl))
				throw GetInvalidContextException ();
		}
Example #33
0
		internal void ImportHandle (X509CertificateImpl impl)
		{
			Reset ();
			this.impl = impl;
		}
Example #34
0
		internal static void ThrowIfContextInvalid (X509CertificateImpl impl)
		{
			X509Helper.ThrowIfContextInvalid (impl);
		}
Example #35
0
		public static bool IsValid (X509CertificateImpl impl)
		{
			return impl != null && impl.IsValid;
		}
Example #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;
		}
Example #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();
 }
Example #39
0
 public virtual void Import(byte[] rawData, SecureString password, X509KeyStorageFlags keyStorageFlags)
 {
     using (var safePasswordHandle = new SafePasswordHandle(password))
         impl = X509Helper.Import(rawData, safePasswordHandle, keyStorageFlags);
 }
Example #40
0
		public X509Certificate (IntPtr handle) 
		{
			if (handle == IntPtr.Zero)
				throw new ArgumentException ("Invalid handle.");

			impl = X509Helper.InitFromHandle (handle);
		}
Example #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);
 }
Example #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;
		}
Example #43
0
 internal void ImportHandle(X509CertificateImpl impl)
 {
     Reset();
     this.impl = impl;
 }
Example #44
0
 public override bool Equals(X509CertificateImpl other, out bool result)
 {
     // Use default implementation
     result = false;
     return(false);
 }
Example #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);
		}
Example #47
0
		static X509Certificate GetNativeInstance (X509CertificateImpl impl)
		{
			throw new PlatformNotSupportedException ();
		}
Example #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);
		}
Example #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);
		}