189
196
extern int EF_ALIGNMENT;
192
static void lookup_fail(char *name,char *tag);
199
static void lookup_fail(const char *name, const char *tag);
193
200
static int certify(X509 **xret, char *infile,EVP_PKEY *pkey,X509 *x509,
194
201
const EVP_MD *dgst,STACK_OF(CONF_VALUE) *policy,CA_DB *db,
195
BIGNUM *serial, char *subj, int email_dn, char *startdate,
202
BIGNUM *serial, char *subj,unsigned long chtype, int multirdn, int email_dn, char *startdate,
196
203
char *enddate, long days, int batch, char *ext_sect, CONF *conf,
197
204
int verbose, unsigned long certopt, unsigned long nameopt,
198
int default_op, int ext_copy);
205
int default_op, int ext_copy, int selfsign);
199
206
static int certify_cert(X509 **xret, char *infile,EVP_PKEY *pkey,X509 *x509,
200
207
const EVP_MD *dgst,STACK_OF(CONF_VALUE) *policy,
201
CA_DB *db, BIGNUM *serial, char *subj, int email_dn,
208
CA_DB *db, BIGNUM *serial, char *subj,unsigned long chtype, int multirdn, int email_dn,
202
209
char *startdate, char *enddate, long days, int batch,
203
210
char *ext_sect, CONF *conf,int verbose, unsigned long certopt,
204
211
unsigned long nameopt, int default_op, int ext_copy,
206
213
static int certify_spkac(X509 **xret, char *infile,EVP_PKEY *pkey,X509 *x509,
207
214
const EVP_MD *dgst,STACK_OF(CONF_VALUE) *policy,
208
CA_DB *db, BIGNUM *serial,char *subj, int email_dn,
215
CA_DB *db, BIGNUM *serial,char *subj,unsigned long chtype, int multirdn, int email_dn,
209
216
char *startdate, char *enddate, long days, char *ext_sect,
210
217
CONF *conf, int verbose, unsigned long certopt,
211
218
unsigned long nameopt, int default_op, int ext_copy);
212
219
static int fix_data(int nid, int *type);
213
220
static void write_new_certificate(BIO *bp, X509 *x, int output_der, int notext);
214
221
static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, const EVP_MD *dgst,
215
STACK_OF(CONF_VALUE) *policy, CA_DB *db, BIGNUM *serial,char *subj,
222
STACK_OF(CONF_VALUE) *policy, CA_DB *db, BIGNUM *serial,char *subj,unsigned long chtype, int multirdn,
216
223
int email_dn, char *startdate, char *enddate, long days, int batch,
217
224
int verbose, X509_REQ *req, char *ext_sect, CONF *conf,
218
225
unsigned long certopt, unsigned long nameopt, int default_op,
226
int ext_copy, int selfsign);
220
227
static int do_revoke(X509 *x509, CA_DB *db, int ext, char *extval);
221
228
static int get_certificate_status(const char *ser_status, CA_DB *db);
222
229
static int do_updatedb(CA_DB *db);
223
230
static int check_time_format(char *str);
224
231
char *make_revocation_str(int rev_type, char *rev_arg);
225
int make_revoked(X509_REVOKED *rev, char *str);
232
int make_revoked(X509_REVOKED *rev, const char *str);
226
233
int old_entry_print(BIO *bp, ASN1_OBJECT *obj, ASN1_STRING *str);
227
234
static CONF *conf=NULL;
228
235
static CONF *extconf=NULL;
633
652
ERR_clear_error();
634
653
app_RAND_load_file(randfile, bio_err, 0);
655
f = NCONF_get_string(conf, section, STRING_MASK);
659
if(f && !ASN1_STRING_set_default_mask_asc(f)) {
660
BIO_printf(bio_err, "Invalid global string mask setting %s\n", f);
664
if (chtype != MBSTRING_UTF8){
665
f = NCONF_get_string(conf, section, UTF8_IN);
668
else if (!strcmp(f, "yes"))
669
chtype = MBSTRING_UTF8;
636
672
db_attr.unique_subject = 1;
637
p = NCONF_get_string(conf, section, "unique_subject");
673
p = NCONF_get_string(conf, section, ENV_UNIQUE_SUBJECT);
641
677
BIO_printf(bio_err, "DEBUG: unique_subject = \"%s\"\n", p);
645
case 'f': /* false */
646
case 'F': /* FALSE */
649
db_attr.unique_subject = 0;
656
db_attr.unique_subject = 1;
679
db_attr.unique_subject = parse_yesno(p,1);
661
682
ERR_clear_error();
728
749
/*****************************************************************/
729
750
/* we need a certificate */
730
if ((certfile == NULL) && ((certfile=NCONF_get_string(conf,
731
section,ENV_CERTIFICATE)) == NULL))
751
if (!selfsign || spkac_file || ss_cert_file || gencrl)
733
lookup_fail(section,ENV_CERTIFICATE);
736
x509=load_cert(bio_err, certfile, FORMAT_PEM, NULL, e,
753
if ((certfile == NULL)
754
&& ((certfile=NCONF_get_string(conf,
755
section,ENV_CERTIFICATE)) == NULL))
757
lookup_fail(section,ENV_CERTIFICATE);
760
x509=load_cert(bio_err, certfile, FORMAT_PEM, NULL, e,
741
if (!X509_check_private_key(x509,pkey))
743
BIO_printf(bio_err,"CA certificate and CA private key do not match\n");
765
if (!X509_check_private_key(x509,pkey))
767
BIO_printf(bio_err,"CA certificate and CA private key do not match\n");
771
if (!selfsign) x509p = x509;
747
773
f=NCONF_get_string(conf,BASE_SECTION,ENV_PRESERVE);
1022
if ((md == NULL) && ((md=NCONF_get_string(conf,
1023
section,ENV_DEFAULT_MD)) == NULL))
1025
lookup_fail(section,ENV_DEFAULT_MD);
1029
if ((dgst=EVP_get_digestbyname(md)) == NULL)
1031
BIO_printf(bio_err,"%s is an unsupported message digest type\n",md);
999
if ((md == NULL) && ((md=NCONF_get_string(conf,
1000
section,ENV_DEFAULT_MD)) == NULL))
1002
lookup_fail(section,ENV_DEFAULT_MD);
1005
1037
if ((email_dn == 1) && ((tmp_email_dn=NCONF_get_string(conf,
1006
1038
section,ENV_DEFAULT_EMAIL_DN)) != NULL ))
1008
1040
if(strcmp(tmp_email_dn,"no") == 0)
1011
if ((dgst=EVP_get_digestbyname(md)) == NULL)
1013
BIO_printf(bio_err,"%s is an unsupported message digest type\n",md);
1017
1044
BIO_printf(bio_err,"message digest is %s\n",
1018
1045
OBJ_nid2ln(dgst->type));
1133
1160
j=certify_spkac(&x,spkac_file,pkey,x509,dgst,attribs,db,
1134
serial,subj,email_dn,startdate,enddate,days,extensions,
1161
serial,subj,chtype,multirdn,email_dn,startdate,enddate,days,extensions,
1135
1162
conf,verbose,certopt,nameopt,default_op,ext_copy);
1136
1163
if (j < 0) goto err;
1157
1184
j=certify_cert(&x,ss_cert_file,pkey,x509,dgst,attribs,
1158
db,serial,subj,email_dn,startdate,enddate,days,batch,
1185
db,serial,subj,chtype,multirdn,email_dn,startdate,enddate,days,batch,
1159
1186
extensions,conf,verbose, certopt, nameopt,
1160
1187
default_op, ext_copy, e);
1161
1188
if (j < 0) goto err;
1174
1201
if (infile != NULL)
1177
j=certify(&x,infile,pkey,x509,dgst,attribs,db,
1178
serial,subj,email_dn,startdate,enddate,days,batch,
1204
j=certify(&x,infile,pkey,x509p,dgst,attribs,db,
1205
serial,subj,chtype,multirdn,email_dn,startdate,enddate,days,batch,
1179
1206
extensions,conf,verbose, certopt, nameopt,
1180
default_op, ext_copy);
1207
default_op, ext_copy, selfsign);
1181
1208
if (j < 0) goto err;
1194
1221
for (i=0; i<argc; i++)
1197
j=certify(&x,argv[i],pkey,x509,dgst,attribs,db,
1198
serial,subj,email_dn,startdate,enddate,days,batch,
1224
j=certify(&x,argv[i],pkey,x509p,dgst,attribs,db,
1225
serial,subj,chtype,multirdn,email_dn,startdate,enddate,days,batch,
1199
1226
extensions,conf,verbose, certopt, nameopt,
1200
default_op, ext_copy);
1227
default_op, ext_copy, selfsign);
1201
1228
if (j < 0) goto err;
1506
1525
OPENSSL_EXIT(ret);
1509
static void lookup_fail(char *name, char *tag)
1528
static void lookup_fail(const char *name, const char *tag)
1511
1530
BIO_printf(bio_err,"variable lookup failed for %s::%s\n",name,tag);
1514
1533
static int certify(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509,
1515
1534
const EVP_MD *dgst, STACK_OF(CONF_VALUE) *policy, CA_DB *db,
1516
BIGNUM *serial, char *subj, int email_dn, char *startdate, char *enddate,
1535
BIGNUM *serial, char *subj,unsigned long chtype, int multirdn, int email_dn, char *startdate, char *enddate,
1517
1536
long days, int batch, char *ext_sect, CONF *lconf, int verbose,
1518
1537
unsigned long certopt, unsigned long nameopt, int default_op,
1538
int ext_copy, int selfsign)
1521
1540
X509_REQ *req=NULL;
1564
1589
BIO_printf(bio_err,"Signature ok\n");
1566
ok=do_body(xret,pkey,x509,dgst,policy,db,serial,subj, email_dn,
1591
ok=do_body(xret,pkey,x509,dgst,policy,db,serial,subj,chtype,multirdn, email_dn,
1567
1592
startdate,enddate,days,batch,verbose,req,ext_sect,lconf,
1568
certopt, nameopt, default_op, ext_copy);
1593
certopt, nameopt, default_op, ext_copy, selfsign);
1571
1596
if (req != NULL) X509_REQ_free(req);
1576
1601
static int certify_cert(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509,
1577
1602
const EVP_MD *dgst, STACK_OF(CONF_VALUE) *policy, CA_DB *db,
1578
BIGNUM *serial, char *subj, int email_dn, char *startdate, char *enddate,
1603
BIGNUM *serial, char *subj, unsigned long chtype, int multirdn, int email_dn, char *startdate, char *enddate,
1579
1604
long days, int batch, char *ext_sect, CONF *lconf, int verbose,
1580
1605
unsigned long certopt, unsigned long nameopt, int default_op,
1581
1606
int ext_copy, ENGINE *e)
1617
1642
if ((rreq=X509_to_X509_REQ(req,NULL,EVP_md5())) == NULL)
1620
ok=do_body(xret,pkey,x509,dgst,policy,db,serial,subj,email_dn,startdate,enddate,
1645
ok=do_body(xret,pkey,x509,dgst,policy,db,serial,subj,chtype,multirdn,email_dn,startdate,enddate,
1621
1646
days,batch,verbose,rreq,ext_sect,lconf, certopt, nameopt, default_op,
1625
1650
if (rreq != NULL) X509_REQ_free(rreq);
1630
1655
static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, const EVP_MD *dgst,
1631
1656
STACK_OF(CONF_VALUE) *policy, CA_DB *db, BIGNUM *serial, char *subj,
1657
unsigned long chtype, int multirdn,
1632
1658
int email_dn, char *startdate, char *enddate, long days, int batch,
1633
1659
int verbose, X509_REQ *req, char *ext_sect, CONF *lconf,
1634
1660
unsigned long certopt, unsigned long nameopt, int default_op,
1661
int ext_copy, int selfsign)
1637
1663
X509_NAME *name=NULL,*CAname=NULL,*subject=NULL, *dn_subject=NULL;
1638
1664
ASN1_UTCTIME *tm,*tmptm;
2175
2225
static int certify_spkac(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509,
2176
2226
const EVP_MD *dgst, STACK_OF(CONF_VALUE) *policy, CA_DB *db,
2177
BIGNUM *serial, char *subj, int email_dn, char *startdate, char *enddate,
2227
BIGNUM *serial, char *subj,unsigned long chtype, int multirdn, int email_dn, char *startdate, char *enddate,
2178
2228
long days, char *ext_sect, CONF *lconf, int verbose, unsigned long certopt,
2179
2229
unsigned long nameopt, int default_op, int ext_copy)
2316
2366
X509_REQ_set_pubkey(req,pktmp);
2317
2367
EVP_PKEY_free(pktmp);
2318
ok=do_body(xret,pkey,x509,dgst,policy,db,serial,subj,email_dn,startdate,enddate,
2368
ok=do_body(xret,pkey,x509,dgst,policy,db,serial,subj,chtype,multirdn,email_dn,startdate,enddate,
2319
2369
days,1,verbose,req,ext_sect,lconf, certopt, nameopt, default_op,
2322
2372
if (req != NULL) X509_REQ_free(req);
2323
2373
if (parms != NULL) CONF_free(parms);
2808
* subject is expected to be in the format /type0=value0/type1=value1/type2=...
2809
* where characters may be escaped by \
2811
X509_NAME *do_subject(char *subject, long chtype)
2813
size_t buflen = strlen(subject)+1; /* to copy the types and values into. due to escaping, the copy can only become shorter */
2814
char *buf = OPENSSL_malloc(buflen);
2815
size_t max_ne = buflen / 2 + 1; /* maximum number of name elements */
2816
char **ne_types = OPENSSL_malloc(max_ne * sizeof (char *));
2817
char **ne_values = OPENSSL_malloc(max_ne * sizeof (char *));
2819
char *sp = subject, *bp = buf;
2822
X509_NAME *n = NULL;
2825
if (!buf || !ne_types || !ne_values)
2827
BIO_printf(bio_err, "malloc error\n");
2831
if (*subject != '/')
2833
BIO_printf(bio_err, "Subject does not start with '/'.\n");
2836
sp++; /* skip leading / */
2841
ne_types[ne_num] = bp;
2844
if (*sp == '\\') /* is there anything to escape in the type...? */
2850
BIO_printf(bio_err, "escape character at end of string\n");
2854
else if (*sp == '=')
2865
BIO_printf(bio_err, "end of string encountered while processing type of subject name element #%d\n", ne_num);
2868
ne_values[ne_num] = bp;
2877
BIO_printf(bio_err, "escape character at end of string\n");
2881
else if (*sp == '/')
2893
if (!(n = X509_NAME_new()))
2896
for (i = 0; i < ne_num; i++)
2898
if ((nid=OBJ_txt2nid(ne_types[i])) == NID_undef)
2900
BIO_printf(bio_err, "Subject Attribute %s has no known NID, skipped\n", ne_types[i]);
2906
BIO_printf(bio_err, "No value provided for Subject Attribute %s, skipped\n", ne_types[i]);
2910
if (!X509_NAME_add_entry_by_NID(n, nid, chtype, (unsigned char*)ne_values[i], -1,-1,0))
2914
OPENSSL_free(ne_values);
2915
OPENSSL_free(ne_types);
2922
OPENSSL_free(ne_values);
2924
OPENSSL_free(ne_types);
2930
2858
int old_entry_print(BIO *bp, ASN1_OBJECT *obj, ASN1_STRING *str)
2932
2860
char buf[25],*pbuf, *p;