[libsoup/carlosgc/client-side-certs2: 9/17] ssl-test: Add test for incorrect client cert




commit 86b0aef240a5b0e0fee546d670f060566d45091a
Author: Patrick Griffis <pgriffis igalia com>
Date:   Tue Apr 27 10:17:50 2021 -0500

    ssl-test: Add test for incorrect client cert

 tests/ssl-test.c      | 21 ++++++++++++++++++++-
 tests/test-cert-2.pem | 11 +++++++++++
 tests/test-key-2.pem  | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+), 1 deletion(-)
---
diff --git a/tests/ssl-test.c b/tests/ssl-test.c
index d0c222aa..909b3a20 100644
--- a/tests/ssl-test.c
+++ b/tests/ssl-test.c
@@ -252,7 +252,7 @@ do_tls_interaction_msg_test (gconstpointer data)
         SoupMessage *msg;
         GBytes *body;
         GTlsDatabase *tls_db;
-        GTlsCertificate *certificate;
+        GTlsCertificate *certificate, *wrong_certificate;
         GError *error = NULL;
 
         SOUP_TEST_SKIP_IF_NO_TLS;
@@ -330,10 +330,29 @@ do_tls_interaction_msg_test (gconstpointer data)
         g_bytes_unref (body);
         g_object_unref (msg);
 
+        /* Using the wrong certificate fails */
+        wrong_certificate = g_tls_certificate_new_from_files (
+                g_test_get_filename (G_TEST_DIST, "test-cert-2.pem", NULL),
+                g_test_get_filename (G_TEST_DIST, "test-key-2.pem", NULL),
+                NULL
+        );
+        g_assert_nonnull (wrong_certificate);
+        msg = soup_message_new_from_uri ("GET", uri);
+        soup_message_add_flags (msg, SOUP_MESSAGE_NEW_CONNECTION);
+        g_signal_connect (msg, "request-certificate",
+                          G_CALLBACK (request_certificate_async_cb),
+                          wrong_certificate);
+        body = soup_test_session_async_send (session, msg, NULL, &error);
+        g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CONNECTION_CLOSED);
+        g_assert_null (body);
+        g_clear_error (&error);
+        g_object_unref (msg);
+
         g_signal_handlers_disconnect_by_data (server, tls_db);
 
         soup_test_session_abort_unref (session);
         g_object_unref (certificate);
+        g_object_unref (wrong_certificate);
 }
 
 static void
diff --git a/tests/test-cert-2.pem b/tests/test-cert-2.pem
new file mode 100644
index 00000000..03d380ce
--- /dev/null
+++ b/tests/test-cert-2.pem
@@ -0,0 +1,11 @@
+-----BEGIN CERTIFICATE-----
+MIIBhTCCASygAwIBAgIUYreSy5OQ1jid5OVDi2wXTVlrBH4wCgYIKoZIzj0EAwIw
+FDESMBAGA1UEAxMJMTI3LjAuMC4xMB4XDTIxMDQyNzE1MDYzNloXDTMxMDQyNTE1
+MDY0MFowFDESMBAGA1UEAxMJMTI3LjAuMC4xMFkwEwYHKoZIzj0CAQYIKoZIzj0D
+AQcDQgAE3d+tXDYxqz8kzxJewzGkwXoBHgyiEyVphoJNVbqQyoFilkNY5l6WNbGo
+DVcM+Q2z8lS58xcfKh8VT+p1x0o6a6NcMFowDAYDVR0TAQH/BAIwADAaBgNVHREE
+EzARgglsb2NhbGhvc3SHBH8AAAEwDwYDVR0PAQH/BAUDAweAADAdBgNVHQ4EFgQU
+LM382FlLIZzriBFnIIqIA4eW4YswCgYIKoZIzj0EAwIDRwAwRAIgHEqJUod+Qa+L
+VpvhMohpiQSwnJHGqZfRqbAmJ46uIdECID8Nq4edInuyvnW8/EFPn36yj1m9cLgf
+EojA8aWwGE3J
+-----END CERTIFICATE-----
diff --git a/tests/test-key-2.pem b/tests/test-key-2.pem
new file mode 100644
index 00000000..4c8be668
--- /dev/null
+++ b/tests/test-key-2.pem
@@ -0,0 +1,32 @@
+Public Key Info:
+       Public Key Algorithm: EC/ECDSA
+       Key Security Level: High (256 bits)
+
+curve: SECP256R1
+private key:
+       00:bb:d3:dc:ab:06:8a:e4:89:20:20:7b:f3:e5:8e:17
+       83:b6:e2:1b:43:c9:1a:cf:15:61:56:03:78:67:24:2d
+       62:
+
+x:
+       00:dd:df:ad:5c:36:31:ab:3f:24:cf:12:5e:c3:31:a4
+       c1:7a:01:1e:0c:a2:13:25:69:86:82:4d:55:ba:90:ca
+       81:
+
+y:
+       62:96:43:58:e6:5e:96:35:b1:a8:0d:57:0c:f9:0d:b3
+       f2:54:b9:f3:17:1f:2a:1f:15:4f:ea:75:c7:4a:3a:6b
+       
+
+
+Public Key PIN:
+       pin-sha256:dplV8juw6nbgCKe4kCSy2MMcY1hSjUrjd0Ru4UU8MkI=
+Public Key ID:
+       sha256:769955f23bb0ea76e008a7b89024b2d8c31c6358528d4ae377446ee1453c3242
+       sha1:2ccdfcd8594b219ceb881167208a88038796e18b
+
+-----BEGIN EC PRIVATE KEY-----
+MHgCAQEEIQC709yrBorkiSAge/PljheDtuIbQ8kazxVhVgN4ZyQtYqAKBggqhkjO
+PQMBB6FEA0IABN3frVw2Mas/JM8SXsMxpMF6AR4MohMlaYaCTVW6kMqBYpZDWOZe
+ljWxqA1XDPkNs/JUufMXHyofFU/qdcdKOms=
+-----END EC PRIVATE KEY-----


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]