public void Test_CertificateValidationCallBack() { Assert.True(HttpClientUtils.CertificateValidationCallBack(null, new X509Certificate2Collection(), null, null, System.Net.Security.SslPolicyErrors.None)); string cert = @"-----BEGIN CERTIFICATE----- MIICVDCCAb0CFAexGL8aJihganALdhlA3+2PuEE4MA0GCSqGSIb3DQEBCwUAMGkx CzAJBgNVBAYTAmFhMQswCQYDVQQIDAJiYjELMAkGA1UEBwwCY2MxCzAJBgNVBAoM AmRkMQswCQYDVQQLDAJlZTELMAkGA1UEAwwCZmYxGTAXBgkqhkiG9w0BCQEWCmFs aUBxcS5jb20wHhcNMjAxMDIxMDE1NzA0WhcNMjExMDIxMDE1NzA0WjBpMQswCQYD VQQGEwJhYTELMAkGA1UECAwCYmIxCzAJBgNVBAcMAmNjMQswCQYDVQQKDAJkZDEL MAkGA1UECwwCZWUxCzAJBgNVBAMMAmZmMRkwFwYJKoZIhvcNAQkBFgphbGlAcXEu Y29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDmTJt4TNH5FcpJ0Lj6cIX IDrkjqveRjg62TT4vBV1UzV/W3hIaMYWTrW3LyqQMq3kIPNbjyJoZlfXosRjhW/Z B1Xxl0rtCvp6YSKy2N+wSvyM5pyWhHXg0xoSQYg9aIqOel67ZRqF/XcADjXCAFNq 4nxY1jb2YiaP1q24QpKWPQIDAQABMA0GCSqGSIb3DQEBCwUAA4GBACRTgas7Q0KV TcUDwSdWCCoTHVDpsk7kFZF+tVFsssCnA5RKqf6WsCncnHP+T7hSnX3ZfNwg6DFv PoE+j53QJ5tkE0TEmffzXaywsKh9rwK4GRaOUTc43cWQU4G6Yv0uWzmgO/Xx9XJ7 juPBOeucQtbgVjyRswrYbqGR6vdBgA+a -----END CERTIFICATE-----"; string certErr = @"-----BEGIN CERTIFICATE----- MIIBuDCCAWICCQCLw4OWpjlJCDANBgkqhkiG9w0BAQsFADBjMQswCQYDVQQGEwJm ZDEMMAoGA1UECAwDYXNkMQswCQYDVQQHDAJxcjEKMAgGA1UECgwBZjEMMAoGA1UE CwwDc2RhMQswCQYDVQQDDAJmZDESMBAGCSqGSIb3DQEJARYDYXNkMB4XDTIwMTAx OTAyNDQwNFoXDTIzMDgwOTAyNDQwNFowYzELMAkGA1UEBhMCZmQxDDAKBgNVBAgM A2FzZDELMAkGA1UEBwwCcXIxCjAIBgNVBAoMAWYxDDAKBgNVBAsMA3NkYTELMAkG A1UEAwwCZmQxEjAQBgkqhkiG9w0BCQEWA2FzZDBcMA0GCSqGSIb3DQEBAQUAA0sA MEgCQQCxXZTl5IO61Lqd0fBBOSy7ER1gsdA0LkvflP5HEaQygjecLGfrAtD/DWu0 /sxCcBVnQRoP9Yp0ijHJwgXvBnrNAgMBAAEwDQYJKoZIhvcNAQELBQADQQBJF+/4 DEMilhlFY+o9mqCygFVxuvHtQVhpPS938H2h7/P6pXN65jK2Y5hHefZEELq9ulQe 91iBwaQ4e9racCgP -----END CERTIFICATE-----"; byte[] certBytes = Encoding.UTF8.GetBytes(cert); byte[] certErrBytes = Encoding.UTF8.GetBytes(certErr); Assert.False(HttpClientUtils.CertificateValidationCallBack(null, new X509Certificate2Collection(), new X509Certificate2(certBytes), new X509Chain(), System.Net.Security.SslPolicyErrors.RemoteCertificateChainErrors)); var collection = new X509Certificate2Collection(); collection.Add(new X509Certificate2(certErrBytes)); Assert.False(HttpClientUtils.CertificateValidationCallBack(null, collection, new X509Certificate2(certBytes), new X509Chain(), System.Net.Security.SslPolicyErrors.RemoteCertificateChainErrors)); collection = new X509Certificate2Collection(); collection.Add(new X509Certificate2(certBytes)); Assert.True(HttpClientUtils.CertificateValidationCallBack(null, collection, new X509Certificate2(certBytes), new X509Chain(), System.Net.Security.SslPolicyErrors.RemoteCertificateChainErrors)); }