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 "internal/cryptlib.h"
12 #include <openssl/asn1.h>
13 #include <openssl/conf.h>
14 #include <openssl/x509.h>
15 #include <openssl/x509v3.h>
17 /* Test application to add extensions from a config file */
19 int main(int argc, char **argv)
28 X509V3_add_standard_extensions();
29 ERR_load_crypto_strings();
31 fprintf(stderr, "Usage: v3conf cert.pem [file.cnf]\n");
36 conf_file = "test.cnf";
37 conf = CONF_load(NULL, "test.cnf", NULL);
39 fprintf(stderr, "Error opening Config file %s\n", conf_file);
40 ERR_print_errors_fp(stderr);
44 inf = fopen(argv[1], "r");
46 fprintf(stderr, "Can't open certificate file %s\n", argv[1]);
49 cert = PEM_read_X509(inf, NULL, NULL);
51 fprintf(stderr, "Error reading certificate file %s\n", argv[1]);
56 sk_pop_free(cert->cert_info->extensions, X509_EXTENSION_free);
57 cert->cert_info->extensions = NULL;
59 if (!X509V3_EXT_add_conf(conf, NULL, "test_section", cert)) {
60 fprintf(stderr, "Error adding extensions\n");
61 ERR_print_errors_fp(stderr);
65 count = X509_get_ext_count(cert);
66 printf("%d extensions\n", count);
67 for (i = 0; i < count; i++) {
68 ext = X509_get_ext(cert, i);
69 printf("%s", OBJ_nid2ln(OBJ_obj2nid(ext->object)));
71 printf(",critical:\n");
74 X509V3_EXT_print_fp(stdout, ext, 0, 0);