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));
        }
Exemplo n.º 2
0
 internal static void ThrowIfContextInvalid(X509CertificateImpl impl)
 {
     if (!IsValid(impl))
     {
         throw GetInvalidContextException();
     }
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 5
0
        public X509Certificate(IntPtr handle)
        {
            if (handle == IntPtr.Zero)
            {
                throw new ArgumentException("Invalid handle.");
            }

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

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

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

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

            fallback = new X509CertificateImplMono(mxCert);
        }
Exemplo n.º 16
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;
		}
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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;
     }
 }
Exemplo n.º 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);
		}
Exemplo n.º 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));
            }
        }
Exemplo n.º 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;
        }
Exemplo n.º 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));
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 26
0
		protected override void Dispose (bool disposing)
		{
			if (handle != IntPtr.Zero){
				CFHelpers.CFRelease (handle);
				handle = IntPtr.Zero;
			}
			if (fallback != null) {
				fallback.Dispose ();
				fallback = null;
			}
		}
Exemplo n.º 27
0
		public override bool Equals (X509CertificateImpl other, out bool result)
		{
			// Use default implementation
			result = false;
			return false;
		}
Exemplo n.º 28
0
 public static byte[] Export(X509CertificateImpl impl, X509ContentType contentType, SafePasswordHandle password)
 {
     ThrowIfContextInvalid(impl);
     return(impl.Export(contentType, password));
 }
Exemplo n.º 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;
		}
Exemplo n.º 30
0
		internal X509Certificate (X509CertificateImpl impl)
		{
			if (impl == null)
				throw new ArgumentNullException ("impl");

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

			impl = X509Helper.InitFromHandle (handle);
		}
Exemplo n.º 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);
 }
Exemplo n.º 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;
		}
Exemplo n.º 43
0
 internal void ImportHandle(X509CertificateImpl impl)
 {
     Reset();
     this.impl = impl;
 }
Exemplo n.º 44
0
 public override bool Equals(X509CertificateImpl other, out bool result)
 {
     // Use default implementation
     result = false;
     return(false);
 }
Exemplo n.º 45
0
 public static X509CertificateImpl InitFromCertificate(X509CertificateImpl impl)
 {
     return(impl?.Clone());
 }
Exemplo n.º 46
0
		void MustFallback ()
		{
			ThrowIfContextInvalid ();
			if (fallback != null)
				return;
			var mxCert = new MX.X509Certificate (GetRawCertData ());
			fallback = new X509CertificateImplMono (mxCert);
		}
Exemplo n.º 47
0
		static X509Certificate GetNativeInstance (X509CertificateImpl impl)
		{
			throw new PlatformNotSupportedException ();
		}
Exemplo n.º 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);
		}
Exemplo n.º 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);
		}