コード例 #1
0
        public static NSUrlCredential FromTrust(SecTrust trust)
        {
            if (trust == null)
                throw new ArgumentNullException ("trust");

            return FromTrust (trust.Handle);
        }
コード例 #2
0
        public static bool InvokeSystemCertificateValidator(
            ICertificateValidator2 validator, string targetHost, bool serverMode,
            X509CertificateCollection certificates, out bool success,
            ref MonoSslPolicyErrors errors, ref int status11)
        {
            if (certificates == null) {
                errors |= MonoSslPolicyErrors.RemoteCertificateNotAvailable;
                success = false;
                return true;
            }

            var policy = SecPolicy.CreateSslPolicy (!serverMode, targetHost);
            var trust = new SecTrust (certificates, policy);

            if (validator.Settings.TrustAnchors != null) {
                var status = trust.SetAnchorCertificates (validator.Settings.TrustAnchors);
                if (status != SecStatusCode.Success)
                    throw new InvalidOperationException (status.ToString ());
                trust.SetAnchorCertificatesOnly (false);
            }

            var result = trust.Evaluate ();
            if (result == SecTrustResult.Unspecified) {
                success = true;
                return true;
            }

            errors |= MonoSslPolicyErrors.RemoteCertificateChainErrors;
            success = false;
            return true;
        }
コード例 #3
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());
                            }
                        }
                    }
                }
        }
コード例 #4
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 ());
					}
				}
			}
		}