65 #include <sys/types.h>
79 # ifdef OPENSSL_SYS_VMS
85 # elif !defined(OPENSSL_SYS_VXWORKS) && !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_NETWARE)
86 # include <sys/file.h>
102 #define BASE_SECTION "ca"
103 #define CONFIG_FILE "openssl.cnf"
105 #define ENV_DEFAULT_CA "default_ca"
107 #define STRING_MASK "string_mask"
108 #define UTF8_IN "utf8"
110 #define ENV_DIR "dir"
111 #define ENV_CERTS "certs"
112 #define ENV_CRL_DIR "crl_dir"
113 #define ENV_CA_DB "CA_DB"
114 #define ENV_NEW_CERTS_DIR "new_certs_dir"
115 #define ENV_CERTIFICATE "certificate"
116 #define ENV_SERIAL "serial"
117 #define ENV_CRLNUMBER "crlnumber"
118 #define ENV_CRL "crl"
119 #define ENV_PRIVATE_KEY "private_key"
120 #define ENV_RANDFILE "RANDFILE"
121 #define ENV_DEFAULT_DAYS "default_days"
122 #define ENV_DEFAULT_STARTDATE "default_startdate"
123 #define ENV_DEFAULT_ENDDATE "default_enddate"
124 #define ENV_DEFAULT_CRL_DAYS "default_crl_days"
125 #define ENV_DEFAULT_CRL_HOURS "default_crl_hours"
126 #define ENV_DEFAULT_MD "default_md"
127 #define ENV_DEFAULT_EMAIL_DN "email_in_dn"
128 #define ENV_PRESERVE "preserve"
129 #define ENV_POLICY "policy"
130 #define ENV_EXTENSIONS "x509_extensions"
131 #define ENV_CRLEXT "crl_extensions"
132 #define ENV_MSIE_HACK "msie_hack"
133 #define ENV_NAMEOPT "name_opt"
134 #define ENV_CERTOPT "cert_opt"
135 #define ENV_EXTCOPY "copy_extensions"
136 #define ENV_UNIQUE_SUBJECT "unique_subject"
138 #define ENV_DATABASE "database"
143 #define REV_CRL_REASON 1
145 #define REV_KEY_COMPROMISE 3
146 #define REV_CA_COMPROMISE 4
148 static const char *ca_usage[]={
151 " -verbose - Talk alot while doing things\n",
152 " -config file - A config file\n",
153 " -name arg - The particular CA definition to use\n",
154 " -gencrl - Generate a new CRL\n",
155 " -crldays days - Days is when the next CRL is due\n",
156 " -crlhours hours - Hours is when the next CRL is due\n",
157 " -startdate YYMMDDHHMMSSZ - certificate validity notBefore\n",
158 " -enddate YYMMDDHHMMSSZ - certificate validity notAfter (overrides -days)\n",
159 " -days arg - number of days to certify the certificate for\n",
160 " -md arg - md to use, one of md2, md5, sha or sha1\n",
161 " -policy arg - The CA 'policy' to support\n",
162 " -keyfile arg - private key file\n",
163 " -keyform arg - private key file format (PEM or ENGINE)\n",
164 " -key arg - key to decode the private key if it is encrypted\n",
165 " -cert file - The CA certificate\n",
166 " -selfsign - sign a certificate with the key associated with it\n",
167 " -in file - The input PEM encoded certificate request(s)\n",
168 " -out file - Where to put the output file(s)\n",
169 " -outdir dir - Where to put output certificates\n",
170 " -infiles .... - The last argument, requests to process\n",
171 " -spkac file - File contains DN and signed public key and challenge\n",
172 " -ss_cert file - File contains a self signed cert to sign\n",
173 " -preserveDN - Don't re-order the DN\n",
174 " -noemailDN - Don't add the EMAIL field into certificate' subject\n",
175 " -batch - Don't ask questions\n",
176 " -msie_hack - msie modifications to handle all those universal strings\n",
177 " -revoke file - Revoke a certificate (given in file)\n",
178 " -subj arg - Use arg instead of request's subject\n",
179 " -utf8 - input characters are UTF8 (default ASCII)\n",
180 " -multivalue-rdn - enable support for multivalued RDNs\n",
181 " -extensions .. - Extension section (override value in config file)\n",
182 " -extfile file - Configuration file with X509v3 extentions to add\n",
183 " -crlexts .. - CRL extension section (override value in config file)\n",
184 #ifndef OPENSSL_NO_ENGINE
185 " -engine e - use engine e, possibly a hardware device.\n",
187 " -status serial - Shows certificate status given the serial number\n",
188 " -updatedb - Updates db for expired certificates\n",
193 extern int EF_PROTECT_FREE;
194 extern int EF_PROTECT_BELOW;
195 extern int EF_ALIGNMENT;
198 static void lookup_fail(
const char *name,
const char *tag);
202 BIGNUM *serial,
char *subj,
unsigned long chtype,
int multirdn,
int email_dn,
char *startdate,
203 char *enddate,
long days,
int batch,
char *ext_sect,
CONF *conf,
204 int verbose,
unsigned long certopt,
unsigned long nameopt,
205 int default_op,
int ext_copy,
int selfsign);
206 static int certify_cert(
X509 **xret,
char *infile,
EVP_PKEY *pkey,
X509 *x509,
209 CA_DB *db,
BIGNUM *serial,
char *subj,
unsigned long chtype,
int multirdn,
int email_dn,
210 char *startdate,
char *enddate,
long days,
int batch,
211 char *ext_sect,
CONF *conf,
int verbose,
unsigned long certopt,
212 unsigned long nameopt,
int default_op,
int ext_copy,
214 static int certify_spkac(
X509 **xret,
char *infile,
EVP_PKEY *pkey,
X509 *x509,
217 CA_DB *db,
BIGNUM *serial,
char *subj,
unsigned long chtype,
int multirdn,
int email_dn,
218 char *startdate,
char *enddate,
long days,
char *ext_sect,
220 unsigned long nameopt,
int default_op,
int ext_copy);
221 static void write_new_certificate(
BIO *
bp,
X509 *x,
int output_der,
int notext);
225 int email_dn,
char *startdate,
char *enddate,
long days,
int batch,
227 unsigned long certopt,
unsigned long nameopt,
int default_op,
228 int ext_copy,
int selfsign);
229 static int do_revoke(
X509 *x509,
CA_DB *db,
int ext,
char *extval);
230 static int get_certificate_status(
const char *ser_status,
CA_DB *db);
231 static int do_updatedb(
CA_DB *db);
232 static int check_time_format(
const char *str);
236 static CONF *conf=NULL;
237 static CONF *extconf=NULL;
238 static char *section=NULL;
240 static int preserve=0;
241 static int msie_hack=0;
244 int MAIN(
int,
char **);
246 int MAIN(
int argc,
char **argv)
249 char *
key=NULL,*passargin=NULL;
266 char *configfile=NULL;
273 char *spkac_file=NULL;
274 char *ss_cert_file=NULL;
275 char *ser_status=NULL;
280 char *serialfile=NULL;
281 char *crlnumberfile=NULL;
282 char *extensions=NULL;
287 char *tmp_email_dn=NULL;
290 char *rev_arg = NULL;
293 char *startdate=NULL;
298 unsigned long nameopt = 0, certopt = 0;
302 X509 *x509=NULL, *x509p = NULL;
304 BIO *
in=NULL,*
out=NULL,*Sout=NULL,*Cout=NULL;
323 #ifndef OPENSSL_NO_ENGINE
351 if (strcmp(*argv,
"-verbose") == 0)
353 else if (strcmp(*argv,
"-config") == 0)
355 if (--argc < 1)
goto bad;
356 configfile= *(++argv);
358 else if (strcmp(*argv,
"-name") == 0)
360 if (--argc < 1)
goto bad;
363 else if (strcmp(*argv,
"-subj") == 0)
365 if (--argc < 1)
goto bad;
369 else if (strcmp(*argv,
"-utf8") == 0)
371 else if (strcmp(*argv,
"-create_serial") == 0)
373 else if (strcmp(*argv,
"-multivalue-rdn") == 0)
375 else if (strcmp(*argv,
"-startdate") == 0)
377 if (--argc < 1)
goto bad;
378 startdate= *(++argv);
380 else if (strcmp(*argv,
"-enddate") == 0)
382 if (--argc < 1)
goto bad;
385 else if (strcmp(*argv,
"-days") == 0)
387 if (--argc < 1)
goto bad;
388 days=atoi(*(++argv));
390 else if (strcmp(*argv,
"-md") == 0)
392 if (--argc < 1)
goto bad;
395 else if (strcmp(*argv,
"-policy") == 0)
397 if (--argc < 1)
goto bad;
400 else if (strcmp(*argv,
"-keyfile") == 0)
402 if (--argc < 1)
goto bad;
405 else if (strcmp(*argv,
"-keyform") == 0)
407 if (--argc < 1)
goto bad;
410 else if (strcmp(*argv,
"-passin") == 0)
412 if (--argc < 1)
goto bad;
413 passargin= *(++argv);
415 else if (strcmp(*argv,
"-key") == 0)
417 if (--argc < 1)
goto bad;
420 else if (strcmp(*argv,
"-cert") == 0)
422 if (--argc < 1)
goto bad;
425 else if (strcmp(*argv,
"-selfsign") == 0)
427 else if (strcmp(*argv,
"-in") == 0)
429 if (--argc < 1)
goto bad;
433 else if (strcmp(*argv,
"-out") == 0)
435 if (--argc < 1)
goto bad;
438 else if (strcmp(*argv,
"-outdir") == 0)
440 if (--argc < 1)
goto bad;
443 else if (strcmp(*argv,
"-sigopt") == 0)
452 else if (strcmp(*argv,
"-notext") == 0)
454 else if (strcmp(*argv,
"-batch") == 0)
456 else if (strcmp(*argv,
"-preserveDN") == 0)
458 else if (strcmp(*argv,
"-noemailDN") == 0)
460 else if (strcmp(*argv,
"-gencrl") == 0)
462 else if (strcmp(*argv,
"-msie_hack") == 0)
464 else if (strcmp(*argv,
"-crldays") == 0)
466 if (--argc < 1)
goto bad;
467 crldays= atol(*(++argv));
469 else if (strcmp(*argv,
"-crlhours") == 0)
471 if (--argc < 1)
goto bad;
472 crlhours= atol(*(++argv));
474 else if (strcmp(*argv,
"-crlsec") == 0)
476 if (--argc < 1)
goto bad;
477 crlsec = atol(*(++argv));
479 else if (strcmp(*argv,
"-infiles") == 0)
486 else if (strcmp(*argv,
"-ss_cert") == 0)
488 if (--argc < 1)
goto bad;
489 ss_cert_file = *(++argv);
492 else if (strcmp(*argv,
"-spkac") == 0)
494 if (--argc < 1)
goto bad;
495 spkac_file = *(++argv);
498 else if (strcmp(*argv,
"-revoke") == 0)
500 if (--argc < 1)
goto bad;
504 else if (strcmp(*argv,
"-extensions") == 0)
506 if (--argc < 1)
goto bad;
507 extensions= *(++argv);
509 else if (strcmp(*argv,
"-extfile") == 0)
511 if (--argc < 1)
goto bad;
514 else if (strcmp(*argv,
"-status") == 0)
516 if (--argc < 1)
goto bad;
517 ser_status= *(++argv);
519 else if (strcmp(*argv,
"-updatedb") == 0)
523 else if (strcmp(*argv,
"-crlexts") == 0)
525 if (--argc < 1)
goto bad;
528 else if (strcmp(*argv,
"-crl_reason") == 0)
530 if (--argc < 1)
goto bad;
534 else if (strcmp(*argv,
"-crl_hold") == 0)
536 if (--argc < 1)
goto bad;
540 else if (strcmp(*argv,
"-crl_compromise") == 0)
542 if (--argc < 1)
goto bad;
546 else if (strcmp(*argv,
"-crl_CA_compromise") == 0)
548 if (--argc < 1)
goto bad;
552 #ifndef OPENSSL_NO_ENGINE
553 else if (strcmp(*argv,
"-engine") == 0)
555 if (--argc < 1)
goto bad;
574 for (pp2=ca_usage; (*pp2 != NULL); pp2++)
583 if (configfile == NULL) configfile = getenv(
"OPENSSL_CONF");
584 if (configfile == NULL) configfile = getenv(
"SSLEAY_CONF");
585 if (configfile == NULL)
590 #ifdef OPENSSL_SYS_VMS
606 if (
NCONF_load(conf,configfile,&errorline) <= 0)
613 ,errorline,configfile);
625 #ifndef OPENSSL_NO_ENGINE
672 if (randfile == NULL)
689 else if (!strcmp(f,
"yes"))
717 if ((in == NULL) || (out == NULL) || (Sout == NULL) || (Cout == NULL))
733 if (db == NULL)
goto err;
737 if (get_certificate_status(ser_status,db) != 1)
772 if (!selfsign || spkac_file || ss_cert_file || gencrl)
774 if ((certfile == NULL)
792 if (!selfsign) x509p = x509;
797 if ((f != NULL) && ((*f ==
'y') || (*f ==
'Y')))
802 if ((f != NULL) && ((*f ==
'y') || (*f ==
'Y')))
848 if ((outdir == NULL) && (req))
854 BIO_printf(
bio_err,
"there needs to be defined a directory for new certificate to be placed in\n");
857 #ifndef OPENSSL_SYS_VMS
896 if (db == NULL)
goto err;
905 BIO_printf(
bio_err,
"entry %d: not revoked yet, but has a revocation date\n",i+1);
926 if ((j&1) || (j < 2))
933 if (!( ((*p >=
'0') && (*p <=
'9')) ||
934 ((*p >=
'A') && (*p <=
'F')) ||
935 ((*p >=
'a') && (*p <=
'f'))) )
946 #ifdef OPENSSL_SYS_VMS
977 "No entries found to mark expired\n");
986 "Done. %d entries marked as expired\n",i);
995 if (
NCONF_load(extconf,extfile,&errorline) <= 0)
1011 if (!extensions && !(extensions =
NCONF_get_string(extconf,
"default",
"extensions")))
1012 extensions =
"default";
1018 if (outfile != NULL)
1029 #ifdef OPENSSL_SYS_VMS
1045 if (!strcmp(md,
"default"))
1067 if(strcmp(tmp_email_dn,
"no") == 0)
1110 "Error Loading extension section %s\n",
1118 if (startdate == NULL)
1122 if (startdate == NULL)
1127 BIO_printf(
bio_err,
"start date is invalid, it should be YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ\n");
1130 if (startdate == NULL) startdate=
"today";
1132 if (enddate == NULL)
1136 if (enddate == NULL)
1141 BIO_printf(
bio_err,
"end date is invalid, it should be YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ\n");
1150 if (!enddate && (days == 0))
1156 if ((serial=
load_serial(serialfile, create_ser, NULL)) == NULL)
1167 if ((f=
BN_bn2hex(serial)) == NULL)
goto err;
1173 if ((attribs=NCONF_get_section(conf,policy)) == NULL)
1184 if (spkac_file != NULL)
1187 j=certify_spkac(&x,spkac_file,pkey,x509,dgst,sigopts,
1188 attribs,db, serial,subj,chtype,multirdn,
1189 email_dn,startdate,enddate,days,extensions,
1190 conf,verbose,certopt,nameopt,default_op,ext_copy);
1191 if (j < 0)
goto err;
1209 if (ss_cert_file != NULL)
1212 j=certify_cert(&x,ss_cert_file,pkey,x509,dgst,sigopts,
1214 db,serial,subj,chtype,multirdn,email_dn,startdate,enddate,days,batch,
1215 extensions,conf,verbose, certopt, nameopt,
1216 default_op, ext_copy, e);
1217 if (j < 0)
goto err;
1233 j=certify(&x,infile,pkey,x509p,dgst,sigopts, attribs,db,
1234 serial,subj,chtype,multirdn,email_dn,startdate,enddate,days,batch,
1235 extensions,conf,verbose, certopt, nameopt,
1236 default_op, ext_copy, selfsign);
1237 if (j < 0)
goto err;
1250 for (i=0; i<argc; i++)
1253 j=certify(&x,argv[i],pkey,x509p,dgst,sigopts,attribs,db,
1254 serial,subj,chtype,multirdn,email_dn,startdate,enddate,days,batch,
1255 extensions,conf,verbose, certopt, nameopt,
1256 default_op, ext_copy, selfsign);
1257 if (j < 0)
goto err;
1278 BIO_printf(
bio_err,
"\n%d out of %d certificate requests certified, commit? [y/n]",total_done,total);
1281 if (!fgets(buf[0],10,stdin))
1287 if ((buf[0][0] !=
'y') && (buf[0][0] !=
'Y'))
1297 if (!
save_serial(serialfile,
"new",serial,NULL))
goto err;
1299 if (!
save_index(dbfile,
"new", db))
goto err;
1314 if(strlen(outdir) >= (size_t)(j ? BSIZE-j*2-6 : BSIZE-8))
1320 strcpy(buf[2],outdir);
1322 #ifndef OPENSSL_SYS_VMS
1326 n=(
char *)&(buf[2][strlen(buf[2])]);
1331 if (n >= &(buf[2][
sizeof(buf[2])]))
1334 &buf[2][0] +
sizeof(buf[2]) - n,
1335 "%02X",(
unsigned char)*(p++));
1344 *(n++)=
'.'; *(n++)=
'p'; *(n++)=
'e'; *(n++)=
'm';
1354 write_new_certificate(Cout,x, 0, notext);
1355 write_new_certificate(Sout,x, output_der, notext);
1388 "Error Loading CRL extension section %s\n",
1397 if ((crlnumber=
load_serial(crlnumberfile,0,NULL)) == NULL)
1403 if (!crldays && !crlhours && !crlsec)
1412 if ((crldays == 0) && (crlhours == 0) && (crlsec == 0))
1419 if ((crl=X509_CRL_new()) == NULL)
goto err;
1422 tmptm = ASN1_TIME_new();
1423 if (!tmptm)
goto err;
1434 ASN1_TIME_free(tmptm);
1441 if ((r=X509_REVOKED_new()) == NULL)
goto err;
1444 if (j == 2) crl_v2 = 1;
1453 ASN1_INTEGER_free(tmpser);
1467 if (crl_ext || crlnumberfile != NULL)
1475 crl_ext, crl))
goto err;
1476 if (crlnumberfile != NULL)
1479 if (!tmpser)
goto err;
1481 ASN1_INTEGER_free(tmpser);
1486 if (crl_ext || crl_v2)
1493 if (crlnumberfile != NULL)
1494 if (!
save_serial(crlnumberfile,
"new",crlnumber,NULL))
goto err;
1504 PEM_write_bio_X509_CRL(Sout,crl);
1506 if (crlnumberfile != NULL)
1523 if (revcert == NULL)
1525 j=do_revoke(revcert,db, rev_type, rev_arg);
1526 if (j <= 0)
goto err;
1529 if (!
save_index(dbfile,
"new", db))
goto err;
1551 if (free_key && key)
1559 if (x509) X509_free(x509);
1568 static void lookup_fail(
const char *name,
const char *tag)
1576 BIGNUM *serial,
char *subj,
unsigned long chtype,
int multirdn,
1577 int email_dn,
char *startdate,
char *enddate,
1578 long days,
int batch,
char *ext_sect,
CONF *lconf,
int verbose,
1579 unsigned long certopt,
unsigned long nameopt,
int default_op,
1580 int ext_copy,
int selfsign)
1594 if ((req=PEM_read_bio_X509_REQ(in,NULL,NULL,NULL)) == NULL)
1633 ok=do_body(xret,pkey,x509,dgst,sigopts, policy,db,serial,subj,chtype,
1635 startdate,enddate,days,batch,verbose,req,ext_sect,lconf,
1636 certopt, nameopt, default_op, ext_copy, selfsign);
1639 if (req != NULL) X509_REQ_free(req);
1644 static int certify_cert(
X509 **xret,
char *infile,
EVP_PKEY *pkey,
X509 *x509,
1647 BIGNUM *serial,
char *subj,
unsigned long chtype,
int multirdn,
int email_dn,
char *startdate,
char *enddate,
1648 long days,
int batch,
char *ext_sect,
CONF *lconf,
int verbose,
1649 unsigned long certopt,
unsigned long nameopt,
int default_op,
1689 ok=do_body(xret,pkey,x509,dgst,sigopts,policy,db,serial,subj,chtype,multirdn,email_dn,startdate,enddate,
1690 days,batch,verbose,rreq,ext_sect,lconf, certopt, nameopt, default_op,
1694 if (rreq != NULL) X509_REQ_free(rreq);
1695 if (req != NULL) X509_free(req);
1702 unsigned long chtype,
int multirdn,
1703 int email_dn,
char *startdate,
char *enddate,
long days,
int batch,
1704 int verbose,
X509_REQ *req,
char *ext_sect,
CONF *lconf,
1705 unsigned long certopt,
unsigned long nameopt,
int default_op,
1706 int ext_copy,
int selfsign)
1708 X509_NAME *name=NULL,*CAname=NULL,*subject=NULL, *dn_subject=NULL;
1717 int ok= -1,i,j,last,
nid;
1725 tmptm=ASN1_UTCTIME_new();
1795 BIO_printf(
bio_err,
"\nThe string contains characters that are illegal for the ASN.1 type\n");
1805 if ((subject=X509_NAME_new()) == NULL)
1816 if (CAname == NULL)
goto err;
1836 if (last != -1)
break;
1847 if (strcmp(cv->
value,
"optional") == 0)
1852 else if (strcmp(cv->
value,
"supplied") == 0)
1862 else if (strcmp(cv->
value,
"match") == 0)
1876 if ((j < 0) && (last2 == -1))
1878 BIO_printf(
bio_err,
"The %s field does not exist in the CA certificate,\nthe 'policy' is misconfigured\n",cv->
name);
1892 BIO_printf(
bio_err,
"The %s field needed to be the same in the\nCA certificate (%s) and the request (%s)\n",cv->
name,((str2 == NULL)?
"NULL":(
char *)str2->
data),((str == NULL)?
"NULL":(
char *)str->
data));
1907 X509_NAME_ENTRY_free(push);
1918 X509_NAME_free(subject);
1921 if (subject == NULL)
goto err;
1925 BIO_printf(
bio_err,
"The subject name appears to be ok, checking data base for clashes\n");
1931 dn_subject = subject;
1948 X509_NAME_ENTRY_free(tmpne);
1970 "ERROR:There is already a certificate for %s\n",
1988 "The matching entry has the following details\n");
1991 else if (rrow[
DB_type][0] ==
'R')
1993 else if (rrow[
DB_type][0] ==
'V')
1996 p=
"\ninvalid type, Data base error\n";
2005 p=rrow[
DB_serial];
if (p == NULL) p=
"undef";
2007 p=rrow[
DB_file];
if (p == NULL) p=
"undef";
2009 p=rrow[
DB_name];
if (p == NULL) p=
"undef";
2017 BIO_printf(
bio_err,
"Everything appears to be ok, creating and signing the certificate\n");
2019 if ((ret=X509_new()) == NULL)
goto err;
2040 if (strcmp(startdate,
"today") == 0)
2044 if (enddate == NULL)
2060 if ((ci->
version=ASN1_INTEGER_new()) == NULL)
2066 if (ci->extensions != NULL)
2068 X509_EXTENSION_free);
2070 ci->extensions = NULL;
2093 "ERROR: adding extensions in section %s\n",
2152 if (!fgets(buf,
sizeof(buf)-1,stdin))
2158 if (!((buf[0] ==
'y') || (buf[0] ==
'Y')))
2180 memcpy(row[DB_exp_date],tm->
data,tm->
length);
2189 if ((row[
DB_type] == NULL) || (row[DB_exp_date] == NULL) ||
2199 if ((irow=(
char **)
OPENSSL_malloc(
sizeof(
char *)*(DB_NUMBER+1))) == NULL)
2224 X509_NAME_free(CAname);
2225 if (subject != NULL)
2226 X509_NAME_free(subject);
2227 if ((dn_subject != NULL) && !email_dn)
2228 X509_NAME_free(dn_subject);
2230 ASN1_UTCTIME_free(tmptm);
2233 if (ret != NULL) X509_free(ret);
2241 static void write_new_certificate(
BIO *
bp,
X509 *x,
int output_der,
int notext)
2262 PEM_write_bio_X509(bp,x);
2265 static int certify_spkac(
X509 **xret,
char *infile,
EVP_PKEY *pkey,
X509 *x509,
2268 BIGNUM *serial,
char *subj,
unsigned long chtype,
int multirdn,
int email_dn,
char *startdate,
char *enddate,
2269 long days,
char *ext_sect,
CONF *lconf,
int verbose,
unsigned long certopt,
2270 unsigned long nameopt,
int default_op,
int ext_copy)
2291 parms=CONF_load(NULL,infile,&errline);
2299 sk=CONF_get_section(parms,
"default");
2336 for (buf = cv->
name; *buf ; buf++)
2337 if ((*buf ==
':') || (*buf ==
',') || (*buf ==
'.'))
2340 if (*buf) type = buf;
2347 if (strcmp(type,
"SPKAC") == 0)
2361 (
unsigned char *)buf, -1, -1, 0))
2393 ok=do_body(xret,pkey,x509,dgst,sigopts,policy,db,serial,subj,chtype,
2394 multirdn,email_dn,startdate,enddate, days,1,verbose,req,
2395 ext_sect,lconf, certopt, nameopt, default_op, ext_copy, 0);
2397 if (req != NULL) X509_REQ_free(req);
2399 if (spki != NULL) NETSCAPE_SPKI_free(spki);
2400 if (ne != NULL) X509_NAME_ENTRY_free(ne);
2405 static int check_time_format(
const char *str)
2410 static int do_revoke(
X509 *x509,
CA_DB *db,
int type,
char *value)
2414 char *rev_str = NULL;
2447 memcpy(row[DB_exp_date],tm->
data,tm->
length);
2467 if ((irow=(
char **)
OPENSSL_malloc(
sizeof(
char *)*(DB_NUMBER+1))) == NULL)
2488 ok = do_revoke(x509,db, type, value);
2499 else if (rrow[
DB_type][0]==
'R')
2528 static int get_certificate_status(
const char *serial,
CA_DB *db)
2545 if (strlen(serial) % 2)
2551 memcpy(row[
DB_serial]+1, serial, strlen(serial));
2557 memcpy(row[
DB_serial], serial, strlen(serial));
2562 for (i=0; row[
DB_serial][i] !=
'\0'; i++)
2577 else if (rrow[
DB_type][0]==
'V')
2583 else if (rrow[
DB_type][0]==
'R')
2589 else if (rrow[
DB_type][0]==
'E')
2595 else if (rrow[
DB_type][0]==
'S')
2616 static int do_updatedb (
CA_DB *db)
2621 char **rrow, *a_tm_s;
2623 a_tm = ASN1_UTCTIME_new();
2635 a_tm_s[a_tm->
length] =
'\0';
2637 if (strncmp(a_tm_s,
"49", 2) <= 0)
2649 if (strncmp(rrow[DB_exp_date],
"49", 2) <= 0)
2654 if (db_y2k == a_y2k)
2657 if (strcmp(rrow[DB_exp_date], a_tm_s) <= 0)
2667 else if (db_y2k < a_y2k)
2682 ASN1_UTCTIME_free(a_tm);
2688 static const char *crl_reasons[] = {
2693 "affiliationChanged",
2695 "cessationOfOperation",
2704 #define NUM_REASONS (sizeof(crl_reasons) / sizeof(char *))
2716 char *other = NULL, *str;
2717 const char *reason = NULL;
2727 for (i = 0; i < 8; i++)
2729 if (!strcasecmp(rev_arg, crl_reasons[i]))
2731 reason = crl_reasons[i];
2754 reason =
"holdInstruction";
2771 reason =
"CAkeyTime";
2781 if (reason) i += strlen(reason) + 1;
2782 if (other) i += strlen(other) + 1;
2786 if (!str)
return NULL;
2799 ASN1_UTCTIME_free(revtm);
2822 i =
unpack_revinfo(&revDate, &reason_code, &hold, &comp_time, str);
2832 rtmp = ASN1_ENUMERATED_new();
2839 if (rev && comp_time)
2858 ASN1_GENERALIZEDTIME_free(comp_time);
2859 ASN1_ENUMERATED_free(rtmp);
2860 ASN1_TIME_free(revDate);
2867 char buf[25],*pbuf, *
p;
2871 for (j=22-j; j>0; j--)
2888 p=(
char *)str->
data;
2889 for (j=str->
length; j>0; j--)
2891 if ((*p >=
' ') && (*p <=
'~'))
2895 else if ((
unsigned char)*p == 0xf7)
2907 char *rtime_str, *reason_str = NULL, *arg_str = NULL, *
p;
2915 p = strchr(tmp,
',');
2934 *prevtm = ASN1_UTCTIME_new();
2945 if(!strcasecmp(reason_str, crl_reasons[i]))
2957 if (reason_code == 7)
2959 else if (reason_code == 8)
2974 if (phold) *phold = hold;
2976 else if ((reason_code == 9) || (reason_code == 10))
2983 comp_time = ASN1_GENERALIZEDTIME_new();
2989 if (reason_code == 9)
2997 if (pinvtm) *pinvtm = comp_time;
2998 else ASN1_GENERALIZEDTIME_free(comp_time);
3006 if (!pinvtm) ASN1_GENERALIZEDTIME_free(comp_time);