コード例 #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
ファイル: SecTrust.cs プロジェクト: zippo227/xamarin-macios
        public void SetPolicy(SecPolicy policy)
        {
            if (policy == null)
            {
                throw new ArgumentNullException("policy");
            }

            SetPolicies(policy.Handle);
        }
コード例 #4
0
ファイル: SecTrust.cs プロジェクト: zippo227/xamarin-macios
        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);
        }