summaryrefslogtreecommitdiff
path: root/tests/x509cert.c
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2017-08-21 07:56:58 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2017-08-21 08:25:51 +0200
commit6b1c00db487e51e80b10126cf7f91a88d3dbfa2f (patch)
treeba34e328715d5a639407b336ae4324ccdd77df27 /tests/x509cert.c
parent0c200934da6501d1f151e46faa86bca4e7d04680 (diff)
downloadgnutls-6b1c00db487e51e80b10126cf7f91a88d3dbfa2f.tar.gz
tests: verify the output size of gnutls_x509_privkey_export
That is, make sure that gnutls_x509_privkey_export() and gnutls_x509_privkey_export2() agrees with the strlen() value on the data. Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
Diffstat (limited to 'tests/x509cert.c')
-rw-r--r--tests/x509cert.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/x509cert.c b/tests/x509cert.c
index 13f0ed3aaf..fe38fc2af6 100644
--- a/tests/x509cert.c
+++ b/tests/x509cert.c
@@ -52,6 +52,7 @@ static void tls_log_func(int level, const char *str)
fprintf(stderr, "<%d>| %s", level, str);
}
+static char buf[16*1024];
#define LIST_SIZE 3
void doit(void)
@@ -64,6 +65,7 @@ void doit(void)
char dn[128];
size_t dn_size;
unsigned int list_size;
+ size_t buf_size;
gnutls_x509_privkey_t get_key;
gnutls_x509_crt_t *get_crts;
@@ -157,8 +159,31 @@ void doit(void)
get_datum.data, server_ca3_key.data);
}
+ if (strlen((char*)get_datum.data) != get_datum.size) {
+ fail("exported key %u vs. %u\n\n%s\n",
+ get_datum.size, (unsigned)strlen((char*)get_datum.data),
+ get_datum.data);
+ }
+
gnutls_free(get_datum.data);
+ buf_size = sizeof(buf);
+ ret =
+ gnutls_x509_privkey_export(get_key,
+ GNUTLS_X509_FMT_PEM,
+ buf, &buf_size);
+ if (ret < 0)
+ fail("gnutls_x509_privkey_export");
+
+ if (buf_size != get_datum.size ||
+ buf_size != strlen(buf) ||
+ memcmp(buf, server_ca3_key.data, buf_size) != 0) {
+ fail(
+ "exported key %u vs. %u\n\n%s\n\nvs.\n\n%s",
+ (int)buf_size, server_ca3_key.size,
+ buf, server_ca3_key.data);
+ }
+
ret =
gnutls_certificate_get_x509_crt(x509_cred, 0, &get_crts, &n_get_crts);
if (ret < 0)