public X509CertificateImplApple(IntPtr handle, bool owns)
 {
     this.handle = handle;
     if (!owns)
     {
         CFHelpers.CFRetain(handle);
     }
 }
        public string GetSubjectSummary()
        {
            ThrowIfContextInvalid();
            IntPtr cfstr = SecCertificateCopySubjectSummary(handle);
            string ret   = CFHelpers.FetchString(cfstr);

            CFHelpers.CFRelease(cfstr);
            return(ret);
        }
 protected override void Dispose(bool disposing)
 {
     if (handle != IntPtr.Zero)
     {
         CFHelpers.CFRelease(handle);
         handle = IntPtr.Zero;
     }
     if (fallback != null)
     {
         fallback.Dispose();
         fallback = null;
     }
 }
예제 #4
0
        public override X509CertificateImpl Import(byte[] data)
        {
            data = ConvertData(data);

            var handle = CFHelpers.CreateCertificateFromData(data);

            if (handle != IntPtr.Zero)
            {
                return(new X509CertificateImplApple(handle, true));
            }

            return(null);
        }
예제 #5
0
        public override byte[] GetRawCertData()
        {
            ThrowIfContextInvalid();
            var data = SecCertificateCopyData(handle);

            if (data == IntPtr.Zero)
            {
                throw new ArgumentException("Not a valid certificate");
            }

            try {
                return(CFHelpers.FetchDataBuffer(data));
            } finally {
                CFHelpers.CFRelease(data);
            }
        }
예제 #6
0
        public static X509CertificateImpl Import(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)
        {
            MX.X509Certificate x509;
            IntPtr             handle;

            if (password == null)
            {
                handle = CFHelpers.CreateCertificateFromData(rawData);
                if (handle != IntPtr.Zero)
                {
                    return(new X509CertificateImplApple(handle, true));
                }

                try {
                    x509 = new MX.X509Certificate(rawData);
                } catch (Exception e) {
                    try {
                        x509 = X509Helper.ImportPkcs12(rawData, null);
                    } catch {
                        string msg = Locale.GetText("Unable to decode certificate.");
                        // inner exception is the original (not second) exception
                        throw new CryptographicException(msg, e);
                    }
                }
            }
            else
            {
                // try PKCS#12
                try {
                    x509 = X509Helper.ImportPkcs12(rawData, password);
                }
                catch {
                    // it's possible to supply a (unrequired/unusued) password
                    // fix bug #79028
                    x509 = new MX.X509Certificate(rawData);
                }
            }

            return(new X509CertificateImplMono(x509));
        }
예제 #7
0
        static X509CertificateImpl ImportApple(byte[] rawData)
        {
            var handle = CFHelpers.CreateCertificateFromData(rawData);

            if (handle != IntPtr.Zero)
            {
                return(new X509CertificateImplApple(handle, true));
            }

            MX.X509Certificate x509;
            try {
                x509 = new MX.X509Certificate(rawData);
            } catch (Exception e) {
                try {
                    x509 = ImportPkcs12(rawData, null);
                } catch {
                    string msg = Locale.GetText("Unable to decode certificate.");
                    // inner exception is the original (not second) exception
                    throw new CryptographicException(msg, e);
                }
            }

            return(new X509CertificateImplMono(x509));
        }