#include <stdio.h>
#include <cryptlib.h>
#include <openssl/objects.h>
-#include <openssl/asn1_mac.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <openssl/x509v3.h>
OCSP_CERTSTATUS *cs = NULL;
if (!(cs = OCSP_CERTSTATUS_new())) goto err;
- if ((cs->tag = status) == V_OCSP_CERTSTATUS_REVOKED)
+ if ((cs->type = status) == V_OCSP_CERTSTATUS_REVOKED)
{
if (!time)
{
OCSPerr(OCSP_F_CERT_STATUS_NEW,OCSP_R_REVOKED_NO_TIME);
goto err;
}
- if (!(cs->revoked = ri = OCSP_REVOKEDINFO_new())) goto err;
+ if (!(cs->value.revoked = ri = OCSP_REVOKEDINFO_new())) goto err;
if (!ASN1_GENERALIZEDTIME_set_string(ri->revocationTime,tim))
goto err;
if (reason != OCSP_REVOKED_STATUS_NOSTATUS)
return 0;
}
-OCSP_BASICRESP *OCSP_basic_response_new(int tag,
+OCSP_BASICRESP *OCSP_basic_response_new(int type,
X509* cert,
STACK_OF(X509_EXTENSION) *extensions)
{
if (!(rsp = OCSP_BASICRESP_new())) goto err;
rid = rsp->tbsResponseData->responderId;
- switch (rid->tag = tag)
+ switch (rid->type = type)
{
case V_OCSP_RESPID_NAME:
/* cert is user cert */
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_REQUEST_print(bp, o)
-BIO *bp;
-OCSP_REQUEST* o;
- {
- int i,j,n;
- long l;
- char *s;
- OCSP_CERTID* cid = NULL;
- OCSP_ONEREQ *one = NULL;
- OCSP_REQINFO *inf = o->tbsRequest;
- OCSP_SIGNATURE *sig = o->optionalSignature;
-
- 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 (inf->requestorName != NULL)
- {
- if (BIO_write(bp,"\n Requestor Name: ",21) <= 0)
- goto err;
- i2a_GENERAL_NAME(bp, inf->requestorName);
- }
- if (BIO_write(bp,"\n Requestor List:\n",21) <= 0) goto err;
- for (i = 0; i < sk_OCSP_ONEREQ_num(inf->requestList); i++)
- {
- if (! sk_OCSP_ONEREQ_value(inf->requestList, i)) continue;
- one = sk_OCSP_ONEREQ_value(inf->requestList, i);
- cid = one->reqCert;
- j=OBJ_obj2nid(cid->hashAlgorithm->algorithm);
- if (BIO_printf(bp,"%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;
- if (!BIO_write(bp,"\n",1)) goto err;
- if (!OCSP_extensions_print(bp, one->singleRequestExtensions,
- "Request Single Extensions"))
- goto err;
- }
- if (!OCSP_extensions_print(bp, inf->requestExtensions,
- "Request Extensions"))
- goto err;
- if (sig)
- {
- i=OBJ_obj2nid(sig->signatureAlgorithm->algorithm);
- if (BIO_printf(bp,"OCSP Request Signature Algorithm: %s",
- (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0)
- goto err;
- n=sig->signature->length;
- s=(char *)sig->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 (sig->certs)
- {
- 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));
- }
- }
- return 1;
-err:
- return 0;
- }
-
-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->tag), cst->tag) <= 0)
- goto err;
- if (cst->tag == V_OCSP_CERTSTATUS_REVOKED)
- {
- rev = cst->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)
{