summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2016-11-23 08:17:13 +0100
committerNikos Mavrogiannopoulos <nmav@redhat.com>2016-11-25 12:03:37 +0100
commitda279ebcd239b747c5b45b001a4e3a44a0048275 (patch)
tree9abaaedfd0c431c8a4167b18bb7109eab697a2bb /tests
parent2a8fd21226c12ac3b41bfae9b5838574282e1107 (diff)
downloadgnutls-da279ebcd239b747c5b45b001a4e3a44a0048275.tar.gz
tests: updated crq_apis to include setting UTF-8 SAN
Diffstat (limited to 'tests')
-rw-r--r--tests/crq_apis.c79
1 files changed, 62 insertions, 17 deletions
diff --git a/tests/crq_apis.c b/tests/crq_apis.c
index 3b43e70bf2..99c02cb4cf 100644
--- a/tests/crq_apis.c
+++ b/tests/crq_apis.c
@@ -29,6 +29,7 @@
#include <string.h>
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
+#include <assert.h>
#include "utils.h"
@@ -37,23 +38,51 @@ static void tls_log_func(int level, const char *str)
fprintf(stderr, "%s |<%d>| %s", "crq_key_id", level, str);
}
+static unsigned char saved_crq_pem[] =
+ "-----BEGIN NEW CERTIFICATE REQUEST-----\n"
+ "MIICHTCCAYYCAQAwKzEOMAwGA1UEAxMFbmlrb3MxGTAXBgNVBAoTEG5vbmUgdG8s\n"
+ "IG1lbnRpb24wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALtmQ/Xyxde2jMzF\n"
+ "3/WIO7HJS2oOoa0gUEAIgKFPXKPQ+GzP5jz37AR2ExeLZIkiW8DdU3w77XwEu4C5\n"
+ "KL6Om8aOoKUSy/VXHqLnu7czSZ/ju0quak1o/8kR4jKNzj2AC41179gAgY8oBAOg\n"
+ "Io1hBAf6tjd9IQdJ0glhaZiQo1ipAgMBAAGggbEwEgYJKoZIhvcNAQkHMQUTA2Zv\n"
+ "bzCBmgYJKoZIhvcNAQkOMYGMMIGJMA8GA1UdEwEB/wQFMAMCAQAwDwYDVR0PAQH/\n"
+ "BAUDAwcAADAjBgNVHREEHDAaggNhcGGCA2Zvb4IOeG4tLWt4YXdoay5jb20wHQYD\n"
+ "VR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMAsGBCoDBAUEA8r+/zAUBggtA4KI\n"
+ "9LkXBQEB/wQFyv7/+v4wDQYJKoZIhvcNAQELBQADgYEAlspSTGu5KPL7iEQObEvs\n"
+ "+FMZpXnPDXyeJyiJFEfDaTDCpeHfZfMXUpPQEAxLjk5t8gPUxepQCjOizOuMD70k\n"
+ "jg8x97E8crA2mZ9Bk/eRhxvdXGN1hBdNzY6BGuPWifN/8dfE6O8wQkZDIZFcYxyr\n"
+ "V1VQd3moq0ge+tR9+xpPVWg=\n"
+ "-----END NEW CERTIFICATE REQUEST-----\n";
+
+const gnutls_datum_t saved_crq = { saved_crq_pem, sizeof(saved_crq_pem)-1 };
+
static unsigned char key_pem[] =
- "-----BEGIN RSA PRIVATE KEY-----\n"
- "MIICXAIBAAKBgQC7ZkP18sXXtozMxd/1iDuxyUtqDqGtIFBACIChT1yj0Phsz+Y8\n"
- "9+wEdhMXi2SJIlvA3VN8O+18BLuAuSi+jpvGjqClEsv1Vx6i57u3M0mf47tKrmpN\n"
- "aP/JEeIyjc49gAuNde/YAIGPKAQDoCKNYQQH+rY3fSEHSdIJYWmYkKNYqQIDAQAB\n"
- "AoGADpmARG5CQxS+AesNkGmpauepiCz1JBF/JwnyiX6vEzUh0Ypd39SZztwrDxvF\n"
- "PJjQaKVljml1zkJpIDVsqvHdyVdse8M+Qn6hw4x2p5rogdvhhIL1mdWo7jWeVJTF\n"
- "RKB7zLdMPs3ySdtcIQaF9nUAQ2KJEvldkO3m/bRJFEp54k0CQQDYy+RlTmwRD6hy\n"
- "7UtMjR0H3CSZJeQ8svMCxHLmOluG9H1UKk55ZBYfRTsXniqUkJBZ5wuV1L+pR9EK\n"
- "ca89a+1VAkEA3UmBelwEv2u9cAU1QjKjmwju1JgXbrjEohK+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TCqZD\n"
+ "ZXtl807ymCipgJm60LiAt0JLr4LiucAsMZz6+j+quQbSakbFCACB8SLV1QJBAKZQ\n"
+ "YKf+EPNtnmta/rRKKvySsi3GQZZN+Dt3q0r094XgeTsAqrqujVNfPhTMeP4qEVBX\n"
+ "/iVX2cmMTSh3w3z8MaECQEp0XJWDVKOwcTW6Ajp9SowtmiZ3YDYo1LF9igb4iaLv\n"
+ "sWZGfbnU3ryjvkb6YuFjgtzbZDZHWQCo8/cOtOBmPdk=\n"
+ "-----END RSA PRIVATE KEY-----\n";
+const gnutls_datum_t key = { key_pem, sizeof(key_pem)-1 };
+
+static time_t mytime(time_t * t)
+{
+ time_t then = 1207000800;
+
+ if (t)
+ *t = then;
+
+ return then;
+}
static gnutls_x509_crq_t generate_crq(void)
{
@@ -153,6 +182,11 @@ static gnutls_x509_crq_t generate_crq(void)
if (ret != 0)
fail("gnutls_x509_crq_set_subject_alt_name\n");
+ ret = gnutls_x509_crq_set_subject_alt_name(crq, GNUTLS_SAN_DNSNAME,
+ "νίκο.com", strlen("νίκο.com"), GNUTLS_FSAN_APPEND);
+ if (ret != 0)
+ fail("gnutls_x509_crq_set_subject_alt_name\n");
+
s = 0;
ret = gnutls_x509_crq_get_key_purpose_oid(crq, 0, NULL, &s, NULL);
if (ret != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE)
@@ -402,10 +436,21 @@ static void run_set_extension_by_oid(gnutls_x509_crq_t crq)
void doit(void)
{
- gnutls_x509_crq_t crq = generate_crq();
+ gnutls_datum_t out;
+ gnutls_x509_crq_t crq;
+
+ gnutls_global_set_time_function(mytime);
+
+ crq = generate_crq();
run_set_extensions(crq);
run_set_extension_by_oid(crq);
+ assert(gnutls_x509_crq_export2(crq, GNUTLS_X509_FMT_PEM, &out) >= 0);
+
+ assert(out.size == saved_crq.size);
+ assert(memcmp(out.data, saved_crq.data, out.size)==0);
+
+ gnutls_free(out.data);
gnutls_x509_crq_deinit(crq);
}