#include <sys/types.h>
#include <sys/stat.h>
#include "apps.h"
-#include "bio.h"
-#include "err.h"
-#include "bn.h"
-#include "txt_db.h"
-#include "evp.h"
-#include "x509.h"
-#include "x509v3.h"
-#include "objects.h"
-#include "pem.h"
-#include "conf.h"
+#include <openssl/conf.h>
+#include <openssl/bio.h>
+#include <openssl/err.h>
+#include <openssl/bn.h>
+#include <openssl/txt_db.h>
+#include <openssl/evp.h>
+#include <openssl/x509.h>
+#include <openssl/x509v3.h>
+#include <openssl/objects.h>
+#include <openssl/pem.h>
#ifndef W_OK
-#include <sys/file.h>
+# ifdef VMS
+# if defined(__DECC)
+# include <unistd.h>
+# else
+# include <unixlib.h>
+# endif
+# else
+# include <sys/file.h>
+# endif
+#endif
+
+#ifndef W_OK
+# define F_OK 0
+# define X_OK 1
+# define W_OK 2
+# define R_OK 4
#endif
#undef PROG
#define PROG ca_main
#define BASE_SECTION "ca"
-#define CONFIG_FILE "lib/openssl.cnf"
+#define CONFIG_FILE "openssl.cnf"
#define ENV_DEFAULT_CA "default_ca"
extern int EF_ALIGNMENT;
#endif
-#ifndef NOPROTO
static int add_oid_section(LHASH *conf);
static void lookup_fail(char *name,char *tag);
static int MS_CALLBACK key_callback(char *buf,int len,int verify);
static BIGNUM *load_serial(char *serialfile);
static int save_serial(char *serialfile, BIGNUM *serial);
static int certify(X509 **xret, char *infile,EVP_PKEY *pkey,X509 *x509,
- EVP_MD *dgst,STACK *policy,TXT_DB *db,BIGNUM *serial,char *startdate,
- int days, int batch, char *ext_sect, LHASH *conf,int verbose);
+ const EVP_MD *dgst,STACK *policy,TXT_DB *db,BIGNUM *serial,
+ char *startdate,int days,int batch,char *ext_sect,
+ LHASH *conf,int verbose);
static int certify_cert(X509 **xret, char *infile,EVP_PKEY *pkey,X509 *x509,
- EVP_MD *dgst,STACK *policy,TXT_DB *db,BIGNUM *serial,char *startdate,
- int days,int batch,char *ext_sect, LHASH *conf,int verbose);
+ const EVP_MD *dgst,STACK *policy,TXT_DB *db,
+ BIGNUM *serial,char *startdate,int days,int batch,
+ char *ext_sect, LHASH *conf,int verbose);
static int certify_spkac(X509 **xret, char *infile,EVP_PKEY *pkey,X509 *x509,
- EVP_MD *dgst,STACK *policy,TXT_DB *db,BIGNUM *serial,char *startdate,
- int days,char *ext_sect,LHASH *conf,int verbose);
+ const EVP_MD *dgst,STACK *policy,TXT_DB *db,
+ BIGNUM *serial,char *startdate,int days,
+ char *ext_sect,LHASH *conf,int verbose);
static int fix_data(int nid, int *type);
static void write_new_certificate(BIO *bp, X509 *x, int output_der);
-static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, EVP_MD *dgst,
+static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, const EVP_MD *dgst,
STACK *policy, TXT_DB *db, BIGNUM *serial, char *startdate,
int days, int batch, int verbose, X509_REQ *req, char *ext_sect,
LHASH *conf);
static int do_revoke(X509 *x509, TXT_DB *db);
static int check_time_format(char *str);
-#else
-static int add_oid_section();
-static void lookup_fail();
-static int MS_CALLBACK key_callback();
-static unsigned long index_serial_hash();
-static int index_serial_cmp();
-static unsigned long index_name_hash();
-static int index_name_qual();
-static int index_name_cmp();
-static int fix_data();
-static BIGNUM *load_serial();
-static int save_serial();
-static int certify();
-static int certify_cert();
-static int certify_spkac();
-static void write_new_certificate();
-static int do_body();
-static int do_revoke();
-static int check_time_format();
-#endif
-
static LHASH *conf;
static char *key=NULL;
static char *section=NULL;
static int preserve=0;
static int msie_hack=0;
-int MAIN(argc, argv)
-int argc;
-char **argv;
+int MAIN(int argc, char **argv)
{
int total=0;
int total_done=0;
char **pp,*p,*f;
int i,j;
long l;
- EVP_MD *dgst=NULL;
+ const EVP_MD *dgst=NULL;
STACK *attribs=NULL;
STACK *cert_sk=NULL;
BIO *hex=NULL;
ERR_load_crypto_strings();
/*****************************************************************/
+ if (configfile == NULL) configfile = getenv("OPENSSL_CONF");
+ if (configfile == NULL) configfile = getenv("SSLEAY_CONF");
if (configfile == NULL)
{
/* We will just use 'buf[0]' as a temporary buffer. */
+#ifdef VMS
+ strncpy(buf[0],X509_get_default_cert_area(),
+ sizeof(buf[0])-1-sizeof(CONFIG_FILE));
+#else
strncpy(buf[0],X509_get_default_cert_area(),
sizeof(buf[0])-2-sizeof(CONFIG_FILE));
strcat(buf[0],"/");
+#endif
strcat(buf[0],CONFIG_FILE);
configfile=buf[0];
}
BIO_printf(bio_err,"there needs to be defined a directory for new certificate to be placed in\n");
goto err;
}
+#ifdef VMS
+ /* For technical reasons, VMS misbehaves with X_OK */
+ if (access(outdir,R_OK|W_OK) != 0)
+#else
if (access(outdir,R_OK|W_OK|X_OK) != 0)
+#endif
{
BIO_printf(bio_err,"I am unable to acces the %s directory\n",outdir);
perror(outdir);
extensions=CONF_get_string(conf,section,ENV_EXTENSIONS);
if(extensions) {
/* Check syntax of file */
- if(!X509V3_EXT_check_conf(conf, extensions)) {
+ X509V3_CTX ctx;
+ X509V3_set_ctx_test(&ctx);
+ X509V3_set_conf_lhash(&ctx, conf);
+ if(!X509V3_EXT_add_conf(conf, &ctx, extensions, NULL)) {
BIO_printf(bio_err,
"Error Loading extension section %s\n",
extensions);
BIO_printf(bio_err,"Write out database with %d new entries\n",sk_num(cert_sk));
strncpy(buf[0],serialfile,BSIZE-4);
+
+#ifdef VMS
+ strcat(buf[0],"-new");
+#else
strcat(buf[0],".new");
+#endif
if (!save_serial(buf[0],serial)) goto err;
strncpy(buf[1],dbfile,BSIZE-4);
+
+#ifdef VMS
+ strcat(buf[1],"-new");
+#else
strcat(buf[1],".new");
+#endif
+
if (BIO_write_filename(out,buf[1]) <= 0)
{
perror(dbfile);
p=(char *)x->cert_info->serialNumber->data;
strncpy(buf[2],outdir,BSIZE-(j*2)-6);
+
+#ifndef VMS
strcat(buf[2],"/");
+#endif
+
n=(unsigned char *)&(buf[2][strlen(buf[2])]);
if (j > 0)
{
{
/* Rename the database and the serial file */
strncpy(buf[2],serialfile,BSIZE-4);
+
+#ifdef VMS
+ strcat(buf[2],"-old");
+#else
strcat(buf[2],".old");
+#endif
+
BIO_free(in);
BIO_free(out);
in=NULL;
}
strncpy(buf[2],dbfile,BSIZE-4);
+
+#ifdef VMS
+ strcat(buf[2],"-old");
+#else
strcat(buf[2],".old");
+#endif
+
if (rename(dbfile,buf[2]) < 0)
{
BIO_printf(bio_err,"unabel to rename %s to %s\n",
crl_ext=CONF_get_string(conf,section,ENV_CRLEXT);
if(crl_ext) {
/* Check syntax of file */
- if(!X509V3_EXT_check_conf(conf, crl_ext)) {
+ X509V3_CTX ctx;
+ X509V3_set_ctx_test(&ctx);
+ X509V3_set_conf_lhash(&ctx, conf);
+ if(!X509V3_EXT_add_conf(conf, &ctx, crl_ext, NULL)) {
BIO_printf(bio_err,
"Error Loading CRL extension section %s\n",
crl_ext);
if (ci->version == NULL)
if ((ci->version=ASN1_INTEGER_new()) == NULL) goto err;
ASN1_INTEGER_set(ci->version,1); /* version 2 CRL */
- crlctx.crl = crl;
- crlctx.issuer_cert = x509;
- crlctx.subject_cert = NULL;
- crlctx.subject_req = NULL;
- crlctx.flags = 0;
+ X509V3_set_ctx(&crlctx, x509, NULL, NULL, crl, 0);
+ X509V3_set_conf_lhash(&crlctx, conf);
if(!X509V3_EXT_CRL_add_conf(conf, &crlctx,
crl_ext, crl)) goto err;
EXIT(ret);
}
-static void lookup_fail(name,tag)
-char *name;
-char *tag;
+static void lookup_fail(char *name, char *tag)
{
BIO_printf(bio_err,"variable lookup failed for %s::%s\n",name,tag);
}
-static int MS_CALLBACK key_callback(buf,len,verify)
-char *buf;
-int len,verify;
+static int MS_CALLBACK key_callback(char *buf, int len, int verify)
{
int i;
return(i);
}
-static unsigned long index_serial_hash(a)
-char **a;
+static unsigned long index_serial_hash(char **a)
{
char *n;
return(lh_strhash(n));
}
-static int index_serial_cmp(a,b)
-char **a;
-char **b;
+static int index_serial_cmp(char **a, char **b)
{
char *aa,*bb;
return(strcmp(aa,bb));
}
-static unsigned long index_name_hash(a)
-char **a;
+static unsigned long index_name_hash(char **a)
{ return(lh_strhash(a[DB_name])); }
-static int index_name_qual(a)
-char **a;
+static int index_name_qual(char **a)
{ return(a[0][0] == 'V'); }
-static int index_name_cmp(a,b)
-char **a;
-char **b;
- { return(strcmp(a[DB_name],b[DB_name])); }
+static int index_name_cmp(char **a, char **b)
+ { return(strcmp(a[DB_name],
+ b[DB_name])); }
-static BIGNUM *load_serial(serialfile)
-char *serialfile;
+static BIGNUM *load_serial(char *serialfile)
{
BIO *in=NULL;
BIGNUM *ret=NULL;
return(ret);
}
-static int save_serial(serialfile,serial)
-char *serialfile;
-BIGNUM *serial;
+static int save_serial(char *serialfile, BIGNUM *serial)
{
BIO *out;
int ret=0;
return(ret);
}
-static int certify(xret,infile,pkey,x509,dgst,policy,db,serial,startdate,days,
- batch,ext_sect,lconf,verbose)
-X509 **xret;
-char *infile;
-EVP_PKEY *pkey;
-X509 *x509;
-EVP_MD *dgst;
-STACK *policy;
-TXT_DB *db;
-BIGNUM *serial;
-char *startdate;
-int days;
-int batch;
-char *ext_sect;
-LHASH *lconf;
-int verbose;
+static int certify(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509,
+ const EVP_MD *dgst, STACK *policy, TXT_DB *db, BIGNUM *serial,
+ char *startdate, int days, int batch, char *ext_sect, LHASH *lconf,
+ int verbose)
{
X509_REQ *req=NULL;
BIO *in=NULL;
return(ok);
}
-static int certify_cert(xret,infile,pkey,x509,dgst,policy,db,serial,startdate,
- days,batch,ext_sect,lconf,verbose)
-X509 **xret;
-char *infile;
-EVP_PKEY *pkey;
-X509 *x509;
-EVP_MD *dgst;
-STACK *policy;
-TXT_DB *db;
-BIGNUM *serial;
-char *startdate;
-int days;
-int batch;
-char *ext_sect;
-LHASH *lconf;
-int verbose;
+static int certify_cert(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509,
+ const EVP_MD *dgst, STACK *policy, TXT_DB *db, BIGNUM *serial,
+ char *startdate, int days, int batch, char *ext_sect, LHASH *lconf,
+ int verbose)
+
{
X509 *req=NULL;
X509_REQ *rreq=NULL;
return(ok);
}
-static int do_body(xret,pkey,x509,dgst,policy,db,serial,startdate,days,
- batch,verbose,req,ext_sect,lconf)
-X509 **xret;
-EVP_PKEY *pkey;
-X509 *x509;
-EVP_MD *dgst;
-STACK *policy;
-TXT_DB *db;
-BIGNUM *serial;
-char *startdate;
-int days;
-int batch;
-int verbose;
-X509_REQ *req;
-char *ext_sect;
-LHASH *lconf;
+static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, const EVP_MD *dgst,
+ STACK *policy, TXT_DB *db, BIGNUM *serial, char *startdate, int days,
+ int batch, int verbose, X509_REQ *req, char *ext_sect, LHASH *lconf)
{
X509_NAME *name=NULL,*CAname=NULL,*subject=NULL;
ASN1_UTCTIME *tm,*tmptm;
/* Free the current entries if any, there should not
* be any I belive */
if (ci->extensions != NULL)
- sk_pop_free(ci->extensions,X509_EXTENSION_free);
+ sk_X509_EXTENSION_pop_free(ci->extensions,
+ X509_EXTENSION_free);
ci->extensions = NULL;
- ctx.subject_cert = ret;
- ctx.issuer_cert = x509;
- ctx.subject_req = req;
- ctx.crl = NULL;
- ctx.flags = 0;
+ X509V3_set_ctx(&ctx, x509, ret, req, NULL, 0);
+ X509V3_set_conf_lhash(&ctx, lconf);
if(!X509V3_EXT_add_conf(lconf, &ctx, ext_sect, ret)) goto err;
return(ok);
}
-static void write_new_certificate(bp,x, output_der)
-BIO *bp;
-X509 *x;
-int output_der;
+static void write_new_certificate(BIO *bp, X509 *x, int output_der)
{
char *f;
char buf[256];
BIO_puts(bp,"\n");
}
-static int certify_spkac(xret,infile,pkey,x509,dgst,policy,db,serial,
- startdate,days,ext_sect,lconf,verbose)
-X509 **xret;
-char *infile;
-EVP_PKEY *pkey;
-X509 *x509;
-EVP_MD *dgst;
-STACK *policy;
-TXT_DB *db;
-BIGNUM *serial;
-char *startdate;
-int days;
-char *ext_sect;
-LHASH *lconf;
-int verbose;
+static int certify_spkac(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509,
+ const EVP_MD *dgst, STACK *policy, TXT_DB *db, BIGNUM *serial,
+ char *startdate, int days, char *ext_sect, LHASH *lconf, int verbose)
{
STACK *sk=NULL;
LHASH *parms=NULL;
return(ok);
}
-static int fix_data(nid,type)
-int nid;
-int *type;
+static int fix_data(int nid, int *type)
{
if (nid == NID_pkcs9_emailAddress)
*type=V_ASN1_IA5STRING;
return(1);
}
-static int check_time_format(str)
-char *str;
+static int check_time_format(char *str)
{
ASN1_UTCTIME tm;
return(ASN1_UTCTIME_check(&tm));
}
-static int add_oid_section(hconf)
-LHASH *hconf;
+static int add_oid_section(LHASH *hconf)
{
char *p;
STACK *sktmp;
return 1;
}
-static int do_revoke(x509,db)
-X509 *x509;
-TXT_DB *db;
+static int do_revoke(X509 *x509, TXT_DB *db)
{
ASN1_UTCTIME *tm=NULL;
char *row[DB_NUMBER],**rrow,**irow;