Skip to content

Commit a4c199d

Browse files
committed
x509storeissuer: tolerate X509_STORE_CTX_get1_issuer() successes, count and report successful calls
Signed-off-by: Eugene Syromiatnikov <[email protected]>
1 parent effd1b7 commit a4c199d

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

source/x509storeissuer.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ static X509 *x509_nonce = NULL;
5858
static int threadcount;
5959

6060
size_t *counts;
61+
size_t *founds;
6162
OSSL_TIME max_time;
6263

6364
static X509 *
@@ -150,6 +151,7 @@ do_x509storeissuer(size_t num)
150151
X509 *issuer = NULL;
151152
OSSL_TIME time = ossl_time_now();
152153
size_t count = 0;
154+
size_t found = 0;
153155

154156
if (ctx == NULL || !X509_STORE_CTX_init(ctx, store, x509_nonce, NULL)) {
155157
warnx("Failed to initialise X509_STORE_CTX");
@@ -158,16 +160,9 @@ do_x509storeissuer(size_t num)
158160
}
159161

160162
do {
161-
/*
162-
* We actually expect this to fail. We've not configured any
163-
* certificates inside our store. We're just testing calling this
164-
* against an empty store.
165-
*/
166163
if (X509_STORE_CTX_get1_issuer(&issuer, ctx, x509_nonce) != 0) {
167-
warnx("Unexpected result from X509_STORE_CTX_get1_issuer");
168-
error = 1;
164+
found++;
169165
X509_free(issuer);
170-
goto err;
171166
}
172167
issuer = NULL;
173168
count++;
@@ -179,6 +174,7 @@ do_x509storeissuer(size_t num)
179174
X509_STORE_CTX_free(ctx);
180175

181176
counts[num] = count;
177+
founds[num] = found;
182178
}
183179

184180
static void
@@ -258,6 +254,7 @@ main(int argc, char *argv[])
258254
int i;
259255
OSSL_TIME duration;
260256
size_t total_count = 0;
257+
size_t total_found = 0;
261258
double avcalltime;
262259
char *cert = NULL;
263260
int ret = EXIT_FAILURE;
@@ -318,6 +315,10 @@ main(int argc, char *argv[])
318315
if (counts == NULL)
319316
errx(EXIT_FAILURE, "Failed to create counts array");
320317

318+
founds = OPENSSL_malloc(sizeof(size_t) * threadcount);
319+
if (founds == NULL)
320+
errx(EXIT_FAILURE, "Failed to create founds array");
321+
321322
x509_nonce = make_nonce(&nonce_cfg);
322323
if (x509_nonce == NULL)
323324
errx(EXIT_FAILURE, "Unable to create the nonce X509 object");
@@ -330,8 +331,10 @@ main(int argc, char *argv[])
330331
if (error)
331332
errx(EXIT_FAILURE, "Error during test");
332333

333-
for (i = 0; i < threadcount; i++)
334+
for (i = 0; i < threadcount; i++) {
334335
total_count += counts[i];
336+
total_found += founds[i];
337+
}
335338

336339
avcalltime = (double)timeout_us * threadcount / total_count;
337340

@@ -342,6 +345,12 @@ main(int argc, char *argv[])
342345
default:
343346
printf("Average time per X509_STORE_CTX_get1_issuer() call: %lfus\n",
344347
avcalltime);
348+
if (verbosity >= VERBOSITY_VERBOSE) {
349+
printf("Successful X509_STORE_CTX_get1_issuer() calls: %zu of %zu"
350+
" (%lf%%)\n",
351+
total_found, total_count,
352+
(double)total_found / total_count * 100.0);
353+
}
345354
}
346355

347356
ret = EXIT_SUCCESS;
@@ -351,6 +360,7 @@ main(int argc, char *argv[])
351360
X509_STORE_free(store);
352361
BIO_free(bio);
353362
OPENSSL_free(cert);
363+
OPENSSL_free(founds);
354364
OPENSSL_free(counts);
355365
return ret;
356366
}

0 commit comments

Comments
 (0)