X-Git-Url: https://www.bearssl.org/gitweb//home/git/?p=BearSSL;a=blobdiff_plain;f=test%2Ftest_x509.c;h=c4f088588002f18370d04508e8bcbbf068c3a58b;hp=a591b46e992a0671bc44aea01c1452a6d58dc988;hb=e61ad42191511226309bad2cbde8cd9e8cc743cb;hpb=3210f38e0491b39aec1ef419cb4114e9483089fb diff --git a/test/test_x509.c b/test/test_x509.c index a591b46..c4f0885 100644 --- a/test/test_x509.c +++ b/test/test_x509.c @@ -258,6 +258,9 @@ HT_expand(HT *ht) n = ht->num_buckets; n2 = n << 1; new_buckets = xmalloc(n2 * sizeof *new_buckets); + for (u = 0; u < n2; u ++) { + new_buckets[u] = NULL; + } for (u = 0; u < n; u ++) { ht_elt *e, *f; @@ -509,7 +512,7 @@ static int string_to_time(const char *s, uint32_t *days, uint32_t *seconds) { int year, month, day, hour, minute, second; - int day_of_year, leaps; + int day_of_year, leaps, i; if (parse_dec(s, 4, &year) < 0) { return -1; @@ -568,7 +571,7 @@ string_to_time(const char *s, uint32_t *days, uint32_t *seconds) return -1; } day_of_year = 0; - for (int i = 1; i < month; i ++) { + for (i = 1; i < month; i ++) { day_of_year += month_length(year, i); } if (day < 1 || day > month_length(year, month)) { @@ -1435,6 +1438,7 @@ run_test_case(test_case *tc) blob *certs; br_x509_pkey *ee_pkey_ref; const br_x509_pkey *ee_pkey; + unsigned usages; unsigned status; printf("%s: ", tc->name); @@ -1474,8 +1478,8 @@ run_test_case(test_case *tc) tta->key_name); exit(EXIT_FAILURE); } - anchors[u].dn = tta->dn; - anchors[u].dn_len = tta->dn_len; + anchors[u].dn.data = tta->dn; + anchors[u].dn.len = tta->dn_len; anchors[u].flags = tta->flags; anchors[u].pkey = *tak; } @@ -1538,8 +1542,7 @@ run_test_case(test_case *tc) * Run the engine. We inject certificates by chunks of 100 bytes * in order to exercise the coroutine API. */ - ctx.vtable->start_chain(&ctx.vtable, - tc->key_type_usage, tc->servername); + ctx.vtable->start_chain(&ctx.vtable, tc->servername); for (u = 0; u < num_certs; u ++) { size_t v; @@ -1558,7 +1561,22 @@ run_test_case(test_case *tc) ctx.vtable->end_cert(&ctx.vtable); } status = ctx.vtable->end_chain(&ctx.vtable); - ee_pkey = ctx.vtable->get_pkey(&ctx.vtable); + ee_pkey = ctx.vtable->get_pkey(&ctx.vtable, &usages); + + /* + * Check key type and usage. + */ + if (ee_pkey != NULL) { + unsigned ktu; + + ktu = ee_pkey->key_type | usages; + if (tc->key_type_usage != (ktu & tc->key_type_usage)) { + fprintf(stderr, "wrong key type + usage" + " (expected 0x%02X, got 0x%02X)\n", + tc->key_type_usage, ktu); + exit(EXIT_FAILURE); + } + } /* * Check results. Note that we may still get a public key if