2 /* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
6 This file was transfered to Richard Levitte from CertCo by Kathy
7 Weinhold in mid-spring 2000 to be included in OpenSSL or released
10 /* ====================================================================
11 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
25 * 3. All advertising materials mentioning features or use of this
26 * software must display the following acknowledgment:
27 * "This product includes software developed by the OpenSSL Project
28 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
30 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
31 * endorse or promote products derived from this software without
32 * prior written permission. For written permission, please contact
33 * openssl-core@openssl.org.
35 * 5. Products derived from this software may not be called "OpenSSL"
36 * nor may "OpenSSL" appear in their names without prior written
37 * permission of the OpenSSL Project.
39 * 6. Redistributions of any form whatsoever must retain the following
41 * "This product includes software developed by the OpenSSL Project
42 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
44 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
45 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
48 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55 * OF THE POSSIBILITY OF SUCH DAMAGE.
56 * ====================================================================
58 * This product includes cryptographic software written by Eric Young
59 * (eay@cryptsoft.com). This product includes software written by Tim
60 * Hudson (tjh@cryptsoft.com).
66 #include <openssl/objects.h>
67 #include <openssl/x509.h>
68 #include <openssl/pem.h>
69 #include <openssl/x509v3.h>
70 #include <openssl/safestack.h>
71 #include <openssl/ocsp.h>
73 static STACK_OF(X509_EXTENSION) *ext_dup(STACK_OF(X509_EXTENSION) *fr)
76 STACK_OF(X509_EXTENSION) *to = NULL;
78 if (!(to = sk_X509_EXTENSION_dup(fr)))
80 for (i = 0; i < sk_X509_EXTENSION_num(fr); i++)
82 sk_X509_EXTENSION_set(to, i,
83 X509_EXTENSION_dup(sk_X509_EXTENSION_value(fr, i)));
84 if (! sk_X509_EXTENSION_value(to, i))
89 if (to) sk_X509_EXTENSION_pop_free(to, X509_EXTENSION_free);
93 OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst,
94 X509_NAME *issuerName,
95 ASN1_BIT_STRING* issuerKey,
96 ASN1_INTEGER *serialNumber)
101 OCSP_CERTID *cid = NULL;
102 unsigned char md[EVP_MAX_MD_SIZE];
105 if (!(cid = OCSP_CERTID_new())) goto err;
107 alg = cid->hashAlgorithm;
108 if (alg->algorithm != NULL) ASN1_OBJECT_free(alg->algorithm);
109 if ((nid = EVP_MD_type(dgst)) == NID_undef)
111 OCSPerr(OCSP_F_CERT_ID_NEW,OCSP_R_UNKNOWN_NID);
114 if (!(alg->algorithm=OBJ_nid2obj(nid))) goto err;
115 if ((alg->parameter=ASN1_TYPE_new()) == NULL) goto err;
116 alg->parameter->type=V_ASN1_NULL;
118 if (!X509_NAME_digest(issuerName, dgst, md, &i)) goto digerr;
119 if (!(ASN1_OCTET_STRING_set(cid->issuerNameHash, md, i))) goto err;
121 /* Calculate the issuerKey hash, excluding tag and length */
122 EVP_DigestInit(&ctx,dgst);
123 EVP_DigestUpdate(&ctx,issuerKey->data, issuerKey->length);
124 EVP_DigestFinal(&ctx,md,&i);
126 if (!(ASN1_OCTET_STRING_set(cid->issuerKeyHash, md, i))) goto err;
128 if (cid->serialNumber != NULL) ASN1_INTEGER_free(cid->serialNumber);
129 if (!(cid->serialNumber = ASN1_INTEGER_dup(serialNumber))) goto err;
132 OCSPerr(OCSP_F_CERT_ID_NEW,OCSP_R_DIGEST_ERR);
134 if (cid) OCSP_CERTID_free(cid);
138 OCSP_CERTSTATUS *OCSP_cert_status_new(int status, int reason, char *tim)
140 OCSP_REVOKEDINFO *ri;
141 OCSP_CERTSTATUS *cs = NULL;
143 if (!(cs = OCSP_CERTSTATUS_new())) goto err;
144 if ((cs->type = status) == V_OCSP_CERTSTATUS_REVOKED)
148 OCSPerr(OCSP_F_CERT_STATUS_NEW,OCSP_R_REVOKED_NO_TIME);
151 if (!(cs->value.revoked = ri = OCSP_REVOKEDINFO_new())) goto err;
152 if (!ASN1_GENERALIZEDTIME_set_string(ri->revocationTime,tim))
154 if (reason != OCSP_REVOKED_STATUS_NOSTATUS)
156 if (!(ri->revocationReason = ASN1_ENUMERATED_new()))
158 if (!(ASN1_ENUMERATED_set(ri->revocationReason,
165 if (cs) OCSP_CERTSTATUS_free(cs);
169 OCSP_REQUEST *OCSP_request_new(X509_NAME* name,
170 STACK_OF(X509_EXTENSION) *extensions)
172 OCSP_REQUEST *req = NULL;
174 if ((req = OCSP_REQUEST_new()) == NULL) goto err;
175 if (name) /* optional */
177 if (!(req->tbsRequest->requestorName=GENERAL_NAME_new()))
179 req->tbsRequest->requestorName->type = GEN_DIRNAME;
180 req->tbsRequest->requestorName->d.dirn = X509_NAME_dup(name);
182 if (!(req->tbsRequest->requestList = sk_OCSP_ONEREQ_new(NULL))) goto err;
184 (!(req->tbsRequest->requestExtensions = ext_dup(extensions))))
188 if (req) OCSP_REQUEST_free(req);
192 int OCSP_request_add(OCSP_REQUEST *req,
194 STACK_OF(X509_EXTENSION) *extensions)
196 OCSP_ONEREQ *one = NULL;
198 if (!(one = OCSP_ONEREQ_new())) goto err;
199 if (one->reqCert) OCSP_CERTID_free(one->reqCert);
200 if (!(one->reqCert = OCSP_CERTID_dup(cid))) goto err;
201 if (extensions&&(!(one->singleRequestExtensions=ext_dup(extensions))))
203 if (!sk_OCSP_ONEREQ_push(req->tbsRequest->requestList, one)) goto err;
206 if (one) OCSP_ONEREQ_free(one);
210 int OCSP_request_sign(OCSP_REQUEST *req,
213 STACK_OF(X509) *certs)
218 if (!(req->optionalSignature = sig = OCSP_SIGNATURE_new())) goto err;
219 if (!OCSP_REQUEST_sign(req, key, dgst)) goto err;
222 if (!(sig->certs = sk_X509_dup(certs))) goto err;
223 for (i = 0; i < sk_X509_num(sig->certs); i++)
225 sk_X509_set(sig->certs, i,
226 X509_dup(sk_X509_value(certs,i)));
227 if (! sk_X509_value(sig->certs, i))
233 if (req->optionalSignature)
235 OCSP_SIGNATURE_free(req->optionalSignature);
236 req->optionalSignature = NULL;
241 OCSP_BASICRESP *OCSP_basic_response_new(int type,
243 STACK_OF(X509_EXTENSION) *extensions)
248 OCSP_BASICRESP *rsp = NULL;
249 unsigned char md[SHA_DIGEST_LENGTH];
251 if (!(rsp = OCSP_BASICRESP_new())) goto err;
252 rid = rsp->tbsResponseData->responderId;
253 switch (rid->type = type)
255 case V_OCSP_RESPID_NAME:
256 /* cert is user cert */
257 if (!(rid->value.byName =
258 X509_NAME_dup(X509_get_subject_name(cert))))
261 case V_OCSP_RESPID_KEY:
262 /* cert is issuer cert */
263 /* SHA-1 hash of responder's public key
264 * (excluding the tag and length fields)
266 bs = cert->cert_info->key->public_key;
267 SHA1(ASN1_STRING_data((ASN1_STRING*)bs),
268 ASN1_STRING_length((ASN1_STRING*)bs), md);
269 if (!(rid->value.byKey = ASN1_OCTET_STRING_new()))
271 if (!(ASN1_OCTET_STRING_set(rid->value.byKey,
276 OCSPerr(OCSP_F_BASIC_RESPONSE_NEW,OCSP_R_BAD_TAG);
281 if (!(ASN1_GENERALIZEDTIME_set(rsp->tbsResponseData->producedAt, t)))
283 if (!(rsp->tbsResponseData->responses = sk_OCSP_SINGLERESP_new(NULL))) goto err;
284 if (extensions && (!(rsp->tbsResponseData->responseExtensions =
285 ext_dup(extensions))))
289 if (rsp) OCSP_BASICRESP_free(rsp);
293 int OCSP_basic_response_add(OCSP_BASICRESP *rsp,
295 OCSP_CERTSTATUS *cst,
298 STACK_OF(X509_EXTENSION) *extensions)
300 OCSP_SINGLERESP *single = NULL;
302 if (!(single = OCSP_SINGLERESP_new())) goto err;
303 if (single->certId) OCSP_CERTID_free(single->certId);
304 if (!(single->certId = OCSP_CERTID_dup(cid))) goto err;
305 if (single->certStatus) OCSP_CERTSTATUS_free(single->certStatus);
306 if (!(single->certStatus = OCSP_CERTSTATUS_dup(cst))) goto err;
307 if (!ASN1_GENERALIZEDTIME_set_string(single->thisUpdate,this))goto err;
310 if (!(single->nextUpdate = ASN1_GENERALIZEDTIME_new()))
312 if (!ASN1_GENERALIZEDTIME_set_string(single->nextUpdate,next))
315 if (extensions && (!(single->singleExtensions = ext_dup(extensions))))
317 if (!sk_OCSP_SINGLERESP_push(rsp->tbsResponseData->responses,single)) goto err;
320 if (single) OCSP_SINGLERESP_free(single);
324 int OCSP_basic_response_sign(OCSP_BASICRESP *brsp,
327 STACK_OF(X509) *certs)
331 /* Right now, I think that not doing double hashing is the right
332 thing. -- Richard Levitte */
333 if (!OCSP_BASICRESP_sign(brsp, key, dgst, 0)) goto err;
336 if (!(brsp->certs = sk_X509_dup(certs))) goto err;
337 for (i = 0; i < sk_X509_num(brsp->certs); i++)
339 sk_X509_set(brsp->certs, i,
340 X509_dup(sk_X509_value(certs, i)));
341 if (! sk_X509_value(brsp->certs, i))
350 OCSP_RESPONSE *OCSP_response_new(int status,
355 OCSP_RESPONSE *rsp = NULL;
357 if (!(rsp = OCSP_RESPONSE_new())) goto err;
358 if (!(ASN1_ENUMERATED_set(rsp->responseStatus, status))) goto err;
359 if (!(rsp->responseBytes = OCSP_RESPBYTES_new())) goto err;
360 if (rsp->responseBytes->responseType) ASN1_OBJECT_free(rsp->responseBytes->responseType);
361 if (!(rsp->responseBytes->responseType = OBJ_nid2obj(nid))) goto err;
362 if (!ASN1_STRING_encode((ASN1_STRING*)rsp->responseBytes->response,
363 i2d, data, NULL)) goto err;
366 if (rsp) OCSP_RESPONSE_free(rsp);
370 char* ocspResponseStatus2string(long s)
372 static struct { long t; char *m; } ts[6]= {
373 { OCSP_RESPONSE_STATUS_SUCCESSFULL, "successful" },
374 { OCSP_RESPONSE_STATUS_MALFORMEDREQUEST, "malformedrequest" },
375 { OCSP_RESPONSE_STATUS_INTERNALERROR, "internalerror" },
376 { OCSP_RESPONSE_STATUS_TRYLATER, "trylater" },
377 { OCSP_RESPONSE_STATUS_SIGREQUIRED, "sigrequired" },
378 { OCSP_RESPONSE_STATUS_UNAUTHORIZED, "unauthorized" } }, *p;
379 for (p=ts; p < &ts[sizeof ts/sizeof ts[0]]; p++)
385 char* ocspCertStatus2string(long s)
387 static struct { long t; char *m; } ts[3]= {
388 { V_OCSP_CERTSTATUS_GOOD, "good" },
389 { V_OCSP_CERTSTATUS_REVOKED, "revoked" },
390 { V_OCSP_CERTSTATUS_UNKNOWN, "unknown" } }, *p;
391 for (p=ts; p < &ts[sizeof ts/sizeof ts[0]]; p++)
397 char * cRLReason2string(long s)
399 static struct { long t; char *m; } ts[8]= {
400 { OCSP_REVOKED_STATUS_UNSPECIFIED, "unspecified" },
401 { OCSP_REVOKED_STATUS_KEYCOMPROMISE, "keyCompromise" },
402 { OCSP_REVOKED_STATUS_CACOMPROMISE, "cACompromise" },
403 { OCSP_REVOKED_STATUS_AFFILIATIONCHANGED, "affiliationChanged" },
404 { OCSP_REVOKED_STATUS_SUPERSEDED, "superseded" },
405 { OCSP_REVOKED_STATUS_CESSATIONOFOPERATION, "cessationOfOperation" },
406 { OCSP_REVOKED_STATUS_CERTIFICATEHOLD, "certificateHold" },
407 { OCSP_REVOKED_STATUS_REMOVEFROMCRL, "removeFromCRL" } }, *p;
408 for (p=ts; p < &ts[sizeof ts/sizeof ts[0]]; p++)
414 static int i2a_GENERAL_NAME(bp,n)
421 if (n == NULL) return(0);
427 X509_NAME_print(bp,n->d.dirn,16);
434 p=(char *)n->d.ip->data;
435 for (j=n->d.ip->length;j>0;j--)
437 if ((*p >= ' ') && (*p <= '~'))
438 BIO_printf(bp,"%c",*p);
440 BIO_printf(bp,"\\0x%02X",*p);
441 else if ((unsigned char)*p == 0xf7)
443 else BIO_printf(bp,"^%c",*p+'@');
449 i2a_ASN1_OBJECT(bp, n->d.rid);
452 /* XXX these are legit, need to support at some time... */
464 int OCSP_REQUEST_print(bp, o)
471 OCSP_CERTID* cid = NULL;
472 OCSP_ONEREQ *one = NULL;
473 OCSP_REQINFO *inf = o->tbsRequest;
474 OCSP_SIGNATURE *sig = o->optionalSignature;
476 if (BIO_write(bp,"OCSP Request Data:\n",19) <= 0) goto err;
477 l=ASN1_INTEGER_get(inf->version);
478 if (BIO_printf(bp,"%4sVersion: %lu (0x%lx)","",l+1,l) <= 0) goto err;
479 if (inf->requestorName != NULL)
481 if (BIO_write(bp,"\n Requestor Name: ",21) <= 0)
483 i2a_GENERAL_NAME(bp, inf->requestorName);
485 if (BIO_write(bp,"\n Requestor List:\n",21) <= 0) goto err;
486 for (i = 0; i < sk_OCSP_ONEREQ_num(inf->requestList); i++)
488 if (! sk_OCSP_ONEREQ_value(inf->requestList, i)) continue;
489 one = sk_OCSP_ONEREQ_value(inf->requestList, i);
491 j=OBJ_obj2nid(cid->hashAlgorithm->algorithm);
492 if (BIO_printf(bp,"%8sHash Algorithm: %s","",
493 (j == NID_undef)?"UNKNOWN":OBJ_nid2ln(j)) <= 0)
495 if (BIO_write(bp,"\n Issuer Name Hash: ",27) <= 0)
497 i2a_ASN1_STRING(bp, cid->issuerNameHash, V_ASN1_OCTET_STRING);
498 if (BIO_write(bp,"\n Issuer Key Hash: ",26) <= 0)
500 i2a_ASN1_STRING(bp, cid->issuerKeyHash, V_ASN1_OCTET_STRING);
501 if (BIO_write(bp,"\n Serial Number: ",24) <= 0)
503 if (!i2a_ASN1_INTEGER(bp, cid->serialNumber))
505 if (!BIO_write(bp,"\n",1)) goto err;
506 if (!OCSP_extensions_print(bp, one->singleRequestExtensions,
507 "Request Single Extensions"))
510 if (!OCSP_extensions_print(bp, inf->requestExtensions,
511 "Request Extensions"))
515 i=OBJ_obj2nid(sig->signatureAlgorithm->algorithm);
516 if (BIO_printf(bp,"OCSP Request Signature Algorithm: %s",
517 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0)
519 n=sig->signature->length;
520 s=(char *)sig->signature->data;
524 if (BIO_write(bp,"\n ",9) <= 0) goto err;
525 if (BIO_printf(bp,"%02x%s",(unsigned char)s[i],
526 ((i+1) == n)?"":":") <= 0) goto err;
528 if (BIO_write(bp,"\n",1) != 1) goto err;
531 for (i=0; i<sk_X509_num(sig->certs); i++)
532 if (sk_X509_value(sig->certs,i) != NULL)
534 sk_X509_value(sig->certs,i));
542 int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE* o)
548 OCSP_CERTID *cid = NULL;
549 OCSP_BASICRESP *br = NULL;
550 OCSP_RESPDATA *rd = NULL;
551 OCSP_CERTSTATUS *cst = NULL;
552 OCSP_REVOKEDINFO *rev = NULL;
553 OCSP_SINGLERESP *single = NULL;
554 OCSP_RESPBYTES *rb = o->responseBytes;
556 l=ASN1_ENUMERATED_get(o->responseStatus);
557 if (BIO_printf(bp,"OCSP Response Status: %s (0x%x)\n",
558 ocspResponseStatus2string(l), l) <= 0) goto err;
559 if (rb == NULL) return 1;
560 i=OBJ_obj2nid(rb->responseType);
561 if (BIO_printf(bp,"OCSP Response Bytes Response Type: %s",
562 (i == NID_undef)?"UNKNOWN":OBJ_nid2sn(i)) <= 0)
564 if (i != NID_id_pkix_OCSP_basic)
566 BIO_printf(bp," (unknown response type)\n");
569 p = ASN1_STRING_data(rb->response);
570 i = ASN1_STRING_length(rb->response);
571 if (!(d2i_OCSP_BASICRESP(&br, &p, i))) goto err;
572 rd = br->tbsResponseData;
573 l=ASN1_INTEGER_get(rd->version);
574 if (BIO_printf(bp,"\nBasic Response Data Version: %lu (0x%lx)\n",
575 l+1,l) <= 0) goto err;
576 if (BIO_printf(bp,"Basic Response Data Responder Id: ") <= 0) goto err;
577 i2a_OCSP_RESPID(bp, rd->responderId);
578 if (BIO_printf(bp,"\nBasic Response Data Produced At: ")<=0) goto err;
579 if (!ASN1_GENERALIZEDTIME_print(bp, rd->producedAt)) goto err;
580 if (BIO_printf(bp,"\nBasic Response Data Responses:\n") <= 0) goto err;
581 for (i = 0; i < sk_OCSP_SINGLERESP_num(rd->responses); i++)
583 if (! sk_OCSP_SINGLERESP_value(rd->responses, i)) continue;
584 single = sk_OCSP_SINGLERESP_value(rd->responses, i);
585 cid = single->certId;
586 j=OBJ_obj2nid(cid->hashAlgorithm->algorithm);
587 if (BIO_printf(bp," Cert Id:") <= 0) goto err;
588 if (BIO_printf(bp,"\n%8sHash Algorithm: %s","",
589 (j == NID_undef)?"UNKNOWN":OBJ_nid2ln(j)) <= 0)
591 if (BIO_write(bp,"\n Issuer Name Hash: ",27) <= 0)
593 i2a_ASN1_STRING(bp, cid->issuerNameHash, V_ASN1_OCTET_STRING);
594 if (BIO_write(bp,"\n Issuer Key Hash: ",26) <= 0)
596 i2a_ASN1_STRING(bp, cid->issuerKeyHash, V_ASN1_OCTET_STRING);
597 if (BIO_write(bp,"\n Serial Number: ",24) <= 0)
599 if (!i2a_ASN1_INTEGER(bp, cid->serialNumber))
601 cst = single->certStatus;
602 if (BIO_printf(bp,"\n Cert Status: %s (0x%x)",
603 ocspCertStatus2string(cst->type), cst->type) <= 0)
605 if (cst->type == V_OCSP_CERTSTATUS_REVOKED)
607 rev = cst->value.revoked;
608 if (BIO_printf(bp, "\n Revocation Time: ") <= 0)
610 if (!ASN1_GENERALIZEDTIME_print(bp,
611 rev->revocationTime))
613 if (rev->revocationReason)
615 l=ASN1_ENUMERATED_get(rev->revocationReason);
617 "\n Revocation Reason: %s (0x%x)",
618 cRLReason2string(l), l) <= 0)
622 if (BIO_printf(bp,"\n This Update: ") <= 0) goto err;
623 if (!ASN1_GENERALIZEDTIME_print(bp, single->thisUpdate))
625 if (single->nextUpdate)
627 if (BIO_printf(bp,"\n Next Update: ") <= 0)goto err;
628 if (!ASN1_GENERALIZEDTIME_print(bp,single->nextUpdate))
631 if (!BIO_write(bp,"\n",1)) goto err;
632 if (!OCSP_extensions_print(bp, single->singleExtensions,
633 "Basic Response Single Extensions"))
636 if (!OCSP_extensions_print(bp, rd->responseExtensions,
637 "Basic Response Extensions")) goto err;
638 i=OBJ_obj2nid(br->signatureAlgorithm->algorithm);
639 if (BIO_printf(bp,"Basic Response Signature Algorithm: %s",
640 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0)
642 n=br->signature->length;
643 s=(char *)br->signature->data;
647 if (BIO_write(bp,"\n ",9) <= 0) goto err;
648 if (BIO_printf(bp,"%02x%s",(unsigned char)s[i],
649 ((i+1) == n)?"":":") <= 0) goto err;
651 if (BIO_write(bp,"\n",1) != 1) goto err;
654 for (i=0; i<sk_X509_num(br->certs); i++)
655 if (sk_X509_value(br->certs,i) != NULL) {
656 X509_print(bp, sk_X509_value(br->certs,i));
657 PEM_write_bio_X509(bp,sk_X509_value(br->certs,i));
665 int OCSP_CRLID_print(BIO *bp, OCSP_CRLID *a, int ind)
669 if (!BIO_printf(bp, "%*scrlUrl: ", ind, "")) goto err;
670 if (!ASN1_STRING_print(bp, (ASN1_STRING*)a->crlUrl)) goto err;
671 if (!BIO_write(bp, "\n", 1)) goto err;
675 if (!BIO_printf(bp, "%*scrlNum: ", ind, "")) goto err;
676 if (!i2a_ASN1_INTEGER(bp, a->crlNum)) goto err;
677 if (!BIO_write(bp, "\n", 1)) goto err;
681 if (!BIO_printf(bp, "%*scrlTime: ", ind, "")) goto err;
682 if (!ASN1_GENERALIZEDTIME_print(bp, a->crlTime)) goto err;
683 if (!BIO_write(bp, "\n", 1)) goto err;
690 int OCSP_SERVICELOC_print(BIO *bp, OCSP_SERVICELOC* a, int ind)
693 ACCESS_DESCRIPTION *ad;
695 if (BIO_printf(bp, "%*sissuer: ", ind, "") <= 0) goto err;
696 if (X509_NAME_print(bp, a->issuer, 16) <= 0) goto err;
697 if (BIO_printf(bp, "\n", 1) <= 0) goto err;
699 /* Service locator is optional */
700 if (a->locator != NULL) {
701 if (BIO_printf(bp, "%*slocator:\n", ind, "") <= 0) goto err;
702 for (i = 0; i < sk_ACCESS_DESCRIPTION_num(a->locator); i++)
704 ad = sk_ACCESS_DESCRIPTION_value(a->locator,i);
705 if (BIO_printf(bp, "%*smethod: ", (2*ind), "") <= 0)
707 j=OBJ_obj2nid(ad->method);
708 if (BIO_printf(bp,"%s", (j == NID_undef)?"UNKNOWN":
711 if (BIO_printf(bp, "\n%*sname: ", (2*ind), "") <= 0)
713 if (i2a_GENERAL_NAME(bp, ad->location) <= 0) goto err;
714 if (BIO_write(bp, "\n", 1) <= 0) goto err;
722 /* XXX assumes certs in signature are sorted root to leaf XXX */
723 int OCSP_request_verify(OCSP_REQUEST *req, EVP_PKEY *pkey)
727 if (!req->optionalSignature) return 0;
730 if (!(sk = req->optionalSignature->certs)) return 0;
731 if (!(pkey=X509_get_pubkey(sk_X509_value(sk, sk_X509_num(sk)-1))))
733 OCSPerr(OCSP_F_REQUEST_VERIFY,OCSP_R_NO_PUBLIC_KEY);
737 return OCSP_REQUEST_verify(req, pkey);
740 int OCSP_response_verify(OCSP_RESPONSE *rsp, EVP_PKEY *pkey)
745 OCSP_BASICRESP *br = NULL;
747 if ((rb = rsp->responseBytes) == NULL)
749 OCSPerr(OCSP_F_RESPONSE_VERIFY,OCSP_R_NO_RESPONSE_DATA);
752 if (OBJ_obj2nid(rb->responseType) != NID_id_pkix_OCSP_basic)
754 OCSPerr(OCSP_F_RESPONSE_VERIFY,OCSP_R_BAD_TAG);
757 p = ASN1_STRING_data(rb->response);
758 i = ASN1_STRING_length(rb->response);
759 if (!(d2i_OCSP_BASICRESP(&br, &p, i))) return 0;
760 r = OCSP_basic_response_verify(br, pkey);
761 OCSP_BASICRESP_free(br);
765 int OCSP_basic_response_verify(OCSP_BASICRESP *rsp, EVP_PKEY *pkey)
772 OCSPerr(OCSP_F_BASIC_RESPONSE_VERIFY,OCSP_R_NO_SIGNATURE);
777 if (!(sk = rsp->certs))
779 OCSPerr(OCSP_F_BASIC_RESPONSE_VERIFY,OCSP_R_NO_CERTIFICATE);
782 if (!(pkey=X509_get_pubkey(sk_X509_value(sk, sk_X509_num(sk)-1))))
784 OCSPerr(OCSP_F_BASIC_RESPONSE_VERIFY,OCSP_R_NO_PUBLIC_KEY);
788 ret = OCSP_BASICRESP_verify(rsp, pkey, 0);