Fix threading issue that at best will leak memory
[openssl.git] / crypto / x509v3 / v3prin.c
1 /*
2  * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #include <stdio.h>
11 #include <openssl/asn1.h>
12 #include <openssl/conf.h>
13 #include <openssl/x509.h>
14 #include <openssl/x509v3.h>
15
16 int main(int argc, char **argv)
17 {
18     X509 *cert;
19     FILE *inf;
20     int i, count;
21     X509_EXTENSION *ext;
22
23     X509V3_add_standard_extensions();
24     ERR_load_crypto_strings();
25     if (!argv[1]) {
26         fprintf(stderr, "Usage v3prin cert.pem\n");
27         exit(1);
28     }
29     if ((inf = fopen(argv[1], "r")) == NULL) {
30         fprintf(stderr, "Can't open %s\n", argv[1]);
31         exit(1);
32     }
33     if ((cert = PEM_read_X509(inf, NULL, NULL)) == NULL) {
34         fprintf(stderr, "Can't read certificate %s\n", argv[1]);
35         ERR_print_errors_fp(stderr);
36         exit(1);
37     }
38     fclose(inf);
39     count = X509_get_ext_count(cert);
40     printf("%d extensions\n", count);
41     for (i = 0; i < count; i++) {
42         ext = X509_get_ext(cert, i);
43         printf("%s\n", OBJ_nid2ln(OBJ_obj2nid(ext->object)));
44         if (!X509V3_EXT_print_fp(stdout, ext, 0, 0))
45             ERR_print_errors_fp(stderr);
46         printf("\n");
47
48     }
49     return 0;
50 }