[glib: 2/4] tests/tls-certificate: Add PEM files containing CRLF



commit 73ca761a8d7461a79ebe62ad97ae0d6054f20822
Author: Fredrik Ternerot <fredrikt axis com>
Date:   Tue Dec 18 11:21:19 2018 +0100

    tests/tls-certificate: Add PEM files containing CRLF
    
    Add test case to ensure correct parsing of PEM files containing CRLF
    (\r\n) line endings.

 gio/tests/Makefile.am              |  2 ++
 gio/tests/cert-tests/cert-crlf.pem | 17 +++++++++++++++
 gio/tests/cert-tests/key-crlf.pem  | 15 ++++++++++++++
 gio/tests/tls-certificate.c        | 42 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 76 insertions(+)
---
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
index 15ab66e93..0ad61e4d1 100644
--- a/gio/tests/Makefile.am
+++ b/gio/tests/Makefile.am
@@ -228,11 +228,13 @@ cert_tests = \
        cert1.pem       \
        cert2.pem       \
        cert3.pem       \
+       cert-crlf.pem   \
        cert-key.pem    \
        cert-list.pem   \
        key8.pem        \
        key-cert.pem    \
        key.pem         \
+       key-crlf.pem    \
        nothing.pem     \
        $(NULL)
 
diff --git a/gio/tests/cert-tests/cert-crlf.pem b/gio/tests/cert-tests/cert-crlf.pem
new file mode 100644
index 000000000..c54f4488e
--- /dev/null
+++ b/gio/tests/cert-tests/cert-crlf.pem
@@ -0,0 +1,17 @@
+-----BEGIN CERTIFICATE-----
+MIICtTCCAh4CCQCMmwFMUPAJYzANBgkqhkiG9w0BAQUFADCBnjELMAkGA1UEBhMC
+Q0ExDzANBgNVBAgMBlF1ZWJlYzERMA8GA1UEBwwITW9udHJlYWwxFzAVBgNVBAoM
+DkNvbGxhYm9yYSBMdGQuMQ8wDQYDVQQLDAZDYW5hZGExEjAQBgNVBAMMCTEyNy4w
+LjAuMTEtMCsGCSqGSIb3DQEJARYebmljb2xhcy5kdWZyZXNuZUBjb2xsYWJvcmEu
+Y29tMB4XDTExMDcyNTE4NDkzNFoXDTEyMDcyNDE4NDkzNFowgZ4xCzAJBgNVBAYT
+AkNBMQ8wDQYDVQQIDAZRdWViZWMxETAPBgNVBAcMCE1vbnRyZWFsMRcwFQYDVQQK
+DA5Db2xsYWJvcmEgTHRkLjEPMA0GA1UECwwGQ2FuYWRhMRIwEAYDVQQDDAkxMjcu
+MC4wLjExLTArBgkqhkiG9w0BCQEWHm5pY29sYXMuZHVmcmVzbmVAY29sbGFib3Jh
+LmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEArJa05foKd5ULBBjHoI4U
+DKMOcoYp6UO8o4t+rKBrlKVMp0D7Oz+bZt6I2T3kBjZmKH9wrHNsk6zC6wonbfMR
+ZHILWcnTifbEEhIMHNqH+J5b33yGW3SEftd1jj1UZkubQVZEFha5UhbUO9AQ4TSt
+0mX5AG+PkJi0kdTCRWlD1q0CAwEAATANBgkqhkiG9w0BAQUFAAOBgQCaaBfCfCiw
+BJ/2pzZOjoFQcMqwPWufJ+F7hv8AK0zaEhsYW/JPPNpVVjM4Rf9dhMFG513GQ6IR
+q3K+okin/2H6XyLD1eyAxAreuyMZPwOsTdgkVROhl+NJEfZKnFZSxK9wkiQRnNhS
++5L8/na5o3vsgGerggQi8pj2JjfVE0R/aQ==
+-----END CERTIFICATE-----
diff --git a/gio/tests/cert-tests/key-crlf.pem b/gio/tests/cert-tests/key-crlf.pem
new file mode 100644
index 000000000..ddb7fd13a
--- /dev/null
+++ b/gio/tests/cert-tests/key-crlf.pem
@@ -0,0 +1,15 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXQIBAAKBgQCslrTl+gp3lQsEGMegjhQMow5yhinpQ7yji36soGuUpUynQPs7
+P5tm3ojZPeQGNmYof3Csc2yTrMLrCidt8xFkcgtZydOJ9sQSEgwc2of4nlvffIZb
+dIR+13WOPVRmS5tBVkQWFrlSFtQ70BDhNK3SZfkAb4+QmLSR1MJFaUPWrQIDAQAB
+AoGAUTnskYAIhRdEQ/1Vlp7HmNr05bl26C3VDjOMvroRZ7gUR3MxykS5YsTBK10R
+gEsB8XVpFgCMzUO1yODShdCsEg9kCB3fzSWkunK8+TF2TKOM5uWlQwifKJvcNisR
+Nbg3r8WygMMXaWSFA3xWoRuZ5It0jOX18v+x5RHHon/kaRECQQDl6FSwgJLeNAkR
+pMNQGdRhmMesHWmNNBv3Wozqm6Wpkwo5ZXPsLt3pprd0GN5jX0IG7clT1/eMD9/G
++3UGqTj3AkEAwC0M2gv+QUhbaB+KSlOZDOi4gsnhnsnaM7HQGDJJ5no4y2EvnYI3
+Y5rPJWedeYlCV3ccMitjnjcIJHInRZBIewJBANgsamVDn9Ua7GQQni1U/COAek7V
+oQfKNXmRROrbyxr1TSnGwQcU0kf+IIUjVQfu67CEKUeSzAqAapM4oULQHuUCQQC9
+J9qdiO6DXXAzRdA9pplgHnT2rzV3sSEoft3f4yfgRu8+KHPQqkpQrSE1pQ5YgWUe
+aGwFabXNFkfab839562fAkBl8jPidQdKWEgSa6h5pm4++sXLdWl7p6jiyetH64W7
+HnhRryE3ptrRGO0hSV1v4bx3DKzeJiJRlWUWiSl7828t
+-----END RSA PRIVATE KEY-----
diff --git a/gio/tests/tls-certificate.c b/gio/tests/tls-certificate.c
index 39e9c77df..02bcf5eec 100644
--- a/gio/tests/tls-certificate.c
+++ b/gio/tests/tls-certificate.c
@@ -27,7 +27,9 @@
 typedef struct
 {
   gchar *cert_pems[3];
+  gchar *cert_crlf_pem;
   gchar *key_pem;
+  gchar *key_crlf_pem;
   gchar *key8_pem;
 } Reference;
 
