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

            Initialize (certificate.Handle, policy);
        }
예제 #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());
            }
        }
예제 #3
0
        public void SetPolicy(SecPolicy policy)
        {
            if (policy == null)
            {
                throw new ArgumentNullException("policy");
            }

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

            Initialize(certificate.Handle, policy);
        }
예제 #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);
            }
        }
예제 #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);
        }
예제 #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);
        }
예제 #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());
                            }
                        }
                    }
                }
        }
예제 #9
0
 void Initialize(SecCertificate[] array, SecPolicy policy)
 {
     using (var certs = CFArray.FromNativeObjects(array)) {
         Initialize(certs.Handle, policy);
     }
 }
예제 #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;
 }
예제 #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);
        }
예제 #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);
            }
        }
예제 #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 ());
 }
예제 #14
0
 void Initialize(SecCertificate[] array, SecPolicy policy)
 {
     using (var certs = CFArray.FromNativeObjects (array)) {
         Initialize (certs.Handle, policy);
     }
 }
예제 #15
0
        public void SetPolicy(SecPolicy policy)
        {
            if (policy == null)
                throw new ArgumentNullException ("policy");

            SetPolicies (policy.Handle);
        }