151
151
PRBool *certIDWasConsumed,
152
152
SECStatus *rv_ocsp);
155
ocsp_CacheEncodedOCSPResponse(CERTCertDBHandle *handle,
156
CERTOCSPCertID *certID,
157
CERTCertificate *cert,
160
SECItem *encodedResponse,
161
PRBool *certIDWasConsumed,
162
PRBool cacheNegative,
154
166
ocsp_GetVerifiedSingleResponseForCertID(CERTCertDBHandle *handle,
155
167
CERTOCSPResponse *response,
4285
4300
static PRUint32 ocspsloptime = OCSP_SLOP; /* seconds */
4303
* If an old response contains the revoked certificate status, we want
4304
* to return SECSuccess so the response will be used.
4307
ocsp_HandleOldSingleResponse(CERTOCSPSingleResponse *single, PRTime time)
4310
ocspCertStatus *status = single->certStatus;
4311
if (status->certStatusType == ocspCertStatus_revoked) {
4312
rv = ocsp_CertRevokedAfter(status->certStatusInfo.revokedInfo, time);
4313
if (rv != SECSuccess &&
4314
PORT_GetError() == SEC_ERROR_REVOKED_CERTIFICATE) {
4316
* Return SECSuccess now. The subsequent ocsp_CertRevokedAfter
4317
* call in ocsp_CertHasGoodStatus will cause
4318
* ocsp_CertHasGoodStatus to fail with
4319
* SEC_ERROR_REVOKED_CERTIFICATE.
4325
PORT_SetError(SEC_ERROR_OCSP_OLD_RESPONSE);
4288
4330
* Check that this single response is okay. A return of SECSuccess means:
4289
4331
* 1. The signer (represented by "signerCert") is authorized to give status
4290
4332
* for the cert represented by the individual response in "single".
4367
4409
LL_ADD(tmp, tmp, nextUpdate);
4368
if (LL_CMP(tmp, <, now) || LL_CMP(producedAt, >, nextUpdate)) {
4369
PORT_SetError(SEC_ERROR_OCSP_OLD_RESPONSE);
4410
if (LL_CMP(tmp, <, now) || LL_CMP(producedAt, >, nextUpdate))
4411
return ocsp_HandleOldSingleResponse(single, now);
4372
4412
} else if (ocsp_TimeIsRecent(thisUpdate) != PR_TRUE) {
4373
PORT_SetError(SEC_ERROR_OCSP_OLD_RESPONSE);
4413
return ocsp_HandleOldSingleResponse(single, now);
4377
4416
return SECSuccess;
4812
* FUNCTION: CERT_CacheOCSPResponseFromSideChannel
4813
* First, this function checks the OCSP cache to see if a good response
4814
* for the given certificate already exists. If it does, then the function
4815
* returns successfully.
4817
* If not, then it validates that the given OCSP response is a valid,
4818
* good response for the given certificate and inserts it into the
4821
* This function is intended for use when OCSP responses are provided via a
4822
* side-channel, i.e. TLS OCSP stapling (a.k.a. the status_request extension).
4825
* CERTCertDBHandle *handle
4826
* certificate DB of the cert that is being checked
4827
* CERTCertificate *cert
4828
* the certificate being checked
4830
* time for which status is to be determined
4831
* SECItem *encodedResponse
4832
* the DER encoded bytes of the OCSP response
4834
* argument for password prompting, if needed
4836
* SECSuccess if the cert was found in the cache, or if the OCSP response was
4837
* found to be valid and inserted into the cache. SECFailure otherwise.
4840
CERT_CacheOCSPResponseFromSideChannel(CERTCertDBHandle *handle,
4841
CERTCertificate *cert,
4843
SECItem *encodedResponse,
4846
CERTOCSPCertID *certID;
4847
PRBool certIDWasConsumed = PR_FALSE;
4848
SECStatus rv = SECFailure;
4850
SECErrorCodes dummy_error_code; /* we ignore this */
4852
certID = CERT_CreateOCSPCertID(cert, time);
4855
rv = ocsp_GetCachedOCSPResponseStatusIfFresh(
4856
certID, time, PR_FALSE, /* ignoreGlobalOcspFailureSetting */
4857
&rvOcsp, &dummy_error_code);
4858
if (rv == SECSuccess && rvOcsp == SECSuccess) {
4859
/* The cached value is good. We don't want to waste time validating
4860
* this OCSP response. */
4861
CERT_DestroyOCSPCertID(certID);
4865
/* Since the OCSP response came from a side channel it is attacker
4866
* controlled. The attacker can have chosen any valid OCSP response,
4867
* including responses from the past. In this case,
4868
* ocsp_GetVerifiedSingleResponseForCertID will fail. If we recorded a
4869
* negative cache entry in this case, then the attacker would have
4870
* 'poisoned' our cache (denial of service), so we don't record negative
4872
rv = ocsp_CacheEncodedOCSPResponse(handle, certID, cert, time, pwArg,
4873
encodedResponse, &certIDWasConsumed,
4874
PR_FALSE /* don't cache failures */,
4876
if (!certIDWasConsumed) {
4877
CERT_DestroyOCSPCertID(certID);
4879
return rv == SECSuccess ? rvOcsp : rv;
4770
4883
* Status in *certIDWasConsumed will always be correct, regardless of
4771
4884
* return value.
4783
4896
PRBool locationIsDefault;
4784
4897
SECItem *encodedResponse = NULL;
4785
4898
CERTOCSPRequest *request = NULL;
4786
CERTOCSPResponse *response = NULL;
4787
CERTCertificate *signerCert = NULL;
4788
CERTCertificate *issuerCert = NULL;
4789
4899
SECStatus rv = SECFailure;
4790
CERTOCSPSingleResponse *single = NULL;
4792
4901
if (!certIDWasConsumed || !rv_ocsp) {
4793
4902
PORT_SetError(SEC_ERROR_INVALID_ARGS);
4961
rv = ocsp_CacheEncodedOCSPResponse(handle, certID, cert, time, pwArg,
4962
encodedResponse, certIDWasConsumed,
4963
PR_TRUE /* cache failures */, rv_ocsp);
4966
if (request != NULL)
4967
CERT_DestroyOCSPRequest(request);
4968
if (encodedResponse != NULL)
4969
SECITEM_FreeItem(encodedResponse, PR_TRUE);
4970
if (location != NULL)
4971
PORT_Free(location);
4977
* FUNCTION: ocsp_CacheEncodedOCSPResponse
4978
* This function decodes an OCSP response and checks for a valid response
4979
* concerning the given certificate. If such a response is not found
4980
* then nothing is cached. Otherwise, if it is a good response, or if
4981
* cacheNegative is true, the results are stored in the OCSP cache.
4983
* Note: a 'valid' response is one that parses successfully, is not an OCSP
4984
* exception (see RFC 2560 Section 2.3), is correctly signed and is current.
4985
* A 'good' response is a valid response that attests that the certificate
4986
* is not currently revoked (see RFC 2560 Section 2.2).
4989
* CERTCertDBHandle *handle
4990
* certificate DB of the cert that is being checked
4991
* CERTOCSPCertID *certID
4992
* the cert ID corresponding to |cert|
4993
* CERTCertificate *cert
4994
* the certificate being checked
4996
* time for which status is to be determined
4998
* the opaque argument to the password prompting function.
4999
* SECItem *encodedResponse
5000
* the DER encoded bytes of the OCSP response
5001
* PRBool *certIDWasConsumed
5002
* (output) on return, this is true iff |certID| was consumed by this
5004
* SECStatus *rv_ocsp
5005
* (output) on return, this is SECSuccess iff the response is good (see
5006
* definition of 'good' above).
5008
* SECSuccess iff the response is valid.
5011
ocsp_CacheEncodedOCSPResponse(CERTCertDBHandle *handle,
5012
CERTOCSPCertID *certID,
5013
CERTCertificate *cert,
5016
SECItem *encodedResponse,
5017
PRBool *certIDWasConsumed,
5018
PRBool cacheNegative,
5021
CERTOCSPResponse *response = NULL;
5022
CERTCertificate *signerCert = NULL;
5023
CERTCertificate *issuerCert = NULL;
5024
CERTOCSPSingleResponse *single = NULL;
5025
SECStatus rv = SECFailure;
5027
*certIDWasConsumed = PR_FALSE;
5028
*rv_ocsp = SECFailure;
4852
5030
response = CERT_DecodeOCSPResponse(encodedResponse);
4853
5031
if (response == NULL) {
4896
5074
*rv_ocsp = ocsp_SingleResponseCertHasGoodStatus(single, time);
4899
PR_EnterMonitor(OCSP_Global.monitor);
4900
if (OCSP_Global.maxCacheEntries >= 0) {
4901
/* single == NULL means: remember response failure */
4902
ocsp_CreateOrUpdateCacheEntry(&OCSP_Global.cache, certID, single,
4904
/* ignore cache update failures */
5077
if (cacheNegative || *rv_ocsp == SECSuccess) {
5078
PR_EnterMonitor(OCSP_Global.monitor);
5079
if (OCSP_Global.maxCacheEntries >= 0) {
5080
/* single == NULL means: remember response failure */
5081
ocsp_CreateOrUpdateCacheEntry(&OCSP_Global.cache, certID, single,
5083
/* ignore cache update failures */
5085
PR_ExitMonitor(OCSP_Global.monitor);
4906
PR_ExitMonitor(OCSP_Global.monitor);
5088
/* 'single' points within the response so there's no need to free it. */
4908
5090
if (issuerCert != NULL)
4909
5091
CERT_DestroyCertificate(issuerCert);