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_DIR "dir"
109 #define ENV_CERTS "certs"
110 #define ENV_CRL_DIR "crl_dir"
111 #define ENV_CA_DB "CA_DB"
112 #define ENV_NEW_CERTS_DIR "new_certs_dir"
113 #define ENV_CERTIFICATE "certificate"
114 #define ENV_SERIAL "serial"
115 #define ENV_CRLNUMBER "crlnumber"
116 #define ENV_CRL "crl"
117 #define ENV_PRIVATE_KEY "private_key"
118 #define ENV_RANDFILE "RANDFILE"
119 #define ENV_DEFAULT_DAYS "default_days"
120 #define ENV_DEFAULT_STARTDATE "default_startdate"
121 #define ENV_DEFAULT_ENDDATE "default_enddate"
122 #define ENV_DEFAULT_CRL_DAYS "default_crl_days"
123 #define ENV_DEFAULT_CRL_HOURS "default_crl_hours"
124 #define ENV_DEFAULT_MD "default_md"
125 #define ENV_DEFAULT_EMAIL_DN "email_in_dn"
126 #define ENV_PRESERVE "preserve"
127 #define ENV_POLICY "policy"
128 #define ENV_EXTENSIONS "x509_extensions"
129 #define ENV_CRLEXT "crl_extensions"
130 #define ENV_MSIE_HACK "msie_hack"
131 #define ENV_NAMEOPT "name_opt"
132 #define ENV_CERTOPT "cert_opt"
133 #define ENV_EXTCOPY "copy_extensions"
134 #define ENV_UNIQUE_SUBJECT "unique_subject"
136 #define ENV_DATABASE "database"
138 /* Additional revocation information types */
140 #define REV_NONE 0 /* No addditional information */
141 #define REV_CRL_REASON 1 /* Value is CRL reason code */
142 #define REV_HOLD 2 /* Value is hold instruction */
143 #define REV_KEY_COMPROMISE 3 /* Value is cert key compromise time */
144 #define REV_CA_COMPROMISE 4 /* Value is CA key compromise time */
146 static void lookup_fail(const char *name, const char *tag);
147 static int certify(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509,
148 const EVP_MD *dgst, STACK_OF(OPENSSL_STRING) *sigopts,
149 STACK_OF(CONF_VALUE) *policy, CA_DB *db,
150 BIGNUM *serial, char *subj, unsigned long chtype,
151 int multirdn, int email_dn, char *startdate, char *enddate,
152 long days, int batch, char *ext_sect, CONF *conf,
153 int verbose, unsigned long certopt, unsigned long nameopt,
154 int default_op, int ext_copy, int selfsign);
155 static int certify_cert(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509,
156 const EVP_MD *dgst, STACK_OF(OPENSSL_STRING) *sigopts,
157 STACK_OF(CONF_VALUE) *policy, CA_DB *db,
158 BIGNUM *serial, char *subj, unsigned long chtype,
159 int multirdn, int email_dn, char *startdate,
160 char *enddate, long days, int batch, char *ext_sect,
161 CONF *conf, int verbose, unsigned long certopt,
162 unsigned long nameopt, int default_op, int ext_copy,
164 static int certify_spkac(X509 **xret, char *infile, EVP_PKEY *pkey,
165 X509 *x509, const EVP_MD *dgst,
166 STACK_OF(OPENSSL_STRING) *sigopts,
167 STACK_OF(CONF_VALUE) *policy, CA_DB *db,
168 BIGNUM *serial, char *subj, unsigned long chtype,
169 int multirdn, int email_dn, char *startdate,
170 char *enddate, long days, char *ext_sect, CONF *conf,
171 int verbose, unsigned long certopt,
172 unsigned long nameopt, int default_op, int ext_copy);
173 static void write_new_certificate(BIO *bp, X509 *x, int output_der,
175 static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509,
176 const EVP_MD *dgst, STACK_OF(OPENSSL_STRING) *sigopts,
177 STACK_OF(CONF_VALUE) *policy, CA_DB *db, BIGNUM *serial,
178 char *subj, unsigned long chtype, int multirdn,
179 int email_dn, char *startdate, char *enddate, long days,
180 int batch, int verbose, X509_REQ *req, char *ext_sect,
181 CONF *conf, unsigned long certopt, unsigned long nameopt,
182 int default_op, int ext_copy, int selfsign);
183 static int do_revoke(X509 *x509, CA_DB *db, int ext, char *extval);
184 static int get_certificate_status(const char *ser_status, CA_DB *db);
185 static int do_updatedb(CA_DB *db);
186 static int check_time_format(const char *str);
187 char *make_revocation_str(int rev_type, char *rev_arg);
188 int make_revoked(X509_REVOKED *rev, const char *str);
189 static int old_entry_print(ASN1_OBJECT *obj, ASN1_STRING *str);
191 static CONF *conf = NULL;
192 static CONF *extconf = NULL;
193 static char *section = NULL;
194 static int preserve = 0;
195 static int msie_hack = 0;
197 typedef enum OPTION_choice {
198 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
199 OPT_ENGINE, OPT_VERBOSE, OPT_CONFIG, OPT_NAME, OPT_SUBJ, OPT_UTF8,
200 OPT_CREATE_SERIAL, OPT_MULTIVALUE_RDN, OPT_STARTDATE, OPT_ENDDATE,
201 OPT_DAYS, OPT_MD, OPT_POLICY, OPT_KEYFILE, OPT_KEYFORM, OPT_PASSIN,
202 OPT_KEY, OPT_CERT, OPT_SELFSIGN, OPT_IN, OPT_OUT, OPT_OUTDIR,
203 OPT_SIGOPT, OPT_NOTEXT, OPT_BATCH, OPT_PRESERVEDN, OPT_NOEMAILDN,
204 OPT_GENCRL, OPT_MSIE_HACK, OPT_CRLDAYS, OPT_CRLHOURS, OPT_CRLSEC,
205 OPT_INFILES, OPT_SS_CERT, OPT_SPKAC, OPT_REVOKE, OPT_VALID,
206 OPT_EXTENSIONS, OPT_EXTFILE, OPT_STATUS, OPT_UPDATEDB, OPT_CRLEXTS,
207 OPT_CRL_REASON, OPT_CRL_HOLD, OPT_CRL_COMPROMISE,
208 OPT_CRL_CA_COMPROMISE
211 OPTIONS ca_options[] = {
212 {"help", OPT_HELP, '-', "Display this summary"},
213 {"verbose", OPT_VERBOSE, '-', "Verbose output during processing"},
214 {"config", OPT_CONFIG, 's', "A config file"},
215 {"name", OPT_NAME, 's', "The particular CA definition to use"},
216 {"subj", OPT_SUBJ, 's', "Use arg instead of request's subject"},
217 {"utf8", OPT_UTF8, '-', "Input characters are UTF8 (default ASCII)"},
218 {"create_serial", OPT_CREATE_SERIAL, '-'},
219 {"multivalue-rdn", OPT_MULTIVALUE_RDN, '-',
220 "Enable support for multivalued RDNs"},
221 {"startdate", OPT_STARTDATE, 's', "Cert notBefore, YYMMDDHHMMSSZ"},
222 {"enddate", OPT_ENDDATE, 's',
223 "YYMMDDHHMMSSZ cert notAfter (overrides -days)"},
224 {"days", OPT_DAYS, 'p', "Number of days to certify the cert for"},
225 {"md", OPT_MD, 's', "md to use; one of md2, md5, sha or sha1"},
226 {"policy", OPT_POLICY, 's', "The CA 'policy' to support"},
227 {"keyfile", OPT_KEYFILE, '<', "Private key file"},
228 {"keyform", OPT_KEYFORM, 'f', "Private key file format (PEM or ENGINE)"},
229 {"passin", OPT_PASSIN, 's'},
230 {"key", OPT_KEY, 's', "Key to decode the private key if it is encrypted"},
231 {"cert", OPT_CERT, '<', "The CA cert"},
232 {"selfsign", OPT_SELFSIGN, '-',
233 "Sign a cert with the key associated with it"},
234 {"in", OPT_IN, '<', "The input PEM encoded cert request(s)"},
235 {"out", OPT_OUT, '>', "Where to put the output file(s)"},
236 {"outdir", OPT_OUTDIR, '/', "Where to put output cert"},
237 {"sigopt", OPT_SIGOPT, 's'},
238 {"notext", OPT_NOTEXT, '-'},
239 {"batch", OPT_BATCH, '-', "Don't ask questions"},
240 {"preserveDN", OPT_PRESERVEDN, '-', "Don't re-order the DN"},
241 {"noemailDN", OPT_NOEMAILDN, '-', "Don't add the EMAIL field to the DN"},
242 {"gencrl", OPT_GENCRL, '-', "Generate a new CRL"},
243 {"msie_hack", OPT_MSIE_HACK, '-',
244 "msie modifications to handle all those universal strings"},
245 {"crldays", OPT_CRLDAYS, 'p', "Days is when the next CRL is due"},
246 {"crlhours", OPT_CRLHOURS, 'p', "Hours is when the next CRL is due"},
247 {"crlsec", OPT_CRLSEC, 'p'},
248 {"infiles", OPT_INFILES, '-', "The last argument, requests to process"},
249 {"ss_cert", OPT_SS_CERT, '<', "File contains a self signed cert to sign"},
250 {"spkac", OPT_SPKAC, '<',
251 "File contains DN and signed public key and challenge"},
252 {"revoke", OPT_REVOKE, '<', "Revoke a cert (given in file)"},
253 {"valid", OPT_VALID, 's'},
254 {"extensions", OPT_EXTENSIONS, 's',
255 "Extension section (override value in config file)"},
256 {"extfile", OPT_EXTFILE, '<',
257 "Configuration file with X509v3 extensions to add"},
258 {"status", OPT_STATUS, 's', "Shows cert status given the serial number"},
259 {"updatedb", OPT_UPDATEDB, '-', "Updates db for expired cert"},
260 {"crlexts", OPT_CRLEXTS, 's',
261 "CRL extension section (override value in config file)"},
262 {"crl_reason", OPT_CRL_REASON, 's'},
263 {"crl_hold", OPT_CRL_HOLD, 's'},
264 {"crl_compromise", OPT_CRL_COMPROMISE, 's'},
265 {"crl_CA_compromise", OPT_CRL_CA_COMPROMISE, 's'},
266 #ifndef OPENSSL_NO_ENGINE
267 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
272 int ca_main(int argc, char **argv)
275 BIGNUM *crlnumber = NULL, *serial = NULL;
276 EVP_PKEY *pkey = NULL;
277 BIO *in = NULL, *out = NULL, *Sout = NULL, *Cout = NULL;
278 ASN1_INTEGER *tmpser;
282 STACK_OF(CONF_VALUE) *attribs = NULL;
283 STACK_OF(OPENSSL_STRING) *sigopts = NULL;
284 STACK_OF(X509) *cert_sk = NULL;
285 X509_CRL *crl = NULL;
286 const EVP_MD *dgst = NULL;
287 char *configfile = default_config_file;
288 char *md = NULL, *policy = NULL, *keyfile = NULL;
289 char *certfile = NULL, *crl_ext = NULL, *crlnumberfile = NULL;
290 char *infile = NULL, *spkac_file = NULL, *ss_cert_file = NULL;
291 char *extensions = NULL, *extfile = NULL, *key = NULL, *passinarg = NULL;
292 char *outdir = NULL, *outfile = NULL, *rev_arg = NULL, *ser_status = NULL;
293 char *serialfile = NULL, *startdate = NULL, *subj = NULL;
294 char *prog, *enddate = NULL, *tmp_email_dn = NULL;
295 char *dbfile = NULL, *f, *randfile = NULL, *tofree = NULL;
299 int create_ser = 0, free_key = 0, total = 0, total_done = 0;
300 int batch = 0, default_op = 1, doupdatedb = 0, ext_copy = EXT_COPY_NONE;
301 int keyformat = FORMAT_PEM, multirdn = 0, notext = 0, output_der = 0;
302 int ret = 1, email_dn = 1, req = 0, verbose = 0, gencrl = 0, dorevoke = 0;
303 int i, j, rev_type = REV_NONE, selfsign = 0;
304 long crldays = 0, crlhours = 0, crlsec = 0, days = 0;
305 unsigned long chtype = MBSTRING_ASC, nameopt = 0, certopt = 0;
306 X509 *x509 = NULL, *x509p = NULL, *x = NULL;
307 X509_REVOKED *r = NULL;
315 prog = opt_init(argc, argv, ca_options);
316 while ((o = opt_next()) != OPT_EOF) {
321 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
324 opt_help(ca_options);
338 configfile = opt_arg();
348 chtype = MBSTRING_UTF8;
350 case OPT_CREATE_SERIAL:
353 case OPT_MULTIVALUE_RDN:
357 startdate = opt_arg();
363 days = atoi(opt_arg());
375 if (!opt_format(opt_arg(), OPT_FMT_ANY, &keyformat))
379 passinarg = opt_arg();
385 certfile = opt_arg();
395 sigopts = sk_OPENSSL_STRING_new_null();
397 || !sk_OPENSSL_STRING_push(sigopts, opt_arg()))
419 crldays = atol(opt_arg());
422 crlhours = atol(opt_arg());
425 crlsec = atol(opt_arg());
431 ss_cert_file = opt_arg();
435 spkac_file = opt_arg();
447 extensions = opt_arg();
453 ser_status = opt_arg();
463 rev_type = REV_CRL_REASON;
469 case OPT_CRL_COMPROMISE:
471 rev_type = REV_KEY_COMPROMISE;
473 case OPT_CRL_CA_COMPROMISE:
475 rev_type = REV_CA_COMPROMISE;
478 e = setup_engine(opt_arg(), 0);
483 argc = opt_num_rest();
486 BIO_printf(bio_err, "Using configuration from %s\n", configfile);
487 if ((conf = app_load_config(configfile)) == NULL)
489 if (!app_load_modules(conf))
492 /* Lets get the config section we are using */
493 if (section == NULL) {
494 section = NCONF_get_string(conf, BASE_SECTION, ENV_DEFAULT_CA);
495 if (section == NULL) {
496 lookup_fail(BASE_SECTION, ENV_DEFAULT_CA);
502 p = NCONF_get_string(conf, NULL, "oid_file");
508 oid_bio = BIO_new_file(p, "r");
509 if (oid_bio == NULL) {
511 BIO_printf(bio_err,"problems opening %s for extra oid's\n",p);
512 ERR_print_errors(bio_err);
516 OBJ_create_objects(oid_bio);
520 if (!add_oid_section(conf)) {
521 ERR_print_errors(bio_err);
526 randfile = NCONF_get_string(conf, BASE_SECTION, "RANDFILE");
527 if (randfile == NULL)
529 app_RAND_load_file(randfile, 0);
531 f = NCONF_get_string(conf, section, STRING_MASK);
535 if (f && !ASN1_STRING_set_default_mask_asc(f)) {
536 BIO_printf(bio_err, "Invalid global string mask setting %s\n", f);
540 if (chtype != MBSTRING_UTF8) {
541 f = NCONF_get_string(conf, section, UTF8_IN);
544 else if (strcmp(f, "yes") == 0)
545 chtype = MBSTRING_UTF8;
548 db_attr.unique_subject = 1;
549 p = NCONF_get_string(conf, section, ENV_UNIQUE_SUBJECT);
551 db_attr.unique_subject = parse_yesno(p, 1);
555 /*****************************************************************/
556 /* report status of cert with serial number given on command line */
558 if ((dbfile = NCONF_get_string(conf, section, ENV_DATABASE)) == NULL) {
559 lookup_fail(section, ENV_DATABASE);
562 db = load_index(dbfile, &db_attr);
566 if (!index_index(db))
569 if (get_certificate_status(ser_status, db) != 1)
570 BIO_printf(bio_err, "Error verifying serial %s!\n", ser_status);
574 /*****************************************************************/
575 /* we definitely need a private key, so let's get it */
577 if ((keyfile == NULL) && ((keyfile = NCONF_get_string(conf,
581 lookup_fail(section, ENV_PRIVATE_KEY);
586 if (!app_passwd(passinarg, NULL, &key, NULL)) {
587 BIO_printf(bio_err, "Error getting password\n");
591 pkey = load_key(keyfile, keyformat, 0, key, e, "CA private key");
593 OPENSSL_cleanse(key, strlen(key));
595 /* load_key() has already printed an appropriate message */
599 /*****************************************************************/
600 /* we need a certificate */
601 if (!selfsign || spkac_file || ss_cert_file || gencrl) {
602 if ((certfile == NULL)
603 && ((certfile = NCONF_get_string(conf,
605 ENV_CERTIFICATE)) == NULL)) {
606 lookup_fail(section, ENV_CERTIFICATE);
609 x509 = load_cert(certfile, FORMAT_PEM, NULL, e, "CA certificate");
613 if (!X509_check_private_key(x509, pkey)) {
615 "CA certificate and CA private key do not match\n");
622 f = NCONF_get_string(conf, BASE_SECTION, ENV_PRESERVE);
625 if ((f != NULL) && ((*f == 'y') || (*f == 'Y')))
627 f = NCONF_get_string(conf, BASE_SECTION, ENV_MSIE_HACK);
630 if ((f != NULL) && ((*f == 'y') || (*f == 'Y')))
633 f = NCONF_get_string(conf, section, ENV_NAMEOPT);
636 if (!set_name_ex(&nameopt, f)) {
637 BIO_printf(bio_err, "Invalid name options: \"%s\"\n", f);
644 f = NCONF_get_string(conf, section, ENV_CERTOPT);
647 if (!set_cert_ex(&certopt, f)) {
648 BIO_printf(bio_err, "Invalid certificate options: \"%s\"\n", f);
655 f = NCONF_get_string(conf, section, ENV_EXTCOPY);
658 if (!set_ext_copy(&ext_copy, f)) {
659 BIO_printf(bio_err, "Invalid extension copy option: \"%s\"\n", f);
665 /*****************************************************************/
666 /* lookup where to write new certificates */
667 if ((outdir == NULL) && (req)) {
669 if ((outdir = NCONF_get_string(conf, section, ENV_NEW_CERTS_DIR))
672 "there needs to be defined a directory for new certificate to be placed in\n");
675 #ifndef OPENSSL_SYS_VMS
677 * outdir is a directory spec, but access() for VMS demands a
678 * filename. We could use the DEC C routine to convert the
679 * directory syntax to Unixly, and give that to app_isdir,
680 * but for now the fopen will catch the error if it's not a
683 if (app_isdir(outdir) <= 0) {
684 BIO_printf(bio_err, "%s: %s is not a directory\n", prog, outdir);
691 /*****************************************************************/
692 /* we need to load the database file */
693 if ((dbfile = NCONF_get_string(conf, section, ENV_DATABASE)) == NULL) {
694 lookup_fail(section, ENV_DATABASE);
697 db = load_index(dbfile, &db_attr);
701 /* Lets check some fields */
702 for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
703 pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
704 if ((pp[DB_type][0] != DB_TYPE_REV) && (pp[DB_rev_date][0] != '\0')) {
706 "entry %d: not revoked yet, but has a revocation date\n",
710 if ((pp[DB_type][0] == DB_TYPE_REV) &&
711 !make_revoked(NULL, pp[DB_rev_date])) {
712 BIO_printf(bio_err, " in entry %d\n", i + 1);
715 if (!check_time_format((char *)pp[DB_exp_date])) {
716 BIO_printf(bio_err, "entry %d: invalid expiry date\n", i + 1);
725 if ((j & 1) || (j < 2)) {
726 BIO_printf(bio_err, "entry %d: bad serial number length (%d)\n",
733 "entry %d: bad char 0%o '%c' in serial number\n",
740 TXT_DB_write(bio_out, db->db);
741 BIO_printf(bio_err, "%d entries loaded from the database\n",
742 sk_OPENSSL_PSTRING_num(db->db->data));
743 BIO_printf(bio_err, "generating index\n");
746 if (!index_index(db))
749 /*****************************************************************/
750 /* Update the db file for expired certificates */
753 BIO_printf(bio_err, "Updating %s ...\n", dbfile);
757 BIO_printf(bio_err, "Malloc failure\n");
761 BIO_printf(bio_err, "No entries found to mark expired\n");
763 if (!save_index(dbfile, "new", db))
766 if (!rotate_index(dbfile, "new", "old"))
771 "Done. %d entries marked as expired\n", i);
775 /*****************************************************************/
776 /* Read extensions config file */
778 if ((extconf = app_load_config(extfile)) == NULL) {
784 BIO_printf(bio_err, "Successfully loaded extensions file %s\n",
787 /* We can have sections in the ext file */
790 NCONF_get_string(extconf, "default", "extensions")))
791 extensions = "default";
794 /*****************************************************************/
796 Sout = bio_open_default(outfile, "w");
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(dgst->type));
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++) {
1056 x = sk_X509_value(cert_sk, i);
1058 j = x->cert_info->serialNumber->length;
1059 p = (const char *)x->cert_info->serialNumber->data;
1061 if (strlen(outdir) >= (size_t)(j ? BSIZE - j * 2 - 6 : BSIZE - 8)) {
1062 BIO_printf(bio_err, "certificate file name too long\n");
1066 strcpy(buf[2], outdir);
1068 #ifndef OPENSSL_SYS_VMS
1069 BUF_strlcat(buf[2], "/", sizeof(buf[2]));
1072 n = (char *)&(buf[2][strlen(buf[2])]);
1074 for (k = 0; k < j; k++) {
1075 if (n >= &(buf[2][sizeof(buf[2])]))
1078 &buf[2][0] + sizeof(buf[2]) - n,
1079 "%02X", (unsigned char)*(p++));
1092 BIO_printf(bio_err, "writing %s\n", buf[2]);
1094 Cout = BIO_new_file(buf[2], "w");
1099 write_new_certificate(Cout, x, 0, notext);
1100 write_new_certificate(Sout, x, output_der, notext);
1103 if (sk_X509_num(cert_sk)) {
1104 /* Rename the database and the serial file */
1105 if (!rotate_serial(serialfile, "new", "old"))
1108 if (!rotate_index(dbfile, "new", "old"))
1111 BIO_printf(bio_err, "Data Base Updated\n");
1115 /*****************************************************************/
1119 crl_ext = NCONF_get_string(conf, section, ENV_CRLEXT);
1124 /* Check syntax of file */
1126 X509V3_set_ctx_test(&ctx);
1127 X509V3_set_nconf(&ctx, conf);
1128 if (!X509V3_EXT_add_nconf(conf, &ctx, crl_ext, NULL)) {
1130 "Error Loading CRL extension section %s\n",
1137 if ((crlnumberfile = NCONF_get_string(conf, section, ENV_CRLNUMBER))
1139 if ((crlnumber = load_serial(crlnumberfile, 0, NULL)) == NULL) {
1140 BIO_printf(bio_err, "error while loading CRL number\n");
1144 if (!crldays && !crlhours && !crlsec) {
1145 if (!NCONF_get_number(conf, section,
1146 ENV_DEFAULT_CRL_DAYS, &crldays))
1148 if (!NCONF_get_number(conf, section,
1149 ENV_DEFAULT_CRL_HOURS, &crlhours))
1153 if ((crldays == 0) && (crlhours == 0) && (crlsec == 0)) {
1155 "cannot lookup how long until the next CRL is issued\n");
1160 BIO_printf(bio_err, "making CRL\n");
1161 if ((crl = X509_CRL_new()) == NULL)
1163 if (!X509_CRL_set_issuer_name(crl, X509_get_subject_name(x509)))
1166 tmptm = ASN1_TIME_new();
1169 X509_gmtime_adj(tmptm, 0);
1170 X509_CRL_set_lastUpdate(crl, tmptm);
1171 if (!X509_time_adj_ex(tmptm, crldays, crlhours * 60 * 60 + crlsec,
1173 BIO_puts(bio_err, "error setting CRL nextUpdate\n");
1176 X509_CRL_set_nextUpdate(crl, tmptm);
1178 ASN1_TIME_free(tmptm);
1180 for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
1181 pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
1182 if (pp[DB_type][0] == DB_TYPE_REV) {
1183 if ((r = X509_REVOKED_new()) == NULL)
1185 j = make_revoked(r, pp[DB_rev_date]);
1190 if (!BN_hex2bn(&serial, pp[DB_serial]))
1192 tmpser = BN_to_ASN1_INTEGER(serial, NULL);
1197 X509_REVOKED_set_serialNumber(r, tmpser);
1198 ASN1_INTEGER_free(tmpser);
1199 X509_CRL_add0_revoked(crl, r);
1204 * sort the data so it will be written in serial number order
1208 /* we now have a CRL */
1210 BIO_printf(bio_err, "signing CRL\n");
1212 /* Add any extensions asked for */
1214 if (crl_ext || crlnumberfile != NULL) {
1216 X509V3_set_ctx(&crlctx, x509, NULL, NULL, crl, 0);
1217 X509V3_set_nconf(&crlctx, conf);
1220 if (!X509V3_EXT_CRL_add_nconf(conf, &crlctx, crl_ext, crl))
1222 if (crlnumberfile != NULL) {
1223 tmpser = BN_to_ASN1_INTEGER(crlnumber, NULL);
1226 X509_CRL_add1_ext_i2d(crl, NID_crl_number, tmpser, 0, 0);
1227 ASN1_INTEGER_free(tmpser);
1229 if (!BN_add_word(crlnumber, 1))
1233 if (crl_ext || crl_v2) {
1234 if (!X509_CRL_set_version(crl, 1))
1235 goto end; /* version 2 CRL */
1238 /* we have a CRL number that need updating */
1239 if (crlnumberfile != NULL)
1240 if (!save_serial(crlnumberfile, "new", crlnumber, NULL))
1246 if (!do_X509_CRL_sign(crl, pkey, dgst, sigopts))
1249 PEM_write_bio_X509_CRL(Sout, crl);
1251 if (crlnumberfile != NULL) /* Rename the crlnumber file */
1252 if (!rotate_serial(crlnumberfile, "new", "old"))
1256 /*****************************************************************/
1258 if (infile == NULL) {
1259 BIO_printf(bio_err, "no input files\n");
1263 revcert = load_cert(infile, FORMAT_PEM, NULL, e, infile);
1264 if (revcert == NULL)
1268 j = do_revoke(revcert, db, rev_type, rev_arg);
1273 if (!save_index(dbfile, "new", db))
1276 if (!rotate_index(dbfile, "new", "old"))
1279 BIO_printf(bio_err, "Data Base Updated\n");
1282 /*****************************************************************/
1285 OPENSSL_free(tofree);
1290 sk_X509_pop_free(cert_sk, X509_free);
1293 ERR_print_errors(bio_err);
1294 app_RAND_write_file(randfile);
1300 sk_OPENSSL_STRING_free(sigopts);
1301 EVP_PKEY_free(pkey);
1305 NCONF_free(extconf);
1310 static void lookup_fail(const char *name, const char *tag)
1312 BIO_printf(bio_err, "variable lookup failed for %s::%s\n", name, tag);
1315 static int certify(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509,
1316 const EVP_MD *dgst, STACK_OF(OPENSSL_STRING) *sigopts,
1317 STACK_OF(CONF_VALUE) *policy, CA_DB *db,
1318 BIGNUM *serial, char *subj, unsigned long chtype,
1319 int multirdn, int email_dn, char *startdate, char *enddate,
1320 long days, int batch, char *ext_sect, CONF *lconf,
1321 int verbose, unsigned long certopt, unsigned long nameopt,
1322 int default_op, int ext_copy, int selfsign)
1324 X509_REQ *req = NULL;
1326 EVP_PKEY *pktmp = NULL;
1329 in = BIO_new_file(infile, "r");
1331 ERR_print_errors(bio_err);
1334 if ((req = PEM_read_bio_X509_REQ(in, NULL, NULL, NULL)) == NULL) {
1335 BIO_printf(bio_err, "Error reading certificate request in %s\n",
1340 X509_REQ_print(bio_err, req);
1342 BIO_printf(bio_err, "Check that the request matches the signature\n");
1344 if (selfsign && !X509_REQ_check_private_key(req, pkey)) {
1346 "Certificate request and CA private key do not match\n");
1350 if ((pktmp = X509_REQ_get_pubkey(req)) == NULL) {
1351 BIO_printf(bio_err, "error unpacking public key\n");
1354 i = X509_REQ_verify(req, pktmp);
1355 EVP_PKEY_free(pktmp);
1358 BIO_printf(bio_err, "Signature verification problems....\n");
1359 ERR_print_errors(bio_err);
1365 "Signature did not match the certificate request\n");
1366 ERR_print_errors(bio_err);
1369 BIO_printf(bio_err, "Signature ok\n");
1371 ok = do_body(xret, pkey, x509, dgst, sigopts, policy, db, serial, subj,
1372 chtype, multirdn, email_dn, startdate, enddate, days, batch,
1373 verbose, req, ext_sect, lconf, certopt, nameopt, default_op,
1374 ext_copy, selfsign);
1382 static int certify_cert(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509,
1383 const EVP_MD *dgst, STACK_OF(OPENSSL_STRING) *sigopts,
1384 STACK_OF(CONF_VALUE) *policy, CA_DB *db,
1385 BIGNUM *serial, char *subj, unsigned long chtype,
1386 int multirdn, int email_dn, char *startdate,
1387 char *enddate, long days, int batch, char *ext_sect,
1388 CONF *lconf, int verbose, unsigned long certopt,
1389 unsigned long nameopt, int default_op, int ext_copy,
1393 X509_REQ *rreq = NULL;
1394 EVP_PKEY *pktmp = NULL;
1397 if ((req = load_cert(infile, FORMAT_PEM, NULL, e, infile)) == NULL)
1400 X509_print(bio_err, req);
1402 BIO_printf(bio_err, "Check that the request matches the signature\n");
1404 if ((pktmp = X509_get_pubkey(req)) == NULL) {
1405 BIO_printf(bio_err, "error unpacking public key\n");
1408 i = X509_verify(req, pktmp);
1409 EVP_PKEY_free(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, EVP_md5())) == 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;
1452 X509_NAME_ENTRY *ne;
1453 X509_NAME_ENTRY *tne, *push;
1455 int ok = -1, i, j, last, nid;
1458 OPENSSL_STRING row[DB_NUMBER];
1459 OPENSSL_STRING *irow = NULL;
1460 OPENSSL_STRING *rrow = NULL;
1463 tmptm = ASN1_UTCTIME_new();
1464 if (tmptm == NULL) {
1465 BIO_printf(bio_err, "malloc error\n");
1469 for (i = 0; i < DB_NUMBER; i++)
1473 X509_NAME *n = parse_name(subj, chtype, multirdn);
1476 ERR_print_errors(bio_err);
1479 X509_REQ_set_subject_name(req, n);
1480 req->req_info->enc.modified = 1;
1486 "The Subject's Distinguished Name is as follows\n");
1488 name = X509_REQ_get_subject_name(req);
1489 for (i = 0; i < X509_NAME_entry_count(name); i++) {
1490 ne = X509_NAME_get_entry(name, i);
1491 str = X509_NAME_ENTRY_get_data(ne);
1492 obj = X509_NAME_ENTRY_get_object(ne);
1495 /* assume all type should be strings */
1496 nid = OBJ_obj2nid(X509_NAME_ENTRY_get_object(ne));
1498 if (str->type == V_ASN1_UNIVERSALSTRING)
1499 ASN1_UNIVERSALSTRING_to_string(str);
1501 if ((str->type == V_ASN1_IA5STRING) &&
1502 (nid != NID_pkcs9_emailAddress))
1503 str->type = V_ASN1_T61STRING;
1505 if ((nid == NID_pkcs9_emailAddress) &&
1506 (str->type == V_ASN1_PRINTABLESTRING))
1507 str->type = V_ASN1_IA5STRING;
1510 /* If no EMAIL is wanted in the subject */
1511 if ((OBJ_obj2nid(obj) == NID_pkcs9_emailAddress) && (!email_dn))
1514 /* check some things */
1515 if ((OBJ_obj2nid(obj) == NID_pkcs9_emailAddress) &&
1516 (str->type != V_ASN1_IA5STRING)) {
1518 "\nemailAddress type needs to be of type IA5STRING\n");
1521 if ((str->type != V_ASN1_BMPSTRING)
1522 && (str->type != V_ASN1_UTF8STRING)) {
1523 j = ASN1_PRINTABLE_type(str->data, str->length);
1524 if (((j == V_ASN1_T61STRING) &&
1525 (str->type != V_ASN1_T61STRING)) ||
1526 ((j == V_ASN1_IA5STRING) &&
1527 (str->type == V_ASN1_PRINTABLESTRING))) {
1529 "\nThe string contains characters that are illegal for the ASN.1 type\n");
1535 old_entry_print(obj, str);
1538 /* Ok, now we check the 'policy' stuff. */
1539 if ((subject = X509_NAME_new()) == NULL) {
1540 BIO_printf(bio_err, "Memory allocation failure\n");
1544 /* take a copy of the issuer name before we mess with it. */
1546 CAname = X509_NAME_dup(name);
1548 CAname = X509_NAME_dup(x509->cert_info->subject);
1553 for (i = 0; i < sk_CONF_VALUE_num(policy); i++) {
1554 cv = sk_CONF_VALUE_value(policy, i); /* get the object id */
1555 if ((j = OBJ_txt2nid(cv->name)) == NID_undef) {
1557 "%s:unknown object type in 'policy' configuration\n",
1561 obj = OBJ_nid2obj(j);
1565 /* lookup the object in the supplied name list */
1566 j = X509_NAME_get_index_by_OBJ(name, obj, last);
1572 tne = X509_NAME_get_entry(name, j);
1576 /* depending on the 'policy', decide what to do. */
1578 if (strcmp(cv->value, "optional") == 0) {
1581 } else if (strcmp(cv->value, "supplied") == 0) {
1584 "The %s field needed to be supplied and was missing\n",
1589 } else if (strcmp(cv->value, "match") == 0) {
1594 "The mandatory %s field was missing\n",
1602 j = X509_NAME_get_index_by_OBJ(CAname, obj, last2);
1603 if ((j < 0) && (last2 == -1)) {
1605 "The %s field does not exist in the CA certificate,\nthe 'policy' is misconfigured\n",
1610 push = X509_NAME_get_entry(CAname, j);
1611 str = X509_NAME_ENTRY_get_data(tne);
1612 str2 = X509_NAME_ENTRY_get_data(push);
1614 if (ASN1_STRING_cmp(str, str2) != 0)
1619 "The %s field needed to be the same in the\nCA certificate (%s) and the request (%s)\n",
1621 ((str2 == NULL) ? "NULL" : (char *)str2->data),
1622 ((str == NULL) ? "NULL" : (char *)str->data));
1627 "%s:invalid type in 'policy' configuration\n",
1633 if (!X509_NAME_add_entry(subject, push, -1, 0)) {
1634 X509_NAME_ENTRY_free(push);
1635 BIO_printf(bio_err, "Memory allocation failure\n");
1645 X509_NAME_free(subject);
1646 /* subject=X509_NAME_dup(X509_REQ_get_subject_name(req)); */
1647 subject = X509_NAME_dup(name);
1648 if (subject == NULL)
1654 "The subject name appears to be ok, checking data base for clashes\n");
1656 /* Build the correct Subject if no e-mail is wanted in the subject */
1658 * and add it later on because of the method extensions are added
1663 dn_subject = subject;
1665 X509_NAME_ENTRY *tmpne;
1667 * Its best to dup the subject DN and then delete any email addresses
1668 * because this retains its structure.
1670 if ((dn_subject = X509_NAME_dup(subject)) == NULL) {
1671 BIO_printf(bio_err, "Memory allocation failure\n");
1674 while ((i = X509_NAME_get_index_by_NID(dn_subject,
1675 NID_pkcs9_emailAddress,
1677 tmpne = X509_NAME_get_entry(dn_subject, i);
1678 X509_NAME_delete_entry(dn_subject, i);
1679 X509_NAME_ENTRY_free(tmpne);
1683 if (BN_is_zero(serial))
1684 row[DB_serial] = BUF_strdup("00");
1686 row[DB_serial] = BN_bn2hex(serial);
1687 if (row[DB_serial] == NULL) {
1688 BIO_printf(bio_err, "Memory allocation failure\n");
1692 if (db->attributes.unique_subject) {
1693 OPENSSL_STRING *crow = row;
1695 rrow = TXT_DB_get_by_index(db->db, DB_name, crow);
1698 "ERROR:There is already a certificate for %s\n",
1703 rrow = TXT_DB_get_by_index(db->db, DB_serial, row);
1706 "ERROR:Serial number %s has already been issued,\n",
1709 " check the database/serial_file for corruption\n");
1714 BIO_printf(bio_err, "The matching entry has the following details\n");
1715 if (rrow[DB_type][0] == 'E')
1717 else if (rrow[DB_type][0] == 'R')
1719 else if (rrow[DB_type][0] == 'V')
1722 p = "\ninvalid type, Data base error\n";
1723 BIO_printf(bio_err, "Type :%s\n", p);;
1724 if (rrow[DB_type][0] == 'R') {
1725 p = rrow[DB_exp_date];
1728 BIO_printf(bio_err, "Was revoked on:%s\n", p);
1730 p = rrow[DB_exp_date];
1733 BIO_printf(bio_err, "Expires on :%s\n", p);
1734 p = rrow[DB_serial];
1737 BIO_printf(bio_err, "Serial Number :%s\n", p);
1741 BIO_printf(bio_err, "File name :%s\n", p);
1745 BIO_printf(bio_err, "Subject Name :%s\n", p);
1746 ok = -1; /* This is now a 'bad' error. */
1750 /* We are now totally happy, lets make and sign the certificate */
1753 "Everything appears to be ok, creating and signing the certificate\n");
1755 if ((ret = X509_new()) == NULL)
1757 ci = ret->cert_info;
1760 /* Make it an X509 v3 certificate. */
1761 if (!X509_set_version(ret, 2))
1765 if (BN_to_ASN1_INTEGER(serial, ci->serialNumber) == NULL)
1768 if (!X509_set_issuer_name(ret, subject))
1771 if (!X509_set_issuer_name(ret, X509_get_subject_name(x509)))
1775 if (strcmp(startdate, "today") == 0)
1776 X509_gmtime_adj(X509_get_notBefore(ret), 0);
1778 ASN1_TIME_set_string(X509_get_notBefore(ret), startdate);
1780 if (enddate == NULL)
1781 X509_time_adj_ex(X509_get_notAfter(ret), days, 0, NULL);
1784 ASN1_TIME_set_string(X509_get_notAfter(ret), enddate);
1785 ASN1_TIME_diff(&tdays, NULL, NULL, X509_get_notAfter(ret));
1789 if (!X509_set_subject_name(ret, subject))
1792 pktmp = X509_REQ_get_pubkey(req);
1793 i = X509_set_pubkey(ret, pktmp);
1794 EVP_PKEY_free(pktmp);
1798 /* Lets add the extensions, if there are any */
1801 if (ci->version == NULL)
1802 if ((ci->version = ASN1_INTEGER_new()) == NULL)
1804 ASN1_INTEGER_set(ci->version, 2); /* version 3 certificate */
1807 * Free the current entries if any, there should not be any I believe
1809 sk_X509_EXTENSION_pop_free(ci->extensions, X509_EXTENSION_free);
1811 ci->extensions = NULL;
1813 /* Initialize the context structure */
1815 X509V3_set_ctx(&ctx, ret, ret, req, NULL, 0);
1817 X509V3_set_ctx(&ctx, x509, ret, req, NULL, 0);
1821 BIO_printf(bio_err, "Extra configuration file found\n");
1823 /* Use the extconf configuration db LHASH */
1824 X509V3_set_nconf(&ctx, extconf);
1826 /* Test the structure (needed?) */
1827 /* X509V3_set_ctx_test(&ctx); */
1829 /* Adds exts contained in the configuration file */
1830 if (!X509V3_EXT_add_nconf(extconf, &ctx, ext_sect, ret)) {
1832 "ERROR: adding extensions in section %s\n",
1834 ERR_print_errors(bio_err);
1839 "Successfully added extensions from file.\n");
1840 } else if (ext_sect) {
1841 /* We found extensions to be set from config file */
1842 X509V3_set_nconf(&ctx, lconf);
1844 if (!X509V3_EXT_add_nconf(lconf, &ctx, ext_sect, ret)) {
1846 "ERROR: adding extensions in section %s\n",
1848 ERR_print_errors(bio_err);
1854 "Successfully added extensions from config\n");
1858 /* Copy extensions from request (if any) */
1860 if (!copy_extensions(ret, req, ext_copy)) {
1861 BIO_printf(bio_err, "ERROR: adding extensions from request\n");
1862 ERR_print_errors(bio_err);
1866 /* Set the right value for the noemailDN option */
1867 if (email_dn == 0) {
1868 if (!X509_set_subject_name(ret, dn_subject))
1873 BIO_printf(bio_err, "Certificate Details:\n");
1875 * Never print signature details because signature not present
1877 certopt |= X509_FLAG_NO_SIGDUMP | X509_FLAG_NO_SIGNAME;
1878 X509_print_ex(bio_err, ret, nameopt, certopt);
1881 BIO_printf(bio_err, "Certificate is to be certified until ");
1882 ASN1_TIME_print(bio_err, X509_get_notAfter(ret));
1884 BIO_printf(bio_err, " (%ld days)", days);
1885 BIO_printf(bio_err, "\n");
1889 BIO_printf(bio_err, "Sign the certificate? [y/n]:");
1890 (void)BIO_flush(bio_err);
1892 if (!fgets(buf, sizeof(buf) - 1, stdin)) {
1894 "CERTIFICATE WILL NOT BE CERTIFIED: I/O error\n");
1898 if (!((buf[0] == 'y') || (buf[0] == 'Y'))) {
1899 BIO_printf(bio_err, "CERTIFICATE WILL NOT BE CERTIFIED\n");
1905 pktmp = X509_get_pubkey(ret);
1906 if (EVP_PKEY_missing_parameters(pktmp) &&
1907 !EVP_PKEY_missing_parameters(pkey))
1908 EVP_PKEY_copy_parameters(pktmp, pkey);
1909 EVP_PKEY_free(pktmp);
1911 if (!do_X509_sign(ret, pkey, dgst, sigopts))
1914 /* We now just add it to the database */
1915 row[DB_type] = app_malloc(2, "row db type");
1917 tm = X509_get_notAfter(ret);
1918 row[DB_exp_date] = app_malloc(tm->length + 1, "row expdate");
1919 memcpy(row[DB_exp_date], tm->data, tm->length);
1920 row[DB_exp_date][tm->length] = '\0';
1922 row[DB_rev_date] = NULL;
1924 /* row[DB_serial] done already */
1925 row[DB_file] = app_malloc(8, "row file");
1926 row[DB_name] = X509_NAME_oneline(X509_get_subject_name(ret), NULL, 0);
1928 if ((row[DB_type] == NULL) || (row[DB_exp_date] == NULL) ||
1929 (row[DB_file] == NULL) || (row[DB_name] == NULL)) {
1930 BIO_printf(bio_err, "Memory allocation failure\n");
1933 BUF_strlcpy(row[DB_file], "unknown", 8);
1934 row[DB_type][0] = 'V';
1935 row[DB_type][1] = '\0';
1937 irow = app_malloc(sizeof(*irow) * (DB_NUMBER + 1), "row space");
1938 for (i = 0; i < DB_NUMBER; i++) {
1942 irow[DB_NUMBER] = NULL;
1944 if (!TXT_DB_insert(db->db, irow)) {
1945 BIO_printf(bio_err, "failed to update database\n");
1946 BIO_printf(bio_err, "TXT_DB error number %ld\n", db->db->error);
1951 for (i = 0; i < DB_NUMBER; i++)
1952 OPENSSL_free(row[i]);
1954 X509_NAME_free(CAname);
1955 X509_NAME_free(subject);
1956 if (dn_subject != subject)
1957 X509_NAME_free(dn_subject);
1958 ASN1_UTCTIME_free(tmptm);
1966 static void write_new_certificate(BIO *bp, X509 *x, int output_der,
1971 (void)i2d_X509_bio(bp, x);
1976 PEM_write_bio_X509(bp, x);
1979 static int certify_spkac(X509 **xret, char *infile, EVP_PKEY *pkey,
1980 X509 *x509, const EVP_MD *dgst,
1981 STACK_OF(OPENSSL_STRING) *sigopts,
1982 STACK_OF(CONF_VALUE) *policy, CA_DB *db,
1983 BIGNUM *serial, char *subj, unsigned long chtype,
1984 int multirdn, int email_dn, char *startdate,
1985 char *enddate, long days, char *ext_sect,
1986 CONF *lconf, int verbose, unsigned long certopt,
1987 unsigned long nameopt, int default_op, int ext_copy)
1989 STACK_OF(CONF_VALUE) *sk = NULL;
1990 LHASH_OF(CONF_VALUE) *parms = NULL;
1991 X509_REQ *req = NULL;
1992 CONF_VALUE *cv = NULL;
1993 NETSCAPE_SPKI *spki = NULL;
1996 EVP_PKEY *pktmp = NULL;
1997 X509_NAME *n = NULL;
1998 X509_NAME_ENTRY *ne = NULL;
2004 * Load input file into a hash table. (This is just an easy
2005 * way to read and parse the file, then put it into a convenient
2008 parms = CONF_load(NULL, infile, &errline);
2009 if (parms == NULL) {
2010 BIO_printf(bio_err, "error on line %ld of %s\n", errline, infile);
2011 ERR_print_errors(bio_err);
2015 sk = CONF_get_section(parms, "default");
2016 if (sk_CONF_VALUE_num(sk) == 0) {
2017 BIO_printf(bio_err, "no name/value pairs found in %s\n", infile);
2023 * Now create a dummy X509 request structure. We don't actually
2024 * have an X509 request, but we have many of the components
2025 * (a public key, various DN components). The idea is that we
2026 * put these components into the right X509 request structure
2027 * and we can use the same code as if you had a real X509 request.
2029 req = X509_REQ_new();
2031 ERR_print_errors(bio_err);
2036 * Build up the subject name set.
2042 if (sk_CONF_VALUE_num(sk) <= i)
2045 cv = sk_CONF_VALUE_value(sk, i);
2048 * Skip past any leading X. X: X, etc to allow for multiple instances
2050 for (buf = cv->name; *buf; buf++)
2051 if ((*buf == ':') || (*buf == ',') || (*buf == '.')) {
2059 if ((nid = OBJ_txt2nid(type)) == NID_undef) {
2060 if (strcmp(type, "SPKAC") == 0) {
2061 spki = NETSCAPE_SPKI_b64_decode(cv->value, -1);
2064 "unable to load Netscape SPKAC structure\n");
2065 ERR_print_errors(bio_err);
2072 if (!X509_NAME_add_entry_by_NID(n, nid, chtype,
2073 (unsigned char *)buf, -1, -1, 0))
2077 BIO_printf(bio_err, "Netscape SPKAC structure not found in %s\n",
2083 * Now extract the key from the SPKI structure.
2087 "Check that the SPKAC request matches the signature\n");
2089 if ((pktmp = NETSCAPE_SPKI_get_pubkey(spki)) == NULL) {
2090 BIO_printf(bio_err, "error unpacking SPKAC public key\n");
2094 j = NETSCAPE_SPKI_verify(spki, pktmp);
2097 "signature verification failed on SPKAC public key\n");
2100 BIO_printf(bio_err, "Signature ok\n");
2102 X509_REQ_set_pubkey(req, pktmp);
2103 EVP_PKEY_free(pktmp);
2104 ok = do_body(xret, pkey, x509, dgst, sigopts, policy, db, serial, subj,
2105 chtype, multirdn, email_dn, startdate, enddate, days, 1,
2106 verbose, req, ext_sect, lconf, certopt, nameopt, default_op,
2111 NETSCAPE_SPKI_free(spki);
2112 X509_NAME_ENTRY_free(ne);
2117 static int check_time_format(const char *str)
2119 return ASN1_TIME_set_string(NULL, str);
2122 static int do_revoke(X509 *x509, CA_DB *db, int type, char *value)
2124 ASN1_UTCTIME *tm = NULL;
2125 char *row[DB_NUMBER], **rrow, **irow;
2126 char *rev_str = NULL;
2130 for (i = 0; i < DB_NUMBER; i++)
2132 row[DB_name] = X509_NAME_oneline(X509_get_subject_name(x509), NULL, 0);
2133 bn = ASN1_INTEGER_to_BN(X509_get_serialNumber(x509), NULL);
2137 row[DB_serial] = BUF_strdup("00");
2139 row[DB_serial] = BN_bn2hex(bn);
2141 if ((row[DB_name] == NULL) || (row[DB_serial] == NULL)) {
2142 BIO_printf(bio_err, "Memory allocation failure\n");
2146 * We have to lookup by serial number because name lookup skips revoked
2149 rrow = TXT_DB_get_by_index(db->db, DB_serial, row);
2152 "Adding Entry with serial number %s to DB for %s\n",
2153 row[DB_serial], row[DB_name]);
2155 /* We now just add it to the database */
2156 row[DB_type] = app_malloc(2, "row type");
2158 tm = X509_get_notAfter(x509);
2159 row[DB_exp_date] = app_malloc(tm->length + 1, "row exp_data");
2160 memcpy(row[DB_exp_date], tm->data, tm->length);
2161 row[DB_exp_date][tm->length] = '\0';
2163 row[DB_rev_date] = NULL;
2165 /* row[DB_serial] done already */
2166 row[DB_file] = app_malloc(8, "row filename");
2168 /* row[DB_name] done already */
2170 BUF_strlcpy(row[DB_file], "unknown", 8);
2171 row[DB_type][0] = 'V';
2172 row[DB_type][1] = '\0';
2174 irow = app_malloc(sizeof(*irow) * (DB_NUMBER + 1), "row ptr");
2175 for (i = 0; i < DB_NUMBER; i++) {
2179 irow[DB_NUMBER] = NULL;
2181 if (!TXT_DB_insert(db->db, irow)) {
2182 BIO_printf(bio_err, "failed to update database\n");
2183 BIO_printf(bio_err, "TXT_DB error number %ld\n", db->db->error);
2187 /* Revoke Certificate */
2191 ok = do_revoke(x509, db, type, value);
2195 } else if (index_name_cmp_noconst(row, rrow)) {
2196 BIO_printf(bio_err, "ERROR:name does not match %s\n", row[DB_name]);
2198 } else if (type == -1) {
2199 BIO_printf(bio_err, "ERROR:Already present, serial number %s\n",
2202 } else if (rrow[DB_type][0] == 'R') {
2203 BIO_printf(bio_err, "ERROR:Already revoked, serial number %s\n",
2207 BIO_printf(bio_err, "Revoking Certificate %s.\n", rrow[DB_serial]);
2208 rev_str = make_revocation_str(type, value);
2210 BIO_printf(bio_err, "Error in revocation arguments\n");
2213 rrow[DB_type][0] = 'R';
2214 rrow[DB_type][1] = '\0';
2215 rrow[DB_rev_date] = rev_str;
2219 for (i = 0; i < DB_NUMBER; i++) {
2220 OPENSSL_free(row[i]);
2225 static int get_certificate_status(const char *serial, CA_DB *db)
2227 char *row[DB_NUMBER], **rrow;
2230 /* Free Resources */
2231 for (i = 0; i < DB_NUMBER; i++)
2234 /* Malloc needed char spaces */
2235 row[DB_serial] = app_malloc(strlen(serial) + 2, "row serial#");
2237 if (strlen(serial) % 2) {
2239 * Set the first char to 0
2241 row[DB_serial][0] = '0';
2243 /* Copy String from serial to row[DB_serial] */
2244 memcpy(row[DB_serial] + 1, serial, strlen(serial));
2245 row[DB_serial][strlen(serial) + 1] = '\0';
2247 /* Copy String from serial to row[DB_serial] */
2248 memcpy(row[DB_serial], serial, strlen(serial));
2249 row[DB_serial][strlen(serial)] = '\0';
2252 /* Make it Upper Case */
2253 for (i = 0; row[DB_serial][i] != '\0'; i++)
2254 row[DB_serial][i] = toupper((unsigned char)row[DB_serial][i]);
2258 /* Search for the certificate */
2259 rrow = TXT_DB_get_by_index(db->db, DB_serial, row);
2261 BIO_printf(bio_err, "Serial %s not present in db.\n", row[DB_serial]);
2264 } else if (rrow[DB_type][0] == 'V') {
2265 BIO_printf(bio_err, "%s=Valid (%c)\n",
2266 row[DB_serial], rrow[DB_type][0]);
2268 } else if (rrow[DB_type][0] == 'R') {
2269 BIO_printf(bio_err, "%s=Revoked (%c)\n",
2270 row[DB_serial], rrow[DB_type][0]);
2272 } else if (rrow[DB_type][0] == 'E') {
2273 BIO_printf(bio_err, "%s=Expired (%c)\n",
2274 row[DB_serial], rrow[DB_type][0]);
2276 } else if (rrow[DB_type][0] == 'S') {
2277 BIO_printf(bio_err, "%s=Suspended (%c)\n",
2278 row[DB_serial], rrow[DB_type][0]);
2281 BIO_printf(bio_err, "%s=Unknown (%c).\n",
2282 row[DB_serial], rrow[DB_type][0]);
2286 for (i = 0; i < DB_NUMBER; i++) {
2287 OPENSSL_free(row[i]);
2292 static int do_updatedb(CA_DB *db)
2294 ASN1_UTCTIME *a_tm = NULL;
2296 int db_y2k, a_y2k; /* flags = 1 if y >= 2000 */
2297 char **rrow, *a_tm_s;
2299 a_tm = ASN1_UTCTIME_new();
2301 /* get actual time and make a string */
2302 a_tm = X509_gmtime_adj(a_tm, 0);
2303 a_tm_s = (char *)OPENSSL_malloc(a_tm->length + 1);
2305 memcpy(a_tm_s, a_tm->data, a_tm->length);
2306 a_tm_s[a_tm->length] = '\0';
2308 if (strncmp(a_tm_s, "49", 2) <= 0)
2313 for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
2314 rrow = sk_OPENSSL_PSTRING_value(db->db->data, i);
2316 if (rrow[DB_type][0] == 'V') {
2317 /* ignore entries that are not valid */
2318 if (strncmp(rrow[DB_exp_date], "49", 2) <= 0)
2323 if (db_y2k == a_y2k) {
2324 /* all on the same y2k side */
2325 if (strcmp(rrow[DB_exp_date], a_tm_s) <= 0) {
2326 rrow[DB_type][0] = 'E';
2327 rrow[DB_type][1] = '\0';
2330 BIO_printf(bio_err, "%s=Expired\n", rrow[DB_serial]);
2332 } else if (db_y2k < a_y2k) {
2333 rrow[DB_type][0] = 'E';
2334 rrow[DB_type][1] = '\0';
2337 BIO_printf(bio_err, "%s=Expired\n", rrow[DB_serial]);
2343 ASN1_UTCTIME_free(a_tm);
2344 OPENSSL_free(a_tm_s);
2348 static const char *crl_reasons[] = {
2349 /* CRL reason strings */
2353 "affiliationChanged",
2355 "cessationOfOperation",
2358 /* Additional pseudo reasons */
2364 #define NUM_REASONS OSSL_NELEM(crl_reasons)
2367 * Given revocation information convert to a DB string. The format of the
2368 * string is: revtime[,reason,extra]. Where 'revtime' is the revocation time
2369 * (the current time). 'reason' is the optional CRL reason and 'extra' is any
2370 * additional argument
2373 char *make_revocation_str(int rev_type, char *rev_arg)
2375 char *other = NULL, *str;
2376 const char *reason = NULL;
2378 ASN1_UTCTIME *revtm = NULL;
2384 case REV_CRL_REASON:
2385 for (i = 0; i < 8; i++) {
2386 if (strcasecmp(rev_arg, crl_reasons[i]) == 0) {
2387 reason = crl_reasons[i];
2391 if (reason == NULL) {
2392 BIO_printf(bio_err, "Unknown CRL reason %s\n", rev_arg);
2398 /* Argument is an OID */
2400 otmp = OBJ_txt2obj(rev_arg, 0);
2401 ASN1_OBJECT_free(otmp);
2404 BIO_printf(bio_err, "Invalid object identifier %s\n", rev_arg);
2408 reason = "holdInstruction";
2412 case REV_KEY_COMPROMISE:
2413 case REV_CA_COMPROMISE:
2415 /* Argument is the key compromise time */
2416 if (!ASN1_GENERALIZEDTIME_set_string(NULL, rev_arg)) {
2418 "Invalid time format %s. Need YYYYMMDDHHMMSSZ\n",
2423 if (rev_type == REV_KEY_COMPROMISE)
2426 reason = "CAkeyTime";
2432 revtm = X509_gmtime_adj(NULL, 0);
2437 i = revtm->length + 1;
2440 i += strlen(reason) + 1;
2442 i += strlen(other) + 1;
2444 str = app_malloc(i, "revocation reason");
2445 BUF_strlcpy(str, (char *)revtm->data, i);
2447 BUF_strlcat(str, ",", i);
2448 BUF_strlcat(str, reason, i);
2451 BUF_strlcat(str, ",", i);
2452 BUF_strlcat(str, other, i);
2454 ASN1_UTCTIME_free(revtm);
2459 * Convert revocation field to X509_REVOKED entry
2463 * 2 OK and some extensions added (i.e. V2 CRL)
2466 int make_revoked(X509_REVOKED *rev, const char *str)
2469 int reason_code = -1;
2471 ASN1_OBJECT *hold = NULL;
2472 ASN1_GENERALIZEDTIME *comp_time = NULL;
2473 ASN1_ENUMERATED *rtmp = NULL;
2475 ASN1_TIME *revDate = NULL;
2477 i = unpack_revinfo(&revDate, &reason_code, &hold, &comp_time, str);
2482 if (rev && !X509_REVOKED_set_revocationDate(rev, revDate))
2485 if (rev && (reason_code != OCSP_REVOKED_STATUS_NOSTATUS)) {
2486 rtmp = ASN1_ENUMERATED_new();
2487 if (!rtmp || !ASN1_ENUMERATED_set(rtmp, reason_code))
2489 if (!X509_REVOKED_add1_ext_i2d(rev, NID_crl_reason, rtmp, 0, 0))
2493 if (rev && comp_time) {
2494 if (!X509_REVOKED_add1_ext_i2d
2495 (rev, NID_invalidity_date, comp_time, 0, 0))
2499 if (!X509_REVOKED_add1_ext_i2d
2500 (rev, NID_hold_instruction_code, hold, 0, 0))
2504 if (reason_code != OCSP_REVOKED_STATUS_NOSTATUS)
2512 ASN1_OBJECT_free(hold);
2513 ASN1_GENERALIZEDTIME_free(comp_time);
2514 ASN1_ENUMERATED_free(rtmp);
2515 ASN1_TIME_free(revDate);
2520 static int old_entry_print(ASN1_OBJECT *obj, ASN1_STRING *str)
2522 char buf[25], *pbuf, *p;
2524 j = i2a_ASN1_OBJECT(bio_err, obj);
2526 for (j = 22 - j; j > 0; j--)
2530 BIO_puts(bio_err, buf);
2532 if (str->type == V_ASN1_PRINTABLESTRING)
2533 BIO_printf(bio_err, "PRINTABLE:'");
2534 else if (str->type == V_ASN1_T61STRING)
2535 BIO_printf(bio_err, "T61STRING:'");
2536 else if (str->type == V_ASN1_IA5STRING)
2537 BIO_printf(bio_err, "IA5STRING:'");
2538 else if (str->type == V_ASN1_UNIVERSALSTRING)
2539 BIO_printf(bio_err, "UNIVERSALSTRING:'");
2541 BIO_printf(bio_err, "ASN.1 %2d:'", str->type);
2543 p = (char *)str->data;
2544 for (j = str->length; j > 0; j--) {
2545 if ((*p >= ' ') && (*p <= '~'))
2546 BIO_printf(bio_err, "%c", *p);
2548 BIO_printf(bio_err, "\\0x%02X", *p);
2549 else if ((unsigned char)*p == 0xf7)
2550 BIO_printf(bio_err, "^?");
2552 BIO_printf(bio_err, "^%c", *p + '@');
2555 BIO_printf(bio_err, "'\n");
2559 int unpack_revinfo(ASN1_TIME **prevtm, int *preason, ASN1_OBJECT **phold,
2560 ASN1_GENERALIZEDTIME **pinvtm, const char *str)
2563 char *rtime_str, *reason_str = NULL, *arg_str = NULL, *p;
2564 int reason_code = -1;
2567 ASN1_OBJECT *hold = NULL;
2568 ASN1_GENERALIZEDTIME *comp_time = NULL;
2570 tmp = BUF_strdup(str);
2572 BIO_printf(bio_err, "memory allocation failure\n");
2576 p = strchr(tmp, ',');
2592 *prevtm = ASN1_UTCTIME_new();
2594 BIO_printf(bio_err, "memory allocation failure\n");
2597 if (!ASN1_UTCTIME_set_string(*prevtm, rtime_str)) {
2598 BIO_printf(bio_err, "invalid revocation date %s\n", rtime_str);
2603 for (i = 0; i < NUM_REASONS; i++) {
2604 if (strcasecmp(reason_str, crl_reasons[i]) == 0) {
2609 if (reason_code == OCSP_REVOKED_STATUS_NOSTATUS) {
2610 BIO_printf(bio_err, "invalid reason code %s\n", reason_str);
2614 if (reason_code == 7)
2615 reason_code = OCSP_REVOKED_STATUS_REMOVEFROMCRL;
2616 else if (reason_code == 8) { /* Hold instruction */
2618 BIO_printf(bio_err, "missing hold instruction\n");
2621 reason_code = OCSP_REVOKED_STATUS_CERTIFICATEHOLD;
2622 hold = OBJ_txt2obj(arg_str, 0);
2625 BIO_printf(bio_err, "invalid object identifier %s\n",
2632 ASN1_OBJECT_free(hold);
2633 } else if ((reason_code == 9) || (reason_code == 10)) {
2635 BIO_printf(bio_err, "missing compromised time\n");
2638 comp_time = ASN1_GENERALIZEDTIME_new();
2640 BIO_printf(bio_err, "memory allocation failure\n");
2643 if (!ASN1_GENERALIZEDTIME_set_string(comp_time, arg_str)) {
2644 BIO_printf(bio_err, "invalid compromised time %s\n", arg_str);
2647 if (reason_code == 9)
2648 reason_code = OCSP_REVOKED_STATUS_KEYCOMPROMISE;
2650 reason_code = OCSP_REVOKED_STATUS_CACOMPROMISE;
2655 *preason = reason_code;
2657 *pinvtm = comp_time;
2666 ASN1_GENERALIZEDTIME_free(comp_time);