X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=test%2Fcrltest.c;h=6a2ef4e90d1f044015122b2437c6abc7828942a4;hp=720c13b3a2d1ac1911944addebdfddf625f40da9;hb=a727627922b8a9ec6628ffaa2054b4b3833d674b;hpb=ad887416f1e59c3294a7d8f83a0ca77120523b4a diff --git a/test/crltest.c b/test/crltest.c index 720c13b3a2..6a2ef4e90d 100644 --- a/test/crltest.c +++ b/test/crltest.c @@ -1,13 +1,13 @@ /* * Copyright 2015-2017 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ -#include "../e_os.h" +#include "internal/nelem.h" #include #include #include @@ -187,20 +187,11 @@ static X509 *test_leaf = NULL; * Glue an array of strings together. Return a BIO and put the string * into |*out| so we can free it. */ -static BIO *glue(const char **pem, char **out) +static BIO *glue2bio(const char **pem, char **out) { - char *dest; - int i; size_t s = 0; - /* Glue the strings together. */ - for (i = 0; pem[i] != NULL; ++i) - s += strlen(pem[i]); - dest = *out = OPENSSL_malloc(s + 1); - if (dest == NULL) - return NULL; - for (i = 0; pem[i] != NULL; ++i) - dest += strlen(strcpy(dest, pem[i])); + *out = glue_strings(pem, &s); return BIO_new_mem_buf(*out, s); } @@ -210,7 +201,7 @@ static BIO *glue(const char **pem, char **out) static X509_CRL *CRL_from_strings(const char **pem) { char *p; - BIO *b = glue(pem, &p); + BIO *b = glue2bio(pem, &p); X509_CRL *crl = PEM_read_bio_X509_CRL(b, NULL, NULL, NULL); OPENSSL_free(p); @@ -224,7 +215,7 @@ static X509_CRL *CRL_from_strings(const char **pem) static X509 *X509_from_strings(const char **pem) { char *p; - BIO *b = glue(pem, &p); + BIO *b = glue2bio(pem, &p); X509 *x = PEM_read_bio_X509(b, NULL, NULL, NULL); OPENSSL_free(p); @@ -261,12 +252,13 @@ static int verify(X509 *leaf, X509 *root, STACK_OF(X509_CRL) *crls, X509_STORE_CTX_set0_trusted_stack(ctx, roots); X509_STORE_CTX_set0_crls(ctx, crls); X509_VERIFY_PARAM_set_time(param, PARAM_TIME); - if (!TEST_long_eq(X509_VERIFY_PARAM_get_time(param), PARAM_TIME)) + if (!TEST_long_eq((long)X509_VERIFY_PARAM_get_time(param), PARAM_TIME)) goto err; X509_VERIFY_PARAM_set_depth(param, 16); if (flags) X509_VERIFY_PARAM_set_flags(param, flags); X509_STORE_CTX_set0_param(ctx, param); + param = NULL; ERR_clear_error(); status = X509_verify_cert(ctx) == 1 ? X509_V_OK @@ -274,6 +266,7 @@ static int verify(X509 *leaf, X509 *root, STACK_OF(X509_CRL) *crls, err: sk_X509_pop_free(roots, X509_free); sk_X509_CRL_pop_free(crls, X509_CRL_free); + X509_VERIFY_PARAM_free(param); X509_STORE_CTX_free(ctx); X509_STORE_free(store); return status; @@ -364,6 +357,20 @@ static int test_unknown_critical_crl(int n) return r; } +static int test_reuse_crl(void) +{ + X509_CRL *reused_crl = CRL_from_strings(kBasicCRL); + char *p; + BIO *b = glue2bio(kRevokedCRL, &p); + + reused_crl = PEM_read_bio_X509_CRL(b, &reused_crl, NULL, NULL); + + OPENSSL_free(p); + BIO_free(b); + X509_CRL_free(reused_crl); + return 1; +} + int setup_tests(void) { if (!TEST_ptr(test_root = X509_from_strings(kCRLTestRoot)) @@ -375,6 +382,7 @@ int setup_tests(void) ADD_TEST(test_bad_issuer_crl); ADD_TEST(test_known_critical_crl); ADD_ALL_TESTS(test_unknown_critical_crl, OSSL_NELEM(unknown_critical_crls)); + ADD_TEST(test_reuse_crl); return 1; }