diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2000-12-17 14:09:43 +0000 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2000-12-17 14:09:43 +0000 |
commit | 1f47ec53a2c12c1466cd502288fe17559ba8c6a1 (patch) | |
tree | 8235b0adae42b9d3728a09c27442e26b561294de | |
parent | 959f67d6a4908639adbe52ca28bc365bdff8c2b7 (diff) |
Redo OCSP response printing. Remove duplicate or
obsolete code. Delete some redundant files.
-rw-r--r-- | crypto/ocsp/Makefile.ssl | 11 | ||||
-rw-r--r-- | crypto/ocsp/ocsp.h | 38 | ||||
-rw-r--r-- | crypto/ocsp/ocsp_cid.c | 82 | ||||
-rw-r--r-- | crypto/ocsp/ocsp_ext.c | 96 | ||||
-rw-r--r-- | crypto/ocsp/ocsp_lib.c | 273 | ||||
-rw-r--r-- | crypto/ocsp/ocsp_prn.c | 175 | ||||
-rw-r--r-- | crypto/ocsp/ocsp_req.c | 124 | ||||
-rw-r--r-- | crypto/ocsp/ocsp_res.c | 232 | ||||
-rw-r--r-- | crypto/ocsp/ocsp_sig.c | 89 |
9 files changed, 178 insertions, 942 deletions
diff --git a/crypto/ocsp/Makefile.ssl b/crypto/ocsp/Makefile.ssl index 9387f34b7d..6697a15333 100644 --- a/crypto/ocsp/Makefile.ssl +++ b/crypto/ocsp/Makefile.ssl @@ -22,12 +22,11 @@ TEST= APPS= LIB=$(TOP)/libcrypto.a -LIBSRC= ocsp_asn.c ocsp_ext.c ocsp_res.c ocsp_sig.c ocsp_cid.c \ - ocsp_lib.c ocsp_prn.c ocsp_err.c -#ocsp_v3.c -LIBOBJ= ocsp_asn.o ocsp_ext.o ocsp_res.o ocsp_sig.o ocsp_cid.o \ - ocsp_lib.o ocsp_prn.o ocsp_err.o -#ocsp_v3.o +LIBSRC= ocsp_asn.c ocsp_ext.c \ + ocsp_lib.c ocsp_prn.c ocsp_err.c + +LIBOBJ= ocsp_asn.o ocsp_ext.o \ + ocsp_lib.o ocsp_prn.o ocsp_err.o SRC= $(LIBSRC) diff --git a/crypto/ocsp/ocsp.h b/crypto/ocsp/ocsp.h index cd591313ba..e6022bf83c 100644 --- a/crypto/ocsp/ocsp.h +++ b/crypto/ocsp/ocsp.h @@ -445,104 +445,72 @@ X509_EXTENSION *OCSP_archive_cutoff_new(char* tim); X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME* issuer, char **urls); DECLARE_ASN1_FUNCTIONS(OCSP_SINGLERESP) -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); +int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE* a, unsigned long flags); 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, unsigned long flags); 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); -DECLARE_ASN1_FUNCTIONS(OCSP_REQINFO) -int i2a_OCSP_REQINFO(BIO *bp, OCSP_REQINFO* a); +DECLARE_ASN1_FUNCTIONS(OCSP_REQINFO) DECLARE_ASN1_FUNCTIONS(OCSP_CRLID) -int i2a_OCSP_CRLID(BIO *bp, OCSP_CRLID* a); -int OCSP_CRLID_print(BIO *bp, OCSP_CRLID *a, int ind); - DECLARE_ASN1_FUNCTIONS(OCSP_SERVICELOC) -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); -#if 0 /* Not yet implemented */ -X509_EXTENSION *OCSP_nochain_new(void); -#endif - -char* ocspResponseStatus2string(long s); -char* ocspCertStatus2string(long s); -char * cRLReason2string(long s); - -#if 0 /* Not yet implemented */ -void OCSP_add_standard_extension(void); -#endif - /* 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. diff --git a/crypto/ocsp/ocsp_cid.c b/crypto/ocsp/ocsp_cid.c deleted file mode 100644 index ba25229b8f..0000000000 --- a/crypto/ocsp/ocsp_cid.c +++ /dev/null @@ -1,82 +0,0 @@ -/* ocsp_cid.c */ -/* Written by Tom Titchener <Tom_Titchener@groove.net> 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 <openssl/bio.h> -#include <openssl/err.h> -#include <openssl/ocsp.h> -#include <openssl/x509.h> - -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_ext.c b/crypto/ocsp/ocsp_ext.c index aac4edb1e5..20a58a3c90 100644 --- a/crypto/ocsp/ocsp_ext.c +++ b/crypto/ocsp/ocsp_ext.c @@ -251,99 +251,3 @@ err: return NULL; } -int OCSP_extensions_print(BIO *bp, - STACK_OF(X509_EXTENSION) *sk, - char *title) - { - int i; - if (!sk) return 1; - if (BIO_printf(bp, "%s:\n", title) <= 0) return 0; - for (i=0; i<sk_X509_EXTENSION_num(sk); i++) - OCSP_extension_print(bp, sk_X509_EXTENSION_value(sk,i), 4); - return sk_X509_EXTENSION_num(sk); - } - -int OCSP_extension_print(BIO *bp, - X509_EXTENSION *x, - int ind) - { - int i, j; - STACK_OF(ASN1_OBJECT) *sk = NULL; - unsigned char *p; - OCSP_CRLID *crlid = NULL; - OCSP_SERVICELOC *sloc = NULL; - ASN1_GENERALIZEDTIME *gt = NULL; - - if (!x) return 1; - switch (OBJ_obj2nid(x->object)) - { - case NID_id_pkix_OCSP_Nonce: - if (BIO_printf(bp, "%*snonce: ", ind, "") <= 0) - goto err; - if (M_ASN1_OCTET_STRING_print(bp, x->value) <= 0) - goto err; - if (BIO_write(bp, "\n", 1) <= 0) goto err; - break; - case NID_id_pkix_OCSP_CrlID: - if (BIO_printf(bp, "%*scrlId:\n", ind, "") <= 0) - goto err; - p = x->value->data; - if (!(d2i_OCSP_CRLID(&crlid, &p, x->value->length))) - goto err; - if (!OCSP_CRLID_print(bp, crlid, (2*ind))) goto err; - OCSP_CRLID_free(crlid); - break; - case NID_id_pkix_OCSP_acceptableResponses: - if (BIO_printf(bp, - "%*sacceptable responses: ", - ind, "") <= 0) - goto err; - p = x->value->data; - if (!(d2i_ASN1_SET_OF_ASN1_OBJECT(&sk, &p, x->value->length, - d2i_ASN1_OBJECT, - ASN1_OBJECT_free, - V_ASN1_SEQUENCE, - V_ASN1_UNIVERSAL))) - goto err; - for (i = 0; i < sk_ASN1_OBJECT_num(sk); i++) - { - j=OBJ_obj2nid(sk_ASN1_OBJECT_value(sk,i)); - if (BIO_printf(bp," %s ", - (j == NID_undef)?"UNKNOWN": - OBJ_nid2ln(j)) <= 0) - goto err; - } - if (BIO_write(bp, "\n", 1) <= 0) goto err; - sk_ASN1_OBJECT_pop_free(sk, ASN1_OBJECT_free); - break; - case NID_id_pkix_OCSP_archiveCutoff: - if (BIO_printf(bp, "%*sarchive cutoff: ", ind, "")<=0) - goto err; - p = x->value->data; - if (!d2i_ASN1_GENERALIZEDTIME(>, &p, - x->value->length)) - goto err; - if (!ASN1_GENERALIZEDTIME_print(bp, gt)) goto err; - if (BIO_write(bp, "\n", 1) <= 0) goto err; - ASN1_GENERALIZEDTIME_free(gt); - break; - case NID_id_pkix_OCSP_serviceLocator: - if (BIO_printf(bp, "%*sservice locator:\n", ind, "") <= 0) - goto err; - p = x->value->data; - if (!d2i_OCSP_SERVICELOC(&sloc, &p, - x->value->length)) - goto err; - if (!OCSP_SERVICELOC_print(bp,sloc,(2*ind))) goto err; - OCSP_SERVICELOC_free(sloc); - break; - case NID_undef: - default: - if (BIO_printf(bp,"%*sunrecognized oid: ",ind,"") <= 0) - goto err; - break; - } - return 1; -err: - return 0; - } diff --git a/crypto/ocsp/ocsp_lib.c b/crypto/ocsp/ocsp_lib.c index 6f810d584d..be1ff96112 100644 --- a/crypto/ocsp/ocsp_lib.c +++ b/crypto/ocsp/ocsp_lib.c @@ -367,279 +367,6 @@ err: return NULL; } -char* ocspResponseStatus2string(long s) - { - static struct { long t; char *m; } ts[6]= { - { OCSP_RESPONSE_STATUS_SUCCESSFULL, "successful" }, - { OCSP_RESPONSE_STATUS_MALFORMEDREQUEST, "malformedrequest" }, - { OCSP_RESPONSE_STATUS_INTERNALERROR, "internalerror" }, - { OCSP_RESPONSE_STATUS_TRYLATER, "trylater" }, - { OCSP_RESPONSE_STATUS_SIGREQUIRED, "sigrequired" }, - { OCSP_RESPONSE_STATUS_UNAUTHORIZED, "unauthorized" } }, *p; - for (p=ts; p < &ts[sizeof ts/sizeof ts[0]]; p++) - if (p->t == s) - return p->m; - return "(UNKNOWN)"; - } - -char* ocspCertStatus2string(long s) - { - static struct { long t; char *m; } ts[3]= { - { V_OCSP_CERTSTATUS_GOOD, "good" }, - { V_OCSP_CERTSTATUS_REVOKED, "revoked" }, - { V_OCSP_CERTSTATUS_UNKNOWN, "unknown" } }, *p; - for (p=ts; p < &ts[sizeof ts/sizeof ts[0]]; p++) - if (p->t == s) - return p->m; - return "(UNKNOWN)"; - } - -char * cRLReason2string(long s) - { - static struct { long t; char *m; } ts[8]= { - { OCSP_REVOKED_STATUS_UNSPECIFIED, "unspecified" }, - { OCSP_REVOKED_STATUS_KEYCOMPROMISE, "keyCompromise" }, - { OCSP_REVOKED_STATUS_CACOMPROMISE, "cACompromise" }, - { OCSP_REVOKED_STATUS_AFFILIATIONCHANGED, "affiliationChanged" }, - { OCSP_REVOKED_STATUS_SUPERSEDED, "superseded" }, - { OCSP_REVOKED_STATUS_CESSATIONOFOPERATION, "cessationOfOperation" }, - { OCSP_REVOKED_STATUS_CERTIFICATEHOLD, "certificateHold" }, - { OCSP_REVOKED_STATUS_REMOVEFROMCRL, "removeFromCRL" } }, *p; - for (p=ts; p < &ts[sizeof ts/sizeof ts[0]]; p++) - if (p->t == s) - return p->m; - return "(UNKNOWN)"; - } - -static int i2a_GENERAL_NAME(bp,n) -BIO *bp; -GENERAL_NAME *n; - { - int j; - char *p; - - if (n == NULL) return(0); - - switch (n->type) - { - - case GEN_DIRNAME: - X509_NAME_print(bp,n->d.dirn,16); - break; - - case GEN_EMAIL: - case GEN_DNS: - case GEN_URI: - case GEN_IPADD: - p=(char *)n->d.ip->data; - for (j=n->d.ip->length;j>0;j--) - { - if ((*p >= ' ') && (*p <= '~')) - BIO_printf(bp,"%c",*p); - else if (*p & 0x80) - BIO_printf(bp,"\\0x%02X",*p); - else if ((unsigned char)*p == 0xf7) - BIO_printf(bp,"^?"); - else BIO_printf(bp,"^%c",*p+'@'); - p++; - } - break; - - case GEN_RID: - i2a_ASN1_OBJECT(bp, n->d.rid); - break; - - /* XXX these are legit, need to support at some time... */ - case GEN_OTHERNAME: - case GEN_X400: - case GEN_EDIPARTY: - default: - return 0; - } - - return 1; - } - -int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE* o) - { - int i, j, n; - long l; - char *s; - unsigned char *p; - OCSP_CERTID *cid = NULL; - OCSP_BASICRESP *br = NULL; - OCSP_RESPDATA *rd = NULL; - OCSP_CERTSTATUS *cst = NULL; - OCSP_REVOKEDINFO *rev = NULL; - OCSP_SINGLERESP *single = NULL; - OCSP_RESPBYTES *rb = o->responseBytes; - - l=ASN1_ENUMERATED_get(o->responseStatus); - if (BIO_printf(bp,"OCSP Response Status: %s (0x%x)\n", - ocspResponseStatus2string(l), l) <= 0) goto err; - if (rb == NULL) return 1; - i=OBJ_obj2nid(rb->responseType); - if (BIO_printf(bp,"OCSP Response Bytes Response Type: %s", - (i == NID_undef)?"UNKNOWN":OBJ_nid2sn(i)) <= 0) - goto err; - if (i != NID_id_pkix_OCSP_basic) - { - BIO_printf(bp," (unknown response type)\n"); - return 1; - } - p = ASN1_STRING_data(rb->response); - i = ASN1_STRING_length(rb->response); - if (!(d2i_OCSP_BASICRESP(&br, &p, i))) goto err; - rd = br->tbsResponseData; - l=ASN1_INTEGER_get(rd->version); - if (BIO_printf(bp,"\nBasic Response Data Version: %lu (0x%lx)\n", - l+1,l) <= 0) goto err; - if (BIO_printf(bp,"Basic Response Data Responder Id: ") <= 0) goto err; - i2a_OCSP_RESPID(bp, rd->responderId); - if (BIO_printf(bp,"\nBasic Response Data Produced At: ")<=0) goto err; - if (!ASN1_GENERALIZEDTIME_print(bp, rd->producedAt)) goto err; - if (BIO_printf(bp,"\nBasic Response Data Responses:\n") <= 0) goto err; - for (i = 0; i < sk_OCSP_SINGLERESP_num(rd->responses); i++) - { - if (! sk_OCSP_SINGLERESP_value(rd->responses, i)) continue; - single = sk_OCSP_SINGLERESP_value(rd->responses, i); - cid = single->certId; - j=OBJ_obj2nid(cid->hashAlgorithm->algorithm); - if (BIO_printf(bp," Cert Id:") <= 0) goto err; - if (BIO_printf(bp,"\n%8sHash Algorithm: %s","", - (j == NID_undef)?"UNKNOWN":OBJ_nid2ln(j)) <= 0) - goto err; - if (BIO_write(bp,"\n Issuer Name Hash: ",27) <= 0) - goto err; - i2a_ASN1_STRING(bp, cid->issuerNameHash, V_ASN1_OCTET_STRING); - if (BIO_write(bp,"\n Issuer Key Hash: ",26) <= 0) - goto err; - i2a_ASN1_STRING(bp, cid->issuerKeyHash, V_ASN1_OCTET_STRING); - if (BIO_write(bp,"\n Serial Number: ",24) <= 0) - goto err; - if (!i2a_ASN1_INTEGER(bp, cid->serialNumber)) - goto err; - cst = single->certStatus; - if (BIO_printf(bp,"\n Cert Status: %s (0x%x)", - ocspCertStatus2string(cst->type), cst->type) <= 0) - goto err; - if (cst->type == V_OCSP_CERTSTATUS_REVOKED) - { - rev = cst->value.revoked; - if (BIO_printf(bp, "\n Revocation Time: ") <= 0) - goto err; - if (!ASN1_GENERALIZEDTIME_print(bp, - rev->revocationTime)) - goto err; - if (rev->revocationReason) - { - l=ASN1_ENUMERATED_get(rev->revocationReason); - if (BIO_printf(bp, - "\n Revocation Reason: %s (0x%x)", - cRLReason2string(l), l) <= 0) - goto err; - } - } - if (BIO_printf(bp,"\n This Update: ") <= 0) goto err; - if (!ASN1_GENERALIZEDTIME_print(bp, single->thisUpdate)) - goto err; - if (single->nextUpdate) - { - if (BIO_printf(bp,"\n Next Update: ") <= 0)goto err; - if (!ASN1_GENERALIZEDTIME_print(bp,single->nextUpdate)) - goto err; - } - if (!BIO_write(bp,"\n",1)) goto err; - if (!OCSP_extensions_print(bp, single->singleExtensions, - "Basic Response Single Extensions")) - goto err; - } - if (!OCSP_extensions_print(bp, rd->responseExtensions, - "Basic Response Extensions")) goto err; - i=OBJ_obj2nid(br->signatureAlgorithm->algorithm); - if (BIO_printf(bp,"Basic Response Signature Algorithm: %s", - (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0) - goto err; - n=br->signature->length; - s=(char *)br->signature->data; - for (i=0; i<n; i++) - { - if ((i%18) == 0) - if (BIO_write(bp,"\n ",9) <= 0) goto err; - if (BIO_printf(bp,"%02x%s",(unsigned char)s[i], - ((i+1) == n)?"":":") <= 0) goto err; - } - if (BIO_write(bp,"\n",1) != 1) goto err; - if (br->certs) - { - for (i=0; i<sk_X509_num(br->certs); i++) - if (sk_X509_value(br->certs,i) != NULL) { - X509_print(bp, sk_X509_value(br->certs,i)); - PEM_write_bio_X509(bp,sk_X509_value(br->certs,i)); - } - } - return 1; -err: - return 0; - } - -int OCSP_CRLID_print(BIO *bp, OCSP_CRLID *a, int ind) - { - if (a->crlUrl) - { - if (!BIO_printf(bp, "%*scrlUrl: ", ind, "")) goto err; - if (!ASN1_STRING_print(bp, (ASN1_STRING*)a->crlUrl)) goto err; - if (!BIO_write(bp, "\n", 1)) goto err; - } - if (a->crlNum) - { - if (!BIO_printf(bp, "%*scrlNum: ", ind, "")) goto err; - if (!i2a_ASN1_INTEGER(bp, a->crlNum)) goto err; - if (!BIO_write(bp, "\n", 1)) goto err; - } - if (a->crlTime) - { - if (!BIO_printf(bp, "%*scrlTime: ", ind, "")) goto err; - if (!ASN1_GENERALIZEDTIME_print(bp, a->crlTime)) goto err; - if (!BIO_write(bp, "\n", 1)) goto err; - } - return 1; -err: - return 0; - } - -int OCSP_SERVICELOC_print(BIO *bp, OCSP_SERVICELOC* a, int ind) - { - int i, j; - ACCESS_DESCRIPTION *ad; - - if (BIO_printf(bp, "%*sissuer: ", ind, "") <= 0) goto err; - if (X509_NAME_print(bp, a->issuer, 16) <= 0) goto err; - if (BIO_printf(bp, "\n", 1) <= 0) goto err; - - /* Service locator is optional */ - if (a->locator != NULL) { - if (BIO_printf(bp, "%*slocator:\n", ind, "") <= 0) goto err; - for (i = 0; i < sk_ACCESS_DESCRIPTION_num(a->locator); i++) - { - ad = sk_ACCESS_DESCRIPTION_value(a->locator,i); - if (BIO_printf(bp, "%*smethod: ", (2*ind), "") <= 0) - goto err; - j=OBJ_obj2nid(ad->method); - if (BIO_printf(bp,"%s", (j == NID_undef)?"UNKNOWN": - OBJ_nid2ln(j)) <= 0) - goto err; - if (BIO_printf(bp, "\n%*sname: ", (2*ind), "") <= 0) - goto err; - if (i2a_GENERAL_NAME(bp, ad->location) <= 0) goto err; - if (BIO_write(bp, "\n", 1) <= 0) goto err; - } - } - return 1; -err: - return 0; - } - /* XXX assumes certs in signature are sorted root to leaf XXX */ int OCSP_request_verify(OCSP_REQUEST *req, EVP_PKEY *pkey) { diff --git a/crypto/ocsp/ocsp_prn.c b/crypto/ocsp/ocsp_prn.c index 436f23e9e3..649a9cec91 100644 --- a/crypto/ocsp/ocsp_prn.c +++ b/crypto/ocsp/ocsp_prn.c @@ -1,4 +1,4 @@ -/* ocsp_cid.c */ +/* ocsp_prn.c */ /* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL * project. */ @@ -64,9 +64,9 @@ #include <openssl/bio.h> #include <openssl/err.h> #include <openssl/ocsp.h> -#include <openssl/x509.h> +#include <openssl/pem.h> -int OCSP_CERTID_print(BIO *bp, OCSP_CERTID* a, int indent) +static int ocsp_certid_print(BIO *bp, OCSP_CERTID* a, int indent) { BIO_printf(bp, "%*sCertificate ID:\n", indent, ""); indent += 2; @@ -82,6 +82,56 @@ int OCSP_CERTID_print(BIO *bp, OCSP_CERTID* a, int indent) return 1; } +typedef struct + { + long t; + char *m; + } OCSP_TBLSTR; + +static char *table2string(long s, OCSP_TBLSTR *ts, int len) +{ + OCSP_TBLSTR *p; + for (p=ts; p < ts + len; p++) + if (p->t == s) + return p->m; + return "(UNKNOWN)"; +} + +static char* ocspResponseStatus2string(long s) + { + static OCSP_TBLSTR rstat_tbl[] = { + { OCSP_RESPONSE_STATUS_SUCCESSFULL, "successful" }, + { OCSP_RESPONSE_STATUS_MALFORMEDREQUEST, "malformedrequest" }, + { OCSP_RESPONSE_STATUS_INTERNALERROR, "internalerror" }, + { OCSP_RESPONSE_STATUS_TRYLATER, "trylater" }, + { OCSP_RESPONSE_STATUS_SIGREQUIRED, "sigrequired" }, + { OCSP_RESPONSE_STATUS_UNAUTHORIZED, "unauthorized" } }; + return table2string(s, rstat_tbl, 6); + } + +static char* ocspCertStatus2string(long s) + { + static OCSP_TBLSTR cstat_tbl[] = { + { V_OCSP_CERTSTATUS_GOOD, "good" }, + { V_OCSP_CERTSTATUS_REVOKED, "revoked" }, + { V_OCSP_CERTSTATUS_UNKNOWN, "unknown" } }; + return table2string(s, cstat_tbl, 3); + } + +static char * cRLReason2string(long s) + { + OCSP_TBLSTR reason_tbl[] = { + { OCSP_REVOKED_STATUS_UNSPECIFIED, "unspecified" }, + { OCSP_REVOKED_STATUS_KEYCOMPROMISE, "keyCompromise" }, + { OCSP_REVOKED_STATUS_CACOMPROMISE, "cACompromise" }, + { OCSP_REVOKED_STATUS_AFFILIATIONCHANGED, "affiliationChanged" }, + { OCSP_REVOKED_STATUS_SUPERSEDED, "superseded" }, + { OCSP_REVOKED_STATUS_CESSATIONOFOPERATION, "cessationOfOperation" }, + { OCSP_REVOKED_STATUS_CERTIFICATEHOLD, "certificateHold" }, + { OCSP_REVOKED_STATUS_REMOVEFROMCRL, "removeFromCRL" } }; + return table2string(s, reason_tbl, 8); + } + int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST* o, unsigned long flags) { int i; @@ -93,7 +143,7 @@ int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST* o, unsigned long flags) if (BIO_write(bp,"OCSP Request Data:\n",19) <= 0) goto err; l=ASN1_INTEGER_get(inf->version); - if (BIO_printf(bp,"%4sVersion: %lu (0x%lx)","",l+1,l) <= 0) goto err; + if (BIO_printf(bp," Version: %lu (0x%lx)",l+1,l) <= 0) goto err; if (inf->requestorName != NULL) { if (BIO_write(bp,"\n Requestor Name: ",21) <= 0) @@ -106,7 +156,7 @@ int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST* o, unsigned long flags) if (!sk_OCSP_ONEREQ_value(inf->requestList, i)) continue; one = sk_OCSP_ONEREQ_value(inf->requestList, i); cid = one->reqCert; - OCSP_CERTID_print(bp, cid, 8); + ocsp_certid_print(bp, cid, 8); if (!X509V3_extensions_print(bp, "OCSP Request Single Extensions", one->singleRequestExtensions, flags, 4)) @@ -119,6 +169,121 @@ int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST* o, unsigned long flags) { X509_signature_print(bp, sig->signatureAlgorithm, sig->signature); } + + for (i=0; i<sk_X509_num(sig->certs); i++) + if (sk_X509_value(sig->certs,i) != NULL) { + X509_print(bp, sk_X509_value(sig->certs,i)); + PEM_write_bio_X509(bp,sk_X509_value(sig->certs,i)); + } + return 1; +err: + return 0; + } + +int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE* o, unsigned long flags) + { + int i; + long l; + unsigned char *p; + OCSP_CERTID *cid = NULL; + OCSP_BASICRESP *br = NULL; + OCSP_RESPID *rid = NULL; + OCSP_RESPDATA *rd = NULL; + OCSP_CERTSTATUS *cst = NULL; + OCSP_REVOKEDINFO *rev = NULL; + OCSP_SINGLERESP *single = NULL; + OCSP_RESPBYTES *rb = o->responseBytes; + + if (BIO_puts(bp,"OCSP Response Data:\n") <= 0) goto err; + l=ASN1_ENUMERATED_get(o->responseStatus); + if (BIO_printf(bp," OCSP Response Status: %s (0x%x)\n", + ocspResponseStatus2string(l), l) <= 0) goto err; + if (rb == NULL) return 1; + if (BIO_puts(bp," Response Type: ") <= 0) + goto err; + if(i2a_ASN1_OBJECT(bp, rb->responseType) <= 0) + goto err; + if (OBJ_obj2nid(rb->responseType) != NID_id_pkix_OCSP_basic) + { + BIO_puts(bp," (unknown response type)\n"); + return 1; + } + p = ASN1_STRING_data(rb->response); + i = ASN1_STRING_length(rb->response); + if (!(d2i_OCSP_BASICRESP(&br, &p, i))) goto err; + rd = br->tbsResponseData; + l=ASN1_INTEGER_get(rd->version); + if (BIO_printf(bp,"\n Version: %lu (0x%lx)\n", + l+1,l) <= 0) goto err; + if (BIO_puts(bp," Responder Id: ") <= 0) goto err; + + rid = rd->responderId; + switch (rid->type) + { + case V_OCSP_RESPID_NAME: + X509_NAME_print_ex(bp, rid->value.byName, 0, XN_FLAG_ONELINE); + break; + case V_OCSP_RESPID_KEY: + i2a_ASN1_STRING(bp, rid->value.byKey, V_ASN1_OCTET_STRING); + break; + } + + if (BIO_printf(bp,"\n Produced At: ")<=0) goto err; + if (!ASN1_GENERALIZEDTIME_print(bp, rd->producedAt)) goto err; + if (BIO_printf(bp,"\n Responses:\n") <= 0) goto err; + for (i = 0; i < sk_OCSP_SINGLERESP_num(rd->responses); i++) + { + if (! sk_OCSP_SINGLERESP_value(rd->responses, i)) continue; + single = sk_OCSP_SINGLERESP_value(rd->responses, i); + cid = single->certId; + if(ocsp_certid_print(bp, cid, 4) <= 0) goto err; + cst = single->certStatus; + if (BIO_printf(bp,"\n Cert Status: %s", + ocspCertStatus2string(cst->type)) <= 0) + goto err; + if (cst->type == V_OCSP_CERTSTATUS_REVOKED) + { + rev = cst->value.revoked; + if (BIO_printf(bp, "\n Revocation Time: ") <= 0) + goto err; + if (!ASN1_GENERALIZEDTIME_print(bp, + rev->revocationTime)) + goto err; + if (rev->revocationReason) + { + l=ASN1_ENUMERATED_get(rev->revocationReason); + if (BIO_printf(bp, + "\n Revocation Reason: %s (0x%x)", + cRLReason2string(l), l) <= 0) + goto err; + } + } + if (BIO_printf(bp,"\n This Update: ") <= 0) goto err; + if (!ASN1_GENERALIZEDTIME_print(bp, single->thisUpdate)) + goto err; + if (single->nextUpdate) + { + if (BIO_printf(bp,"\n Next Update: ") <= 0)goto err; + if (!ASN1_GENERALIZEDTIME_print(bp,single->nextUpdate)) + goto err; + } + if (!BIO_write(bp,"\n",1)) goto err; + if (!X509V3_extensions_print(bp, + "OCSP Basic Response Single Extensions", + single->singleExtensions, flags, 4)) + goto err; + } + if (!X509V3_extensions_print(bp, "OCSP Basic Response Extensions", + rd->responseExtensions, flags, 4)) + if(X509_signature_print(bp, br->signatureAlgorithm, br->signature) <= 0) + goto err; + + for (i=0; i<sk_X509_num(br->certs); i++) + if (sk_X509_value(br->certs,i) != NULL) { + X509_print(bp, sk_X509_value(br->certs,i)); + PEM_write_bio_X509(bp,sk_X509_value(br->certs,i)); + } + return 1; err: return 0; diff --git a/crypto/ocsp/ocsp_req.c b/crypto/ocsp/ocsp_req.c deleted file mode 100644 index eb3a09e31b..0000000000 --- a/crypto/ocsp/ocsp_req.c +++ /dev/null @@ -1,124 +0,0 @@ -/* ocsp_req.c */ -/* Written by Tom Titchener <Tom_Titchener@groove.net> 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 <openssl/bio.h> -#include <openssl/asn1.h> -#include <openssl/err.h> -#include <openssl/ocsp.h> -#include <openssl/x509v3.h> - -int i2a_OCSP_REQINFO(BIO *bp, - OCSP_REQINFO* a) - { - int i, j=1; - if (a->version == NULL) BIO_puts(bp, "0"); - else i2a_ASN1_INTEGER(bp, a->version); - if (a->requestorName != NULL) - { - j++; -#ifdef UNDEF - i2a_GENERAL_NAME(bp, a->requestorName); /* does not exist */ -#endif - } - if (a->requestList != NULL) - { - for (i=0; i<sk_OCSP_ONEREQ_num(a->requestList); i++) - if (sk_OCSP_ONEREQ_value(a->requestList,i) != NULL) - i2a_OCSP_ONEREQ(bp, - sk_OCSP_ONEREQ_value(a->requestList,i)); - j+=sk_OCSP_ONEREQ_num(a->requestList); - } - j+=OCSP_extensions_print(bp, a->reque |