summaryrefslogtreecommitdiff
path: root/tests/set_x509_key_utf8.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/set_x509_key_utf8.c')
-rw-r--r--tests/set_x509_key_utf8.c71
1 files changed, 43 insertions, 28 deletions
diff --git a/tests/set_x509_key_utf8.c b/tests/set_x509_key_utf8.c
index d5354871be..c93f61eaa8 100644
--- a/tests/set_x509_key_utf8.c
+++ b/tests/set_x509_key_utf8.c
@@ -22,7 +22,7 @@
/* Parts copied from GnuTLS example programs. */
#ifdef HAVE_CONFIG_H
-#include <config.h>
+# include <config.h>
#endif
#include <stdio.h>
@@ -30,10 +30,10 @@
#include <string.h>
#include <sys/types.h>
#if !defined(_WIN32)
-#include <netinet/in.h>
-#include <sys/socket.h>
-#include <sys/wait.h>
-#include <arpa/inet.h>
+# include <netinet/in.h>
+# include <sys/socket.h>
+# include <sys/wait.h>
+# include <arpa/inet.h>
#endif
#include <unistd.h>
#include <assert.h>
@@ -64,9 +64,9 @@ static time_t mytime(time_t * t)
return then;
}
-static void compare(const gnutls_datum_t *der, const void *ipem)
+static void compare(const gnutls_datum_t * der, const void *ipem)
{
- gnutls_datum_t pem = {(void*)ipem, strlen((char*)ipem)};
+ gnutls_datum_t pem = { (void *)ipem, strlen((char *)ipem) };
gnutls_datum_t new_der;
int ret;
@@ -75,7 +75,8 @@ static void compare(const gnutls_datum_t *der, const void *ipem)
fail("error: %s\n", gnutls_strerror(ret));
}
- if (der->size != new_der.size || memcmp(der->data, new_der.data, der->size) != 0) {
+ if (der->size != new_der.size
+ || memcmp(der->data, new_der.data, der->size) != 0) {
fail("error in %d: %s\n", __LINE__, "cert don't match");
exit(1);
}
@@ -83,7 +84,8 @@ static void compare(const gnutls_datum_t *der, const void *ipem)
return;
}
-static int import_key(gnutls_certificate_credentials_t xcred, const gnutls_datum_t *skey, const gnutls_datum_t *cert)
+static int import_key(gnutls_certificate_credentials_t xcred,
+ const gnutls_datum_t * skey, const gnutls_datum_t * cert)
{
gnutls_x509_privkey_t key;
gnutls_x509_crt_t *crt_list;
@@ -91,11 +93,14 @@ static int import_key(gnutls_certificate_credentials_t xcred, const gnutls_datum
gnutls_datum_t tcert;
int ret;
- assert(gnutls_x509_privkey_init(&key)>=0);
+ assert(gnutls_x509_privkey_init(&key) >= 0);
- ret = gnutls_x509_crt_list_import2(&crt_list, &crt_list_size, cert, GNUTLS_X509_FMT_PEM, 0);
+ ret =
+ gnutls_x509_crt_list_import2(&crt_list, &crt_list_size, cert,
+ GNUTLS_X509_FMT_PEM, 0);
if (ret < 0) {
- fail("error in gnutls_x509_crt_list_import2: %s\n", gnutls_strerror(ret));
+ fail("error in gnutls_x509_crt_list_import2: %s\n",
+ gnutls_strerror(ret));
}
ret = gnutls_x509_privkey_import(key, skey, GNUTLS_X509_FMT_PEM);
@@ -104,9 +109,10 @@ static int import_key(gnutls_certificate_credentials_t xcred, const gnutls_datum
}
ret = gnutls_certificate_set_x509_key(xcred, crt_list,
- crt_list_size, key);
+ crt_list_size, key);
if (ret < 0) {
- success("error in gnutls_certificate_set_x509_key: %s\n", gnutls_strerror(ret));
+ success("error in gnutls_certificate_set_x509_key: %s\n",
+ gnutls_strerror(ret));
idx = ret;
goto cleanup;
}
@@ -115,19 +121,20 @@ static int import_key(gnutls_certificate_credentials_t xcred, const gnutls_datum
idx = ret;
/* verify whether the stored certificate match the ones we have */
- for (i=0;i<MIN(2, crt_list_size);i++) {
+ for (i = 0; i < MIN(2, crt_list_size); i++) {
ret = gnutls_certificate_get_crt_raw(xcred, idx, i, &tcert);
if (ret < 0) {
- fail("error in %d: cert: %d: %s\n", __LINE__, i, gnutls_strerror(ret));
+ fail("error in %d: cert: %d: %s\n", __LINE__, i,
+ gnutls_strerror(ret));
exit(1);
}
- compare(&tcert, cert->data+i);
+ compare(&tcert, cert->data + i);
}
cleanup:
gnutls_x509_privkey_deinit(key);
- for (i=0;i<crt_list_size;i++) {
+ for (i = 0; i < crt_list_size; i++) {
gnutls_x509_crt_deinit(crt_list[i]);
}
gnutls_free(crt_list);
@@ -157,26 +164,35 @@ void doit(void)
gnutls_global_set_log_level(6);
assert(gnutls_certificate_allocate_credentials(&clicred) >= 0);
- assert(gnutls_certificate_allocate_credentials(&x509_cred)>=0);
+ assert(gnutls_certificate_allocate_credentials(&x509_cred) >= 0);
gnutls_certificate_set_flags(x509_cred, GNUTLS_CERTIFICATE_API_V2);
- ret = gnutls_certificate_set_x509_trust_mem(clicred, &ca3_cert, GNUTLS_X509_FMT_PEM);
+ ret =
+ gnutls_certificate_set_x509_trust_mem(clicred, &ca3_cert,
+ GNUTLS_X509_FMT_PEM);
if (ret < 0)
fail("set_x509_trust_file failed: %s\n", gnutls_strerror(ret));
- idx = import_key(x509_cred, &server_ca3_key, &server_ca3_localhost_cert_chain);
+ idx =
+ import_key(x509_cred, &server_ca3_key,
+ &server_ca3_localhost_cert_chain);
assert(idx == 0);
- idx = import_key(x509_cred, &server_ca3_key, &server_ca3_localhost_utf8_cert);
+ idx =
+ import_key(x509_cred, &server_ca3_key,
+ &server_ca3_localhost_utf8_cert);
assert(idx == 1);
- test_cli_serv(x509_cred, clicred, "NORMAL", "localhost", NULL, NULL, NULL);
- test_cli_serv(x509_cred, clicred, "NORMAL", "www.xn--kxawhku.com", NULL, NULL, NULL); /* the previous name in IDNA format */
- test_cli_serv(x509_cred, clicred, "NORMAL", "简体中文.εξτρα.com", NULL, NULL, NULL); /* the second DNS name of cert */
- test_cli_serv(x509_cred, clicred, "NORMAL", "xn--fiqu1az03c18t.xn--mxah1amo.com", NULL, NULL, NULL); /* its IDNA equivalent */
+ test_cli_serv(x509_cred, clicred, "NORMAL", "localhost", NULL, NULL,
+ NULL);
+ test_cli_serv(x509_cred, clicred, "NORMAL", "www.xn--kxawhku.com", NULL, NULL, NULL); /* the previous name in IDNA format */
+ test_cli_serv(x509_cred, clicred, "NORMAL", "简体中文.εξτρα.com", NULL, NULL, NULL); /* the second DNS name of cert */
+ test_cli_serv(x509_cred, clicred, "NORMAL", "xn--fiqu1az03c18t.xn--mxah1amo.com", NULL, NULL, NULL); /* its IDNA equivalent */
- test_cli_serv_expect(x509_cred, clicred, "NORMAL", "NORMAL", "raw:简体中文.εξτρα.com", GNUTLS_E_RECEIVED_DISALLOWED_NAME, GNUTLS_E_AGAIN);
+ test_cli_serv_expect(x509_cred, clicred, "NORMAL", "NORMAL",
+ "raw:简体中文.εξτρα.com",
+ GNUTLS_E_RECEIVED_DISALLOWED_NAME, GNUTLS_E_AGAIN);
gnutls_certificate_free_credentials(x509_cred);
gnutls_certificate_free_credentials(clicred);
@@ -186,4 +202,3 @@ void doit(void)
if (debug)
success("success");
}
-