2 * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
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
11 #include <openssl/asn1.h>
12 #include <openssl/conf.h>
13 #include <openssl/x509.h>
14 #include <openssl/x509v3.h>
16 int main(int argc, char **argv)
23 X509V3_add_standard_extensions();
24 ERR_load_crypto_strings();
26 fprintf(stderr, "Usage v3prin cert.pem\n");
29 if ((inf = fopen(argv[1], "r")) == NULL) {
30 fprintf(stderr, "Can't open %s\n", argv[1]);
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);
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);