1 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
4 * This package is an SSL implementation written
5 * by Eric Young (eay@cryptsoft.com).
6 * The implementation was written so as to conform with Netscapes SSL.
8 * This library is free for commercial and non-commercial use as long as
9 * the following conditions are aheared to. The following conditions
10 * apply to all code found in this distribution, be it the RC4, RSA,
11 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
12 * included with this distribution is covered by the same copyright terms
13 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * Copyright remains Eric Young's, and as such any Copyright notices in
16 * the code are not to be removed.
17 * If this package is used in a product, Eric Young should be given attribution
18 * as the author of the parts of the library used.
19 * This can be in the form of a textual message at program startup or
20 * in documentation (online or textual) provided with the package.
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
25 * 1. Redistributions of source code must retain the copyright
26 * notice, this list of conditions and the following disclaimer.
27 * 2. Redistributions in binary form must reproduce the above copyright
28 * notice, this list of conditions and the following disclaimer in the
29 * documentation and/or other materials provided with the distribution.
30 * 3. All advertising materials mentioning features or use of this software
31 * must display the following acknowledgement:
32 * "This product includes cryptographic software written by
33 * Eric Young (eay@cryptsoft.com)"
34 * The word 'cryptographic' can be left out if the rouines from the library
35 * being used are not cryptographic related :-).
36 * 4. If you include any Windows specific code (or a derivative thereof) from
37 * the apps directory (application code) you must include an acknowledgement:
38 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 * The licence and distribution terms for any publically available version or
53 * derivative of this code cannot be changed. i.e. this code cannot simply be
54 * copied and put under another distribution licence
55 * [including the GNU Public Licence.]
58 /* The PPKI stuff has been donated by Jeff Barber <jeffb@issl.atl.hp.com> */
64 #include <sys/types.h>
65 #include <openssl/conf.h>
66 #include <openssl/bio.h>
67 #include <openssl/err.h>
68 #include <openssl/bn.h>
69 #include <openssl/txt_db.h>
70 #include <openssl/evp.h>
71 #include <openssl/x509.h>
72 #include <openssl/x509v3.h>
73 #include <openssl/objects.h>
74 #include <openssl/ocsp.h>
75 #include <openssl/pem.h>
78 # ifdef OPENSSL_SYS_VMS
84 # elif !defined(OPENSSL_SYS_VXWORKS) && !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_NETWARE)
85 # include <sys/file.h>
101 #define BASE_SECTION "ca"
103 #define ENV_DEFAULT_CA "default_ca"
105 #define STRING_MASK "string_mask"
106 #define UTF8_IN "utf8"
108 #define ENV_NEW_CERTS_DIR "new_certs_dir"
109 #define ENV_CERTIFICATE "certificate"
110 #define ENV_SERIAL "serial"
111 #define ENV_CRLNUMBER "crlnumber"
112 #define ENV_PRIVATE_KEY "private_key"
113 #define ENV_DEFAULT_DAYS "default_days"
114 #define ENV_DEFAULT_STARTDATE "default_startdate"
115 #define ENV_DEFAULT_ENDDATE "default_enddate"
116 #define ENV_DEFAULT_CRL_DAYS "default_crl_days"
117 #define ENV_DEFAULT_CRL_HOURS "default_crl_hours"
118 #define ENV_DEFAULT_MD "default_md"
119 #define ENV_DEFAULT_EMAIL_DN "email_in_dn"
120 #define ENV_PRESERVE "preserve"
121 #define ENV_POLICY "policy"
122 #define ENV_EXTENSIONS "x509_extensions"
123 #define ENV_CRLEXT "crl_extensions"
124 #define ENV_MSIE_HACK "msie_hack"
125 #define ENV_NAMEOPT "name_opt"
126 #define ENV_CERTOPT "cert_opt"
127 #define ENV_EXTCOPY "copy_extensions"
128 #define ENV_UNIQUE_SUBJECT "unique_subject"
130 #define ENV_DATABASE "database"
132 /* Additional revocation information types */
134 #define REV_NONE 0 /* No addditional information */
135 #define REV_CRL_REASON 1 /* Value is CRL reason code */
136 #define REV_HOLD 2 /* Value is hold instruction */
137 #define REV_KEY_COMPROMISE 3 /* Value is cert key compromise time */
138 #define REV_CA_COMPROMISE 4 /* Value is CA key compromise time */
140 static void lookup_fail(const char *name, const char *tag);
141 static int certify(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509,
142 const EVP_MD *dgst, STACK_OF(OPENSSL_STRING) *sigopts,
143 STACK_OF(CONF_VALUE) *policy, CA_DB *db,
144 BIGNUM *serial, char *subj, unsigned long chtype,
145 int multirdn, int email_dn, char *startdate, char *enddate,
146 long days, int batch, char *ext_sect, CONF *conf,
147 int verbose, unsigned long certopt, unsigned long nameopt,
148 int default_op, int ext_copy, int selfsign);
149 static int certify_cert(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509,
150 const EVP_MD *dgst, STACK_OF(OPENSSL_STRING) *sigopts,
151 STACK_OF(CONF_VALUE) *policy, CA_DB *db,
152 BIGNUM *serial, char *subj, unsigned long chtype,
153 int multirdn, int email_dn, char *startdate,
154 char *enddate, long days, int batch, char *ext_sect,
155 CONF *conf, int verbose, unsigned long certopt,
156 unsigned long nameopt, int default_op, int ext_copy,
158 static int certify_spkac(X509 **xret, char *infile, EVP_PKEY *pkey,
159 X509 *x509, const EVP_MD *dgst,
160 STACK_OF(OPENSSL_STRING) *sigopts,
161 STACK_OF(CONF_VALUE) *policy, CA_DB *db,
162 BIGNUM *serial, char *subj, unsigned long chtype,
163 int multirdn, int email_dn, char *startdate,
164 char *enddate, long days, char *ext_sect, CONF *conf,
165 int verbose, unsigned long certopt,
166 unsigned long nameopt, int default_op, int ext_copy);
167 static void write_new_certificate(BIO *bp, X509 *x, int output_der,
169 static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509,
170 const EVP_MD *dgst, STACK_OF(OPENSSL_STRING) *sigopts,
171 STACK_OF(CONF_VALUE) *policy, CA_DB *db, BIGNUM *serial,
172 char *subj, unsigned long chtype, int multirdn,
173 int email_dn, char *startdate, char *enddate, long days,
174 int batch, int verbose, X509_REQ *req, char *ext_sect,
175 CONF *conf, unsigned long certopt, unsigned long nameopt,
176 int default_op, int ext_copy, int selfsign);
177 static int do_revoke(X509 *x509, CA_DB *db, int ext, char *extval);
178 static int get_certificate_status(const char *ser_status, CA_DB *db);
179 static int do_updatedb(CA_DB *db);
180 static int check_time_format(const char *str);
181 char *make_revocation_str(int rev_type, char *rev_arg);
182 int make_revoked(X509_REVOKED *rev, const char *str);
183 static int old_entry_print(ASN1_OBJECT *obj, ASN1_STRING *str);
185 static CONF *conf = NULL;
186 static CONF *extconf = NULL;
187 static char *section = NULL;
188 static int preserve = 0;
189 static int msie_hack = 0;
191 typedef enum OPTION_choice {
192 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
193 OPT_ENGINE, OPT_VERBOSE, OPT_CONFIG, OPT_NAME, OPT_SUBJ, OPT_UTF8,
194 OPT_CREATE_SERIAL, OPT_MULTIVALUE_RDN, OPT_STARTDATE, OPT_ENDDATE,
195 OPT_DAYS, OPT_MD, OPT_POLICY, OPT_KEYFILE, OPT_KEYFORM, OPT_PASSIN,
196 OPT_KEY, OPT_CERT, OPT_SELFSIGN, OPT_IN, OPT_OUT, OPT_OUTDIR,
197 OPT_SIGOPT, OPT_NOTEXT, OPT_BATCH, OPT_PRESERVEDN, OPT_NOEMAILDN,
198 OPT_GENCRL, OPT_MSIE_HACK, OPT_CRLDAYS, OPT_CRLHOURS, OPT_CRLSEC,
199 OPT_INFILES, OPT_SS_CERT, OPT_SPKAC, OPT_REVOKE, OPT_VALID,
200 OPT_EXTENSIONS, OPT_EXTFILE, OPT_STATUS, OPT_UPDATEDB, OPT_CRLEXTS,
201 OPT_CRL_REASON, OPT_CRL_HOLD, OPT_CRL_COMPROMISE,
202 OPT_CRL_CA_COMPROMISE
205 OPTIONS ca_options[] = {
206 {"help", OPT_HELP, '-', "Display this summary"},
207 {"verbose", OPT_VERBOSE, '-', "Verbose output during processing"},
208 {"config", OPT_CONFIG, 's', "A config file"},
209 {"name", OPT_NAME, 's', "The particular CA definition to use"},
210 {"subj", OPT_SUBJ, 's', "Use arg instead of request's subject"},
211 {"utf8", OPT_UTF8, '-', "Input characters are UTF8 (default ASCII)"},
212 {"create_serial", OPT_CREATE_SERIAL, '-'},
213 {"multivalue-rdn", OPT_MULTIVALUE_RDN, '-',
214 "Enable support for multivalued RDNs"},
215 {"startdate", OPT_STARTDATE, 's', "Cert notBefore, YYMMDDHHMMSSZ"},
216 {"enddate", OPT_ENDDATE, 's',
217 "YYMMDDHHMMSSZ cert notAfter (overrides -days)"},
218 {"days", OPT_DAYS, 'p', "Number of days to certify the cert for"},
219 {"md", OPT_MD, 's', "md to use; one of md2, md5, sha or sha1"},
220 {"policy", OPT_POLICY, 's', "The CA 'policy' to support"},
221 {"keyfile", OPT_KEYFILE, '<', "Private key file"},
222 {"keyform", OPT_KEYFORM, 'f', "Private key file format (PEM or ENGINE)"},
223 {"passin", OPT_PASSIN, 's'},
224 {"key", OPT_KEY, 's', "Key to decode the private key if it is encrypted"},
225 {"cert", OPT_CERT, '<', "The CA cert"},
226 {"selfsign", OPT_SELFSIGN, '-',
227 "Sign a cert with the key associated with it"},
228 {"in", OPT_IN, '<', "The input PEM encoded cert request(s)"},
229 {"out", OPT_OUT, '>', "Where to put the output file(s)"},
230 {"outdir", OPT_OUTDIR, '/', "Where to put output cert"},
231 {"sigopt", OPT_SIGOPT, 's'},
232 {"notext", OPT_NOTEXT, '-'},
233 {"batch", OPT_BATCH, '-', "Don't ask questions"},
234 {"preserveDN", OPT_PRESERVEDN, '-', "Don't re-order the DN"},
235 {"noemailDN", OPT_NOEMAILDN, '-', "Don't add the EMAIL field to the DN"},
236 {"gencrl", OPT_GENCRL, '-', "Generate a new CRL"},
237 {"msie_hack", OPT_MSIE_HACK, '-',
238 "msie modifications to handle all those universal strings"},
239 {"crldays", OPT_CRLDAYS, 'p', "Days is when the next CRL is due"},
240 {"crlhours", OPT_CRLHOURS, 'p', "Hours is when the next CRL is due"},
241 {"crlsec", OPT_CRLSEC, 'p'},
242 {"infiles", OPT_INFILES, '-', "The last argument, requests to process"},
243 {"ss_cert", OPT_SS_CERT, '<', "File contains a self signed cert to sign"},
244 {"spkac", OPT_SPKAC, '<',
245 "File contains DN and signed public key and challenge"},
246 {"revoke", OPT_REVOKE, '<', "Revoke a cert (given in file)"},
247 {"valid", OPT_VALID, 's'},
248 {"extensions", OPT_EXTENSIONS, 's',
249 "Extension section (override value in config file)"},
250 {"extfile", OPT_EXTFILE, '<',
251 "Configuration file with X509v3 extensions to add"},
252 {"status", OPT_STATUS, 's', "Shows cert status given the serial number"},
253 {"updatedb", OPT_UPDATEDB, '-', "Updates db for expired cert"},
254 {"crlexts", OPT_CRLEXTS, 's',
255 "CRL extension section (override value in config file)"},
256 {"crl_reason", OPT_CRL_REASON, 's'},
257 {"crl_hold", OPT_CRL_HOLD, 's'},
258 {"crl_compromise", OPT_CRL_COMPROMISE, 's'},
259 {"crl_CA_compromise", OPT_CRL_CA_COMPROMISE, 's'},
260 #ifndef OPENSSL_NO_ENGINE
261 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
266 int ca_main(int argc, char **argv)
269 BIGNUM *crlnumber = NULL, *serial = NULL;
270 EVP_PKEY *pkey = NULL;
271 BIO *in = NULL, *out = NULL, *Sout = NULL, *Cout = NULL;
272 ASN1_INTEGER *tmpser;
276 STACK_OF(CONF_VALUE) *attribs = NULL;
277 STACK_OF(OPENSSL_STRING) *sigopts = NULL;
278 STACK_OF(X509) *cert_sk = NULL;
279 X509_CRL *crl = NULL;
280 const EVP_MD *dgst = NULL;
281 char *configfile = default_config_file;
282 char *md = NULL, *policy = NULL, *keyfile = NULL;
283 char *certfile = NULL, *crl_ext = NULL, *crlnumberfile = NULL;
284 char *infile = NULL, *spkac_file = NULL, *ss_cert_file = NULL;
285 char *extensions = NULL, *extfile = NULL, *key = NULL, *passinarg = NULL;
286 char *outdir = NULL, *outfile = NULL, *rev_arg = NULL, *ser_status = NULL;
287 char *serialfile = NULL, *startdate = NULL, *subj = NULL;
288 char *prog, *enddate = NULL, *tmp_email_dn = NULL;
289 char *dbfile = NULL, *f, *randfile = NULL, *tofree = NULL;
293 int create_ser = 0, free_key = 0, total = 0, total_done = 0;
294 int batch = 0, default_op = 1, doupdatedb = 0, ext_copy = EXT_COPY_NONE;
295 int keyformat = FORMAT_PEM, multirdn = 0, notext = 0, output_der = 0;
296 int ret = 1, email_dn = 1, req = 0, verbose = 0, gencrl = 0, dorevoke = 0;
297 int i, j, rev_type = REV_NONE, selfsign = 0;
298 long crldays = 0, crlhours = 0, crlsec = 0, days = 0;
299 unsigned long chtype = MBSTRING_ASC, nameopt = 0, certopt = 0;
300 X509 *x509 = NULL, *x509p = NULL, *x = NULL;
301 X509_REVOKED *r = NULL;
309 prog = opt_init(argc, argv, ca_options);
310 while ((o = opt_next()) != OPT_EOF) {
315 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
318 opt_help(ca_options);
332 configfile = opt_arg();
342 chtype = MBSTRING_UTF8;
344 case OPT_CREATE_SERIAL:
347 case OPT_MULTIVALUE_RDN:
351 startdate = opt_arg();
357 days = atoi(opt_arg());
369 if (!opt_format(opt_arg(), OPT_FMT_ANY, &keyformat))
373 passinarg = opt_arg();
379 certfile = opt_arg();
389 sigopts = sk_OPENSSL_STRING_new_null();
391 || !sk_OPENSSL_STRING_push(sigopts, opt_arg()))
413 crldays = atol(opt_arg());
416 crlhours = atol(opt_arg());
419 crlsec = atol(opt_arg());
425 ss_cert_file = opt_arg();
429 spkac_file = opt_arg();
441 extensions = opt_arg();
447 ser_status = opt_arg();
457 rev_type = REV_CRL_REASON;
463 case OPT_CRL_COMPROMISE:
465 rev_type = REV_KEY_COMPROMISE;
467 case OPT_CRL_CA_COMPROMISE:
469 rev_type = REV_CA_COMPROMISE;
472 e = setup_engine(opt_arg(), 0);
477 argc = opt_num_rest();
480 BIO_printf(bio_err, "Using configuration from %s\n", configfile);
481 /* We already loaded the default config file */
482 if (configfile != default_config_file) {
483 if ((conf = app_load_config(configfile)) == NULL)
485 if (!app_load_modules(conf))
489 /* Lets get the config section we are using */
490 if (section == NULL) {
491 section = NCONF_get_string(conf, BASE_SECTION, ENV_DEFAULT_CA);
492 if (section == NULL) {
493 lookup_fail(BASE_SECTION, ENV_DEFAULT_CA);
499 p = NCONF_get_string(conf, NULL, "oid_file");
505 oid_bio = BIO_new_file(p, "r");
506 if (oid_bio == NULL) {
508 BIO_printf(bio_err,"problems opening %s for extra oid's\n",p);
509 ERR_print_errors(bio_err);
513 OBJ_create_objects(oid_bio);
517 if (!add_oid_section(conf)) {
518 ERR_print_errors(bio_err);
523 randfile = NCONF_get_string(conf, BASE_SECTION, "RANDFILE");
524 if (randfile == NULL)
526 app_RAND_load_file(randfile, 0);
528 f = NCONF_get_string(conf, section, STRING_MASK);
532 if (f && !ASN1_STRING_set_default_mask_asc(f)) {
533 BIO_printf(bio_err, "Invalid global string mask setting %s\n", f);
537 if (chtype != MBSTRING_UTF8) {
538 f = NCONF_get_string(conf, section, UTF8_IN);
541 else if (strcmp(f, "yes") == 0)
542 chtype = MBSTRING_UTF8;
545 db_attr.unique_subject = 1;
546 p = NCONF_get_string(conf, section, ENV_UNIQUE_SUBJECT);
548 db_attr.unique_subject = parse_yesno(p, 1);
552 /*****************************************************************/
553 /* report status of cert with serial number given on command line */
555 if ((dbfile = NCONF_get_string(conf, section, ENV_DATABASE)) == NULL) {
556 lookup_fail(section, ENV_DATABASE);
559 db = load_index(dbfile, &db_attr);
563 if (!index_index(db))
566 if (get_certificate_status(ser_status, db) != 1)
567 BIO_printf(bio_err, "Error verifying serial %s!\n", ser_status);
571 /*****************************************************************/
572 /* we definitely need a private key, so let's get it */
574 if ((keyfile == NULL) && ((keyfile = NCONF_get_string(conf,
578 lookup_fail(section, ENV_PRIVATE_KEY);
583 if (!app_passwd(passinarg, NULL, &key, NULL)) {
584 BIO_printf(bio_err, "Error getting password\n");
588 pkey = load_key(keyfile, keyformat, 0, key, e, "CA private key");
590 OPENSSL_cleanse(key, strlen(key));
592 /* load_key() has already printed an appropriate message */
596 /*****************************************************************/
597 /* we need a certificate */
598 if (!selfsign || spkac_file || ss_cert_file || gencrl) {
599 if ((certfile == NULL)
600 && ((certfile = NCONF_get_string(conf,
602 ENV_CERTIFICATE)) == NULL)) {
603 lookup_fail(section, ENV_CERTIFICATE);
606 x509 = load_cert(certfile, FORMAT_PEM, NULL, e, "CA certificate");
610 if (!X509_check_private_key(x509, pkey)) {
612 "CA certificate and CA private key do not match\n");
619 f = NCONF_get_string(conf, BASE_SECTION, ENV_PRESERVE);
622 if ((f != NULL) && ((*f == 'y') || (*f == 'Y')))
624 f = NCONF_get_string(conf, BASE_SECTION, ENV_MSIE_HACK);
627 if ((f != NULL) && ((*f == 'y') || (*f == 'Y')))
630 f = NCONF_get_string(conf, section, ENV_NAMEOPT);
633 if (!set_name_ex(&nameopt, f)) {
634 BIO_printf(bio_err, "Invalid name options: \"%s\"\n", f);
639 nameopt = XN_FLAG_ONELINE;
643 f = NCONF_get_string(conf, section, ENV_CERTOPT);
646 if (!set_cert_ex(&certopt, f)) {
647 BIO_printf(bio_err, "Invalid certificate options: \"%s\"\n", f);
654 f = NCONF_get_string(conf, section, ENV_EXTCOPY);
657 if (!set_ext_copy(&ext_copy, f)) {
658 BIO_printf(bio_err, "Invalid extension copy option: \"%s\"\n", f);
664 /*****************************************************************/
665 /* lookup where to write new certificates */
666 if ((outdir == NULL) && (req)) {
668 if ((outdir = NCONF_get_string(conf, section, ENV_NEW_CERTS_DIR))
671 "there needs to be defined a directory for new certificate to be placed in\n");
674 #ifndef OPENSSL_SYS_VMS
676 * outdir is a directory spec, but access() for VMS demands a
677 * filename. We could use the DEC C routine to convert the
678 * directory syntax to Unixly, and give that to app_isdir,
679 * but for now the fopen will catch the error if it's not a
682 if (app_isdir(outdir) <= 0) {
683 BIO_printf(bio_err, "%s: %s is not a directory\n", prog, outdir);
690 /*****************************************************************/
691 /* we need to load the database file */
692 if ((dbfile = NCONF_get_string(conf, section, ENV_DATABASE)) == NULL) {
693 lookup_fail(section, ENV_DATABASE);
696 db = load_index(dbfile, &db_attr);
700 /* Lets check some fields */
701 for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
702 pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
703 if ((pp[DB_type][0] != DB_TYPE_REV) && (pp[DB_rev_date][0] != '\0')) {
705 "entry %d: not revoked yet, but has a revocation date\n",
709 if ((pp[DB_type][0] == DB_TYPE_REV) &&
710 !make_revoked(NULL, pp[DB_rev_date])) {
711 BIO_printf(bio_err, " in entry %d\n", i + 1);
714 if (!check_time_format((char *)pp[DB_exp_date])) {
715 BIO_printf(bio_err, "entry %d: invalid expiry date\n", i + 1);
724 if ((j & 1) || (j < 2)) {
725 BIO_printf(bio_err, "entry %d: bad serial number length (%d)\n",
732 "entry %d: bad char 0%o '%c' in serial number\n",
739 TXT_DB_write(bio_out, db->db);
740 BIO_printf(bio_err, "%d entries loaded from the database\n",
741 sk_OPENSSL_PSTRING_num(db->db->data));
742 BIO_printf(bio_err, "generating index\n");
745 if (!index_index(db))
748 /*****************************************************************/
749 /* Update the db file for expired certificates */
752 BIO_printf(bio_err, "Updating %s ...\n", dbfile);
756 BIO_printf(bio_err, "Malloc failure\n");
760 BIO_printf(bio_err, "No entries found to mark expired\n");
762 if (!save_index(dbfile, "new", db))
765 if (!rotate_index(dbfile, "new", "old"))
770 "Done. %d entries marked as expired\n", i);
774 /*****************************************************************/
775 /* Read extensions config file */
777 if ((extconf = app_load_config(extfile)) == NULL) {
783 BIO_printf(bio_err, "Successfully loaded extensions file %s\n",
786 /* We can have sections in the ext file */
789 NCONF_get_string(extconf, "default", "extensions")))
790 extensions = "default";
793 /*****************************************************************/
795 /* FIXME: Is it really always text? */
796 Sout = bio_open_default(outfile, 'w', FORMAT_TEXT);
801 if ((md == NULL) && ((md = NCONF_get_string(conf,
803 ENV_DEFAULT_MD)) == NULL)) {
804 lookup_fail(section, ENV_DEFAULT_MD);
808 if (strcmp(md, "default") == 0) {
810 if (EVP_PKEY_get_default_digest_nid(pkey, &def_nid) <= 0) {
811 BIO_puts(bio_err, "no default digest\n");
814 md = (char *)OBJ_nid2sn(def_nid);
817 if (!opt_md(md, &dgst)) {
822 if ((email_dn == 1) && ((tmp_email_dn = NCONF_get_string(conf,
824 ENV_DEFAULT_EMAIL_DN))
826 if (strcmp(tmp_email_dn, "no") == 0)
830 BIO_printf(bio_err, "message digest is %s\n",
831 OBJ_nid2ln(EVP_MD_type(dgst)));
832 if ((policy == NULL) && ((policy = NCONF_get_string(conf,
836 lookup_fail(section, ENV_POLICY);
840 BIO_printf(bio_err, "policy is %s\n", policy);
842 if ((serialfile = NCONF_get_string(conf, section, ENV_SERIAL))
844 lookup_fail(section, ENV_SERIAL);
850 * no '-extfile' option, so we look for extensions in the main
854 extensions = NCONF_get_string(conf, section, ENV_EXTENSIONS);
859 /* Check syntax of file */
861 X509V3_set_ctx_test(&ctx);
862 X509V3_set_nconf(&ctx, conf);
863 if (!X509V3_EXT_add_nconf(conf, &ctx, extensions, NULL)) {
865 "Error Loading extension section %s\n",
873 if (startdate == NULL) {
874 startdate = NCONF_get_string(conf, section,
875 ENV_DEFAULT_STARTDATE);
876 if (startdate == NULL)
879 if (startdate && !ASN1_TIME_set_string(NULL, startdate)) {
881 "start date is invalid, it should be YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ\n");
884 if (startdate == NULL)
887 if (enddate == NULL) {
888 enddate = NCONF_get_string(conf, section, ENV_DEFAULT_ENDDATE);
892 if (enddate && !ASN1_TIME_set_string(NULL, enddate)) {
894 "end date is invalid, it should be YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ\n");
899 if (!NCONF_get_number(conf, section, ENV_DEFAULT_DAYS, &days))
902 if (!enddate && (days == 0)) {
904 "cannot lookup how many days to certify for\n");
908 if ((serial = load_serial(serialfile, create_ser, NULL)) == NULL) {
909 BIO_printf(bio_err, "error while loading serial number\n");
913 if (BN_is_zero(serial))
914 BIO_printf(bio_err, "next serial number is 00\n");
916 if ((f = BN_bn2hex(serial)) == NULL)
918 BIO_printf(bio_err, "next serial number is %s\n", f);
923 if ((attribs = NCONF_get_section(conf, policy)) == NULL) {
924 BIO_printf(bio_err, "unable to find 'section' for %s\n", policy);
928 if ((cert_sk = sk_X509_new_null()) == NULL) {
929 BIO_printf(bio_err, "Memory allocation failure\n");
932 if (spkac_file != NULL) {
934 j = certify_spkac(&x, spkac_file, pkey, x509, dgst, sigopts,
935 attribs, db, serial, subj, chtype, multirdn,
936 email_dn, startdate, enddate, days, extensions,
937 conf, verbose, certopt, nameopt, default_op,
943 BIO_printf(bio_err, "\n");
944 if (!BN_add_word(serial, 1))
946 if (!sk_X509_push(cert_sk, x)) {
947 BIO_printf(bio_err, "Memory allocation failure\n");
956 if (ss_cert_file != NULL) {
958 j = certify_cert(&x, ss_cert_file, pkey, x509, dgst, sigopts,
960 db, serial, subj, chtype, multirdn, email_dn,
961 startdate, enddate, days, batch, extensions,
962 conf, verbose, certopt, nameopt, default_op,
968 BIO_printf(bio_err, "\n");
969 if (!BN_add_word(serial, 1))
971 if (!sk_X509_push(cert_sk, x)) {
972 BIO_printf(bio_err, "Memory allocation failure\n");
977 if (infile != NULL) {
979 j = certify(&x, infile, pkey, x509p, dgst, sigopts, attribs, db,
980 serial, subj, chtype, multirdn, email_dn, startdate,
981 enddate, days, batch, extensions, conf, verbose,
982 certopt, nameopt, default_op, ext_copy, selfsign);
987 BIO_printf(bio_err, "\n");
988 if (!BN_add_word(serial, 1))
990 if (!sk_X509_push(cert_sk, x)) {
991 BIO_printf(bio_err, "Memory allocation failure\n");
996 for (i = 0; i < argc; i++) {
998 j = certify(&x, argv[i], pkey, x509p, dgst, sigopts, attribs, db,
999 serial, subj, chtype, multirdn, email_dn, startdate,
1000 enddate, days, batch, extensions, conf, verbose,
1001 certopt, nameopt, default_op, ext_copy, selfsign);
1006 BIO_printf(bio_err, "\n");
1007 if (!BN_add_word(serial, 1))
1009 if (!sk_X509_push(cert_sk, x)) {
1010 BIO_printf(bio_err, "Memory allocation failure\n");
1016 * we have a stack of newly certified certificates and a data base
1017 * and serial number that need updating
1020 if (sk_X509_num(cert_sk) > 0) {
1023 "\n%d out of %d certificate requests certified, commit? [y/n]",
1025 (void)BIO_flush(bio_err);
1027 if (!fgets(buf[0], 10, stdin)) {
1029 "CERTIFICATION CANCELED: I/O error\n");
1033 if ((buf[0][0] != 'y') && (buf[0][0] != 'Y')) {
1034 BIO_printf(bio_err, "CERTIFICATION CANCELED\n");
1040 BIO_printf(bio_err, "Write out database with %d new entries\n",
1041 sk_X509_num(cert_sk));
1043 if (!save_serial(serialfile, "new", serial, NULL))
1046 if (!save_index(dbfile, "new", db))
1051 BIO_printf(bio_err, "writing new certificates\n");
1052 for (i = 0; i < sk_X509_num(cert_sk); i++) {
1053 ASN1_INTEGER *serialNumber = X509_get_serialNumber(x);
1057 x = sk_X509_value(cert_sk, i);
1059 j = ASN1_STRING_length(serialNumber);
1060 p = (const char *)ASN1_STRING_data(serialNumber);
1062 if (strlen(outdir) >= (size_t)(j ? BSIZE - j * 2 - 6 : BSIZE - 8)) {
1063 BIO_printf(bio_err, "certificate file name too long\n");
1067 strcpy(buf[2], outdir);
1069 #ifndef OPENSSL_SYS_VMS
1070 OPENSSL_strlcat(buf[2], "/", sizeof(buf[2]));
1073 n = (char *)&(buf[2][strlen(buf[2])]);
1075 for (k = 0; k < j; k++) {
1076 if (n >= &(buf[2][sizeof(buf[2])]))
1079 &buf[2][0] + sizeof(buf[2]) - n,
1080 "%02X", (unsigned char)*(p++));
1093 BIO_printf(bio_err, "writing %s\n", buf[2]);
1095 Cout = BIO_new_file(buf[2], "w");
1100 write_new_certificate(Cout, x, 0, notext);
1101 write_new_certificate(Sout, x, output_der, notext);
1104 if (sk_X509_num(cert_sk)) {
1105 /* Rename the database and the serial file */
1106 if (!rotate_serial(serialfile, "new", "old"))
1109 if (!rotate_index(dbfile, "new", "old"))
1112 BIO_printf(bio_err, "Data Base Updated\n");
1116 /*****************************************************************/
1120 crl_ext = NCONF_get_string(conf, section, ENV_CRLEXT);
1125 /* Check syntax of file */
1127 X509V3_set_ctx_test(&ctx);
1128 X509V3_set_nconf(&ctx, conf);
1129 if (!X509V3_EXT_add_nconf(conf, &ctx, crl_ext, NULL)) {
1131 "Error Loading CRL extension section %s\n",
1138 if ((crlnumberfile = NCONF_get_string(conf, section, ENV_CRLNUMBER))
1140 if ((crlnumber = load_serial(crlnumberfile, 0, NULL)) == NULL) {
1141 BIO_printf(bio_err, "error while loading CRL number\n");
1145 if (!crldays && !crlhours && !crlsec) {
1146 if (!NCONF_get_number(conf, section,
1147 ENV_DEFAULT_CRL_DAYS, &crldays))
1149 if (!NCONF_get_number(conf, section,
1150 ENV_DEFAULT_CRL_HOURS, &crlhours))
1154 if ((crldays == 0) && (crlhours == 0) && (crlsec == 0)) {
1156 "cannot lookup how long until the next CRL is issued\n");
1161 BIO_printf(bio_err, "making CRL\n");
1162 if ((crl = X509_CRL_new()) == NULL)
1164 if (!X509_CRL_set_issuer_name(crl, X509_get_subject_name(x509)))
1167 tmptm = ASN1_TIME_new();
1170 X509_gmtime_adj(tmptm, 0);
1171 X509_CRL_set_lastUpdate(crl, tmptm);
1172 if (!X509_time_adj_ex(tmptm, crldays, crlhours * 60 * 60 + crlsec,
1174 BIO_puts(bio_err, "error setting CRL nextUpdate\n");
1177 X509_CRL_set_nextUpdate(crl, tmptm);
1179 ASN1_TIME_free(tmptm);
1181 for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
1182 pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
1183 if (pp[DB_type][0] == DB_TYPE_REV) {
1184 if ((r = X509_REVOKED_new()) == NULL)
1186 j = make_revoked(r, pp[DB_rev_date]);
1191 if (!BN_hex2bn(&serial, pp[DB_serial]))
1193 tmpser = BN_to_ASN1_INTEGER(serial, NULL);
1198 X509_REVOKED_set_serialNumber(r, tmpser);
1199 ASN1_INTEGER_free(tmpser);
1200 X509_CRL_add0_revoked(crl, r);
1205 * sort the data so it will be written in serial number order
1209 /* we now have a CRL */
1211 BIO_printf(bio_err, "signing CRL\n");
1213 /* Add any extensions asked for */
1215 if (crl_ext || crlnumberfile != NULL) {
1217 X509V3_set_ctx(&crlctx, x509, NULL, NULL, crl, 0);
1218 X509V3_set_nconf(&crlctx, conf);
1221 if (!X509V3_EXT_CRL_add_nconf(conf, &crlctx, crl_ext, crl))
1223 if (crlnumberfile != NULL) {
1224 tmpser = BN_to_ASN1_INTEGER(crlnumber, NULL);
1227 X509_CRL_add1_ext_i2d(crl, NID_crl_number, tmpser, 0, 0);
1228 ASN1_INTEGER_free(tmpser);
1230 if (!BN_add_word(crlnumber, 1))
1234 if (crl_ext || crl_v2) {
1235 if (!X509_CRL_set_version(crl, 1))
1236 goto end; /* version 2 CRL */
1239 /* we have a CRL number that need updating */
1240 if (crlnumberfile != NULL)
1241 if (!save_serial(crlnumberfile, "new", crlnumber, NULL))
1247 if (!do_X509_CRL_sign(crl, pkey, dgst, sigopts))
1250 PEM_write_bio_X509_CRL(Sout, crl);
1252 if (crlnumberfile != NULL) /* Rename the crlnumber file */
1253 if (!rotate_serial(crlnumberfile, "new", "old"))
1257 /*****************************************************************/
1259 if (infile == NULL) {
1260 BIO_printf(bio_err, "no input files\n");
1264 revcert = load_cert(infile, FORMAT_PEM, NULL, e, infile);
1265 if (revcert == NULL)
1269 j = do_revoke(revcert, db, rev_type, rev_arg);
1274 if (!save_index(dbfile, "new", db))
1277 if (!rotate_index(dbfile, "new", "old"))
1280 BIO_printf(bio_err, "Data Base Updated\n");
1283 /*****************************************************************/
1286 OPENSSL_free(tofree);
1291 sk_X509_pop_free(cert_sk, X509_free);
1294 ERR_print_errors(bio_err);
1295 app_RAND_write_file(randfile);
1301 sk_OPENSSL_STRING_free(sigopts);
1302 EVP_PKEY_free(pkey);
1306 NCONF_free(extconf);
1311 static void lookup_fail(const char *name, const char *tag)
1313 BIO_printf(bio_err, "variable lookup failed for %s::%s\n", name, tag);
1316 static int certify(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509,
1317 const EVP_MD *dgst, STACK_OF(OPENSSL_STRING) *sigopts,
1318 STACK_OF(CONF_VALUE) *policy, CA_DB *db,
1319 BIGNUM *serial, char *subj, unsigned long chtype,
1320 int multirdn, int email_dn, char *startdate, char *enddate,
1321 long days, int batch, char *ext_sect, CONF *lconf,
1322 int verbose, unsigned long certopt, unsigned long nameopt,
1323 int default_op, int ext_copy, int selfsign)
1325 X509_REQ *req = NULL;
1327 EVP_PKEY *pktmp = NULL;
1330 in = BIO_new_file(infile, "r");
1332 ERR_print_errors(bio_err);
1335 if ((req = PEM_read_bio_X509_REQ(in, NULL, NULL, NULL)) == NULL) {
1336 BIO_printf(bio_err, "Error reading certificate request in %s\n",
1341 X509_REQ_print(bio_err, req);
1343 BIO_printf(bio_err, "Check that the request matches the signature\n");
1345 if (selfsign && !X509_REQ_check_private_key(req, pkey)) {
1347 "Certificate request and CA private key do not match\n");
1351 if ((pktmp = X509_REQ_get_pubkey(req)) == NULL) {
1352 BIO_printf(bio_err, "error unpacking public key\n");
1355 i = X509_REQ_verify(req, pktmp);
1356 EVP_PKEY_free(pktmp);
1359 BIO_printf(bio_err, "Signature verification problems....\n");
1360 ERR_print_errors(bio_err);
1366 "Signature did not match the certificate request\n");
1367 ERR_print_errors(bio_err);
1370 BIO_printf(bio_err, "Signature ok\n");
1372 ok = do_body(xret, pkey, x509, dgst, sigopts, policy, db, serial, subj,
1373 chtype, multirdn, email_dn, startdate, enddate, days, batch,
1374 verbose, req, ext_sect, lconf, certopt, nameopt, default_op,
1375 ext_copy, selfsign);
1383 static int certify_cert(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509,
1384 const EVP_MD *dgst, STACK_OF(OPENSSL_STRING) *sigopts,
1385 STACK_OF(CONF_VALUE) *policy, CA_DB *db,
1386 BIGNUM *serial, char *subj, unsigned long chtype,
1387 int multirdn, int email_dn, char *startdate,
1388 char *enddate, long days, int batch, char *ext_sect,
1389 CONF *lconf, int verbose, unsigned long certopt,
1390 unsigned long nameopt, int default_op, int ext_copy,
1394 X509_REQ *rreq = NULL;
1395 EVP_PKEY *pktmp = NULL;
1398 if ((req = load_cert(infile, FORMAT_PEM, NULL, e, infile)) == NULL)
1401 X509_print(bio_err, req);
1403 BIO_printf(bio_err, "Check that the request matches the signature\n");
1405 if ((pktmp = X509_get0_pubkey(req)) == NULL) {
1406 BIO_printf(bio_err, "error unpacking public key\n");
1409 i = X509_verify(req, pktmp);
1412 BIO_printf(bio_err, "Signature verification problems....\n");
1417 BIO_printf(bio_err, "Signature did not match the certificate\n");
1420 BIO_printf(bio_err, "Signature ok\n");
1422 if ((rreq = X509_to_X509_REQ(req, NULL, NULL)) == NULL)
1425 ok = do_body(xret, pkey, x509, dgst, sigopts, policy, db, serial, subj,
1426 chtype, multirdn, email_dn, startdate, enddate, days, batch,
1427 verbose, rreq, ext_sect, lconf, certopt, nameopt, default_op,
1431 X509_REQ_free(rreq);
1436 static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509,
1437 const EVP_MD *dgst, STACK_OF(OPENSSL_STRING) *sigopts,
1438 STACK_OF(CONF_VALUE) *policy, CA_DB *db, BIGNUM *serial,
1439 char *subj, unsigned long chtype, int multirdn,
1440 int email_dn, char *startdate, char *enddate, long days,
1441 int batch, int verbose, X509_REQ *req, char *ext_sect,
1442 CONF *lconf, unsigned long certopt, unsigned long nameopt,
1443 int default_op, int ext_copy, int selfsign)
1445 X509_NAME *name = NULL, *CAname = NULL, *subject = NULL, *dn_subject =
1447 ASN1_UTCTIME *tm, *tmptm;
1448 ASN1_STRING *str, *str2;
1451 X509_NAME_ENTRY *ne;
1452 X509_NAME_ENTRY *tne, *push;
1454 int ok = -1, i, j, last, nid;
1457 OPENSSL_STRING row[DB_NUMBER];
1458 OPENSSL_STRING *irow = NULL;
1459 OPENSSL_STRING *rrow = NULL;
1462 tmptm = ASN1_UTCTIME_new();
1463 if (tmptm == NULL) {
1464 BIO_printf(bio_err, "malloc error\n");
1468 for (i = 0; i < DB_NUMBER; i++)
1472 X509_NAME *n = parse_name(subj, chtype, multirdn);
1475 ERR_print_errors(bio_err);
1478 X509_REQ_set_subject_name(req, n);
1484 "The Subject's Distinguished Name is as follows\n");
1486 name = X509_REQ_get_subject_name(req);
1487 for (i = 0; i < X509_NAME_entry_count(name); i++) {
1488 ne = X509_NAME_get_entry(name, i);
1489 str = X509_NAME_ENTRY_get_data(ne);
1490 obj = X509_NAME_ENTRY_get_object(ne);
1493 /* assume all type should be strings */
1494 nid = OBJ_obj2nid(X509_NAME_ENTRY_get_object(ne));
1496 if (str->type == V_ASN1_UNIVERSALSTRING)
1497 ASN1_UNIVERSALSTRING_to_string(str);
1499 if ((str->type == V_ASN1_IA5STRING) &&
1500 (nid != NID_pkcs9_emailAddress))
1501 str->type = V_ASN1_T61STRING;
1503 if ((nid == NID_pkcs9_emailAddress) &&
1504 (str->type == V_ASN1_PRINTABLESTRING))
1505 str->type = V_ASN1_IA5STRING;
1508 /* If no EMAIL is wanted in the subject */
1509 if ((OBJ_obj2nid(obj) == NID_pkcs9_emailAddress) && (!email_dn))
1512 /* check some things */
1513 if ((OBJ_obj2nid(obj) == NID_pkcs9_emailAddress) &&
1514 (str->type != V_ASN1_IA5STRING)) {
1516 "\nemailAddress type needs to be of type IA5STRING\n");
1519 if ((str->type != V_ASN1_BMPSTRING)
1520 && (str->type != V_ASN1_UTF8STRING)) {
1521 j = ASN1_PRINTABLE_type(str->data, str->length);
1522 if (((j == V_ASN1_T61STRING) &&
1523 (str->type != V_ASN1_T61STRING)) ||
1524 ((j == V_ASN1_IA5STRING) &&
1525 (str->type == V_ASN1_PRINTABLESTRING))) {
1527 "\nThe string contains characters that are illegal for the ASN.1 type\n");
1533 old_entry_print(obj, str);
1536 /* Ok, now we check the 'policy' stuff. */
1537 if ((subject = X509_NAME_new()) == NULL) {
1538 BIO_printf(bio_err, "Memory allocation failure\n");
1542 /* take a copy of the issuer name before we mess with it. */
1544 CAname = X509_NAME_dup(name);
1546 CAname = X509_NAME_dup(X509_get_subject_name(x509));
1551 for (i = 0; i < sk_CONF_VALUE_num(policy); i++) {
1552 cv = sk_CONF_VALUE_value(policy, i); /* get the object id */
1553 if ((j = OBJ_txt2nid(cv->name)) == NID_undef) {
1555 "%s:unknown object type in 'policy' configuration\n",
1559 obj = OBJ_nid2obj(j);
1563 /* lookup the object in the supplied name list */
1564 j = X509_NAME_get_index_by_OBJ(name, obj, last);
1570 tne = X509_NAME_get_entry(name, j);
1574 /* depending on the 'policy', decide what to do. */
1576 if (strcmp(cv->value, "optional") == 0) {
1579 } else if (strcmp(cv->value, "supplied") == 0) {
1582 "The %s field needed to be supplied and was missing\n",
1587 } else if (strcmp(cv->value, "match") == 0) {
1592 "The mandatory %s field was missing\n",
1600 j = X509_NAME_get_index_by_OBJ(CAname, obj, last2);
1601 if ((j < 0) && (last2 == -1)) {
1603 "The %s field does not exist in the CA certificate,\nthe 'policy' is misconfigured\n",
1608 push = X509_NAME_get_entry(CAname, j);
1609 str = X509_NAME_ENTRY_get_data(tne);
1610 str2 = X509_NAME_ENTRY_get_data(push);
1612 if (ASN1_STRING_cmp(str, str2) != 0)
1617 "The %s field needed to be the same in the\nCA certificate (%s) and the request (%s)\n",
1619 ((str2 == NULL) ? "NULL" : (char *)str2->data),
1620 ((str == NULL) ? "NULL" : (char *)str->data));
1625 "%s:invalid type in 'policy' configuration\n",
1631 if (!X509_NAME_add_entry(subject, push, -1, 0)) {
1632 X509_NAME_ENTRY_free(push);
1633 BIO_printf(bio_err, "Memory allocation failure\n");
1643 X509_NAME_free(subject);
1644 /* subject=X509_NAME_dup(X509_REQ_get_subject_name(req)); */
1645 subject = X509_NAME_dup(name);
1646 if (subject == NULL)
1652 "The subject name appears to be ok, checking data base for clashes\n");
1654 /* Build the correct Subject if no e-mail is wanted in the subject */
1656 * and add it later on because of the method extensions are added
1661 dn_subject = subject;
1663 X509_NAME_ENTRY *tmpne;
1665 * Its best to dup the subject DN and then delete any email addresses
1666 * because this retains its structure.
1668 if ((dn_subject = X509_NAME_dup(subject)) == NULL) {
1669 BIO_printf(bio_err, "Memory allocation failure\n");
1672 while ((i = X509_NAME_get_index_by_NID(dn_subject,
1673 NID_pkcs9_emailAddress,
1675 tmpne = X509_NAME_get_entry(dn_subject, i);
1676 X509_NAME_delete_entry(dn_subject, i);
1677 X509_NAME_ENTRY_free(tmpne);
1681 if (BN_is_zero(serial))
1682 row[DB_serial] = OPENSSL_strdup("00");
1684 row[DB_serial] = BN_bn2hex(serial);
1685 if (row[DB_serial] == NULL) {
1686 BIO_printf(bio_err, "Memory allocation failure\n");
1690 if (db->attributes.unique_subject) {
1691 OPENSSL_STRING *crow = row;
1693 rrow = TXT_DB_get_by_index(db->db, DB_name, crow);
1696 "ERROR:There is already a certificate for %s\n",
1701 rrow = TXT_DB_get_by_index(db->db, DB_serial, row);
1704 "ERROR:Serial number %s has already been issued,\n",
1707 " check the database/serial_file for corruption\n");
1712 BIO_printf(bio_err, "The matching entry has the following details\n");
1713 if (rrow[DB_type][0] == 'E')
1715 else if (rrow[DB_type][0] == 'R')
1717 else if (rrow[DB_type][0] == 'V')
1720 p = "\ninvalid type, Data base error\n";
1721 BIO_printf(bio_err, "Type :%s\n", p);;
1722 if (rrow[DB_type][0] == 'R') {
1723 p = rrow[DB_exp_date];
1726 BIO_printf(bio_err, "Was revoked on:%s\n", p);
1728 p = rrow[DB_exp_date];
1731 BIO_printf(bio_err, "Expires on :%s\n", p);
1732 p = rrow[DB_serial];
1735 BIO_printf(bio_err, "Serial Number :%s\n", p);
1739 BIO_printf(bio_err, "File name :%s\n", p);
1743 BIO_printf(bio_err, "Subject Name :%s\n", p);
1744 ok = -1; /* This is now a 'bad' error. */
1748 /* We are now totally happy, lets make and sign the certificate */
1751 "Everything appears to be ok, creating and signing the certificate\n");
1753 if ((ret = X509_new()) == NULL)
1757 /* Make it an X509 v3 certificate. */
1758 if (!X509_set_version(ret, 2))
1762 if (BN_to_ASN1_INTEGER(serial, X509_get_serialNumber(ret)) == NULL)
1765 if (!X509_set_issuer_name(ret, subject))
1768 if (!X509_set_issuer_name(ret, X509_get_subject_name(x509)))
1772 if (strcmp(startdate, "today") == 0)
1773 X509_gmtime_adj(X509_get_notBefore(ret), 0);
1775 ASN1_TIME_set_string(X509_get_notBefore(ret), startdate);
1777 if (enddate == NULL)
1778 X509_time_adj_ex(X509_get_notAfter(ret), days, 0, NULL);
1781 ASN1_TIME_set_string(X509_get_notAfter(ret), enddate);
1782 ASN1_TIME_diff(&tdays, NULL, NULL, X509_get_notAfter(ret));
1786 if (!X509_set_subject_name(ret, subject))
1789 pktmp = X509_REQ_get_pubkey(req);
1790 i = X509_set_pubkey(ret, pktmp);
1791 EVP_PKEY_free(pktmp);
1795 /* Lets add the extensions, if there are any */
1798 X509_set_version(ret, 2);
1800 /* Initialize the context structure */
1802 X509V3_set_ctx(&ctx, ret, ret, req, NULL, 0);
1804 X509V3_set_ctx(&ctx, x509, ret, req, NULL, 0);
1808 BIO_printf(bio_err, "Extra configuration file found\n");
1810 /* Use the extconf configuration db LHASH */
1811 X509V3_set_nconf(&ctx, extconf);
1813 /* Test the structure (needed?) */
1814 /* X509V3_set_ctx_test(&ctx); */
1816 /* Adds exts contained in the configuration file */
1817 if (!X509V3_EXT_add_nconf(extconf, &ctx, ext_sect, ret)) {
1819 "ERROR: adding extensions in section %s\n",
1821 ERR_print_errors(bio_err);
1826 "Successfully added extensions from file.\n");
1827 } else if (ext_sect) {
1828 /* We found extensions to be set from config file */
1829 X509V3_set_nconf(&ctx, lconf);
1831 if (!X509V3_EXT_add_nconf(lconf, &ctx, ext_sect, ret)) {
1833 "ERROR: adding extensions in section %s\n",
1835 ERR_print_errors(bio_err);
1841 "Successfully added extensions from config\n");
1845 /* Copy extensions from request (if any) */
1847 if (!copy_extensions(ret, req, ext_copy)) {
1848 BIO_printf(bio_err, "ERROR: adding extensions from request\n");
1849 ERR_print_errors(bio_err);
1853 /* Set the right value for the noemailDN option */
1854 if (email_dn == 0) {
1855 if (!X509_set_subject_name(ret, dn_subject))
1860 BIO_printf(bio_err, "Certificate Details:\n");
1862 * Never print signature details because signature not present
1864 certopt |= X509_FLAG_NO_SIGDUMP | X509_FLAG_NO_SIGNAME;
1865 X509_print_ex(bio_err, ret, nameopt, certopt);
1868 BIO_printf(bio_err, "Certificate is to be certified until ");
1869 ASN1_TIME_print(bio_err, X509_get_notAfter(ret));
1871 BIO_printf(bio_err, " (%ld days)", days);
1872 BIO_printf(bio_err, "\n");
1876 BIO_printf(bio_err, "Sign the certificate? [y/n]:");
1877 (void)BIO_flush(bio_err);
1879 if (!fgets(buf, sizeof(buf) - 1, stdin)) {
1881 "CERTIFICATE WILL NOT BE CERTIFIED: I/O error\n");
1885 if (!((buf[0] == 'y') || (buf[0] == 'Y'))) {
1886 BIO_printf(bio_err, "CERTIFICATE WILL NOT BE CERTIFIED\n");
1892 pktmp = X509_get0_pubkey(ret);
1893 if (EVP_PKEY_missing_parameters(pktmp) &&
1894 !EVP_PKEY_missing_parameters(pkey))
1895 EVP_PKEY_copy_parameters(pktmp, pkey);
1897 if (!do_X509_sign(ret, pkey, dgst, sigopts))
1900 /* We now just add it to the database */
1901 row[DB_type] = OPENSSL_strdup("V");
1902 tm = X509_get_notAfter(ret);
1903 row[DB_exp_date] = app_malloc(tm->length + 1, "row expdate");
1904 memcpy(row[DB_exp_date], tm->data, tm->length);
1905 row[DB_exp_date][tm->length] = '\0';
1906 row[DB_rev_date] = NULL;
1907 row[DB_file] = OPENSSL_strdup("unknown");
1908 row[DB_name] = X509_NAME_oneline(X509_get_subject_name(ret), NULL, 0);
1910 if ((row[DB_type] == NULL) || (row[DB_exp_date] == NULL) ||
1911 (row[DB_file] == NULL) || (row[DB_name] == NULL)) {
1912 BIO_printf(bio_err, "Memory allocation failure\n");
1916 irow = app_malloc(sizeof(*irow) * (DB_NUMBER + 1), "row space");
1917 for (i = 0; i < DB_NUMBER; i++) {
1921 irow[DB_NUMBER] = NULL;
1923 if (!TXT_DB_insert(db->db, irow)) {
1924 BIO_printf(bio_err, "failed to update database\n");
1925 BIO_printf(bio_err, "TXT_DB error number %ld\n", db->db->error);
1930 for (i = 0; i < DB_NUMBER; i++)
1931 OPENSSL_free(row[i]);
1933 X509_NAME_free(CAname);
1934 X509_NAME_free(subject);
1935 if (dn_subject != subject)
1936 X509_NAME_free(dn_subject);
1937 ASN1_UTCTIME_free(tmptm);
1945 static void write_new_certificate(BIO *bp, X509 *x, int output_der,
1950 (void)i2d_X509_bio(bp, x);
1955 PEM_write_bio_X509(bp, x);
1958 static int certify_spkac(X509 **xret, char *infile, EVP_PKEY *pkey,
1959 X509 *x509, const EVP_MD *dgst,
1960 STACK_OF(OPENSSL_STRING) *sigopts,
1961 STACK_OF(CONF_VALUE) *policy, CA_DB *db,
1962 BIGNUM *serial, char *subj, unsigned long chtype,
1963 int multirdn, int email_dn, char *startdate,
1964 char *enddate, long days, char *ext_sect,
1965 CONF *lconf, int verbose, unsigned long certopt,
1966 unsigned long nameopt, int default_op, int ext_copy)
1968 STACK_OF(CONF_VALUE) *sk = NULL;
1969 LHASH_OF(CONF_VALUE) *parms = NULL;
1970 X509_REQ *req = NULL;
1971 CONF_VALUE *cv = NULL;
1972 NETSCAPE_SPKI *spki = NULL;
1974 EVP_PKEY *pktmp = NULL;
1975 X509_NAME *n = NULL;
1976 X509_NAME_ENTRY *ne = NULL;
1982 * Load input file into a hash table. (This is just an easy
1983 * way to read and parse the file, then put it into a convenient
1986 parms = CONF_load(NULL, infile, &errline);
1987 if (parms == NULL) {
1988 BIO_printf(bio_err, "error on line %ld of %s\n", errline, infile);
1989 ERR_print_errors(bio_err);
1993 sk = CONF_get_section(parms, "default");
1994 if (sk_CONF_VALUE_num(sk) == 0) {
1995 BIO_printf(bio_err, "no name/value pairs found in %s\n", infile);
2001 * Now create a dummy X509 request structure. We don't actually
2002 * have an X509 request, but we have many of the components
2003 * (a public key, various DN components). The idea is that we
2004 * put these components into the right X509 request structure
2005 * and we can use the same code as if you had a real X509 request.
2007 req = X509_REQ_new();
2009 ERR_print_errors(bio_err);
2014 * Build up the subject name set.
2016 n = X509_REQ_get_subject_name(req);
2019 if (sk_CONF_VALUE_num(sk) <= i)
2022 cv = sk_CONF_VALUE_value(sk, i);
2025 * Skip past any leading X. X: X, etc to allow for multiple instances
2027 for (buf = cv->name; *buf; buf++)
2028 if ((*buf == ':') || (*buf == ',') || (*buf == '.')) {
2036 if ((nid = OBJ_txt2nid(type)) == NID_undef) {
2037 if (strcmp(type, "SPKAC") == 0) {
2038 spki = NETSCAPE_SPKI_b64_decode(cv->value, -1);
2041 "unable to load Netscape SPKAC structure\n");
2042 ERR_print_errors(bio_err);
2049 if (!X509_NAME_add_entry_by_NID(n, nid, chtype,
2050 (unsigned char *)buf, -1, -1, 0))
2054 BIO_printf(bio_err, "Netscape SPKAC structure not found in %s\n",
2060 * Now extract the key from the SPKI structure.
2064 "Check that the SPKAC request matches the signature\n");
2066 if ((pktmp = NETSCAPE_SPKI_get_pubkey(spki)) == NULL) {
2067 BIO_printf(bio_err, "error unpacking SPKAC public key\n");
2071 j = NETSCAPE_SPKI_verify(spki, pktmp);
2074 "signature verification failed on SPKAC public key\n");
2077 BIO_printf(bio_err, "Signature ok\n");
2079 X509_REQ_set_pubkey(req, pktmp);
2080 EVP_PKEY_free(pktmp);
2081 ok = do_body(xret, pkey, x509, dgst, sigopts, policy, db, serial, subj,
2082 chtype, multirdn, email_dn, startdate, enddate, days, 1,
2083 verbose, req, ext_sect, lconf, certopt, nameopt, default_op,
2088 NETSCAPE_SPKI_free(spki);
2089 X509_NAME_ENTRY_free(ne);
2094 static int check_time_format(const char *str)
2096 return ASN1_TIME_set_string(NULL, str);
2099 static int do_revoke(X509 *x509, CA_DB *db, int type, char *value)
2101 ASN1_UTCTIME *tm = NULL;
2102 char *row[DB_NUMBER], **rrow, **irow;
2103 char *rev_str = NULL;
2107 for (i = 0; i < DB_NUMBER; i++)
2109 row[DB_name] = X509_NAME_oneline(X509_get_subject_name(x509), NULL, 0);
2110 bn = ASN1_INTEGER_to_BN(X509_get_serialNumber(x509), NULL);
2114 row[DB_serial] = OPENSSL_strdup("00");
2116 row[DB_serial] = BN_bn2hex(bn);
2118 if ((row[DB_name] == NULL) || (row[DB_serial] == NULL)) {
2119 BIO_printf(bio_err, "Memory allocation failure\n");
2123 * We have to lookup by serial number because name lookup skips revoked
2126 rrow = TXT_DB_get_by_index(db->db, DB_serial, row);
2129 "Adding Entry with serial number %s to DB for %s\n",
2130 row[DB_serial], row[DB_name]);
2132 /* We now just add it to the database */
2133 row[DB_type] = OPENSSL_strdup("V");
2134 tm = X509_get_notAfter(x509);
2135 row[DB_exp_date] = app_malloc(tm->length + 1, "row exp_data");
2136 memcpy(row[DB_exp_date], tm->data, tm->length);
2137 row[DB_exp_date][tm->length] = '\0';
2138 row[DB_rev_date] = NULL;
2139 row[DB_file] = OPENSSL_strdup("unknown");
2141 irow = app_malloc(sizeof(*irow) * (DB_NUMBER + 1), "row ptr");
2142 for (i = 0; i < DB_NUMBER; i++) {
2146 irow[DB_NUMBER] = NULL;
2148 if (!TXT_DB_insert(db->db, irow)) {
2149 BIO_printf(bio_err, "failed to update database\n");
2150 BIO_printf(bio_err, "TXT_DB error number %ld\n", db->db->error);
2154 /* Revoke Certificate */
2158 ok = do_revoke(x509, db, type, value);
2162 } else if (index_name_cmp_noconst(row, rrow)) {
2163 BIO_printf(bio_err, "ERROR:name does not match %s\n", row[DB_name]);
2165 } else if (type == -1) {
2166 BIO_printf(bio_err, "ERROR:Already present, serial number %s\n",
2169 } else if (rrow[DB_type][0] == 'R') {
2170 BIO_printf(bio_err, "ERROR:Already revoked, serial number %s\n",
2174 BIO_printf(bio_err, "Revoking Certificate %s.\n", rrow[DB_serial]);
2175 rev_str = make_revocation_str(type, value);
2177 BIO_printf(bio_err, "Error in revocation arguments\n");
2180 rrow[DB_type][0] = 'R';
2181 rrow[DB_type][1] = '\0';
2182 rrow[DB_rev_date] = rev_str;
2186 for (i = 0; i < DB_NUMBER; i++) {
2187 OPENSSL_free(row[i]);
2192 static int get_certificate_status(const char *serial, CA_DB *db)
2194 char *row[DB_NUMBER], **rrow;
2197 /* Free Resources */
2198 for (i = 0; i < DB_NUMBER; i++)
2201 /* Malloc needed char spaces */
2202 row[DB_serial] = app_malloc(strlen(serial) + 2, "row serial#");
2204 if (strlen(serial) % 2) {
2206 * Set the first char to 0
2208 row[DB_serial][0] = '0';
2210 /* Copy String from serial to row[DB_serial] */
2211 memcpy(row[DB_serial] + 1, serial, strlen(serial));
2212 row[DB_serial][strlen(serial) + 1] = '\0';
2214 /* Copy String from serial to row[DB_serial] */
2215 memcpy(row[DB_serial], serial, strlen(serial));
2216 row[DB_serial][strlen(serial)] = '\0';
2219 /* Make it Upper Case */
2220 for (i = 0; row[DB_serial][i] != '\0'; i++)
2221 row[DB_serial][i] = toupper((unsigned char)row[DB_serial][i]);
2225 /* Search for the certificate */
2226 rrow = TXT_DB_get_by_index(db->db, DB_serial, row);
2228 BIO_printf(bio_err, "Serial %s not present in db.\n", row[DB_serial]);
2231 } else if (rrow[DB_type][0] == 'V') {
2232 BIO_printf(bio_err, "%s=Valid (%c)\n",
2233 row[DB_serial], rrow[DB_type][0]);
2235 } else if (rrow[DB_type][0] == 'R') {
2236 BIO_printf(bio_err, "%s=Revoked (%c)\n",
2237 row[DB_serial], rrow[DB_type][0]);
2239 } else if (rrow[DB_type][0] == 'E') {
2240 BIO_printf(bio_err, "%s=Expired (%c)\n",
2241 row[DB_serial], rrow[DB_type][0]);
2243 } else if (rrow[DB_type][0] == 'S') {
2244 BIO_printf(bio_err, "%s=Suspended (%c)\n",
2245 row[DB_serial], rrow[DB_type][0]);
2248 BIO_printf(bio_err, "%s=Unknown (%c).\n",
2249 row[DB_serial], rrow[DB_type][0]);
2253 for (i = 0; i < DB_NUMBER; i++) {
2254 OPENSSL_free(row[i]);
2259 static int do_updatedb(CA_DB *db)
2261 ASN1_UTCTIME *a_tm = NULL;
2263 int db_y2k, a_y2k; /* flags = 1 if y >= 2000 */
2264 char **rrow, *a_tm_s;
2266 a_tm = ASN1_UTCTIME_new();
2270 /* get actual time and make a string */
2271 a_tm = X509_gmtime_adj(a_tm, 0);
2272 a_tm_s = (char *)app_malloc(a_tm->length + 1, "time string");
2274 memcpy(a_tm_s, a_tm->data, a_tm->length);
2275 a_tm_s[a_tm->length] = '\0';
2277 if (strncmp(a_tm_s, "49", 2) <= 0)
2282 for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
2283 rrow = sk_OPENSSL_PSTRING_value(db->db->data, i);
2285 if (rrow[DB_type][0] == 'V') {
2286 /* ignore entries that are not valid */
2287 if (strncmp(rrow[DB_exp_date], "49", 2) <= 0)
2292 if (db_y2k == a_y2k) {
2293 /* all on the same y2k side */
2294 if (strcmp(rrow[DB_exp_date], a_tm_s) <= 0) {
2295 rrow[DB_type][0] = 'E';
2296 rrow[DB_type][1] = '\0';
2299 BIO_printf(bio_err, "%s=Expired\n", rrow[DB_serial]);
2301 } else if (db_y2k < a_y2k) {
2302 rrow[DB_type][0] = 'E';
2303 rrow[DB_type][1] = '\0';
2306 BIO_printf(bio_err, "%s=Expired\n", rrow[DB_serial]);
2312 ASN1_UTCTIME_free(a_tm);
2313 OPENSSL_free(a_tm_s);
2317 static const char *crl_reasons[] = {
2318 /* CRL reason strings */
2322 "affiliationChanged",
2324 "cessationOfOperation",
2327 /* Additional pseudo reasons */
2333 #define NUM_REASONS OSSL_NELEM(crl_reasons)
2336 * Given revocation information convert to a DB string. The format of the
2337 * string is: revtime[,reason,extra]. Where 'revtime' is the revocation time
2338 * (the current time). 'reason' is the optional CRL reason and 'extra' is any
2339 * additional argument
2342 char *make_revocation_str(int rev_type, char *rev_arg)
2344 char *other = NULL, *str;
2345 const char *reason = NULL;
2347 ASN1_UTCTIME *revtm = NULL;
2353 case REV_CRL_REASON:
2354 for (i = 0; i < 8; i++) {
2355 if (strcasecmp(rev_arg, crl_reasons[i]) == 0) {
2356 reason = crl_reasons[i];
2360 if (reason == NULL) {
2361 BIO_printf(bio_err, "Unknown CRL reason %s\n", rev_arg);
2367 /* Argument is an OID */
2369 otmp = OBJ_txt2obj(rev_arg, 0);
2370 ASN1_OBJECT_free(otmp);
2373 BIO_printf(bio_err, "Invalid object identifier %s\n", rev_arg);
2377 reason = "holdInstruction";
2381 case REV_KEY_COMPROMISE:
2382 case REV_CA_COMPROMISE:
2384 /* Argument is the key compromise time */
2385 if (!ASN1_GENERALIZEDTIME_set_string(NULL, rev_arg)) {
2387 "Invalid time format %s. Need YYYYMMDDHHMMSSZ\n",
2392 if (rev_type == REV_KEY_COMPROMISE)
2395 reason = "CAkeyTime";
2401 revtm = X509_gmtime_adj(NULL, 0);
2406 i = revtm->length + 1;
2409 i += strlen(reason) + 1;
2411 i += strlen(other) + 1;
2413 str = app_malloc(i, "revocation reason");
2414 OPENSSL_strlcpy(str, (char *)revtm->data, i);
2416 OPENSSL_strlcat(str, ",", i);
2417 OPENSSL_strlcat(str, reason, i);
2420 OPENSSL_strlcat(str, ",", i);
2421 OPENSSL_strlcat(str, other, i);
2423 ASN1_UTCTIME_free(revtm);
2428 * Convert revocation field to X509_REVOKED entry
2432 * 2 OK and some extensions added (i.e. V2 CRL)
2435 int make_revoked(X509_REVOKED *rev, const char *str)
2438 int reason_code = -1;
2440 ASN1_OBJECT *hold = NULL;
2441 ASN1_GENERALIZEDTIME *comp_time = NULL;
2442 ASN1_ENUMERATED *rtmp = NULL;
2444 ASN1_TIME *revDate = NULL;
2446 i = unpack_revinfo(&revDate, &reason_code, &hold, &comp_time, str);
2451 if (rev && !X509_REVOKED_set_revocationDate(rev, revDate))
2454 if (rev && (reason_code != OCSP_REVOKED_STATUS_NOSTATUS)) {
2455 rtmp = ASN1_ENUMERATED_new();
2456 if (rtmp == NULL || !ASN1_ENUMERATED_set(rtmp, reason_code))
2458 if (!X509_REVOKED_add1_ext_i2d(rev, NID_crl_reason, rtmp, 0, 0))
2462 if (rev && comp_time) {
2463 if (!X509_REVOKED_add1_ext_i2d
2464 (rev, NID_invalidity_date, comp_time, 0, 0))
2468 if (!X509_REVOKED_add1_ext_i2d
2469 (rev, NID_hold_instruction_code, hold, 0, 0))
2473 if (reason_code != OCSP_REVOKED_STATUS_NOSTATUS)
2481 ASN1_OBJECT_free(hold);
2482 ASN1_GENERALIZEDTIME_free(comp_time);
2483 ASN1_ENUMERATED_free(rtmp);
2484 ASN1_TIME_free(revDate);
2489 static int old_entry_print(ASN1_OBJECT *obj, ASN1_STRING *str)
2491 char buf[25], *pbuf, *p;
2493 j = i2a_ASN1_OBJECT(bio_err, obj);
2495 for (j = 22 - j; j > 0; j--)
2499 BIO_puts(bio_err, buf);
2501 if (str->type == V_ASN1_PRINTABLESTRING)
2502 BIO_printf(bio_err, "PRINTABLE:'");
2503 else if (str->type == V_ASN1_T61STRING)
2504 BIO_printf(bio_err, "T61STRING:'");
2505 else if (str->type == V_ASN1_IA5STRING)
2506 BIO_printf(bio_err, "IA5STRING:'");
2507 else if (str->type == V_ASN1_UNIVERSALSTRING)
2508 BIO_printf(bio_err, "UNIVERSALSTRING:'");
2510 BIO_printf(bio_err, "ASN.1 %2d:'", str->type);
2512 p = (char *)str->data;
2513 for (j = str->length; j > 0; j--) {
2514 if ((*p >= ' ') && (*p <= '~'))
2515 BIO_printf(bio_err, "%c", *p);
2517 BIO_printf(bio_err, "\\0x%02X", *p);
2518 else if ((unsigned char)*p == 0xf7)
2519 BIO_printf(bio_err, "^?");
2521 BIO_printf(bio_err, "^%c", *p + '@');
2524 BIO_printf(bio_err, "'\n");
2528 int unpack_revinfo(ASN1_TIME **prevtm, int *preason, ASN1_OBJECT **phold,
2529 ASN1_GENERALIZEDTIME **pinvtm, const char *str)
2532 char *rtime_str, *reason_str = NULL, *arg_str = NULL, *p;
2533 int reason_code = -1;
2536 ASN1_OBJECT *hold = NULL;
2537 ASN1_GENERALIZEDTIME *comp_time = NULL;
2539 tmp = OPENSSL_strdup(str);
2541 BIO_printf(bio_err, "memory allocation failure\n");
2545 p = strchr(tmp, ',');
2561 *prevtm = ASN1_UTCTIME_new();
2562 if (*prevtm == NULL) {
2563 BIO_printf(bio_err, "memory allocation failure\n");
2566 if (!ASN1_UTCTIME_set_string(*prevtm, rtime_str)) {
2567 BIO_printf(bio_err, "invalid revocation date %s\n", rtime_str);
2572 for (i = 0; i < NUM_REASONS; i++) {
2573 if (strcasecmp(reason_str, crl_reasons[i]) == 0) {
2578 if (reason_code == OCSP_REVOKED_STATUS_NOSTATUS) {
2579 BIO_printf(bio_err, "invalid reason code %s\n", reason_str);
2583 if (reason_code == 7)
2584 reason_code = OCSP_REVOKED_STATUS_REMOVEFROMCRL;
2585 else if (reason_code == 8) { /* Hold instruction */
2587 BIO_printf(bio_err, "missing hold instruction\n");
2590 reason_code = OCSP_REVOKED_STATUS_CERTIFICATEHOLD;
2591 hold = OBJ_txt2obj(arg_str, 0);
2594 BIO_printf(bio_err, "invalid object identifier %s\n",
2601 ASN1_OBJECT_free(hold);
2602 } else if ((reason_code == 9) || (reason_code == 10)) {
2604 BIO_printf(bio_err, "missing compromised time\n");
2607 comp_time = ASN1_GENERALIZEDTIME_new();
2608 if (comp_time == NULL) {
2609 BIO_printf(bio_err, "memory allocation failure\n");
2612 if (!ASN1_GENERALIZEDTIME_set_string(comp_time, arg_str)) {
2613 BIO_printf(bio_err, "invalid compromised time %s\n", arg_str);
2616 if (reason_code == 9)
2617 reason_code = OCSP_REVOKED_STATUS_KEYCOMPROMISE;
2619 reason_code = OCSP_REVOKED_STATUS_CACOMPROMISE;
2624 *preason = reason_code;
2626 *pinvtm = comp_time;
2635 ASN1_GENERALIZEDTIME_free(comp_time);