From eb64730b9cb6fe9cb5bfa4b0b54bf8c9193ced2b Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Fri, 27 Oct 2000 11:05:35 +0000 Subject: The majority of the OCSP code from CertCo. --- Makefile.org | 2 +- apps/x509.c | 8 + crypto/asn1/asn1.h | 30 ++ crypto/asn1/asn1_err.c | 30 ++ crypto/asn1/t_x509.c | 50 +++ crypto/err/err.h | 2 + crypto/err/openssl.ec | 1 + crypto/ocsp/Makefile.ssl | 243 +++++++++++++ crypto/ocsp/ocsp.h | 591 +++++++++++++++++++++++++++++++ crypto/ocsp/ocsp_cid.c | 157 +++++++++ crypto/ocsp/ocsp_err.c | 116 ++++++ crypto/ocsp/ocsp_ext.c | 347 ++++++++++++++++++ crypto/ocsp/ocsp_lib.c | 791 +++++++++++++++++++++++++++++++++++++++++ crypto/ocsp/ocsp_req.c | 316 +++++++++++++++++ crypto/ocsp/ocsp_res.c | 896 +++++++++++++++++++++++++++++++++++++++++++++++ crypto/ocsp/ocsp_sig.c | 157 +++++++++ crypto/stack/safestack.h | 58 +++ crypto/x509/x509.h | 1 + crypto/x509v3/v3_info.c | 9 + crypto/x509v3/x509v3.h | 1 + util/mkdef.pl | 1 + util/mkfiles.pl | 1 + 22 files changed, 3807 insertions(+), 1 deletion(-) create mode 100644 crypto/ocsp/Makefile.ssl create mode 100644 crypto/ocsp/ocsp.h create mode 100644 crypto/ocsp/ocsp_cid.c create mode 100644 crypto/ocsp/ocsp_err.c create mode 100644 crypto/ocsp/ocsp_ext.c create mode 100644 crypto/ocsp/ocsp_lib.c create mode 100644 crypto/ocsp/ocsp_req.c create mode 100644 crypto/ocsp/ocsp_res.c create mode 100644 crypto/ocsp/ocsp_sig.c diff --git a/Makefile.org b/Makefile.org index 184fd768e1..fe19c526e1 100644 --- a/Makefile.org +++ b/Makefile.org @@ -163,7 +163,7 @@ SDIRS= \ des rc2 rc4 rc5 idea bf cast \ bn rsa dsa dh dso engine rijndael \ buffer bio stack lhash rand err objects \ - evp asn1 pem x509 x509v3 conf txt_db pkcs7 pkcs12 comp + evp asn1 pem x509 x509v3 conf txt_db pkcs7 pkcs12 comp ocsp MAKEFILE= Makefile.ssl MAKE= make -f Makefile.ssl diff --git a/apps/x509.c b/apps/x509.c index 8712339717..ea5b0b8526 100644 --- a/apps/x509.c +++ b/apps/x509.c @@ -106,6 +106,7 @@ static char *x509_usage[]={ " -fingerprint - print the certificate fingerprint\n", " -alias - output certificate alias\n", " -noout - no certificate output\n", +" -ocspid - print OCSP hash values for the subject name and public key\n", " -trustout - output a \"trusted\" certificate\n", " -clrtrust - clear all trusted purposes\n", " -clrreject - clear all rejected purposes\n", @@ -163,6 +164,7 @@ int MAIN(int argc, char **argv) char *CAkeyfile=NULL,*CAserial=NULL; char *alias=NULL; int text=0,serial=0,hash=0,subject=0,issuer=0,startdate=0,enddate=0; + int ocspid=0; int noout=0,sign_flag=0,CA_flag=0,CA_createserial=0,email=0; int trustout=0,clrtrust=0,clrreject=0,aliasout=0,clrext=0; int C=0; @@ -412,6 +414,8 @@ int MAIN(int argc, char **argv) clrext = 1; } #endif + else if (strcmp(*argv,"-ocspid") == 0) + ocspid= ++num; else if ((md_alg=EVP_get_digestbyname(*argv + 1))) { /* ok */ @@ -917,6 +921,10 @@ bad: } noout=1; } + else if (ocspid == i) + { + X509_ocspid_print(out, x); + } } } diff --git a/crypto/asn1/asn1.h b/crypto/asn1/asn1.h index 6f956b1963..3daf4e483a 100644 --- a/crypto/asn1/asn1.h +++ b/crypto/asn1/asn1.h @@ -956,6 +956,21 @@ void ASN1_STRING_TABLE_cleanup(void); #define ASN1_F_D2I_NETSCAPE_SPKAC 143 #define ASN1_F_D2I_NETSCAPE_SPKI 144 #define ASN1_F_D2I_NOTICEREF 268 +#define ASN1_F_D2I_OCSP_BASICRESP 293 +#define ASN1_F_D2I_OCSP_CERTID 294 +#define ASN1_F_D2I_OCSP_CERTSTATUS 295 +#define ASN1_F_D2I_OCSP_CRLID 296 +#define ASN1_F_D2I_OCSP_ONEREQ 297 +#define ASN1_F_D2I_OCSP_REQINFO 298 +#define ASN1_F_D2I_OCSP_REQUEST 299 +#define ASN1_F_D2I_OCSP_RESPBYTES 300 +#define ASN1_F_D2I_OCSP_RESPDATA 301 +#define ASN1_F_D2I_OCSP_RESPID 302 +#define ASN1_F_D2I_OCSP_RESPONSE 303 +#define ASN1_F_D2I_OCSP_REVOKEDINFO 304 +#define ASN1_F_D2I_OCSP_SERVICELOC 305 +#define ASN1_F_D2I_OCSP_SIGNATURE 306 +#define ASN1_F_D2I_OCSP_SINGLERESP 307 #define ASN1_F_D2I_OTHERNAME 287 #define ASN1_F_D2I_PBE2PARAM 262 #define ASN1_F_D2I_PBEPARAM 249 @@ -1027,6 +1042,21 @@ void ASN1_STRING_TABLE_cleanup(void); #define ASN1_F_NETSCAPE_SPKAC_NEW 190 #define ASN1_F_NETSCAPE_SPKI_NEW 191 #define ASN1_F_NOTICEREF_NEW 272 +#define ASN1_F_OCSP_BASICRESP_NEW 308 +#define ASN1_F_OCSP_CERTID_NEW 309 +#define ASN1_F_OCSP_CERTSTATUS_NEW 310 +#define ASN1_F_OCSP_CRLID_NEW 311 +#define ASN1_F_OCSP_ONEREQ_NEW 312 +#define ASN1_F_OCSP_REQINFO_NEW 313 +#define ASN1_F_OCSP_REQUEST_NEW 314 +#define ASN1_F_OCSP_RESPBYTES_NEW 315 +#define ASN1_F_OCSP_RESPDATA_NEW 316 +#define ASN1_F_OCSP_RESPID_NEW 317 +#define ASN1_F_OCSP_RESPONSE_NEW 318 +#define ASN1_F_OCSP_REVOKEDINFO_NEW 319 +#define ASN1_F_OCSP_SERVICELOC_NEW 320 +#define ASN1_F_OCSP_SIGNATURE_NEW 321 +#define ASN1_F_OCSP_SINGLERESP_NEW 322 #define ASN1_F_OTHERNAME_NEW 288 #define ASN1_F_PBE2PARAM_NEW 264 #define ASN1_F_PBEPARAM_NEW 251 diff --git a/crypto/asn1/asn1_err.c b/crypto/asn1/asn1_err.c index cecd555c88..3a53cb33c5 100644 --- a/crypto/asn1/asn1_err.c +++ b/crypto/asn1/asn1_err.c @@ -141,6 +141,21 @@ static ERR_STRING_DATA ASN1_str_functs[]= {ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKAC,0), "d2i_NETSCAPE_SPKAC"}, {ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKI,0), "d2i_NETSCAPE_SPKI"}, {ERR_PACK(0,ASN1_F_D2I_NOTICEREF,0), "d2i_NOTICEREF"}, +{ERR_PACK(0,ASN1_F_D2I_OCSP_BASICRESP,0), "d2i_OCSP_BASICRESP"}, +{ERR_PACK(0,ASN1_F_D2I_OCSP_CERTID,0), "d2i_OCSP_CERTID"}, +{ERR_PACK(0,ASN1_F_D2I_OCSP_CERTSTATUS,0), "d2i_OCSP_CERTSTATUS"}, +{ERR_PACK(0,ASN1_F_D2I_OCSP_CRLID,0), "d2i_OCSP_CRLID"}, +{ERR_PACK(0,ASN1_F_D2I_OCSP_ONEREQ,0), "d2i_OCSP_ONEREQ"}, +{ERR_PACK(0,ASN1_F_D2I_OCSP_REQINFO,0), "d2i_OCSP_REQINFO"}, +{ERR_PACK(0,ASN1_F_D2I_OCSP_REQUEST,0), "d2i_OCSP_REQUEST"}, +{ERR_PACK(0,ASN1_F_D2I_OCSP_RESPBYTES,0), "d2i_OCSP_RESPBYTES"}, +{ERR_PACK(0,ASN1_F_D2I_OCSP_RESPDATA,0), "d2i_OCSP_RESPDATA"}, +{ERR_PACK(0,ASN1_F_D2I_OCSP_RESPID,0), "d2i_OCSP_RESPID"}, +{ERR_PACK(0,ASN1_F_D2I_OCSP_RESPONSE,0), "d2i_OCSP_RESPONSE"}, +{ERR_PACK(0,ASN1_F_D2I_OCSP_REVOKEDINFO,0), "d2i_OCSP_REVOKEDINFO"}, +{ERR_PACK(0,ASN1_F_D2I_OCSP_SERVICELOC,0), "d2i_OCSP_SERVICELOC"}, +{ERR_PACK(0,ASN1_F_D2I_OCSP_SIGNATURE,0), "d2i_OCSP_SIGNATURE"}, +{ERR_PACK(0,ASN1_F_D2I_OCSP_SINGLERESP,0), "d2i_OCSP_SINGLERESP"}, {ERR_PACK(0,ASN1_F_D2I_OTHERNAME,0), "d2i_OTHERNAME"}, {ERR_PACK(0,ASN1_F_D2I_PBE2PARAM,0), "d2i_PBE2PARAM"}, {ERR_PACK(0,ASN1_F_D2I_PBEPARAM,0), "d2i_PBEPARAM"}, @@ -212,6 +227,21 @@ static ERR_STRING_DATA ASN1_str_functs[]= {ERR_PACK(0,ASN1_F_NETSCAPE_SPKAC_NEW,0), "NETSCAPE_SPKAC_new"}, {ERR_PACK(0,ASN1_F_NETSCAPE_SPKI_NEW,0), "NETSCAPE_SPKI_new"}, {ERR_PACK(0,ASN1_F_NOTICEREF_NEW,0), "NOTICEREF_new"}, +{ERR_PACK(0,ASN1_F_OCSP_BASICRESP_NEW,0), "OCSP_BASICRESP_new"}, +{ERR_PACK(0,ASN1_F_OCSP_CERTID_NEW,0), "OCSP_CERTID_new"}, +{ERR_PACK(0,ASN1_F_OCSP_CERTSTATUS_NEW,0), "OCSP_CERTSTATUS_new"}, +{ERR_PACK(0,ASN1_F_OCSP_CRLID_NEW,0), "OCSP_CRLID_new"}, +{ERR_PACK(0,ASN1_F_OCSP_ONEREQ_NEW,0), "OCSP_ONEREQ_new"}, +{ERR_PACK(0,ASN1_F_OCSP_REQINFO_NEW,0), "OCSP_REQINFO_new"}, +{ERR_PACK(0,ASN1_F_OCSP_REQUEST_NEW,0), "OCSP_REQUEST_new"}, +{ERR_PACK(0,ASN1_F_OCSP_RESPBYTES_NEW,0), "OCSP_RESPBYTES_new"}, +{ERR_PACK(0,ASN1_F_OCSP_RESPDATA_NEW,0), "OCSP_RESPDATA_new"}, +{ERR_PACK(0,ASN1_F_OCSP_RESPID_NEW,0), "OCSP_RESPID_new"}, +{ERR_PACK(0,ASN1_F_OCSP_RESPONSE_NEW,0), "OCSP_RESPONSE_new"}, +{ERR_PACK(0,ASN1_F_OCSP_REVOKEDINFO_NEW,0), "OCSP_REVOKEDINFO_new"}, +{ERR_PACK(0,ASN1_F_OCSP_SERVICELOC_NEW,0), "OCSP_SERVICELOC_new"}, +{ERR_PACK(0,ASN1_F_OCSP_SIGNATURE_NEW,0), "OCSP_SIGNATURE_new"}, +{ERR_PACK(0,ASN1_F_OCSP_SINGLERESP_NEW,0), "OCSP_SINGLERESP_new"}, {ERR_PACK(0,ASN1_F_OTHERNAME_NEW,0), "OTHERNAME_new"}, {ERR_PACK(0,ASN1_F_PBE2PARAM_NEW,0), "PBE2PARAM_new"}, {ERR_PACK(0,ASN1_F_PBEPARAM_NEW,0), "PBEPARAM_new"}, diff --git a/crypto/asn1/t_x509.c b/crypto/asn1/t_x509.c index f2979bf5a7..823c20860c 100644 --- a/crypto/asn1/t_x509.c +++ b/crypto/asn1/t_x509.c @@ -282,6 +282,56 @@ err: return(ret); } +int X509_ocspid_print (BIO *bp, X509 *x) + { + unsigned char *der=NULL ; + unsigned char *dertmp; + int derlen; + int i; + SHA_CTX SHA1buf ; + unsigned char SHA1md[SHA_DIGEST_LENGTH]; + + /* display the hash of the subject as it would appear + in OCSP requests */ + if (BIO_printf(bp," Subject OCSP hash: ") <= 0) + goto err; + derlen = i2d_X509_NAME(x->cert_info->subject, NULL); + if ((der = dertmp = (unsigned char *)OPENSSL_malloc (derlen)) == NULL) + goto err; + i2d_X509_NAME(x->cert_info->subject, &dertmp); + + SHA1_Init(&SHA1buf); + SHA1_Update(&SHA1buf, der, derlen); + SHA1_Final(SHA1md,&SHA1buf); + for (i=0; i < SHA_DIGEST_LENGTH; i++) + { + if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err; + } + OPENSSL_free (der); + der=NULL; + + /* display the hash of the public key as it would appear + in OCSP requests */ + if (BIO_printf(bp,"\n Public key OCSP hash: ") <= 0) + goto err; + + SHA1_Init(&SHA1buf); + SHA1_Update(&SHA1buf, x->cert_info->key->public_key->data, + x->cert_info->key->public_key->length); + SHA1_Final(SHA1md,&SHA1buf); + for (i=0; i < SHA_DIGEST_LENGTH; i++) + { + if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) + goto err; + } + BIO_printf(bp,"\n"); + + return (1); +err: + if (der != NULL) OPENSSL_free(der); + return(0); + } + int ASN1_STRING_print(BIO *bp, ASN1_STRING *v) { int i,n; diff --git a/crypto/err/err.h b/crypto/err/err.h index 7388a4a937..b4ced575df 100644 --- a/crypto/err/err.h +++ b/crypto/err/err.h @@ -133,6 +133,7 @@ typedef struct err_state_st #define ERR_LIB_RAND 36 #define ERR_LIB_DSO 37 #define ERR_LIB_ENGINE 38 +#define ERR_LIB_OCSP 39 #define ERR_LIB_USER 128 @@ -163,6 +164,7 @@ typedef struct err_state_st #define RANDerr(f,r) ERR_PUT_error(ERR_LIB_RAND,(f),(r),ERR_file_name,__LINE__) #define DSOerr(f,r) ERR_PUT_error(ERR_LIB_DSO,(f),(r),ERR_file_name,__LINE__) #define ENGINEerr(f,r) ERR_PUT_error(ERR_LIB_ENGINE,(f),(r),ERR_file_name,__LINE__) +#define OCSPerr(f,r) ERR_PUT_error(ERR_LIB_OCSP,(f),(r),ERR_file_name,__LINE__) /* Borland C seems too stupid to be able to shift and do longs in * the pre-processor :-( */ diff --git a/crypto/err/openssl.ec b/crypto/err/openssl.ec index 861d680e07..9bd267bda2 100644 --- a/crypto/err/openssl.ec +++ b/crypto/err/openssl.ec @@ -9,6 +9,7 @@ L EVP crypto/evp/evp.h crypto/evp/evp_err.c L BUF crypto/buffer/buffer.h crypto/buffer/buf_err.c L BIO crypto/bio/bio.h crypto/bio/bio_err.c L OBJ crypto/objects/objects.h crypto/objects/obj_err.c +L OCSP crypto/ocsp/ocsp.h crypto/ocsp/ocsp_err.c L PEM crypto/pem/pem.h crypto/pem/pem_err.c L X509 crypto/x509/x509.h crypto/x509/x509_err.c L NONE crypto/x509/x509_vfy.h NONE diff --git a/crypto/ocsp/Makefile.ssl b/crypto/ocsp/Makefile.ssl new file mode 100644 index 0000000000..4f6378cd34 --- /dev/null +++ b/crypto/ocsp/Makefile.ssl @@ -0,0 +1,243 @@ +# +# OpenSSL/ocsp/Makefile.ssl +# + +DIR= ocsp +TOP= ../.. +CC= cc +INCLUDES= -I.. -I../../include +CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl +INSTALLTOP=/usr/local/ssl +MAKE= make -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) +MAKEFILE= Makefile.ssl +AR= ar r + +CFLAGS= $(INCLUDES) $(CFLAG) + +GENERAL=Makefile README +TEST= +APPS= + +LIB=$(TOP)/libcrypto.a +LIBSRC= ocsp_req.c ocsp_res.c ocsp_sig.c ocsp_cid.c ocsp_ext.c \ + ocsp_lib.c ocsp_err.c +#ocsp_v3.c +LIBOBJ= ocsp_req.o ocsp_res.o ocsp_sig.o ocsp_cid.o ocsp_ext.o \ + ocsp_lib.o ocsp_err.o +#ocsp_v3.o + +SRC= $(LIBSRC) + +EXHEADER= ocsp.h +HEADER= $(EXHEADER) + +ALL= $(GENERAL) $(SRC) $(HEADER) + +top: + (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) + +all: lib + +lib: $(LIBOBJ) + $(AR) $(LIB) $(LIBOBJ) + $(RANLIB) $(LIB) + @touch lib + +files: + perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + +links: + $(TOP)/util/point.sh Makefile.ssl Makefile ; + $(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + $(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + $(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) + +install: + @for i in $(EXHEADER) ; \ + do \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ + done; + +tags: + ctags $(SRC) + +tests: + +lint: + lint -DLINT $(INCLUDES) $(SRC)>fluff + +depend: + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(LIBSRC) + +dclean: + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + mv -f Makefile.new $(MAKEFILE) + +clean: + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +ocsp_cid.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +ocsp_cid.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +ocsp_cid.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +ocsp_cid.o: ../../include/openssl/cast.h ../../include/openssl/conf.h +ocsp_cid.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +ocsp_cid.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +ocsp_cid.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +ocsp_cid.o: ../../include/openssl/err.h ../../include/openssl/evp.h +ocsp_cid.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h +ocsp_cid.o: ../../include/openssl/md2.h ../../include/openssl/md4.h +ocsp_cid.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +ocsp_cid.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h +ocsp_cid.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h +ocsp_cid.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +ocsp_cid.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +ocsp_cid.o: ../../include/openssl/rc5.h +ocsp_cid.o: ../../include/openssl/rijndael-alg-fst.h +ocsp_cid.o: ../../include/openssl/rijndael.h ../../include/openssl/ripemd.h +ocsp_cid.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +ocsp_cid.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +ocsp_cid.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h +ocsp_cid.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h +ocsp_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +ocsp_err.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +ocsp_err.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +ocsp_err.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h +ocsp_err.o: ../../include/openssl/des.h ../../include/openssl/dh.h +ocsp_err.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +ocsp_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +ocsp_err.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +ocsp_err.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h +ocsp_err.o: ../../include/openssl/md4.h ../../include/openssl/md5.h +ocsp_err.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h +ocsp_err.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h +ocsp_err.o: ../../include/openssl/opensslconf.h +ocsp_err.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +ocsp_err.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +ocsp_err.o: ../../include/openssl/rc5.h +ocsp_err.o: ../../include/openssl/rijndael-alg-fst.h +ocsp_err.o: ../../include/openssl/rijndael.h ../../include/openssl/ripemd.h +ocsp_err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +ocsp_err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +ocsp_err.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h +ocsp_err.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h +ocsp_ext.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +ocsp_ext.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +ocsp_ext.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +ocsp_ext.o: ../../include/openssl/cast.h ../../include/openssl/conf.h +ocsp_ext.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +ocsp_ext.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +ocsp_ext.o: ../../include/openssl/e_os.h ../../include/openssl/e_os.h +ocsp_ext.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +ocsp_ext.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +ocsp_ext.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h +ocsp_ext.o: ../../include/openssl/md4.h ../../include/openssl/md5.h +ocsp_ext.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h +ocsp_ext.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h +ocsp_ext.o: ../../include/openssl/opensslconf.h +ocsp_ext.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +ocsp_ext.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +ocsp_ext.o: ../../include/openssl/rc5.h +ocsp_ext.o: ../../include/openssl/rijndael-alg-fst.h +ocsp_ext.o: ../../include/openssl/rijndael.h ../../include/openssl/ripemd.h +ocsp_ext.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +ocsp_ext.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +ocsp_ext.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h +ocsp_ext.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h +ocsp_ext.o: ../cryptlib.h +ocsp_lib.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +ocsp_lib.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +ocsp_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +ocsp_lib.o: ../../include/openssl/cast.h ../../include/openssl/conf.h +ocsp_lib.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +ocsp_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +ocsp_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os.h +ocsp_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +ocsp_lib.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +ocsp_lib.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h +ocsp_lib.o: ../../include/openssl/md4.h ../../include/openssl/md5.h +ocsp_lib.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h +ocsp_lib.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h +ocsp_lib.o: ../../include/openssl/opensslconf.h +ocsp_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h +ocsp_lib.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h +ocsp_lib.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +ocsp_lib.o: ../../include/openssl/rc5.h +ocsp_lib.o: ../../include/openssl/rijndael-alg-fst.h +ocsp_lib.o: ../../include/openssl/rijndael.h ../../include/openssl/ripemd.h +ocsp_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +ocsp_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +ocsp_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h +ocsp_lib.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h +ocsp_lib.o: ../cryptlib.h +ocsp_req.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +ocsp_req.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +ocsp_req.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +ocsp_req.o: ../../include/openssl/cast.h ../../include/openssl/conf.h +ocsp_req.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +ocsp_req.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +ocsp_req.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +ocsp_req.o: ../../include/openssl/err.h ../../include/openssl/evp.h +ocsp_req.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h +ocsp_req.o: ../../include/openssl/md2.h ../../include/openssl/md4.h +ocsp_req.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +ocsp_req.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h +ocsp_req.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h +ocsp_req.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +ocsp_req.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +ocsp_req.o: ../../include/openssl/rc5.h +ocsp_req.o: ../../include/openssl/rijndael-alg-fst.h +ocsp_req.o: ../../include/openssl/rijndael.h ../../include/openssl/ripemd.h +ocsp_req.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +ocsp_req.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +ocsp_req.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h +ocsp_req.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h +ocsp_res.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +ocsp_res.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +ocsp_res.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +ocsp_res.o: ../../include/openssl/cast.h ../../include/openssl/conf.h +ocsp_res.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +ocsp_res.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +ocsp_res.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +ocsp_res.o: ../../include/openssl/err.h ../../include/openssl/evp.h +ocsp_res.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h +ocsp_res.o: ../../include/openssl/md2.h ../../include/openssl/md4.h +ocsp_res.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +ocsp_res.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h +ocsp_res.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h +ocsp_res.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +ocsp_res.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +ocsp_res.o: ../../include/openssl/rc5.h +ocsp_res.o: ../../include/openssl/rijndael-alg-fst.h +ocsp_res.o: ../../include/openssl/rijndael.h ../../include/openssl/ripemd.h +ocsp_res.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +ocsp_res.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +ocsp_res.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h +ocsp_res.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h +ocsp_sig.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +ocsp_sig.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +ocsp_sig.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +ocsp_sig.o: ../../include/openssl/cast.h ../../include/openssl/conf.h +ocsp_sig.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +ocsp_sig.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +ocsp_sig.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +ocsp_sig.o: ../../include/openssl/err.h ../../include/openssl/evp.h +ocsp_sig.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h +ocsp_sig.o: ../../include/openssl/md2.h ../../include/openssl/md4.h +ocsp_sig.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +ocsp_sig.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h +ocsp_sig.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h +ocsp_sig.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +ocsp_sig.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +ocsp_sig.o: ../../include/openssl/rc5.h +ocsp_sig.o: ../../include/openssl/rijndael-alg-fst.h +ocsp_sig.o: ../../include/openssl/rijndael.h ../../include/openssl/ripemd.h +ocsp_sig.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +ocsp_sig.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +ocsp_sig.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h +ocsp_sig.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h diff --git a/crypto/ocsp/ocsp.h b/crypto/ocsp/ocsp.h new file mode 100644 index 0000000000..34563bf9c4 --- /dev/null +++ b/crypto/ocsp/ocsp.h @@ -0,0 +1,591 @@ +/* ocsp.h */ +/* Written by Tom Titchener for the OpenSSL + * project. */ + +/* History: + This file was transfered to Richard Levitte from CertCo by Kathy + Weinhold in mid-spring 2000 to be included in OpenSSL or released + as a patch kit. */ + +/* ==================================================================== + * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#ifndef HEADER_OCSP_H +#define HEADER_OCSP_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* CertID ::= SEQUENCE { + * hashAlgorithm AlgorithmIdentifier, + * issuerNameHash OCTET STRING, -- Hash of Issuer's DN + * issuerKeyHash OCTET STRING, -- Hash of Issuers public key (excluding the tag & length fields) + * serialNumber CertificateSerialNumber } + */ +typedef struct ocsp_cert_id_st + { + X509_ALGOR *hashAlgorithm; + ASN1_OCTET_STRING *issuerNameHash; + ASN1_OCTET_STRING *issuerKeyHash; + ASN1_INTEGER *serialNumber; + } OCSP_CERTID; + +/* Request ::= SEQUENCE { + * reqCert CertID, + * singleRequestExtensions [0] EXPLICIT Extensions OPTIONAL } + */ +typedef struct ocsp_one_request_st + { + OCSP_CERTID *reqCert; + STACK_OF(X509_EXTENSION) *singleRequestExtensions; + } OCSP_ONEREQ; + +DECLARE_STACK_OF(OCSP_ONEREQ) +DECLARE_ASN1_SET_OF(OCSP_ONEREQ) + + +/* TBSRequest ::= SEQUENCE { + * version [0] EXPLICIT Version DEFAULT v1, + * requestorName [1] EXPLICIT GeneralName OPTIONAL, + * requestList SEQUENCE OF Request, + * requestExtensions [2] EXPLICIT Extensions OPTIONAL } + */ +typedef struct ocsp_req_info_st + { + ASN1_INTEGER *version; + GENERAL_NAME *requestorName; + STACK_OF(OCSP_ONEREQ) *requestList; + STACK_OF(X509_EXTENSION) *requestExtensions; + } OCSP_REQINFO; + +/* Signature ::= SEQUENCE { + * signatureAlgorithm AlgorithmIdentifier, + * signature BIT STRING, + * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL } + */ +typedef struct ocsp_signature_st + { + X509_ALGOR *signatureAlgorithm; + ASN1_BIT_STRING *signature; + STACK_OF(X509) *certs; + } OCSP_SIGNATURE; + +/* OCSPRequest ::= SEQUENCE { + * tbsRequest TBSRequest, + * optionalSignature [0] EXPLICIT Signature OPTIONAL } + */ +typedef struct ocsp_request_st + { + OCSP_REQINFO *tbsRequest; + OCSP_SIGNATURE *optionalSignature; /* OPTIONAL */ + } OCSP_REQUEST; + +/* OCSPResponseStatus ::= ENUMERATED { + * successful (0), --Response has valid confirmations + * malformedRequest (1), --Illegal confirmation request + * internalError (2), --Internal error in issuer + * tryLater (3), --Try again later + * --(4) is not used + * sigRequired (5), --Must sign the request + * unauthorized (6) --Request unauthorized + * } + */ +#define OCSP_RESPONSE_STATUS_SUCCESSFULL 0 +#define OCSP_RESPONSE_STATUS_MALFORMEDREQUEST 1 +#define OCSP_RESPONSE_STATUS_INTERNALERROR 2 +#define OCSP_RESPONSE_STATUS_TRYLATER 3 +#define OCSP_RESPONSE_STATUS_SIGREQUIRED 5 +#define OCSP_RESPONSE_STATUS_UNAUTHORIZED 6 + +/* ResponseBytes ::= SEQUENCE { + * responseType OBJECT IDENTIFIER, + * response OCTET STRING } + */ +typedef struct ocsp_resp_bytes_st + { + ASN1_OBJECT *responseType; + ASN1_OCTET_STRING *response; + } OCSP_RESPBYTES; + +/* OCSPResponse ::= SEQUENCE { + * responseStatus OCSPResponseStatus, + * responseBytes [0] EXPLICIT ResponseBytes OPTIONAL } + */ +typedef struct ocsp_response_st + { + ASN1_ENUMERATED *responseStatus; + OCSP_RESPBYTES *responseBytes; + } OCSP_RESPONSE; + +/* ResponderID ::= CHOICE { + * byName [1] Name, + * byKey [2] KeyHash } + */ +#define V_OCSP_RESPID_NAME 1 +#define V_OCSP_RESPID_KEY 2 +typedef struct ocsp_responder_id_st + { + int tag; + union { + X509_NAME* byName; + ASN1_OCTET_STRING *byKey; + } value; + } OCSP_RESPID; +/* KeyHash ::= OCTET STRING --SHA-1 hash of responder's public key + * --(excluding the tag and length fields) + */ + +/* RevokedInfo ::= SEQUENCE { + * revocationTime GeneralizedTime, + * revocationReason [0] EXPLICIT CRLReason OPTIONAL } + */ +typedef struct ocsp_revoked_info_st + { + ASN1_GENERALIZEDTIME *revocationTime; + ASN1_ENUMERATED *revocationReason; + } OCSP_REVOKEDINFO; + +/* CertStatus ::= CHOICE { + * good [0] IMPLICIT NULL, + * revoked [1] IMPLICIT RevokedInfo, + * unknown [2] IMPLICIT UnknownInfo } + */ +#define V_OCSP_CERTSTATUS_GOOD 0 +#define V_OCSP_CERTSTATUS_REVOKED 1 +#define V_OCSP_CERTSTATUS_UNKNOWN 2 +typedef struct ocsp_cert_status_st + { + int tag; + /* good [0] IMPLICIT NULL */ + OCSP_REVOKEDINFO *revoked; + /* unknown [2] OCSP_UNKNOWNINFO *unknown, which is NULL */ + } OCSP_CERTSTATUS; + +/* SingleResponse ::= SEQUENCE { + * certID CertID, + * certStatus CertStatus, + * thisUpdate GeneralizedTime, + * nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL, + * singleExtensions [1] EXPLICIT Extensions OPTIONAL } + */ +typedef struct ocsp_single_response_st + { + OCSP_CERTID *certId; + OCSP_CERTSTATUS *certStatus; + ASN1_GENERALIZEDTIME *thisUpdate; + ASN1_GENERALIZEDTIME *nextUpdate; + STACK_OF(X509_EXTENSION) *singleExtensions; + } OCSP_SINGLERESP; + +DECLARE_STACK_OF(OCSP_SINGLERESP) +DECLARE_ASN1_SET_OF(OCSP_SINGLERESP) + +/* ResponseData ::= SEQUENCE { + * version [0] EXPLICIT Version DEFAULT v1, + * responderID ResponderID, + * producedAt GeneralizedTime, + * responses SEQUENCE OF SingleResponse, + * responseExtensions [1] EXPLICIT Extensions OPTIONAL } + */ +typedef struct ocsp_response_data_st + { + ASN1_INTEGER *version; + OCSP_RESPID *responderId; + ASN1_GENERALIZEDTIME *producedAt; + STACK_OF(OCSP_SINGLERESP) *responses; + STACK_OF(X509_EXTENSION) *responseExtensions; + } OCSP_RESPDATA; + +/* BasicOCSPResponse ::= SEQUENCE { + * tbsResponseData ResponseData, + * signatureAlgorithm AlgorithmIdentifier, + * signature BIT STRING, + * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL } + */ + /* Note 1: + The value for "signature" is specified in the OCSP rfc2560 as follows: + "The value for the signature SHALL be computed on the hash of the DER + encoding ResponseData." This means that you must hash the DER-encoded + tbsResponseData, and then run it through a crypto-signing function, which + will (at least w/RSA) do a hash-'n'-private-encrypt operation. This seems + a bit odd, but that's the spec. Also note that the data structures do not + leave anywhere to independently specify the algorithm used for the initial + hash. So, we look at the signature-specification algorithm, and try to do + something intelligent. -- Kathy Weinhold, CertCo */ + /* Note 2: + It seems that the mentioned passage from RFC 2560 (section 4.2.1) is open + for interpretation. I've done tests against another responder, and found + that it doesn't do the double hashing that the RFC seems to say one + should. Therefore, all relevant functions take a flag saying which + variant should be used. -- Richard Levitte, OpenSSL team and CeloCom */ +typedef struct ocsp_basic_response_st + { + OCSP_RESPDATA *tbsResponseData; + X509_ALGOR *signatureAlgorithm; + ASN1_BIT_STRING *signature; + STACK_OF(X509) *certs; + } OCSP_BASICRESP; + +/* + * CRLReason ::= ENUMERATED { + * unspecified (0), + * keyCompromise (1), + * cACompromise (2), + * affiliationChanged (3), + * superseded (4), + * cessationOfOperation (5), + * certificateHold (6), + * removeFromCRL (8) } + */ +#define OCSP_REVOKED_STATUS_NOSTATUS -1 +#define OCSP_REVOKED_STATUS_UNSPECIFIED 0 +#define OCSP_REVOKED_STATUS_KEYCOMPROMISE 1 +#define OCSP_REVOKED_STATUS_CACOMPROMISE 2 +#define OCSP_REVOKED_STATUS_AFFILIATIONCHANGED 3 +#define OCSP_REVOKED_STATUS_SUPERSEDED 4 +#define OCSP_REVOKED_STATUS_CESSATIONOFOPERATION 5 +#define OCSP_REVOKED_STATUS_CERTIFICATEHOLD 6 +#define OCSP_REVOKED_STATUS_REMOVEFROMCRL 8 + +/* CrlID ::= SEQUENCE { + * crlUrl [0] EXPLICIT IA5String OPTIONAL, + * crlNum [1] EXPLICIT INTEGER OPTIONAL, + * crlTime [2] EXPLICIT GeneralizedTime OPTIONAL } + */ +typedef struct ocsp_crl_id_st + { + ASN1_IA5STRING *crlUrl; + ASN1_INTEGER *crlNum; + ASN1_GENERALIZEDTIME *crlTime; + } OCSP_CRLID; + +/* ServiceLocator ::= SEQUENCE { + * issuer Name, + * locator AuthorityInfoAccessSyntax OPTIONAL } + */ +typedef struct ocsp_service_locator_st + { + X509_NAME* issuer; + STACK_OF(ACCESS_DESCRIPTION) *locator; + } OCSP_SERVICELOC; + +#define PEM_STRING_OCSP_REQUEST "OCSP REQUEST" +#define PEM_STRING_OCSP_RESPONSE "OCSP RESPONSE" + +#define d2i_OCSP_REQUEST_bio(bp,p) (OCSP_REQUEST*)ASN1_d2i_bio((char*(*)()) \ + OCSP_REQUEST_new,(char *(*)())d2i_OCSP_REQUEST, (bp),\ + (unsigned char **)(p)) + +#define d2i_OCSP_RESPONSE_bio(bp,p) (OCSP_RESPONSE*)ASN1_d2i_bio((char*(*)())\ + OCSP_REQUEST_new,(char *(*)())d2i_OCSP_RESPONSE, (bp),\ + (unsigned char **)(p)) + +#define PEM_read_bio_OCSP_REQUEST(bp,x,cb) (OCSP_REQUEST *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST,bp,(char **)x,cb,NULL) + +#define PEM_read_bio_OCSP_RESPONSE(bp,x,cb)(OCSP_RESPONSE *)PEM_ASN1_read_bio(\ + (char *(*)())d2i_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE,bp,(char **)x,cb,NULL) + +#define PEM_write_bio_OCSP_REQUEST(bp,o) \ + PEM_ASN1_write_bio((int (*)())i2d_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST,\ + bp,(char *)o, NULL,NULL,0,NULL,NULL) + +#define PEM_write_bio_OCSP_RESPONSE(bp,o) \ + PEM_ASN1_write_bio((int (*)())i2d_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE,\ + bp,(char *)o, NULL,NULL,0,NULL,NULL) + +#define i2d_OCSP_RESPONSE_bio(bp,o) ASN1_i2d_bio(i2d_OCSP_RESPONSE,bp,\ + (unsigned char *)o) + +#define i2d_OCSP_REQUEST_bio(bp,o) ASN1_i2d_bio(i2d_OCSP_REQUEST,bp,\ + (unsigned char *)o) + +#define OCSP_REQUEST_sign(o,pkey,md) \ + ASN1_sign((int(*)())i2d_OCSP_REQINFO,\ + o->optionalSignature->signatureAlgorithm,NULL,\ + o->optionalSignature->signature,(char *)o->tbsRequest,pkey,md) + +#define OCSP_BASICRESP_sign(o,pkey,md,d) \ + ASN1_sign((int(*)())i2d_OCSP_RESPDATA,o->signatureAlgorithm,NULL,\ + o->signature,(char *)o->tbsResponseData,pkey,md) + +#define OCSP_REQUEST_verify(a,r) ASN1_verify((int (*)())i2d_OCSP_REQINFO,\ + a->optionalSignature->signatureAlgorithm,\ + a->optionalSignature->signature,(char *)a->tbsRequest,r) + +#define OCSP_BASICRESP_verify(a,r,d) ASN1_verify((int (*)())i2d_OCSP_RESPDATA,\ + a->signatureAlgorithm,a->signature,(char *)a->tbsResponseData,r) + +#define ASN1_BIT_STRING_digest(data,type,md,len) \ + ASN1_digest((int (*)())i2d_ASN1_BIT_STRING,type,(char *)data,md,len) + +#define OCSP_CERTID_dup(cid) (OCSP_CERTID*)ASN1_dup((int(*)())i2d_OCSP_CERTID,\ + (char *(*)())d2i_OCSP_CERTID,(char *)(cid)) + +#define OCSP_CERTSTATUS_dup(cs)\ + (OCSP_CERTSTATUS*)ASN1_dup((int(*)())i2d_OCSP_CERTSTATUS,\ + (char *(*)())d2i_OCSP_CERTSTATUS,(char *)(cs)) + +OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst, + X509_NAME *issuerName, + ASN1_BIT_STRING* issuerKey, + ASN1_INTEGER *serialNumber); + +OCSP_CERTSTATUS *OCSP_cert_status_new(int status, int reason, char *tim); + +OCSP_REQUEST *OCSP_request_new(X509_NAME* name, + STACK_OF(X509_EXTENSION) *extensions); + +int OCSP_request_add(OCSP_REQUEST *req, + OCSP_CERTID *cid, + STACK_OF(X509_EXTENSION) *extensions); + +int OCSP_request_sign(OCSP_REQUEST *req, + EVP_PKEY *key, + const EVP_MD *dgst, + STACK_OF(X509) *certs); + +int OCSP_request_verify(OCSP_REQUEST *req, EVP_PKEY *pkey); + +OCSP_BASICRESP *OCSP_basic_response_new(int tag, + X509* cert, + STACK_OF(X509_EXTENSION) *extensions); + +int OCSP_basic_response_add(OCSP_BASICRESP *rsp, + OCSP_CERTID *cid, + OCSP_CERTSTATUS *cst, + char *thisUpdate, + char *nextUpdate, + STACK_OF(X509_EXTENSION) *extensions); + +int OCSP_basic_response_sign(OCSP_BASICRESP *brsp, + EVP_PKEY *key, + const EVP_MD *dgst, + STACK_OF(X509) *certs); + +int OCSP_response_verify(OCSP_RESPONSE *rsp, EVP_PKEY *pkey); + +int OCSP_basic_response_verify(OCSP_BASICRESP *rsp, EVP_PKEY *pkey); + + +OCSP_RESPONSE *OCSP_response_new(int status, + int nid, + int (*i2d)(), + char *data); + +ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, int (*i2d)(), + char *data, STACK *sk); + +X509_EXTENSION *OCSP_nonce_new(void *p, unsigned int len); + +X509_EXTENSION *OCSP_crlID_new(char *url, long *n, char *tim); + +X509_EXTENSION *OCSP_accept_responses_new(char **oids); + +X509_EXTENSION *OCSP_archive_cutoff_new(char* tim); + +X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME* issuer, char **urls); + +OCSP_SINGLERESP *OCSP_SINGLERESP_new(void); +void OCSP_SINGLERESP_free(OCSP_SINGLERESP *a); +int i2d_OCSP_SINGLERESP(OCSP_SINGLERESP *a, unsigned char **pp); +OCSP_SINGLERESP *d2i_OCSP_SINGLERESP(OCSP_SINGLERESP **a, unsigned char **pp, long length); +int i2a_OCSP_SINGLERESP(BIO *bp, OCSP_SINGLERESP* a); + +OCSP_CERTSTATUS *OCSP_CERTSTATUS_new(void); +void OCSP_CERTSTATUS_free(OCSP_CERTSTATUS *a); +int i2d_OCSP_CERTSTATUS(OCSP_CERTSTATUS *a, unsigned char **pp); +OCSP_CERTSTATUS *d2i_OCSP_CERTSTATUS(OCSP_CERTSTATUS **a, unsigned char **pp, long length); +int i2a_OCSP_CERTSTATUS(BIO *bp, OCSP_CERTSTATUS* a); + +OCSP_REVOKEDINFO *OCSP_REVOKEDINFO_new(void); +void OCSP_REVOKEDINFO_free(OCSP_REVOKEDINFO *a); +int i2d_OCSP_REVOKEDINFO(OCSP_REVOKEDINFO *a, unsigned char **pp); +OCSP_REVOKEDINFO *d2i_OCSP_REVOKEDINFO(OCSP_REVOKEDINFO **a, unsigned char **pp, long length); +int i2a_OCSP_REVOKEDINFO(BIO *bp, OCSP_REVOKEDINFO* a); + +OCSP_BASICRESP *OCSP_BASICRESP_new(void); +void OCSP_BASICRESP_free(OCSP_BASICRESP *a); +int i2d_OCSP_BASICRESP(OCSP_BASICRESP *a, unsigned char **pp); +OCSP_BASICRESP *d2i_OCSP_BASICRESP(OCSP_BASICRESP **a, unsigned char **pp, long length); +int i2a_OCSP_BASICRESP(BIO *bp, OCSP_BASICRESP* a); + +OCSP_RESPDATA *OCSP_RESPDATA_new(void); +void OCSP_RESPDATA_free(OCSP_RESPDATA *a); +int i2d_OCSP_RESPDATA(OCSP_RESPDATA *a, unsigned char **pp); +OCSP_RESPDATA *d2i_OCSP_RESPDATA(OCSP_RESPDATA **a, unsigned char **pp, long length); +int i2a_OCSP_RESPDATA(BIO *bp, OCSP_RESPDATA* a); + +OCSP_RESPID *OCSP_RESPID_new(void); +void OCSP_RESPID_free(OCSP_RESPID *a); +int i2d_OCSP_RESPID(OCSP_RESPID *a, unsigned char **pp); +OCSP_RESPID *d2i_OCSP_RESPID(OCSP_RESPID **a, unsigned char **pp, long length); +int i2a_OCSP_RESPID(BIO *bp, OCSP_RESPID* a); + +OCSP_RESPONSE *OCSP_RESPONSE_new(void); +void OCSP_RESPONSE_free(OCSP_RESPONSE *a); +int i2d_OCSP_RESPONSE(OCSP_RESPONSE *a, unsigned char **pp); +OCSP_RESPONSE *d2i_OCSP_RESPONSE(OCSP_RESPONSE **a, unsigned char **pp, long length); +int i2a_OCSP_RESPONSE(BIO *bp, OCSP_RESPONSE* a); +int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE* a); + +OCSP_RESPBYTES *OCSP_RESPBYTES_new(void); +void OCSP_RESPBYTES_free(OCSP_RESPBYTES *a); +int i2d_OCSP_RESPBYTES(OCSP_RESPBYTES *a, unsigned char **pp); +OCSP_RESPBYTES *d2i_OCSP_RESPBYTES(OCSP_RESPBYTES **a, unsigned char **pp, long length); +int i2a_OCSP_RESPBYTES(BIO *bp, OCSP_RESPBYTES* a); + +OCSP_ONEREQ *OCSP_ONEREQ_new(void); +void OCSP_ONEREQ_free(OCSP_ONEREQ *a); +int i2d_OCSP_ONEREQ(OCSP_ONEREQ *a, unsigned char **pp); +OCSP_ONEREQ *d2i_OCSP_ONEREQ(OCSP_ONEREQ **a, unsigned char **pp, long length); +int i2a_OCSP_ONEREQ(BIO *bp, OCSP_ONEREQ* a); + +OCSP_CERTID *OCSP_CERTID_new(void); +void OCSP_CERTID_free(OCSP_CERTID *a); +int i2d_OCSP_CERTID(OCSP_CERTID *a, unsigned char **pp); +OCSP_CERTID *d2i_OCSP_CERTID(OCSP_CERTID **a, unsigned char **pp, long length); +int i2a_OCSP_CERTID(BIO *bp, OCSP_CERTID* a); + +OCSP_REQUEST *OCSP_REQUEST_new(void); +void OCSP_REQUEST_free(OCSP_REQUEST *a); +int i2d_OCSP_REQUEST(OCSP_REQUEST *a, unsigned char **pp); +OCSP_REQUEST *d2i_OCSP_REQUEST(OCSP_REQUEST **a, unsigned char **pp, long length); +int i2a_OCSP_REQUEST(BIO *bp, OCSP_REQUEST* a); +int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST* a); + +OCSP_SIGNATURE *OCSP_SIGNATURE_new(void); +void OCSP_SIGNATURE_free(OCSP_SIGNATURE *a); +int i2d_OCSP_SIGNATURE(OCSP_SIGNATURE *a, unsigned char **pp); +OCSP_SIGNATURE *d2i_OCSP_SIGNATURE(OCSP_SIGNATURE **a, unsigned char **pp, long length); +int i2a_OCSP_SIGNATURE(BIO *bp, OCSP_SIGNATURE* a); + +OCSP_REQINFO *OCSP_REQINFO_new(void); +void OCSP_REQINFO_free(OCSP_REQINFO *a); +int i2d_OCSP_REQINFO(OCSP_REQINFO *a, unsigned char **pp); +OCSP_REQINFO *d2i_OCSP_REQINFO(OCSP_REQINFO **a, unsigned char **pp, long length); +int i2a_OCSP_REQINFO(BIO *bp, OCSP_REQINFO* a); + +OCSP_CRLID *OCSP_CRLID_new(void); +void OCSP_CRLID_free(OCSP_CRLID *a); +int i2d_OCSP_CRLID(OCSP_CRLID *a, unsigned char **pp); +OCSP_CRLID *d2i_OCSP_CRLID(OCSP_CRLID **a, unsigned char **pp, long length); +int i2a_OCSP_CRLID(BIO *bp, OCSP_CRLID* a); +int OCSP_CRLID_print(BIO *bp, OCSP_CRLID *a, int ind); + +OCSP_SERVICELOC *OCSP_SERVICELOC_new(void); +void OCSP_SERVICELOC_free(OCSP_SERVICELOC *a); +int i2d_OCSP_SERVICELOC(OCSP_SERVICELOC *a, unsigned char **pp); +OCSP_SERVICELOC *d2i_OCSP_SERVICELOC(OCSP_SERVICELOC **a, unsigned char **pp, long length); +int i2a_OCSP_SERVICELOC(BIO *bp, OCSP_SERVICELOC* a); +int OCSP_SERVICELOC_print(BIO *bp, OCSP_SERVICELOC* a, int ind); + +int OCSP_extensions_print(BIO *bp, STACK_OF(X509_EXTENSION) *sk, char *title); +int OCSP_extension_print(BIO *bp, X509_EXTENSION *x, int ind); + +void ERR_load_OCSP_strings(void); + +X509_EXTENSION *OCSP_nochain_new(void); + +char* ocspResponseStatus2string(long s); +char* ocspCertStatus2string(long s); +char * cRLReason2string(long s); + +void OCSP_add_standard_extension(void); + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +/* Error codes for the OCSP functions. */ + +/* Function codes. */ +#define OCSP_F_ASN1_STRING_ENCODE 106 +#define OCSP_F_BASIC_RESPONSE_NEW 100 +#define OCSP_F_BASIC_RESPONSE_VERIFY 101 +#define OCSP_F_CERT_ID_NEW 102 +#define OCSP_F_CERT_STATUS_NEW 103 +#define OCSP_F_REQUEST_VERIFY 104 +#define OCSP_F_RESPONSE_VERIFY 105 +#define OCSP_F_S2I_OCSP_NONCE 107 +#define OCSP_F_V2I_OCSP_CRLID 108 + +/* Reason codes. */ +#define OCSP_R_BAD_DATA 108 +#define OCSP_R_BAD_TAG 100 +#define OCSP_R_DIGEST_ERR 101 +#define OCSP_R_FAILED_TO_OPEN 109 +#define OCSP_R_FAILED_TO_READ 110 +#define OCSP_R_FAILED_TO_STAT 111 +#define OCSP_R_MISSING_VALUE 112 +#define OCSP_R_NO_CERTIFICATE 102 +#define OCSP_R_NO_PUBLIC_KEY 103 +#define OCSP_R_NO_RESPONSE_DATA 104 +#define OCSP_R_NO_SIGNATURE 105 +#define OCSP_R_REVOKED_NO_TIME 106 +#define OCSP_R_UNKNOWN_NID 107 +#define OCSP_R_UNSUPPORTED_OPTION 113 +#define OCSP_R_VALUE_ALREADY 114 + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/crypto/ocsp/ocsp_cid.c b/crypto/ocsp/ocsp_cid.c new file mode 100644 index 0000000000..b27531b5e2 --- /dev/null +++ b/crypto/ocsp/ocsp_cid.c @@ -0,0 +1,157 @@ +/* ocsp_cid.c */ +/* Written by Tom Titchener for the OpenSSL + * project. */ + +/* History: + This file was originally part of ocsp.c and was transfered to Richard + Levitte from CertCo by Kathy Weinhold in mid-spring 2000 to be included + in OpenSSL or released as a patch kit. */ + +/* ==================================================================== + * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include +#include +#include +#include +#include + +/* Make sure we work well with older variants of OpenSSL */ +#ifndef OPENSSL_malloc +#define OPENSSL_malloc Malloc +#endif +#ifndef OPENSSL_realloc +#define OPENSSL_realloc Realloc +#endif +#ifndef OPENSSL_free +#define OPENSSL_free Free +#endif + +OCSP_CERTID *OCSP_CERTID_new(void) + { + ASN1_CTX c; + OCSP_CERTID *ret=NULL; + + M_ASN1_New_Malloc(ret, OCSP_CERTID); + M_ASN1_New(ret->hashAlgorithm, X509_ALGOR_new); + M_ASN1_New(ret->issuerNameHash, ASN1_OCTET_STRING_new); + M_ASN1_New(ret->issuerKeyHash, ASN1_OCTET_STRING_new); + M_ASN1_New(ret->serialNumber, ASN1_INTEGER_new); + return(ret); + M_ASN1_New_Error(ASN1_F_OCSP_CERTID_NEW); + } + +void OCSP_CERTID_free(OCSP_CERTID *a) + { + if (a == NULL) return; + X509_ALGOR_free(a->hashAlgorithm); + ASN1_OCTET_STRING_free(a->issuerNameHash); + ASN1_OCTET_STRING_free(a->issuerKeyHash); + ASN1_INTEGER_free(a->serialNumber); + OPENSSL_free((char *)a); + } + +int i2d_OCSP_CERTID(OCSP_CERTID *a, + unsigned char **pp) + { + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len(a->hashAlgorithm, i2d_X509_ALGOR); + M_ASN1_I2D_len(a->issuerNameHash, i2d_ASN1_OCTET_STRING); + M_ASN1_I2D_len(a->issuerKeyHash, i2d_ASN1_OCTET_STRING); + M_ASN1_I2D_len(a->serialNumber, i2d_ASN1_INTEGER); + M_ASN1_I2D_seq_total(); + M_ASN1_I2D_put(a->hashAlgorithm, i2d_X509_ALGOR); + M_ASN1_I2D_put(a->issuerNameHash, i2d_ASN1_OCTET_STRING); + M_ASN1_I2D_put(a->issuerKeyHash, i2d_ASN1_OCTET_STRING); + M_ASN1_I2D_put(a->serialNumber, i2d_ASN1_INTEGER); + M_ASN1_I2D_finish(); + } + +OCSP_CERTID *d2i_OCSP_CERTID(OCSP_CERTID **a, + unsigned char **pp, + long length) + { + M_ASN1_D2I_vars(a,OCSP_CERTID *,OCSP_CERTID_new); + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(ret->hashAlgorithm, d2i_X509_ALGOR); + M_ASN1_D2I_get(ret->issuerNameHash, d2i_ASN1_OCTET_STRING); + M_ASN1_D2I_get(ret->issuerKeyHash, d2i_ASN1_OCTET_STRING); + M_ASN1_D2I_get(ret->serialNumber, d2i_ASN1_INTEGER); + + /* protect against malformed CERTID's */ + if (ASN1_STRING_length(ret->issuerNameHash) == 0 || + ASN1_STRING_length(ret->issuerKeyHash) == 0 || + ASN1_STRING_length(ret->serialNumber) == 0) + goto err; + + M_ASN1_D2I_Finish(a,OCSP_CERTID_free,ASN1_F_D2I_OCSP_CERTID); + } + +int i2a_OCSP_CERTID(BIO *bp, + OCSP_CERTID* a) + { +#ifdef UNDEF + /* XXX this guy isn't implemented. */ + i2a_X509_ALGOR(bp, a->hashAlgorithm); +#else /* instead, just show OID, not param */ + i2a_ASN1_OBJECT(bp, a->hashAlgorithm->algorithm); +#endif + i2a_ASN1_STRING(bp, a->issuerNameHash, V_ASN1_OCTET_STRING); + i2a_ASN1_STRING(bp, a->issuerKeyHash, V_ASN1_OCTET_STRING); + i2a_ASN1_INTEGER(bp, a->serialNumber); + return 4; + } diff --git a/crypto/ocsp/ocsp_err.c b/crypto/ocsp/ocsp_err.c new file mode 100644 index 0000000000..e7e0c90b4e --- /dev/null +++ b/crypto/ocsp/ocsp_err.c @@ -0,0 +1,116 @@ +/* crypto/ocsp/ocsp_err.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file, + * only reason strings will be preserved. + */ + +#include +#include +#include + +/* BEGIN ERROR CODES */ +#ifndef NO_ERR +static ERR_STRING_DATA OCSP_str_functs[]= + { +{ERR_PACK(0,OCSP_F_ASN1_STRING_ENCODE,0), "ASN1_STRING_encode"}, +{ERR_PACK(0,OCSP_F_BASIC_RESPONSE_NEW,0), "BASIC_RESPONSE_NEW"}, +{ERR_PACK(0,OCSP_F_BASIC_RESPONSE_VERIFY,0), "BASIC_RESPONSE_VERIFY"}, +{ERR_PACK(0,OCSP_F_CERT_ID_NEW,0), "CERT_ID_NEW"}, +{ERR_PACK(0,OCSP_F_CERT_STATUS_NEW,0), "CERT_STATUS_NEW"}, +{ERR_PACK(0,OCSP_F_REQUEST_VERIFY,0), "REQUEST_VERIFY"}, +{ERR_PACK(0,OCSP_F_RESPONSE_VERIFY,0), "RESPONSE_VERIFY"}, +{ERR_PACK(0,OCSP_F_S2I_OCSP_NONCE,0), "S2I_OCSP_NONCE"}, +{ERR_PACK(0,OCSP_F_V2I_OCSP_CRLID,0), "V2I_OCSP_CRLID"}, +{0,NULL} + }; + +static ERR_STRING_DATA OCSP_str_reasons[]= + { +{OCSP_R_BAD_DATA ,"bad data"}, +{OCSP_R_BAD_TAG ,"bad tag"}, +{OCSP_R_DIGEST_ERR ,"digest err"}, +{OCSP_R_FAILED_TO_OPEN ,"failed to open"}, +{OCSP_R_FAILED_TO_READ ,"failed to read"}, +{OCSP_R_FAILED_TO_STAT ,"failed to stat"}, +{OCSP_R_MISSING_VALUE ,"missing value"}, +{OCSP_R_NO_CERTIFICATE ,"no certificate"}, +{OCSP_R_NO_PUBLIC_KEY ,"no public key"}, +{OCSP_R_NO_RESPONSE_DATA ,"no response data"}, +{OCSP_R_NO_SIGNATURE ,"no signature"}, +{OCSP_R_REVOKED_NO_TIME ,"revoked no time"}, +{OCSP_R_UNKNOWN_NID ,"unknown nid"}, +{OCSP_R_UNSUPPORTED_OPTION ,"unsupported option"}, +{OCSP_R_VALUE_ALREADY ,"value already"}, +{0,NULL} + }; + +#endif + +void ERR_load_OCSP_strings(void) + { + static int init=1; + + if (init) + { + init=0; +#ifndef NO_ERR + ERR_load_strings(ERR_LIB_OCSP,OCSP_str_functs); + ERR_load_strings(ERR_LIB_OCSP,OCSP_str_reasons); +#endif + + } + } diff --git a/crypto/ocsp/ocsp_ext.c b/crypto/ocsp/ocsp_ext.c new file mode 100644 index 0000000000..b55f572e1a --- /dev/null +++ b/crypto/ocsp/ocsp_ext.c @@ -0,0 +1,347 @@ +/* ocsp_ext.c */ +/* Written by Tom Titchener for the OpenSSL + * project. */ + +/* History: + This file was transfered to Richard Levitte from CertCo by Kathy + Weinhold in mid-spring 2000 to be included in OpenSSL or released + as a patch kit. */ + +/* ==================================================================== + * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include +#include +#include +#include +#include +#include +#include + +/* Make sure we work well with older variants of OpenSSL */ +#ifndef OPENSSL_malloc +#define OPENSSL_malloc Malloc +#endif +#ifndef OPENSSL_realloc +#define OPENSSL_realloc Realloc +#endif +#ifndef OPENSSL_free +#define OPENSSL_free Free +#endif + +/* also CRL Entry Extensions */ + +ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, int (*i2d)(), + char *data, STACK *sk) + { + int i; + unsigned char *p, *b = NULL; + + if (data) + { + if ((i=i2d(data,NULL)) <= 0) goto err; + if (!(b=p=(unsigned char*)OPENSSL_malloc((unsigned int)i))) + goto err; + if (i2d(data, &p) <= 0) goto err; + } + else if (sk) + { + if ((i=i2d_ASN1_SET(sk,NULL,i2d,V_ASN1_SEQUENCE, + V_ASN1_UNIVERSAL,IS_SEQUENCE))<=0) goto err; + if (!(b=p=(unsigned char*)OPENSSL_malloc((unsigned int)i))) + goto err; + if (i2d_ASN1_SET(sk,&p,i2d,V_ASN1_SEQUENCE, + V_ASN1_UNIVERSAL,IS_SEQUENCE)<=0) goto err; + } + else + { + OCSPerr(OCSP_F_ASN1_STRING_ENCODE,OCSP_R_BAD_DATA); + goto err; + } + if (!s && !(s = ASN1_STRING_new())) goto err; + if (!(ASN1_STRING_set(s, b, i))) goto err; + OPENSSL_free(b); + return s; +err: + if (b) OPENSSL_free(b); + return NULL; + } + +X509_EXTENSION *OCSP_nonce_new(void *p, unsigned int len) + { + X509_EXTENSION *x=NULL; + if (!(x = X509_EXTENSION_new())) goto err; + if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_Nonce))) goto err; + if (!(ASN1_OCTET_STRING_set(x->value, p, len))) goto err; + return x; +err: + if (x) X509_EXTENSION_free(x); + return NULL; + } + +X509_EXTENSION *OCSP_crlID_new(char *url, long *n, char *tim) + { + X509_EXTENSION *x = NULL; + OCSP_CRLID *cid = NULL; + + if (!(cid = OCSP_CRLID_new())) goto err; + if (url) + { + if (!(cid->crlUrl = ASN1_IA5STRING_new())) goto err; + if (!(ASN1_STRING_set(cid->crlUrl, url, -1))) goto err; + } + if (n) + { + if (!(cid->crlNum = ASN1_INTEGER_new())) goto err; + if (!(ASN1_INTEGER_set(cid->crlNum, *n))) goto err; + } + if (time) + { + if (!(cid->crlTime = ASN1_GENERALIZEDTIME_new())) goto err; + if (!(ASN1_GENERALIZEDTIME_set_string(cid->crlTime, tim))) + goto err; + } + if (!(x = X509_EXTENSION_new())) goto err; + if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_CrlID))) goto err; + if (!(ASN1_STRING_encode(x->value,i2d_OCSP_CRLID,(char*)cid,NULL))) + goto err; + OCSP_CRLID_free(cid); + return x; +err: + if (x) X509_EXTENSION_free(x); + if (cid) OCSP_CRLID_free(cid); + return NULL; + } + +/* AcceptableResponses ::= SEQUENCE OF OBJECT IDENTIFIER */ +X509_EXTENSION *OCSP_accept_responses_new(char **oids) + { + int nid; + STACK *sk = NULL; + ASN1_OBJECT *o = NULL; + X509_EXTENSION *x = NULL; + if (!(sk = sk_new(NULL))) goto err; + while (oids && *oids) + { + if ((nid=OBJ_txt2nid(*oids))!=NID_undef&&(o=OBJ_nid2obj(nid))) + sk_push(sk, (char*) o); + oids++; + } + if (!(x = X509_EXTENSION_new())) goto err; + if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_acceptableResponses))) + goto err; + if (!(ASN1_STRING_encode(x->value,i2d_ASN1_OBJECT,NULL,sk))) + goto err; + sk_pop_free(sk, ASN1_OBJECT_free); + return x; +err: + if (x) X509_EXTENSION_free(x); + if (sk) sk_pop_free(sk, ASN1_OBJECT_free); + return NULL; + } + +/* ArchiveCutoff ::= GeneralizedTime */ +X509_EXTENSION *OCSP_archive_cutoff_new(char* tim) + { + X509_EXTENSION *x=NULL; + ASN1_GENERALIZEDTIME *gt = NULL; + + if (!(gt = ASN1_GENERALIZEDTIME_new())) goto err; + if (!(ASN1_GENERALIZEDTIME_set_string(gt, tim))) goto err; + if (!(x = X509_EXTENSION_new())) goto err; + if (!(x->object=OBJ_nid2obj(NID_id_pkix_OCSP_archiveCutoff)))goto err; + if (!(ASN1_STRING_encode(x->value,i2d_ASN1_GENERALIZEDTIME, + (char*)gt,NULL))) goto err; + ASN1_GENERALIZEDTIME_free(gt); + return x; +err: + if (gt) ASN1_GENERALIZEDTIME_free(gt); + if (x) X509_EXTENSION_free(x); + return NULL; + } + +/* per ACCESS_DESCRIPTION parameter are oids, of which there are currently + * two--NID_ad_ocsp, NID_id_ad_caIssuers--and GeneralName value. This + * met