10Sstevel@tonic-gate /* ocsp_cl.c */
20Sstevel@tonic-gate /* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
30Sstevel@tonic-gate * project. */
40Sstevel@tonic-gate
50Sstevel@tonic-gate /* History:
60Sstevel@tonic-gate This file was transfered to Richard Levitte from CertCo by Kathy
70Sstevel@tonic-gate Weinhold in mid-spring 2000 to be included in OpenSSL or released
80Sstevel@tonic-gate as a patch kit. */
90Sstevel@tonic-gate
100Sstevel@tonic-gate /* ====================================================================
110Sstevel@tonic-gate * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
140Sstevel@tonic-gate * modification, are permitted provided that the following conditions
150Sstevel@tonic-gate * are met:
160Sstevel@tonic-gate *
170Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright
180Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer.
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
210Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in
220Sstevel@tonic-gate * the documentation and/or other materials provided with the
230Sstevel@tonic-gate * distribution.
240Sstevel@tonic-gate *
250Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this
260Sstevel@tonic-gate * software must display the following acknowledgment:
270Sstevel@tonic-gate * "This product includes software developed by the OpenSSL Project
280Sstevel@tonic-gate * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
290Sstevel@tonic-gate *
300Sstevel@tonic-gate * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
310Sstevel@tonic-gate * endorse or promote products derived from this software without
320Sstevel@tonic-gate * prior written permission. For written permission, please contact
330Sstevel@tonic-gate * openssl-core@openssl.org.
340Sstevel@tonic-gate *
350Sstevel@tonic-gate * 5. Products derived from this software may not be called "OpenSSL"
360Sstevel@tonic-gate * nor may "OpenSSL" appear in their names without prior written
370Sstevel@tonic-gate * permission of the OpenSSL Project.
380Sstevel@tonic-gate *
390Sstevel@tonic-gate * 6. Redistributions of any form whatsoever must retain the following
400Sstevel@tonic-gate * acknowledgment:
410Sstevel@tonic-gate * "This product includes software developed by the OpenSSL Project
420Sstevel@tonic-gate * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
430Sstevel@tonic-gate *
440Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
450Sstevel@tonic-gate * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
460Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
470Sstevel@tonic-gate * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
480Sstevel@tonic-gate * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
490Sstevel@tonic-gate * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
500Sstevel@tonic-gate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
510Sstevel@tonic-gate * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
520Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
530Sstevel@tonic-gate * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
540Sstevel@tonic-gate * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
550Sstevel@tonic-gate * OF THE POSSIBILITY OF SUCH DAMAGE.
560Sstevel@tonic-gate * ====================================================================
570Sstevel@tonic-gate *
580Sstevel@tonic-gate * This product includes cryptographic software written by Eric Young
590Sstevel@tonic-gate * (eay@cryptsoft.com). This product includes software written by Tim
600Sstevel@tonic-gate * Hudson (tjh@cryptsoft.com).
610Sstevel@tonic-gate *
620Sstevel@tonic-gate */
630Sstevel@tonic-gate
640Sstevel@tonic-gate #include <stdio.h>
650Sstevel@tonic-gate #include <time.h>
660Sstevel@tonic-gate #include <cryptlib.h>
670Sstevel@tonic-gate #include <openssl/objects.h>
680Sstevel@tonic-gate #include <openssl/rand.h>
690Sstevel@tonic-gate #include <openssl/x509.h>
700Sstevel@tonic-gate #include <openssl/pem.h>
710Sstevel@tonic-gate #include <openssl/x509v3.h>
720Sstevel@tonic-gate #include <openssl/ocsp.h>
730Sstevel@tonic-gate
740Sstevel@tonic-gate /* Utility functions related to sending OCSP requests and extracting
750Sstevel@tonic-gate * relevant information from the response.
760Sstevel@tonic-gate */
770Sstevel@tonic-gate
780Sstevel@tonic-gate /* Add an OCSP_CERTID to an OCSP request. Return new OCSP_ONEREQ
790Sstevel@tonic-gate * pointer: useful if we want to add extensions.
800Sstevel@tonic-gate */
810Sstevel@tonic-gate
OCSP_request_add0_id(OCSP_REQUEST * req,OCSP_CERTID * cid)820Sstevel@tonic-gate OCSP_ONEREQ *OCSP_request_add0_id(OCSP_REQUEST *req, OCSP_CERTID *cid)
830Sstevel@tonic-gate {
840Sstevel@tonic-gate OCSP_ONEREQ *one = NULL;
850Sstevel@tonic-gate
860Sstevel@tonic-gate if (!(one = OCSP_ONEREQ_new())) goto err;
870Sstevel@tonic-gate if (one->reqCert) OCSP_CERTID_free(one->reqCert);
880Sstevel@tonic-gate one->reqCert = cid;
890Sstevel@tonic-gate if (req &&
900Sstevel@tonic-gate !sk_OCSP_ONEREQ_push(req->tbsRequest->requestList, one))
910Sstevel@tonic-gate goto err;
920Sstevel@tonic-gate return one;
930Sstevel@tonic-gate err:
940Sstevel@tonic-gate OCSP_ONEREQ_free(one);
950Sstevel@tonic-gate return NULL;
960Sstevel@tonic-gate }
970Sstevel@tonic-gate
980Sstevel@tonic-gate /* Set requestorName from an X509_NAME structure */
990Sstevel@tonic-gate
OCSP_request_set1_name(OCSP_REQUEST * req,X509_NAME * nm)1000Sstevel@tonic-gate int OCSP_request_set1_name(OCSP_REQUEST *req, X509_NAME *nm)
1010Sstevel@tonic-gate {
1020Sstevel@tonic-gate GENERAL_NAME *gen;
1030Sstevel@tonic-gate gen = GENERAL_NAME_new();
104*2139Sjp161948 if (gen == NULL)
105*2139Sjp161948 return 0;
1060Sstevel@tonic-gate if (!X509_NAME_set(&gen->d.directoryName, nm))
1070Sstevel@tonic-gate {
1080Sstevel@tonic-gate GENERAL_NAME_free(gen);
1090Sstevel@tonic-gate return 0;
1100Sstevel@tonic-gate }
1110Sstevel@tonic-gate gen->type = GEN_DIRNAME;
1120Sstevel@tonic-gate if (req->tbsRequest->requestorName)
1130Sstevel@tonic-gate GENERAL_NAME_free(req->tbsRequest->requestorName);
1140Sstevel@tonic-gate req->tbsRequest->requestorName = gen;
1150Sstevel@tonic-gate return 1;
1160Sstevel@tonic-gate }
1170Sstevel@tonic-gate
1180Sstevel@tonic-gate
1190Sstevel@tonic-gate /* Add a certificate to an OCSP request */
1200Sstevel@tonic-gate
OCSP_request_add1_cert(OCSP_REQUEST * req,X509 * cert)1210Sstevel@tonic-gate int OCSP_request_add1_cert(OCSP_REQUEST *req, X509 *cert)
1220Sstevel@tonic-gate {
1230Sstevel@tonic-gate OCSP_SIGNATURE *sig;
1240Sstevel@tonic-gate if (!req->optionalSignature)
1250Sstevel@tonic-gate req->optionalSignature = OCSP_SIGNATURE_new();
1260Sstevel@tonic-gate sig = req->optionalSignature;
1270Sstevel@tonic-gate if (!sig) return 0;
1280Sstevel@tonic-gate if (!cert) return 1;
1290Sstevel@tonic-gate if (!sig->certs && !(sig->certs = sk_X509_new_null()))
1300Sstevel@tonic-gate return 0;
1310Sstevel@tonic-gate
1320Sstevel@tonic-gate if(!sk_X509_push(sig->certs, cert)) return 0;
1330Sstevel@tonic-gate CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509);
1340Sstevel@tonic-gate return 1;
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate /* Sign an OCSP request set the requestorName to the subjec
1380Sstevel@tonic-gate * name of an optional signers certificate and include one
1390Sstevel@tonic-gate * or more optional certificates in the request. Behaves
1400Sstevel@tonic-gate * like PKCS7_sign().
1410Sstevel@tonic-gate */
1420Sstevel@tonic-gate
OCSP_request_sign(OCSP_REQUEST * req,X509 * signer,EVP_PKEY * key,const EVP_MD * dgst,STACK_OF (X509)* certs,unsigned long flags)1430Sstevel@tonic-gate int OCSP_request_sign(OCSP_REQUEST *req,
1440Sstevel@tonic-gate X509 *signer,
1450Sstevel@tonic-gate EVP_PKEY *key,
1460Sstevel@tonic-gate const EVP_MD *dgst,
1470Sstevel@tonic-gate STACK_OF(X509) *certs,
1480Sstevel@tonic-gate unsigned long flags)
1490Sstevel@tonic-gate {
1500Sstevel@tonic-gate int i;
1510Sstevel@tonic-gate OCSP_SIGNATURE *sig;
1520Sstevel@tonic-gate X509 *x;
1530Sstevel@tonic-gate
1540Sstevel@tonic-gate if (!OCSP_request_set1_name(req, X509_get_subject_name(signer)))
1550Sstevel@tonic-gate goto err;
1560Sstevel@tonic-gate
1570Sstevel@tonic-gate if (!(req->optionalSignature = sig = OCSP_SIGNATURE_new())) goto err;
1580Sstevel@tonic-gate if (!dgst) dgst = EVP_sha1();
1590Sstevel@tonic-gate if (key)
1600Sstevel@tonic-gate {
1610Sstevel@tonic-gate if (!X509_check_private_key(signer, key))
1620Sstevel@tonic-gate {
1630Sstevel@tonic-gate OCSPerr(OCSP_F_OCSP_REQUEST_SIGN, OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
1640Sstevel@tonic-gate goto err;
1650Sstevel@tonic-gate }
1660Sstevel@tonic-gate if (!OCSP_REQUEST_sign(req, key, dgst)) goto err;
1670Sstevel@tonic-gate }
1680Sstevel@tonic-gate
1690Sstevel@tonic-gate if (!(flags & OCSP_NOCERTS))
1700Sstevel@tonic-gate {
1710Sstevel@tonic-gate if(!OCSP_request_add1_cert(req, signer)) goto err;
1720Sstevel@tonic-gate for (i = 0; i < sk_X509_num(certs); i++)
1730Sstevel@tonic-gate {
1740Sstevel@tonic-gate x = sk_X509_value(certs, i);
1750Sstevel@tonic-gate if (!OCSP_request_add1_cert(req, x)) goto err;
1760Sstevel@tonic-gate }
1770Sstevel@tonic-gate }
1780Sstevel@tonic-gate
1790Sstevel@tonic-gate return 1;
1800Sstevel@tonic-gate err:
1810Sstevel@tonic-gate OCSP_SIGNATURE_free(req->optionalSignature);
1820Sstevel@tonic-gate req->optionalSignature = NULL;
1830Sstevel@tonic-gate return 0;
1840Sstevel@tonic-gate }
1850Sstevel@tonic-gate
1860Sstevel@tonic-gate /* Get response status */
1870Sstevel@tonic-gate
OCSP_response_status(OCSP_RESPONSE * resp)1880Sstevel@tonic-gate int OCSP_response_status(OCSP_RESPONSE *resp)
1890Sstevel@tonic-gate {
1900Sstevel@tonic-gate return ASN1_ENUMERATED_get(resp->responseStatus);
1910Sstevel@tonic-gate }
1920Sstevel@tonic-gate
1930Sstevel@tonic-gate /* Extract basic response from OCSP_RESPONSE or NULL if
1940Sstevel@tonic-gate * no basic response present.
1950Sstevel@tonic-gate */
1960Sstevel@tonic-gate
1970Sstevel@tonic-gate
OCSP_response_get1_basic(OCSP_RESPONSE * resp)1980Sstevel@tonic-gate OCSP_BASICRESP *OCSP_response_get1_basic(OCSP_RESPONSE *resp)
1990Sstevel@tonic-gate {
2000Sstevel@tonic-gate OCSP_RESPBYTES *rb;
2010Sstevel@tonic-gate rb = resp->responseBytes;
2020Sstevel@tonic-gate if (!rb)
2030Sstevel@tonic-gate {
2040Sstevel@tonic-gate OCSPerr(OCSP_F_OCSP_RESPONSE_GET1_BASIC, OCSP_R_NO_RESPONSE_DATA);
2050Sstevel@tonic-gate return NULL;
2060Sstevel@tonic-gate }
2070Sstevel@tonic-gate if (OBJ_obj2nid(rb->responseType) != NID_id_pkix_OCSP_basic)
2080Sstevel@tonic-gate {
2090Sstevel@tonic-gate OCSPerr(OCSP_F_OCSP_RESPONSE_GET1_BASIC, OCSP_R_NOT_BASIC_RESPONSE);
2100Sstevel@tonic-gate return NULL;
2110Sstevel@tonic-gate }
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate return ASN1_item_unpack(rb->response, ASN1_ITEM_rptr(OCSP_BASICRESP));
2140Sstevel@tonic-gate }
2150Sstevel@tonic-gate
2160Sstevel@tonic-gate /* Return number of OCSP_SINGLERESP reponses present in
2170Sstevel@tonic-gate * a basic response.
2180Sstevel@tonic-gate */
2190Sstevel@tonic-gate
OCSP_resp_count(OCSP_BASICRESP * bs)2200Sstevel@tonic-gate int OCSP_resp_count(OCSP_BASICRESP *bs)
2210Sstevel@tonic-gate {
2220Sstevel@tonic-gate if (!bs) return -1;
2230Sstevel@tonic-gate return sk_OCSP_SINGLERESP_num(bs->tbsResponseData->responses);
2240Sstevel@tonic-gate }
2250Sstevel@tonic-gate
2260Sstevel@tonic-gate /* Extract an OCSP_SINGLERESP response with a given index */
2270Sstevel@tonic-gate
OCSP_resp_get0(OCSP_BASICRESP * bs,int idx)2280Sstevel@tonic-gate OCSP_SINGLERESP *OCSP_resp_get0(OCSP_BASICRESP *bs, int idx)
2290Sstevel@tonic-gate {
2300Sstevel@tonic-gate if (!bs) return NULL;
2310Sstevel@tonic-gate return sk_OCSP_SINGLERESP_value(bs->tbsResponseData->responses, idx);
2320Sstevel@tonic-gate }
2330Sstevel@tonic-gate
2340Sstevel@tonic-gate /* Look single response matching a given certificate ID */
2350Sstevel@tonic-gate
OCSP_resp_find(OCSP_BASICRESP * bs,OCSP_CERTID * id,int last)2360Sstevel@tonic-gate int OCSP_resp_find(OCSP_BASICRESP *bs, OCSP_CERTID *id, int last)
2370Sstevel@tonic-gate {
2380Sstevel@tonic-gate int i;
2390Sstevel@tonic-gate STACK_OF(OCSP_SINGLERESP) *sresp;
2400Sstevel@tonic-gate OCSP_SINGLERESP *single;
2410Sstevel@tonic-gate if (!bs) return -1;
2420Sstevel@tonic-gate if (last < 0) last = 0;
2430Sstevel@tonic-gate else last++;
2440Sstevel@tonic-gate sresp = bs->tbsResponseData->responses;
2450Sstevel@tonic-gate for (i = last; i < sk_OCSP_SINGLERESP_num(sresp); i++)
2460Sstevel@tonic-gate {
2470Sstevel@tonic-gate single = sk_OCSP_SINGLERESP_value(sresp, i);
2480Sstevel@tonic-gate if (!OCSP_id_cmp(id, single->certId)) return i;
2490Sstevel@tonic-gate }
2500Sstevel@tonic-gate return -1;
2510Sstevel@tonic-gate }
2520Sstevel@tonic-gate
2530Sstevel@tonic-gate /* Extract status information from an OCSP_SINGLERESP structure.
2540Sstevel@tonic-gate * Note: the revtime and reason values are only set if the
2550Sstevel@tonic-gate * certificate status is revoked. Returns numerical value of
2560Sstevel@tonic-gate * status.
2570Sstevel@tonic-gate */
2580Sstevel@tonic-gate
OCSP_single_get0_status(OCSP_SINGLERESP * single,int * reason,ASN1_GENERALIZEDTIME ** revtime,ASN1_GENERALIZEDTIME ** thisupd,ASN1_GENERALIZEDTIME ** nextupd)2590Sstevel@tonic-gate int OCSP_single_get0_status(OCSP_SINGLERESP *single, int *reason,
2600Sstevel@tonic-gate ASN1_GENERALIZEDTIME **revtime,
2610Sstevel@tonic-gate ASN1_GENERALIZEDTIME **thisupd,
2620Sstevel@tonic-gate ASN1_GENERALIZEDTIME **nextupd)
2630Sstevel@tonic-gate {
2640Sstevel@tonic-gate int ret;
2650Sstevel@tonic-gate OCSP_CERTSTATUS *cst;
2660Sstevel@tonic-gate if(!single) return -1;
2670Sstevel@tonic-gate cst = single->certStatus;
2680Sstevel@tonic-gate ret = cst->type;
2690Sstevel@tonic-gate if (ret == V_OCSP_CERTSTATUS_REVOKED)
2700Sstevel@tonic-gate {
2710Sstevel@tonic-gate OCSP_REVOKEDINFO *rev = cst->value.revoked;
2720Sstevel@tonic-gate if (revtime) *revtime = rev->revocationTime;
2730Sstevel@tonic-gate if (reason)
2740Sstevel@tonic-gate {
2750Sstevel@tonic-gate if(rev->revocationReason)
2760Sstevel@tonic-gate *reason = ASN1_ENUMERATED_get(rev->revocationReason);
2770Sstevel@tonic-gate else *reason = -1;
2780Sstevel@tonic-gate }
2790Sstevel@tonic-gate }
2800Sstevel@tonic-gate if(thisupd) *thisupd = single->thisUpdate;
2810Sstevel@tonic-gate if(nextupd) *nextupd = single->nextUpdate;
2820Sstevel@tonic-gate return ret;
2830Sstevel@tonic-gate }
2840Sstevel@tonic-gate
2850Sstevel@tonic-gate /* This function combines the previous ones: look up a certificate ID and
2860Sstevel@tonic-gate * if found extract status information. Return 0 is successful.
2870Sstevel@tonic-gate */
2880Sstevel@tonic-gate
OCSP_resp_find_status(OCSP_BASICRESP * bs,OCSP_CERTID * id,int * status,int * reason,ASN1_GENERALIZEDTIME ** revtime,ASN1_GENERALIZEDTIME ** thisupd,ASN1_GENERALIZEDTIME ** nextupd)2890Sstevel@tonic-gate int OCSP_resp_find_status(OCSP_BASICRESP *bs, OCSP_CERTID *id, int *status,
2900Sstevel@tonic-gate int *reason,
2910Sstevel@tonic-gate ASN1_GENERALIZEDTIME **revtime,
2920Sstevel@tonic-gate ASN1_GENERALIZEDTIME **thisupd,
2930Sstevel@tonic-gate ASN1_GENERALIZEDTIME **nextupd)
2940Sstevel@tonic-gate {
2950Sstevel@tonic-gate int i;
2960Sstevel@tonic-gate OCSP_SINGLERESP *single;
2970Sstevel@tonic-gate i = OCSP_resp_find(bs, id, -1);
2980Sstevel@tonic-gate /* Maybe check for multiple responses and give an error? */
2990Sstevel@tonic-gate if(i < 0) return 0;
3000Sstevel@tonic-gate single = OCSP_resp_get0(bs, i);
3010Sstevel@tonic-gate i = OCSP_single_get0_status(single, reason, revtime, thisupd, nextupd);
3020Sstevel@tonic-gate if(status) *status = i;
3030Sstevel@tonic-gate return 1;
3040Sstevel@tonic-gate }
3050Sstevel@tonic-gate
3060Sstevel@tonic-gate /* Check validity of thisUpdate and nextUpdate fields. It is possible that the request will
3070Sstevel@tonic-gate * take a few seconds to process and/or the time wont be totally accurate. Therefore to avoid
3080Sstevel@tonic-gate * rejecting otherwise valid time we allow the times to be within 'nsec' of the current time.
3090Sstevel@tonic-gate * Also to avoid accepting very old responses without a nextUpdate field an optional maxage
3100Sstevel@tonic-gate * parameter specifies the maximum age the thisUpdate field can be.
3110Sstevel@tonic-gate */
3120Sstevel@tonic-gate
OCSP_check_validity(ASN1_GENERALIZEDTIME * thisupd,ASN1_GENERALIZEDTIME * nextupd,long nsec,long maxsec)3130Sstevel@tonic-gate int OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd, ASN1_GENERALIZEDTIME *nextupd, long nsec, long maxsec)
3140Sstevel@tonic-gate {
3150Sstevel@tonic-gate int ret = 1;
3160Sstevel@tonic-gate time_t t_now, t_tmp;
3170Sstevel@tonic-gate time(&t_now);
3180Sstevel@tonic-gate /* Check thisUpdate is valid and not more than nsec in the future */
3190Sstevel@tonic-gate if (!ASN1_GENERALIZEDTIME_check(thisupd))
3200Sstevel@tonic-gate {
3210Sstevel@tonic-gate OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_ERROR_IN_THISUPDATE_FIELD);
3220Sstevel@tonic-gate ret = 0;
3230Sstevel@tonic-gate }
3240Sstevel@tonic-gate else
3250Sstevel@tonic-gate {
3260Sstevel@tonic-gate t_tmp = t_now + nsec;
3270Sstevel@tonic-gate if (X509_cmp_time(thisupd, &t_tmp) > 0)
3280Sstevel@tonic-gate {
3290Sstevel@tonic-gate OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_STATUS_NOT_YET_VALID);
3300Sstevel@tonic-gate ret = 0;
3310Sstevel@tonic-gate }
3320Sstevel@tonic-gate
3330Sstevel@tonic-gate /* If maxsec specified check thisUpdate is not more than maxsec in the past */
3340Sstevel@tonic-gate if (maxsec >= 0)
3350Sstevel@tonic-gate {
3360Sstevel@tonic-gate t_tmp = t_now - maxsec;
3370Sstevel@tonic-gate if (X509_cmp_time(thisupd, &t_tmp) < 0)
3380Sstevel@tonic-gate {
3390Sstevel@tonic-gate OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_STATUS_TOO_OLD);
3400Sstevel@tonic-gate ret = 0;
3410Sstevel@tonic-gate }
3420Sstevel@tonic-gate }
3430Sstevel@tonic-gate }
3440Sstevel@tonic-gate
3450Sstevel@tonic-gate
3460Sstevel@tonic-gate if (!nextupd) return ret;
3470Sstevel@tonic-gate
3480Sstevel@tonic-gate /* Check nextUpdate is valid and not more than nsec in the past */
3490Sstevel@tonic-gate if (!ASN1_GENERALIZEDTIME_check(nextupd))
3500Sstevel@tonic-gate {
3510Sstevel@tonic-gate OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_ERROR_IN_NEXTUPDATE_FIELD);
3520Sstevel@tonic-gate ret = 0;
3530Sstevel@tonic-gate }
3540Sstevel@tonic-gate else
3550Sstevel@tonic-gate {
3560Sstevel@tonic-gate t_tmp = t_now - nsec;
3570Sstevel@tonic-gate if (X509_cmp_time(nextupd, &t_tmp) < 0)
3580Sstevel@tonic-gate {
3590Sstevel@tonic-gate OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_STATUS_EXPIRED);
3600Sstevel@tonic-gate ret = 0;
3610Sstevel@tonic-gate }
3620Sstevel@tonic-gate }
3630Sstevel@tonic-gate
3640Sstevel@tonic-gate /* Also don't allow nextUpdate to precede thisUpdate */
3650Sstevel@tonic-gate if (ASN1_STRING_cmp(nextupd, thisupd) < 0)
3660Sstevel@tonic-gate {
3670Sstevel@tonic-gate OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE);
3680Sstevel@tonic-gate ret = 0;
3690Sstevel@tonic-gate }
3700Sstevel@tonic-gate
3710Sstevel@tonic-gate return ret;
3720Sstevel@tonic-gate }
373