xref: /freebsd-src/crypto/openssl/test/x509_dup_cert_test.c (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1*e0c4386eSCy Schubert /*
2*e0c4386eSCy Schubert  * Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved.
3*e0c4386eSCy Schubert  * Copyright (c) 2017, Oracle and/or its affiliates.  All rights reserved.
4*e0c4386eSCy Schubert  *
5*e0c4386eSCy Schubert  * Licensed under the Apache License 2.0 (the "License").  You may not use
6*e0c4386eSCy Schubert  * this file except in compliance with the License.  You can obtain a copy
7*e0c4386eSCy Schubert  * in the file LICENSE in the source distribution or at
8*e0c4386eSCy Schubert  * https://www.openssl.org/source/license.html
9*e0c4386eSCy Schubert  */
10*e0c4386eSCy Schubert 
11*e0c4386eSCy Schubert #include <stdio.h>
12*e0c4386eSCy Schubert #include <openssl/err.h>
13*e0c4386eSCy Schubert #include <openssl/x509_vfy.h>
14*e0c4386eSCy Schubert 
15*e0c4386eSCy Schubert #include "testutil.h"
16*e0c4386eSCy Schubert 
test_509_dup_cert(int n)17*e0c4386eSCy Schubert static int test_509_dup_cert(int n)
18*e0c4386eSCy Schubert {
19*e0c4386eSCy Schubert     int ret = 0;
20*e0c4386eSCy Schubert     X509_STORE_CTX *sctx = NULL;
21*e0c4386eSCy Schubert     X509_STORE *store = NULL;
22*e0c4386eSCy Schubert     X509_LOOKUP *lookup = NULL;
23*e0c4386eSCy Schubert     const char *cert_f = test_get_argument(n);
24*e0c4386eSCy Schubert 
25*e0c4386eSCy Schubert     if (TEST_ptr(store = X509_STORE_new())
26*e0c4386eSCy Schubert         && TEST_ptr(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()))
27*e0c4386eSCy Schubert         && TEST_true(X509_load_cert_file(lookup, cert_f, X509_FILETYPE_PEM))
28*e0c4386eSCy Schubert         && TEST_true(X509_load_cert_file(lookup, cert_f, X509_FILETYPE_PEM)))
29*e0c4386eSCy Schubert         ret = 1;
30*e0c4386eSCy Schubert 
31*e0c4386eSCy Schubert     X509_STORE_CTX_free(sctx);
32*e0c4386eSCy Schubert     X509_STORE_free(store);
33*e0c4386eSCy Schubert     return ret;
34*e0c4386eSCy Schubert }
35*e0c4386eSCy Schubert 
36*e0c4386eSCy Schubert OPT_TEST_DECLARE_USAGE("cert.pem...\n")
37*e0c4386eSCy Schubert 
setup_tests(void)38*e0c4386eSCy Schubert int setup_tests(void)
39*e0c4386eSCy Schubert {
40*e0c4386eSCy Schubert     size_t n;
41*e0c4386eSCy Schubert 
42*e0c4386eSCy Schubert     if (!test_skip_common_options()) {
43*e0c4386eSCy Schubert         TEST_error("Error parsing test options\n");
44*e0c4386eSCy Schubert         return 0;
45*e0c4386eSCy Schubert     }
46*e0c4386eSCy Schubert 
47*e0c4386eSCy Schubert     n = test_get_argument_count();
48*e0c4386eSCy Schubert     if (!TEST_int_gt(n, 0))
49*e0c4386eSCy Schubert         return 0;
50*e0c4386eSCy Schubert 
51*e0c4386eSCy Schubert     ADD_ALL_TESTS(test_509_dup_cert, n);
52*e0c4386eSCy Schubert     return 1;
53*e0c4386eSCy Schubert }
54