@@ -277,6 +279,32 @@ from_files (const Reference *ref)
   g_object_unref (cert);
 }
 
+static void
+from_files_crlf (const Reference *ref)
+{
+  GTlsCertificate *cert;
+  gchar *parsed_cert_pem = NULL;
+  const gchar *parsed_key_pem = NULL;
+  GError *error = NULL;
+
+  cert = g_tls_certificate_new_from_files (g_test_get_filename (G_TEST_DIST, "cert-tests", "cert-crlf.pem", 
NULL),
+                                           g_test_get_filename (G_TEST_DIST, "cert-tests", "key-crlf.pem", 
NULL),
+                                           &error);
+  g_assert_no_error (error);
+  g_assert_nonnull (cert);
+
+  g_object_get (cert,
+      "certificate-pem", &parsed_cert_pem,
+      NULL);
+  parsed_key_pem = g_test_tls_connection_get_private_key_pem (cert);
+  g_assert_cmpstr (parsed_cert_pem, ==, ref->cert_crlf_pem);
+  g_free (parsed_cert_pem);
+  parsed_cert_pem = NULL;
+  g_assert_cmpstr (parsed_key_pem, ==, ref->key_crlf_pem);
+  parsed_key_pem = NULL;
+
+  g_object_unref (cert);
+}
 
 static void
 from_files_pkcs8 (const Reference *ref)
@@ -368,11 +396,21 @@ main (int   argc,
   g_assert_no_error (error);
   g_assert_nonnull (ref.cert_pems[2]);
   g_free (path);
+  path = g_test_build_filename (G_TEST_DIST, "cert-tests", "cert-crlf.pem", NULL);
+  g_file_get_contents (path, &ref.cert_crlf_pem, NULL, &error);
+  g_assert_no_error (error);
+  g_assert_nonnull (ref.cert_crlf_pem);
+  g_free (path);
   path = g_test_build_filename (G_TEST_DIST, "cert-tests", "key.pem", NULL);
   g_file_get_contents (path, &ref.key_pem, NULL, &error);
   g_assert_no_error (error);
   g_assert_nonnull (ref.key_pem);
   g_free (path);
+  path = g_test_build_filename (G_TEST_DIST, "cert-tests", "key-crlf.pem", NULL);
+  g_file_get_contents (path, &ref.key_crlf_pem, NULL, &error);
+  g_assert_no_error (error);
+  g_assert_nonnull (ref.key_crlf_pem);
+  g_free (path);
   path = g_test_build_filename (G_TEST_DIST, "cert-tests", "key8.pem", NULL);
   g_file_get_contents (path, &ref.key8_pem, NULL, &error);
   g_assert_no_error (error);
@@ -387,6 +425,8 @@ main (int   argc,
                         &ref, (GTestDataFunc)from_file);
   g_test_add_data_func ("/tls-certificate/from_files",
                         &ref, (GTestDataFunc)from_files);
+  g_test_add_data_func ("/tls-certificate/from_files_crlf",
+                        &ref, (GTestDataFunc)from_files_crlf);
   g_test_add_data_func ("/tls-certificate/from_files_pkcs8",
                         &ref, (GTestDataFunc)from_files_pkcs8);
   g_test_add_data_func ("/tls-certificate/list_from_file",
@@ -397,7 +437,9 @@ main (int   argc,
   g_free (ref.cert_pems[0]);
   g_free (ref.cert_pems[1]);
   g_free (ref.cert_pems[2]);
+  g_free (ref.cert_crlf_pem);
   g_free (ref.key_pem);
+  g_free (ref.key_crlf_pem);
   g_free (ref.key8_pem);
 
   return rtv;


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