public void NoHostName() { X509Certificate x = new X509Certificate(CertificateTest.mail_google_com); // a null host name means "*" (accept any name) which is not stated in Apple documentation using (var policy = SecPolicy.CreateSslPolicy(true, null)) using (var trust = new SecTrust(x, policy)) { // that certificate stopped being valid on September 30th, 2013 so we validate it with a date earlier than that trust.SetVerifyDate(new DateTime(635108745218945450, DateTimeKind.Utc)); Assert.That(Evaluate(trust, true), Is.EqualTo(SecTrustResult.RecoverableTrustFailure), "Evaluate"); if (TestRuntime.CheckXcodeVersion(5, 0)) { using (var rev = SecPolicy.CreateRevocationPolicy(SecRevocation.UseAnyAvailableMethod)) { List <SecPolicy> list = new List <SecPolicy> () { policy, rev }; trust.SetPolicies(list); var policies = trust.GetPolicies(); Assert.That(policies.Length, Is.EqualTo(2), "Policies.Length"); } } } }
public void RevocationPolicy() { TestRuntime.AssertXcodeVersion(5, 0); using (var policy = SecPolicy.CreateRevocationPolicy(SecRevocation.UseAnyAvailableMethod | SecRevocation.RequirePositiveResponse)) { Assert.That(policy.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle"); Assert.That(CFGetRetainCount(policy.Handle), Is.EqualTo((nint)1), "RetainCount"); using (var properties = policy.GetProperties()) { Assert.That(properties.Handle, Is.Not.EqualTo(IntPtr.Zero), "Properties.Handle"); Assert.That(CFGetRetainCount(properties.Handle), Is.EqualTo((nint)1), "Properties.RetainCount"); Assert.That(properties.Count, Is.EqualTo((nuint)1), "Count"); Assert.That(properties [SecPolicyPropertyKey.Oid].ToString(), Is.EqualTo("1.2.840.113635.100.1.21"), "SecPolicyOid"); } } }
public void RevocationPolicy () { TestRuntime.AssertXcodeVersion (5, 0); TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 10, 9, throwIfOtherPlatform: false); using (var policy = SecPolicy.CreateRevocationPolicy (SecRevocation.UseAnyAvailableMethod | SecRevocation.RequirePositiveResponse)) { Assert.That (policy.Handle, Is.Not.EqualTo (IntPtr.Zero), "Handle"); Assert.That (CFGetRetainCount (policy.Handle), Is.EqualTo ((nint) 1), "RetainCount"); using (var properties = policy.GetProperties ()) { Assert.That (properties.Handle, Is.Not.EqualTo (IntPtr.Zero), "Properties.Handle"); Assert.That (CFGetRetainCount (properties.Handle), Is.EqualTo ((nint) 1), "Properties.RetainCount"); var expectedCount = (nuint) 1; #if __MACOS__ if (TestRuntime.CheckSystemVersion (PlatformName.MacOSX, 10, 11) && !TestRuntime.CheckSystemVersion (PlatformName.MacOSX, 10, 12)) expectedCount = 2; #endif Assert.That (properties.Count, Is.EqualTo (expectedCount), "Count"); Assert.That (properties [SecPolicyPropertyKey.Oid].ToString (), Is.EqualTo ("1.2.840.113635.100.1.21"), "SecPolicyOid"); } } }