Example #1
0
        public SecTrust(SecCertificate certificate, SecPolicy policy)
        {
            if (certificate == null)
                throw new ArgumentNullException ("certificate");

            Initialize (certificate.Handle, policy);
        }
Example #2
0
        void Initialize(IntPtr certHandle, SecPolicy policy)
        {
            SecStatusCode result = SecTrustCreateWithCertificates(certHandle, policy == null ? IntPtr.Zero : policy.Handle, out handle);

            if (result != SecStatusCode.Success)
            {
                throw new ArgumentException(result.ToString());
            }
        }
Example #3
0
        public void SetPolicy(SecPolicy policy)
        {
            if (policy == null)
            {
                throw new ArgumentNullException("policy");
            }

            SetPolicies(policy.Handle);
        }
Example #4
0
        public SecTrust(SecCertificate certificate, SecPolicy policy)
        {
            if (certificate == null)
            {
                throw new ArgumentNullException("certificate");
            }

            Initialize(certificate.Handle, policy);
        }
Example #5
0
        public SecTrust(X509Certificate2 certificate, SecPolicy policy)
        {
            if (certificate == null)
            {
                throw new ArgumentNullException("certificate");
            }

            using (SecCertificate cert = new SecCertificate(certificate)) {
                Initialize(cert.Handle, policy);
            }
        }
Example #6
0
        static public SecPolicy CreateSslPolicy(bool server, string hostName)
        {
            NSString  host   = hostName == null ? null : new NSString(hostName);
            IntPtr    handle = host == null ? IntPtr.Zero : host.Handle;
            SecPolicy policy = new SecPolicy(SecPolicyCreateSSL(server, handle), true);

            if (host != null)
            {
                host.Dispose();
            }
            return(policy);
        }
Example #7
0
        public SecTrust(X509CertificateCollection certificates, SecPolicy policy)
        {
            if (certificates == null)
            {
                throw new ArgumentNullException("certificates");
            }

            SecCertificate[] array = new SecCertificate [certificates.Count];
            int i = 0;

            foreach (var certificate in certificates)
            {
                array [i++] = new SecCertificate(certificate);
            }
            Initialize(array, policy);
        }
Example #8
0
        //
        // EXPERIMENTAL
        // Needs some more testing before we can make this public.
        // AppleTls does not actually use this API, so it may be removed again.
        //
        internal NSData GetPublicKey()
        {
            if (handle == IntPtr.Zero)
            {
                throw new ObjectDisposedException("SecCertificate");
            }

            var policy = SecPolicy.CreateBasicX509Policy();
            var trust  = new SecTrust(this, policy);

            trust.Evaluate();

            SecStatusCode status;

            using (var key = trust.GetPublicKey())
                using (var query = new SecRecord(SecKind.Key)) {
                    query.SetValueRef(key);

                    status = SecKeyChain.Add(query);
                    if (status != SecStatusCode.Success && status != SecStatusCode.DuplicateItem)
                    {
                        throw new InvalidOperationException(status.ToString());
                    }

                    bool added = status == SecStatusCode.Success;

                    try {
                        var data = SecKeyChain.QueryAsData(query, false, out status);
                        if (status != SecStatusCode.Success)
                        {
                            throw new InvalidOperationException(status.ToString());
                        }

                        return(data);
                    } finally {
                        if (added)
                        {
                            status = SecKeyChain.Remove(query);
                            if (status != SecStatusCode.Success)
                            {
                                throw new InvalidOperationException(status.ToString());
                            }
                        }
                    }
                }
        }
Example #9
0
 void Initialize(SecCertificate[] array, SecPolicy policy)
 {
     using (var certs = CFArray.FromNativeObjects(array)) {
         Initialize(certs.Handle, policy);
     }
 }
Example #10
0
 public static SecPolicy CreateSslPolicy(bool server, string hostName)
 {
     NSString host = hostName == null ? null : new NSString (hostName);
     IntPtr handle = host == null ? IntPtr.Zero : host.Handle;
     SecPolicy policy = new SecPolicy (SecPolicyCreateSSL (server, handle), true);
     if (host != null)
         host.Dispose ();
     return policy;
 }
Example #11
0
        public SecTrust(X509Certificate2Collection certificates, SecPolicy policy)
        {
            if (certificates == null)
                throw new ArgumentNullException ("certificates");

            SecCertificate[] array = new SecCertificate [certificates.Count];
            int i = 0;
            foreach (var certificate in certificates)
                array [i++] = new SecCertificate (certificate);
            Initialize (array, policy);
        }
Example #12
0
        public SecTrust(X509Certificate2 certificate, SecPolicy policy)
        {
            if (certificate == null)
                throw new ArgumentNullException ("certificate");

            using (SecCertificate cert = new SecCertificate (certificate)) {
                Initialize (cert.Handle, policy);
            }
        }
Example #13
0
 void Initialize(IntPtr certHandle, SecPolicy policy)
 {
     SecStatusCode result = SecTrustCreateWithCertificates (certHandle, policy == null ? IntPtr.Zero : policy.Handle, out handle);
     if (result != SecStatusCode.Success)
         throw new ArgumentException (result.ToString ());
 }
Example #14
0
 void Initialize(SecCertificate[] array, SecPolicy policy)
 {
     using (var certs = CFArray.FromNativeObjects (array)) {
         Initialize (certs.Handle, policy);
     }
 }
Example #15
0
        public void SetPolicy(SecPolicy policy)
        {
            if (policy == null)
                throw new ArgumentNullException ("policy");

            SetPolicies (policy.Handle);
        }