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