2014-01-21 10:10:33 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "NSSCertDBTrustDomain.h"
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2014-02-24 10:15:53 +04:00
|
|
|
#include "ExtendedValidation.h"
|
2014-07-07 02:55:38 +04:00
|
|
|
#include "nsNSSCertificate.h"
|
2014-05-29 02:28:03 +04:00
|
|
|
#include "NSSErrorsService.h"
|
2014-05-02 02:07:55 +04:00
|
|
|
#include "OCSPRequestor.h"
|
2013-07-09 03:30:59 +04:00
|
|
|
#include "certdb.h"
|
2014-03-13 20:41:03 +04:00
|
|
|
#include "mozilla/Telemetry.h"
|
2014-01-21 10:10:33 +04:00
|
|
|
#include "nss.h"
|
2013-07-09 03:30:59 +04:00
|
|
|
#include "pk11pub.h"
|
2014-05-02 02:07:55 +04:00
|
|
|
#include "pkix/pkix.h"
|
2014-07-18 22:48:49 +04:00
|
|
|
#include "pkix/pkixnss.h"
|
2014-07-07 02:55:38 +04:00
|
|
|
#include "pkix/ScopedPtr.h"
|
2014-01-21 10:10:33 +04:00
|
|
|
#include "prerror.h"
|
2013-07-09 03:30:59 +04:00
|
|
|
#include "prmem.h"
|
2014-01-21 10:10:33 +04:00
|
|
|
#include "prprf.h"
|
2014-07-04 08:49:56 +04:00
|
|
|
#include "ScopedNSSTypes.h"
|
2014-01-21 10:10:33 +04:00
|
|
|
#include "secerr.h"
|
|
|
|
#include "secmod.h"
|
|
|
|
|
2014-07-04 08:49:56 +04:00
|
|
|
using namespace mozilla;
|
2014-03-21 01:29:21 +04:00
|
|
|
using namespace mozilla::pkix;
|
2014-01-21 10:10:33 +04:00
|
|
|
|
2014-02-10 23:41:12 +04:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
extern PRLogModuleInfo* gCertVerifierLog;
|
|
|
|
#endif
|
|
|
|
|
2014-08-02 19:49:12 +04:00
|
|
|
static const uint64_t ServerFailureDelaySeconds = 5 * 60;
|
|
|
|
|
2014-01-21 10:10:33 +04:00
|
|
|
namespace mozilla { namespace psm {
|
|
|
|
|
|
|
|
const char BUILTIN_ROOTS_MODULE_DEFAULT_NAME[] = "Builtin Roots Module";
|
|
|
|
|
2014-03-13 00:08:48 +04:00
|
|
|
void PORT_Free_string(char* str) { PORT_Free(str); }
|
2014-01-21 10:10:33 +04:00
|
|
|
|
2014-03-13 00:08:48 +04:00
|
|
|
namespace {
|
2014-01-21 10:10:33 +04:00
|
|
|
|
|
|
|
typedef ScopedPtr<SECMODModule, SECMOD_DestroyModule> ScopedSECMODModule;
|
|
|
|
|
2014-02-10 23:41:12 +04:00
|
|
|
} // unnamed namespace
|
|
|
|
|
|
|
|
NSSCertDBTrustDomain::NSSCertDBTrustDomain(SECTrustType certDBTrustType,
|
2014-02-24 10:15:53 +04:00
|
|
|
OCSPFetching ocspFetching,
|
2014-03-13 00:08:48 +04:00
|
|
|
OCSPCache& ocspCache,
|
2014-07-07 02:55:38 +04:00
|
|
|
/*optional but shouldn't be*/ void* pinArg,
|
2014-05-22 02:42:21 +04:00
|
|
|
CertVerifier::ocsp_get_config ocspGETConfig,
|
2014-07-07 02:55:38 +04:00
|
|
|
/*optional*/ CERTChainVerifyCallback* checkChainCallback,
|
|
|
|
/*optional*/ ScopedCERTCertList* builtChain)
|
2014-02-10 23:41:12 +04:00
|
|
|
: mCertDBTrustType(certDBTrustType)
|
2014-02-24 10:15:53 +04:00
|
|
|
, mOCSPFetching(ocspFetching)
|
2014-03-13 00:08:48 +04:00
|
|
|
, mOCSPCache(ocspCache)
|
2014-02-10 23:41:12 +04:00
|
|
|
, mPinArg(pinArg)
|
2014-05-22 02:42:21 +04:00
|
|
|
, mOCSPGetConfig(ocspGETConfig)
|
2014-02-06 02:49:10 +04:00
|
|
|
, mCheckChainCallback(checkChainCallback)
|
2014-07-07 02:55:38 +04:00
|
|
|
, mBuiltChain(builtChain)
|
2014-02-10 23:41:12 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-07-11 09:38:59 +04:00
|
|
|
// E=igca@sgdn.pm.gouv.fr,CN=IGC/A,OU=DCSSI,O=PM/SGDN,L=Paris,ST=France,C=FR
|
|
|
|
static const uint8_t ANSSI_SUBJECT_DATA[] =
|
|
|
|
"\x30\x81\x85\x31\x0B\x30\x09\x06\x03\x55\x04"
|
|
|
|
"\x06\x13\x02\x46\x52\x31\x0F\x30\x0D\x06\x03"
|
|
|
|
"\x55\x04\x08\x13\x06\x46\x72\x61\x6E\x63\x65"
|
|
|
|
"\x31\x0E\x30\x0C\x06\x03\x55\x04\x07\x13\x05"
|
|
|
|
"\x50\x61\x72\x69\x73\x31\x10\x30\x0E\x06\x03"
|
|
|
|
"\x55\x04\x0A\x13\x07\x50\x4D\x2F\x53\x47\x44"
|
|
|
|
"\x4E\x31\x0E\x30\x0C\x06\x03\x55\x04\x0B\x13"
|
|
|
|
"\x05\x44\x43\x53\x53\x49\x31\x0E\x30\x0C\x06"
|
|
|
|
"\x03\x55\x04\x03\x13\x05\x49\x47\x43\x2F\x41"
|
|
|
|
"\x31\x23\x30\x21\x06\x09\x2A\x86\x48\x86\xF7"
|
|
|
|
"\x0D\x01\x09\x01\x16\x14\x69\x67\x63\x61\x40"
|
|
|
|
"\x73\x67\x64\x6E\x2E\x70\x6D\x2E\x67\x6F\x75"
|
|
|
|
"\x76\x2E\x66\x72";
|
|
|
|
|
|
|
|
static const uint8_t PERMIT_FRANCE_GOV_NAME_CONSTRAINTS_DATA[] =
|
|
|
|
"\x30\x5D" // SEQUENCE (length=93)
|
|
|
|
"\xA0\x5B" // permittedSubtrees (length=91)
|
|
|
|
"\x30\x05\x82\x03" ".fr"
|
|
|
|
"\x30\x05\x82\x03" ".gp"
|
|
|
|
"\x30\x05\x82\x03" ".gf"
|
|
|
|
"\x30\x05\x82\x03" ".mq"
|
|
|
|
"\x30\x05\x82\x03" ".re"
|
|
|
|
"\x30\x05\x82\x03" ".yt"
|
|
|
|
"\x30\x05\x82\x03" ".pm"
|
|
|
|
"\x30\x05\x82\x03" ".bl"
|
|
|
|
"\x30\x05\x82\x03" ".mf"
|
|
|
|
"\x30\x05\x82\x03" ".wf"
|
|
|
|
"\x30\x05\x82\x03" ".pf"
|
|
|
|
"\x30\x05\x82\x03" ".nc"
|
|
|
|
"\x30\x05\x82\x03" ".tf";
|
|
|
|
|
2014-07-18 22:48:49 +04:00
|
|
|
Result
|
2014-07-31 23:17:31 +04:00
|
|
|
NSSCertDBTrustDomain::FindIssuer(Input encodedIssuerName,
|
2014-08-02 19:49:12 +04:00
|
|
|
IssuerChecker& checker, Time)
|
2014-02-10 23:41:12 +04:00
|
|
|
{
|
|
|
|
// TODO: NSS seems to be ambiguous between "no potential issuers found" and
|
|
|
|
// "there was an error trying to retrieve the potential issuers."
|
2014-07-31 23:17:31 +04:00
|
|
|
SECItem encodedIssuerNameSECItem = UnsafeMapInputToSECItem(encodedIssuerName);
|
2014-07-07 02:55:38 +04:00
|
|
|
ScopedCERTCertList
|
2014-07-03 03:15:16 +04:00
|
|
|
candidates(CERT_CreateSubjectCertList(nullptr, CERT_GetDefaultCertDB(),
|
2014-08-02 10:16:21 +04:00
|
|
|
&encodedIssuerNameSECItem, 0,
|
|
|
|
false));
|
2014-07-03 03:15:16 +04:00
|
|
|
if (candidates) {
|
|
|
|
for (CERTCertListNode* n = CERT_LIST_HEAD(candidates);
|
|
|
|
!CERT_LIST_END(n, candidates); n = CERT_LIST_NEXT(n)) {
|
2014-07-31 23:17:31 +04:00
|
|
|
Input certDER;
|
2014-07-19 09:30:51 +04:00
|
|
|
Result rv = certDER.Init(n->cert->derCert.data, n->cert->derCert.len);
|
|
|
|
if (rv != Success) {
|
|
|
|
continue; // probably too big
|
2014-07-11 09:38:59 +04:00
|
|
|
}
|
2014-07-19 09:30:51 +04:00
|
|
|
|
2014-07-03 03:15:16 +04:00
|
|
|
bool keepGoing;
|
2014-07-31 23:17:31 +04:00
|
|
|
Input anssiSubject;
|
2014-07-19 09:30:51 +04:00
|
|
|
rv = anssiSubject.Init(ANSSI_SUBJECT_DATA,
|
|
|
|
sizeof(ANSSI_SUBJECT_DATA) - 1);
|
|
|
|
if (rv != Success) {
|
|
|
|
return Result::FATAL_ERROR_LIBRARY_FAILURE;
|
|
|
|
}
|
|
|
|
// TODO: Use CERT_CompareName or equivalent
|
2014-07-31 23:17:31 +04:00
|
|
|
if (InputsAreEqual(encodedIssuerName, anssiSubject)) {
|
|
|
|
Input anssiNameConstraints;
|
2014-07-19 09:30:51 +04:00
|
|
|
if (anssiNameConstraints.Init(
|
|
|
|
PERMIT_FRANCE_GOV_NAME_CONSTRAINTS_DATA,
|
|
|
|
sizeof(PERMIT_FRANCE_GOV_NAME_CONSTRAINTS_DATA) - 1)
|
|
|
|
!= Success) {
|
|
|
|
return Result::FATAL_ERROR_LIBRARY_FAILURE;
|
|
|
|
}
|
|
|
|
rv = checker.Check(certDER, &anssiNameConstraints, keepGoing);
|
|
|
|
} else {
|
|
|
|
rv = checker.Check(certDER, nullptr, keepGoing);
|
|
|
|
}
|
2014-07-18 22:48:49 +04:00
|
|
|
if (rv != Success) {
|
|
|
|
return rv;
|
2014-07-03 03:15:16 +04:00
|
|
|
}
|
|
|
|
if (!keepGoing) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-18 22:48:49 +04:00
|
|
|
return Success;
|
2014-02-10 23:41:12 +04:00
|
|
|
}
|
|
|
|
|
2014-07-18 22:48:49 +04:00
|
|
|
Result
|
2014-02-10 23:41:12 +04:00
|
|
|
NSSCertDBTrustDomain::GetCertTrust(EndEntityOrCA endEntityOrCA,
|
2014-05-16 05:59:52 +04:00
|
|
|
const CertPolicyId& policy,
|
2014-07-31 23:17:31 +04:00
|
|
|
Input candidateCertDER,
|
2014-07-20 22:06:26 +04:00
|
|
|
/*out*/ TrustLevel& trustLevel)
|
2014-02-10 23:41:12 +04:00
|
|
|
{
|
2014-02-24 10:15:53 +04:00
|
|
|
#ifdef MOZ_NO_EV_CERTS
|
2014-05-16 05:59:52 +04:00
|
|
|
if (!policy.IsAnyPolicy()) {
|
2014-07-18 22:48:49 +04:00
|
|
|
return Result::ERROR_POLICY_VALIDATION_FAILED;
|
2014-02-10 23:41:12 +04:00
|
|
|
}
|
2014-02-24 10:15:53 +04:00
|
|
|
#endif
|
2014-02-10 23:41:12 +04:00
|
|
|
|
2014-06-03 21:47:25 +04:00
|
|
|
// XXX: This would be cleaner and more efficient if we could get the trust
|
|
|
|
// information without constructing a CERTCertificate here, but NSS doesn't
|
|
|
|
// expose it in any other easy-to-use fashion. The use of
|
|
|
|
// CERT_NewTempCertificate to get a CERTCertificate shouldn't be a
|
|
|
|
// performance problem because NSS will just find the existing
|
|
|
|
// CERTCertificate in its in-memory cache and return it.
|
2014-07-31 23:17:31 +04:00
|
|
|
SECItem candidateCertDERSECItem = UnsafeMapInputToSECItem(candidateCertDER);
|
2014-06-03 21:47:25 +04:00
|
|
|
ScopedCERTCertificate candidateCert(
|
2014-07-19 09:30:51 +04:00
|
|
|
CERT_NewTempCertificate(CERT_GetDefaultCertDB(), &candidateCertDERSECItem,
|
|
|
|
nullptr, false, true));
|
2014-06-03 21:47:25 +04:00
|
|
|
if (!candidateCert) {
|
2014-07-18 22:48:49 +04:00
|
|
|
return MapPRErrorCodeToResult(PR_GetError());
|
2014-06-03 21:47:25 +04:00
|
|
|
}
|
|
|
|
|
2014-02-10 23:41:12 +04:00
|
|
|
// XXX: CERT_GetCertTrust seems to be abusing SECStatus as a boolean, where
|
|
|
|
// SECSuccess means that there is a trust record and SECFailure means there
|
|
|
|
// is not a trust record. I looked at NSS's internal uses of
|
|
|
|
// CERT_GetCertTrust, and all that code uses the result as a boolean meaning
|
|
|
|
// "We have a trust record."
|
|
|
|
CERTCertTrust trust;
|
2014-06-03 21:47:25 +04:00
|
|
|
if (CERT_GetCertTrust(candidateCert.get(), &trust) == SECSuccess) {
|
2014-08-08 16:39:07 +04:00
|
|
|
uint32_t flags = SEC_GET_TRUST_FLAGS(&trust, mCertDBTrustType);
|
2014-02-10 23:41:12 +04:00
|
|
|
|
|
|
|
// For DISTRUST, we use the CERTDB_TRUSTED or CERTDB_TRUSTED_CA bit,
|
|
|
|
// because we can have active distrust for either type of cert. Note that
|
|
|
|
// CERTDB_TERMINAL_RECORD means "stop trying to inherit trust" so if the
|
|
|
|
// relevant trust bit isn't set then that means the cert must be considered
|
|
|
|
// distrusted.
|
2014-08-08 16:39:07 +04:00
|
|
|
uint32_t relevantTrustBit =
|
2014-04-26 03:29:26 +04:00
|
|
|
endEntityOrCA == EndEntityOrCA::MustBeCA ? CERTDB_TRUSTED_CA
|
|
|
|
: CERTDB_TRUSTED;
|
2014-02-10 23:41:12 +04:00
|
|
|
if (((flags & (relevantTrustBit|CERTDB_TERMINAL_RECORD)))
|
|
|
|
== CERTDB_TERMINAL_RECORD) {
|
2014-07-20 22:06:26 +04:00
|
|
|
trustLevel = TrustLevel::ActivelyDistrusted;
|
2014-07-18 22:48:49 +04:00
|
|
|
return Success;
|
2014-02-10 23:41:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// For TRUST, we only use the CERTDB_TRUSTED_CA bit, because Gecko hasn't
|
|
|
|
// needed to consider end-entity certs to be their own trust anchors since
|
|
|
|
// Gecko implemented nsICertOverrideService.
|
|
|
|
if (flags & CERTDB_TRUSTED_CA) {
|
2014-05-16 05:59:52 +04:00
|
|
|
if (policy.IsAnyPolicy()) {
|
2014-07-20 22:06:26 +04:00
|
|
|
trustLevel = TrustLevel::TrustAnchor;
|
2014-07-18 22:48:49 +04:00
|
|
|
return Success;
|
2014-02-24 10:15:53 +04:00
|
|
|
}
|
|
|
|
#ifndef MOZ_NO_EV_CERTS
|
2014-06-03 21:47:25 +04:00
|
|
|
if (CertIsAuthoritativeForEVPolicy(candidateCert.get(), policy)) {
|
2014-07-20 22:06:26 +04:00
|
|
|
trustLevel = TrustLevel::TrustAnchor;
|
2014-07-18 22:48:49 +04:00
|
|
|
return Success;
|
2014-02-24 10:15:53 +04:00
|
|
|
}
|
|
|
|
#endif
|
2014-02-10 23:41:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-20 22:06:26 +04:00
|
|
|
trustLevel = TrustLevel::InheritsTrust;
|
2014-07-18 22:48:49 +04:00
|
|
|
return Success;
|
2014-02-10 23:41:12 +04:00
|
|
|
}
|
|
|
|
|
2014-07-18 22:48:49 +04:00
|
|
|
Result
|
2014-07-11 06:00:32 +04:00
|
|
|
NSSCertDBTrustDomain::VerifySignedData(const SignedDataWithSignature& signedData,
|
2014-07-31 23:17:31 +04:00
|
|
|
Input subjectPublicKeyInfo)
|
2014-02-10 23:41:12 +04:00
|
|
|
{
|
2014-06-06 02:18:32 +04:00
|
|
|
return ::mozilla::pkix::VerifySignedData(signedData, subjectPublicKeyInfo,
|
|
|
|
mPinArg);
|
2014-02-10 23:41:12 +04:00
|
|
|
}
|
|
|
|
|
2014-07-18 22:48:49 +04:00
|
|
|
Result
|
2014-07-31 23:17:31 +04:00
|
|
|
NSSCertDBTrustDomain::DigestBuf(Input item,
|
2014-07-07 06:36:05 +04:00
|
|
|
/*out*/ uint8_t* digestBuf, size_t digestBufLen)
|
|
|
|
{
|
|
|
|
return ::mozilla::pkix::DigestBuf(item, digestBuf, digestBufLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-02 02:07:55 +04:00
|
|
|
static PRIntervalTime
|
|
|
|
OCSPFetchingTypeToTimeoutTime(NSSCertDBTrustDomain::OCSPFetching ocspFetching)
|
|
|
|
{
|
|
|
|
switch (ocspFetching) {
|
|
|
|
case NSSCertDBTrustDomain::FetchOCSPForDVSoftFail:
|
|
|
|
return PR_SecondsToInterval(2);
|
|
|
|
case NSSCertDBTrustDomain::FetchOCSPForEV:
|
|
|
|
case NSSCertDBTrustDomain::FetchOCSPForDVHardFail:
|
|
|
|
return PR_SecondsToInterval(10);
|
|
|
|
// The rest of these are error cases. Assert in debug builds, but return
|
|
|
|
// the default value corresponding to 2 seconds in release builds.
|
|
|
|
case NSSCertDBTrustDomain::NeverFetchOCSP:
|
|
|
|
case NSSCertDBTrustDomain::LocalOnlyOCSPForEV:
|
|
|
|
PR_NOT_REACHED("we should never see this OCSPFetching type here");
|
|
|
|
default:
|
|
|
|
PR_NOT_REACHED("we're not handling every OCSPFetching type");
|
|
|
|
}
|
|
|
|
return PR_SecondsToInterval(2);
|
|
|
|
}
|
|
|
|
|
2014-06-20 21:10:51 +04:00
|
|
|
// Copied and modified from CERT_GetOCSPAuthorityInfoAccessLocation and
|
|
|
|
// CERT_GetGeneralNameByType. Returns SECFailure on error, SECSuccess
|
|
|
|
// with url == nullptr when an OCSP URI was not found, and SECSuccess with
|
|
|
|
// url != nullptr when an OCSP URI was found. The output url will be owned
|
|
|
|
// by the arena.
|
2014-07-18 22:48:49 +04:00
|
|
|
static Result
|
2014-06-20 21:10:51 +04:00
|
|
|
GetOCSPAuthorityInfoAccessLocation(PLArenaPool* arena,
|
2014-07-31 23:17:31 +04:00
|
|
|
Input aiaExtension,
|
2014-06-20 21:10:51 +04:00
|
|
|
/*out*/ char const*& url)
|
|
|
|
{
|
|
|
|
url = nullptr;
|
2014-07-31 23:17:31 +04:00
|
|
|
SECItem aiaExtensionSECItem = UnsafeMapInputToSECItem(aiaExtension);
|
2014-07-19 09:30:51 +04:00
|
|
|
CERTAuthInfoAccess** aia =
|
|
|
|
CERT_DecodeAuthInfoAccessExtension(arena, &aiaExtensionSECItem);
|
2014-06-20 21:10:51 +04:00
|
|
|
if (!aia) {
|
2014-07-18 22:48:49 +04:00
|
|
|
return Result::ERROR_CERT_BAD_ACCESS_LOCATION;
|
2014-06-20 21:10:51 +04:00
|
|
|
}
|
|
|
|
for (size_t i = 0; aia[i]; ++i) {
|
|
|
|
if (SECOID_FindOIDTag(&aia[i]->method) == SEC_OID_PKIX_OCSP) {
|
|
|
|
// NSS chooses the **last** OCSP URL; we choose the **first**
|
|
|
|
CERTGeneralName* current = aia[i]->location;
|
|
|
|
if (!current) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
if (current->type == certURI) {
|
|
|
|
const SECItem& location = current->name.other;
|
|
|
|
// (location.len + 1) must be small enough to fit into a uint32_t,
|
|
|
|
// but we limit it to a smaller bound to reduce OOM risk.
|
|
|
|
if (location.len > 1024 || memchr(location.data, 0, location.len)) {
|
|
|
|
// Reject embedded nulls. (NSS doesn't do this)
|
2014-07-18 22:48:49 +04:00
|
|
|
return Result::ERROR_CERT_BAD_ACCESS_LOCATION;
|
2014-06-20 21:10:51 +04:00
|
|
|
}
|
|
|
|
// Copy the non-null-terminated SECItem into a null-terminated string.
|
|
|
|
char* nullTerminatedURL(static_cast<char*>(
|
|
|
|
PORT_ArenaAlloc(arena, location.len + 1)));
|
|
|
|
if (!nullTerminatedURL) {
|
2014-07-18 22:48:49 +04:00
|
|
|
return Result::FATAL_ERROR_NO_MEMORY;
|
2014-06-20 21:10:51 +04:00
|
|
|
}
|
|
|
|
memcpy(nullTerminatedURL, location.data, location.len);
|
|
|
|
nullTerminatedURL[location.len] = 0;
|
|
|
|
url = nullTerminatedURL;
|
2014-07-18 22:48:49 +04:00
|
|
|
return Success;
|
2014-06-20 21:10:51 +04:00
|
|
|
}
|
|
|
|
current = CERT_GetNextGeneralName(current);
|
|
|
|
} while (current != aia[i]->location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-18 22:48:49 +04:00
|
|
|
return Success;
|
2014-06-20 21:10:51 +04:00
|
|
|
}
|
|
|
|
|
2014-07-18 22:48:49 +04:00
|
|
|
Result
|
2014-06-20 21:10:51 +04:00
|
|
|
NSSCertDBTrustDomain::CheckRevocation(EndEntityOrCA endEntityOrCA,
|
2014-08-02 19:49:12 +04:00
|
|
|
const CertID& certID, Time time,
|
2014-07-31 23:17:31 +04:00
|
|
|
/*optional*/ const Input* stapledOCSPResponse,
|
|
|
|
/*optional*/ const Input* aiaExtension)
|
2014-02-17 05:35:40 +04:00
|
|
|
{
|
|
|
|
// Actively distrusted certificates will have already been blocked by
|
|
|
|
// GetCertTrust.
|
|
|
|
|
|
|
|
// TODO: need to verify that IsRevoked isn't called for trust anchors AND
|
2014-03-21 01:29:21 +04:00
|
|
|
// that that fact is documented in mozillapkix.
|
2014-02-17 05:35:40 +04:00
|
|
|
|
|
|
|
PR_LOG(gCertVerifierLog, PR_LOG_DEBUG,
|
|
|
|
("NSSCertDBTrustDomain: Top of CheckRevocation\n"));
|
|
|
|
|
2014-05-31 03:12:36 +04:00
|
|
|
// Bug 991815: The BR allow OCSP for intermediates to be up to one year old.
|
|
|
|
// Since this affects EV there is no reason why DV should be more strict
|
|
|
|
// so all intermediatates are allowed to have OCSP responses up to one year
|
|
|
|
// old.
|
|
|
|
uint16_t maxOCSPLifetimeInDays = 10;
|
|
|
|
if (endEntityOrCA == EndEntityOrCA::MustBeCA) {
|
|
|
|
maxOCSPLifetimeInDays = 365;
|
|
|
|
}
|
|
|
|
|
2014-02-17 05:35:40 +04:00
|
|
|
// If we have a stapled OCSP response then the verification of that response
|
|
|
|
// determines the result unless the OCSP response is expired. We make an
|
|
|
|
// exception for expired responses because some servers, nginx in particular,
|
|
|
|
// are known to serve expired responses due to bugs.
|
2014-06-20 20:01:57 +04:00
|
|
|
// We keep track of the result of verifying the stapled response but don't
|
|
|
|
// immediately return failure if the response has expired.
|
2014-07-18 22:48:49 +04:00
|
|
|
Result stapledOCSPResponseResult = Success;
|
2014-02-17 05:35:40 +04:00
|
|
|
if (stapledOCSPResponse) {
|
2014-04-26 03:29:26 +04:00
|
|
|
PR_ASSERT(endEntityOrCA == EndEntityOrCA::MustBeEndEntity);
|
2014-06-20 20:01:57 +04:00
|
|
|
bool expired;
|
2014-07-18 22:48:49 +04:00
|
|
|
stapledOCSPResponseResult =
|
|
|
|
VerifyAndMaybeCacheEncodedOCSPResponse(certID, time,
|
|
|
|
maxOCSPLifetimeInDays,
|
|
|
|
*stapledOCSPResponse,
|
|
|
|
ResponseWasStapled, expired);
|
|
|
|
if (stapledOCSPResponseResult == Success) {
|
2014-03-13 20:41:03 +04:00
|
|
|
// stapled OCSP response present and good
|
|
|
|
Telemetry::Accumulate(Telemetry::SSL_OCSP_STAPLING, 1);
|
2014-03-13 00:08:48 +04:00
|
|
|
PR_LOG(gCertVerifierLog, PR_LOG_DEBUG,
|
|
|
|
("NSSCertDBTrustDomain: stapled OCSP response: good"));
|
2014-07-18 22:48:49 +04:00
|
|
|
return Success;
|
2014-02-17 05:35:40 +04:00
|
|
|
}
|
2014-07-18 22:48:49 +04:00
|
|
|
if (stapledOCSPResponseResult == Result::ERROR_OCSP_OLD_RESPONSE ||
|
2014-06-20 20:01:57 +04:00
|
|
|
expired) {
|
|
|
|
// stapled OCSP response present but expired
|
|
|
|
Telemetry::Accumulate(Telemetry::SSL_OCSP_STAPLING, 3);
|
|
|
|
PR_LOG(gCertVerifierLog, PR_LOG_DEBUG,
|
|
|
|
("NSSCertDBTrustDomain: expired stapled OCSP response"));
|
|
|
|
} else {
|
2014-03-13 20:41:03 +04:00
|
|
|
// stapled OCSP response present but invalid for some reason
|
|
|
|
Telemetry::Accumulate(Telemetry::SSL_OCSP_STAPLING, 4);
|
2014-03-13 00:08:48 +04:00
|
|
|
PR_LOG(gCertVerifierLog, PR_LOG_DEBUG,
|
|
|
|
("NSSCertDBTrustDomain: stapled OCSP response: failure"));
|
2014-07-18 22:48:49 +04:00
|
|
|
return stapledOCSPResponseResult;
|
2014-02-17 05:35:40 +04:00
|
|
|
}
|
2014-03-13 00:08:48 +04:00
|
|
|
} else {
|
2014-03-13 20:41:03 +04:00
|
|
|
// no stapled OCSP response
|
|
|
|
Telemetry::Accumulate(Telemetry::SSL_OCSP_STAPLING, 2);
|
2014-03-13 00:08:48 +04:00
|
|
|
PR_LOG(gCertVerifierLog, PR_LOG_DEBUG,
|
|
|
|
("NSSCertDBTrustDomain: no stapled OCSP response"));
|
2014-02-17 05:35:40 +04:00
|
|
|
}
|
|
|
|
|
2014-07-18 22:48:49 +04:00
|
|
|
Result cachedResponseResult = Success;
|
2014-08-02 19:49:12 +04:00
|
|
|
Time cachedResponseValidThrough(Time::uninitialized);
|
2014-06-20 21:10:51 +04:00
|
|
|
bool cachedResponsePresent = mOCSPCache.Get(certID,
|
2014-07-18 22:48:49 +04:00
|
|
|
cachedResponseResult,
|
2014-03-13 00:08:48 +04:00
|
|
|
cachedResponseValidThrough);
|
|
|
|
if (cachedResponsePresent) {
|
2014-07-18 22:48:49 +04:00
|
|
|
if (cachedResponseResult == Success && cachedResponseValidThrough >= time) {
|
2014-03-13 00:08:48 +04:00
|
|
|
PR_LOG(gCertVerifierLog, PR_LOG_DEBUG,
|
|
|
|
("NSSCertDBTrustDomain: cached OCSP response: good"));
|
2014-07-18 22:48:49 +04:00
|
|
|
return Success;
|
2014-03-13 00:08:48 +04:00
|
|
|
}
|
|
|
|
// If we have a cached revoked response, use it.
|
2014-07-18 22:48:49 +04:00
|
|
|
if (cachedResponseResult == Result::ERROR_REVOKED_CERTIFICATE) {
|
2014-03-13 00:08:48 +04:00
|
|
|
PR_LOG(gCertVerifierLog, PR_LOG_DEBUG,
|
|
|
|
("NSSCertDBTrustDomain: cached OCSP response: revoked"));
|
2014-07-18 22:48:49 +04:00
|
|
|
return Result::ERROR_REVOKED_CERTIFICATE;
|
2014-03-13 00:08:48 +04:00
|
|
|
}
|
|
|
|
// The cached response may indicate an unknown certificate or it may be
|
|
|
|
// expired. Don't return with either of these statuses yet - we may be
|
|
|
|
// able to fetch a more recent one.
|
|
|
|
PR_LOG(gCertVerifierLog, PR_LOG_DEBUG,
|
|
|
|
("NSSCertDBTrustDomain: cached OCSP response: error %ld valid "
|
2014-07-18 22:48:49 +04:00
|
|
|
"until %lld", cachedResponseResult, cachedResponseValidThrough));
|
2014-03-13 00:08:48 +04:00
|
|
|
// When a good cached response has expired, it is more convenient
|
|
|
|
// to convert that to an error code and just deal with
|
2014-07-18 22:48:49 +04:00
|
|
|
// cachedResponseResult from here on out.
|
|
|
|
if (cachedResponseResult == Success && cachedResponseValidThrough < time) {
|
|
|
|
cachedResponseResult = Result::ERROR_OCSP_OLD_RESPONSE;
|
2014-03-13 00:08:48 +04:00
|
|
|
}
|
2014-04-29 03:38:15 +04:00
|
|
|
// We may have a cached indication of server failure. Ignore it if
|
|
|
|
// it has expired.
|
2014-07-18 22:48:49 +04:00
|
|
|
if (cachedResponseResult != Success &&
|
|
|
|
cachedResponseResult != Result::ERROR_OCSP_UNKNOWN_CERT &&
|
|
|
|
cachedResponseResult != Result::ERROR_OCSP_OLD_RESPONSE &&
|
2014-04-29 03:38:15 +04:00
|
|
|
cachedResponseValidThrough < time) {
|
2014-07-18 22:48:49 +04:00
|
|
|
cachedResponseResult = Success;
|
2014-04-29 03:38:15 +04:00
|
|
|
cachedResponsePresent = false;
|
|
|
|
}
|
2014-03-13 00:08:48 +04:00
|
|
|
} else {
|
|
|
|
PR_LOG(gCertVerifierLog, PR_LOG_DEBUG,
|
|
|
|
("NSSCertDBTrustDomain: no cached OCSP response"));
|
|
|
|
}
|
2014-07-18 22:48:49 +04:00
|
|
|
// At this point, if and only if cachedErrorResult is Success, there was no
|
2014-03-13 00:08:48 +04:00
|
|
|
// cached response.
|
2014-07-18 22:48:49 +04:00
|
|
|
PR_ASSERT((!cachedResponsePresent && cachedResponseResult == Success) ||
|
|
|
|
(cachedResponsePresent && cachedResponseResult != Success));
|
2014-02-17 05:35:40 +04:00
|
|
|
|
2014-02-24 10:15:53 +04:00
|
|
|
// TODO: We still need to handle the fallback for expired responses. But,
|
|
|
|
// if/when we disable OCSP fetching by default, it would be ambiguous whether
|
|
|
|
// security.OCSP.enable==0 means "I want the default" or "I really never want
|
|
|
|
// you to ever fetch OCSP."
|
2014-02-17 05:35:40 +04:00
|
|
|
|
2014-02-24 10:15:53 +04:00
|
|
|
if ((mOCSPFetching == NeverFetchOCSP) ||
|
2014-04-26 03:29:26 +04:00
|
|
|
(endEntityOrCA == EndEntityOrCA::MustBeCA &&
|
|
|
|
(mOCSPFetching == FetchOCSPForDVHardFail ||
|
|
|
|
mOCSPFetching == FetchOCSPForDVSoftFail))) {
|
2014-03-13 00:08:48 +04:00
|
|
|
// We're not going to be doing any fetching, so if there was a cached
|
|
|
|
// "unknown" response, say so.
|
2014-07-18 22:48:49 +04:00
|
|
|
if (cachedResponseResult == Result::ERROR_OCSP_UNKNOWN_CERT) {
|
|
|
|
return Result::ERROR_OCSP_UNKNOWN_CERT;
|
2014-03-13 00:08:48 +04:00
|
|
|
}
|
|
|
|
// If we're doing hard-fail, we want to know if we have a cached response
|
|
|
|
// that has expired.
|
|
|
|
if (mOCSPFetching == FetchOCSPForDVHardFail &&
|
2014-07-18 22:48:49 +04:00
|
|
|
cachedResponseResult == Result::ERROR_OCSP_OLD_RESPONSE) {
|
|
|
|
return Result::ERROR_OCSP_OLD_RESPONSE;
|
2014-03-13 00:08:48 +04:00
|
|
|
}
|
|
|
|
|
2014-07-18 22:48:49 +04:00
|
|
|
return Success;
|
2014-02-24 10:15:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mOCSPFetching == LocalOnlyOCSPForEV) {
|
2014-07-18 22:48:49 +04:00
|
|
|
if (cachedResponseResult != Success) {
|
|
|
|
return cachedResponseResult;
|
|
|
|
}
|
|
|
|
return Result::ERROR_OCSP_UNKNOWN_CERT;
|
2014-02-24 10:15:53 +04:00
|
|
|
}
|
|
|
|
|
2014-06-20 21:10:51 +04:00
|
|
|
ScopedPLArenaPool arena(PORT_NewArena(DER_DEFAULT_CHUNKSIZE));
|
|
|
|
if (!arena) {
|
2014-07-18 22:48:49 +04:00
|
|
|
return Result::FATAL_ERROR_NO_MEMORY;
|
2014-06-20 21:10:51 +04:00
|
|
|
}
|
|
|
|
|
2014-07-18 22:48:49 +04:00
|
|
|
Result rv;
|
2014-06-20 21:10:51 +04:00
|
|
|
const char* url = nullptr; // owned by the arena
|
|
|
|
|
|
|
|
if (aiaExtension) {
|
2014-07-18 22:48:49 +04:00
|
|
|
rv = GetOCSPAuthorityInfoAccessLocation(arena.get(), *aiaExtension, url);
|
|
|
|
if (rv != Success) {
|
|
|
|
return rv;
|
2014-06-20 21:10:51 +04:00
|
|
|
}
|
|
|
|
}
|
2014-02-24 10:15:53 +04:00
|
|
|
|
|
|
|
if (!url) {
|
2014-03-13 00:08:48 +04:00
|
|
|
if (mOCSPFetching == FetchOCSPForEV ||
|
2014-07-18 22:48:49 +04:00
|
|
|
cachedResponseResult == Result::ERROR_OCSP_UNKNOWN_CERT) {
|
|
|
|
return Result::ERROR_OCSP_UNKNOWN_CERT;
|
2014-02-24 10:15:53 +04:00
|
|
|
}
|
2014-07-18 22:48:49 +04:00
|
|
|
if (cachedResponseResult == Result::ERROR_OCSP_OLD_RESPONSE) {
|
|
|
|
return Result::ERROR_OCSP_OLD_RESPONSE;
|
2014-02-24 10:15:53 +04:00
|
|
|
}
|
2014-07-18 22:48:49 +04:00
|
|
|
if (stapledOCSPResponseResult != Success) {
|
|
|
|
return stapledOCSPResponseResult;
|
2014-06-20 20:01:57 +04:00
|
|
|
}
|
2014-02-17 05:35:40 +04:00
|
|
|
|
|
|
|
// Nothing to do if we don't have an OCSP responder URI for the cert; just
|
|
|
|
// assume it is good. Note that this is the confusing, but intended,
|
|
|
|
// interpretation of "strict" revocation checking in the face of a
|
|
|
|
// certificate that lacks an OCSP responder URI.
|
2014-07-18 22:48:49 +04:00
|
|
|
return Success;
|
2014-02-24 10:15:53 +04:00
|
|
|
}
|
2014-02-17 05:35:40 +04:00
|
|
|
|
2014-04-29 03:38:15 +04:00
|
|
|
// Only request a response if we didn't have a cached indication of failure
|
|
|
|
// (don't keep requesting responses from a failing server).
|
2014-07-31 23:17:31 +04:00
|
|
|
Input response;
|
2014-07-26 03:59:22 +04:00
|
|
|
bool attemptedRequest;
|
2014-07-18 22:48:49 +04:00
|
|
|
if (cachedResponseResult == Success ||
|
|
|
|
cachedResponseResult == Result::ERROR_OCSP_UNKNOWN_CERT ||
|
|
|
|
cachedResponseResult == Result::ERROR_OCSP_OLD_RESPONSE) {
|
|
|
|
uint8_t ocspRequest[OCSP_REQUEST_MAX_LENGTH];
|
|
|
|
size_t ocspRequestLength;
|
|
|
|
rv = CreateEncodedOCSPRequest(*this, certID, ocspRequest,
|
|
|
|
ocspRequestLength);
|
|
|
|
if (rv != Success) {
|
|
|
|
return rv;
|
2014-04-29 03:38:15 +04:00
|
|
|
}
|
2014-07-18 22:48:49 +04:00
|
|
|
SECItem ocspRequestItem = {
|
|
|
|
siBuffer,
|
|
|
|
ocspRequest,
|
|
|
|
static_cast<unsigned int>(ocspRequestLength)
|
|
|
|
};
|
2014-07-19 09:30:51 +04:00
|
|
|
// Owned by arena
|
|
|
|
const SECItem* responseSECItem =
|
|
|
|
DoOCSPRequest(arena.get(), url, &ocspRequestItem,
|
|
|
|
OCSPFetchingTypeToTimeoutTime(mOCSPFetching),
|
|
|
|
mOCSPGetConfig == CertVerifier::ocsp_get_enabled);
|
|
|
|
if (!responseSECItem) {
|
2014-07-18 22:48:49 +04:00
|
|
|
rv = MapPRErrorCodeToResult(PR_GetError());
|
2014-07-19 09:30:51 +04:00
|
|
|
} else if (response.Init(responseSECItem->data, responseSECItem->len)
|
|
|
|
!= Success) {
|
|
|
|
rv = Result::ERROR_OCSP_MALFORMED_RESPONSE; // too big
|
2014-07-26 03:59:22 +04:00
|
|
|
}
|
|
|
|
attemptedRequest = true;
|
|
|
|
} else {
|
2014-07-18 22:48:49 +04:00
|
|
|
rv = cachedResponseResult;
|
2014-07-26 03:59:22 +04:00
|
|
|
attemptedRequest = false;
|
2014-02-24 10:15:53 +04:00
|
|
|
}
|
2014-02-17 05:35:40 +04:00
|
|
|
|
2014-07-19 09:30:51 +04:00
|
|
|
if (response.GetLength() == 0) {
|
2014-07-18 22:48:49 +04:00
|
|
|
Result error = rv;
|
2014-07-26 03:59:22 +04:00
|
|
|
if (attemptedRequest) {
|
2014-08-02 19:49:12 +04:00
|
|
|
Time timeout(time);
|
|
|
|
if ( timeout.AddSeconds(ServerFailureDelaySeconds) != Success) {
|
|
|
|
return Result::FATAL_ERROR_LIBRARY_FAILURE; // integer overflow
|
|
|
|
}
|
2014-07-18 22:48:49 +04:00
|
|
|
rv = mOCSPCache.Put(certID, error, time, timeout);
|
|
|
|
if (rv != Success) {
|
|
|
|
return rv;
|
2014-07-26 03:59:22 +04:00
|
|
|
}
|
2014-04-29 03:38:15 +04:00
|
|
|
}
|
2014-02-24 10:15:53 +04:00
|
|
|
if (mOCSPFetching != FetchOCSPForDVSoftFail) {
|
|
|
|
PR_LOG(gCertVerifierLog, PR_LOG_DEBUG,
|
|
|
|
("NSSCertDBTrustDomain: returning SECFailure after "
|
2014-05-02 02:07:55 +04:00
|
|
|
"OCSP request failure"));
|
2014-07-18 22:48:49 +04:00
|
|
|
return error;
|
2014-02-17 05:35:40 +04:00
|
|
|
}
|
2014-07-18 22:48:49 +04:00
|
|
|
if (cachedResponseResult == Result::ERROR_OCSP_UNKNOWN_CERT) {
|
2014-03-13 00:08:48 +04:00
|
|
|
PR_LOG(gCertVerifierLog, PR_LOG_DEBUG,
|
|
|
|
("NSSCertDBTrustDomain: returning SECFailure from cached "
|
2014-05-02 02:07:55 +04:00
|
|
|
"response after OCSP request failure"));
|
2014-07-18 22:48:49 +04:00
|
|
|
return cachedResponseResult;
|
2014-03-13 00:08:48 +04:00
|
|
|
}
|
2014-07-18 22:48:49 +04:00
|
|
|
if (stapledOCSPResponseResult != Success) {
|
2014-06-06 20:20:50 +04:00
|
|
|
PR_LOG(gCertVerifierLog, PR_LOG_DEBUG,
|
|
|
|
("NSSCertDBTrustDomain: returning SECFailure from expired "
|
|
|
|
"stapled response after OCSP request failure"));
|
2014-07-18 22:48:49 +04:00
|
|
|
return stapledOCSPResponseResult;
|
2014-06-06 20:20:50 +04:00
|
|
|
}
|
2014-02-17 05:35:40 +04:00
|
|
|
|
2014-02-24 10:15:53 +04:00
|
|
|
PR_LOG(gCertVerifierLog, PR_LOG_DEBUG,
|
|
|
|
("NSSCertDBTrustDomain: returning SECSuccess after "
|
2014-05-02 02:07:55 +04:00
|
|
|
"OCSP request failure"));
|
2014-07-18 22:48:49 +04:00
|
|
|
return Success; // Soft fail -> success :(
|
2014-02-24 10:15:53 +04:00
|
|
|
}
|
|
|
|
|
2014-06-20 20:01:57 +04:00
|
|
|
// If the response from the network has expired but indicates a revoked
|
|
|
|
// or unknown certificate, PR_GetError() will return the appropriate error.
|
|
|
|
// We actually ignore expired here.
|
|
|
|
bool expired;
|
2014-07-18 22:48:49 +04:00
|
|
|
rv = VerifyAndMaybeCacheEncodedOCSPResponse(certID, time,
|
|
|
|
maxOCSPLifetimeInDays,
|
2014-07-19 09:30:51 +04:00
|
|
|
response, ResponseIsFromNetwork,
|
2014-07-18 22:48:49 +04:00
|
|
|
expired);
|
|
|
|
if (rv == Success || mOCSPFetching != FetchOCSPForDVSoftFail) {
|
2014-02-24 10:15:53 +04:00
|
|
|
PR_LOG(gCertVerifierLog, PR_LOG_DEBUG,
|
|
|
|
("NSSCertDBTrustDomain: returning after VerifyEncodedOCSPResponse"));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-07-18 22:48:49 +04:00
|
|
|
if (rv == Result::ERROR_OCSP_UNKNOWN_CERT ||
|
|
|
|
rv == Result::ERROR_REVOKED_CERTIFICATE) {
|
2014-02-24 10:15:53 +04:00
|
|
|
return rv;
|
2014-02-17 05:35:40 +04:00
|
|
|
}
|
2014-07-18 22:48:49 +04:00
|
|
|
if (stapledOCSPResponseResult != Success) {
|
2014-06-06 20:20:50 +04:00
|
|
|
PR_LOG(gCertVerifierLog, PR_LOG_DEBUG,
|
|
|
|
("NSSCertDBTrustDomain: returning SECFailure from expired stapled "
|
|
|
|
"response after OCSP request verification failure"));
|
2014-07-18 22:48:49 +04:00
|
|
|
return stapledOCSPResponseResult;
|
2014-06-06 20:20:50 +04:00
|
|
|
}
|
|
|
|
|
2014-02-17 05:35:40 +04:00
|
|
|
PR_LOG(gCertVerifierLog, PR_LOG_DEBUG,
|
|
|
|
("NSSCertDBTrustDomain: end of CheckRevocation"));
|
|
|
|
|
2014-07-18 22:48:49 +04:00
|
|
|
return Success; // Soft fail -> success :(
|
2014-02-17 05:35:40 +04:00
|
|
|
}
|
|
|
|
|
2014-07-18 22:48:49 +04:00
|
|
|
Result
|
2014-03-13 00:08:48 +04:00
|
|
|
NSSCertDBTrustDomain::VerifyAndMaybeCacheEncodedOCSPResponse(
|
2014-08-02 19:49:12 +04:00
|
|
|
const CertID& certID, Time time, uint16_t maxLifetimeInDays,
|
2014-07-31 23:17:31 +04:00
|
|
|
Input encodedResponse, EncodedResponseSource responseSource,
|
2014-06-20 21:10:51 +04:00
|
|
|
/*out*/ bool& expired)
|
2014-03-13 00:08:48 +04:00
|
|
|
{
|
2014-08-02 19:49:12 +04:00
|
|
|
Time thisUpdate(Time::uninitialized);
|
|
|
|
Time validThrough(Time::uninitialized);
|
2014-07-18 22:48:49 +04:00
|
|
|
Result rv = VerifyEncodedOCSPResponse(*this, certID, time,
|
|
|
|
maxLifetimeInDays, encodedResponse,
|
|
|
|
expired, &thisUpdate, &validThrough);
|
2014-06-20 20:01:57 +04:00
|
|
|
// If a response was stapled and expired, we don't want to cache it. Return
|
|
|
|
// early to simplify the logic here.
|
|
|
|
if (responseSource == ResponseWasStapled && expired) {
|
2014-07-18 22:48:49 +04:00
|
|
|
PR_ASSERT(rv != Success);
|
2014-06-20 20:01:57 +04:00
|
|
|
return rv;
|
|
|
|
}
|
2014-04-29 03:38:15 +04:00
|
|
|
// validThrough is only trustworthy if the response successfully verifies
|
|
|
|
// or it indicates a revoked or unknown certificate.
|
|
|
|
// If this isn't the case, store an indication of failure (to prevent
|
|
|
|
// repeatedly requesting a response from a failing server).
|
2014-07-18 22:48:49 +04:00
|
|
|
if (rv != Success && rv != Result::ERROR_REVOKED_CERTIFICATE &&
|
|
|
|
rv != Result::ERROR_OCSP_UNKNOWN_CERT) {
|
2014-08-02 19:49:12 +04:00
|
|
|
validThrough = time;
|
|
|
|
if (validThrough.AddSeconds(ServerFailureDelaySeconds) != Success) {
|
|
|
|
return Result::FATAL_ERROR_LIBRARY_FAILURE; // integer overflow
|
|
|
|
}
|
2014-04-29 03:38:15 +04:00
|
|
|
}
|
|
|
|
if (responseSource == ResponseIsFromNetwork ||
|
2014-07-18 22:48:49 +04:00
|
|
|
rv == Success ||
|
|
|
|
rv == Result::ERROR_REVOKED_CERTIFICATE ||
|
|
|
|
rv == Result::ERROR_OCSP_UNKNOWN_CERT) {
|
2014-03-13 00:08:48 +04:00
|
|
|
PR_LOG(gCertVerifierLog, PR_LOG_DEBUG,
|
|
|
|
("NSSCertDBTrustDomain: caching OCSP response"));
|
2014-07-18 22:48:49 +04:00
|
|
|
Result putRV = mOCSPCache.Put(certID, rv, thisUpdate, validThrough);
|
|
|
|
if (putRV != Success) {
|
|
|
|
return putRV;
|
2014-03-13 00:08:48 +04:00
|
|
|
}
|
2014-04-29 03:38:15 +04:00
|
|
|
}
|
|
|
|
|
2014-03-13 00:08:48 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-07-18 22:48:49 +04:00
|
|
|
Result
|
2014-07-07 02:55:38 +04:00
|
|
|
NSSCertDBTrustDomain::IsChainValid(const DERArray& certArray)
|
|
|
|
{
|
2014-02-06 02:49:10 +04:00
|
|
|
PR_LOG(gCertVerifierLog, PR_LOG_DEBUG,
|
2014-07-07 02:55:38 +04:00
|
|
|
("NSSCertDBTrustDomain: Top of IsChainValid mCheckChainCallback=%p",
|
2014-02-06 02:49:10 +04:00
|
|
|
mCheckChainCallback));
|
|
|
|
|
2014-07-07 02:55:38 +04:00
|
|
|
if (!mBuiltChain && !mCheckChainCallback) {
|
|
|
|
// No need to create a CERTCertList, and nothing else to do.
|
2014-07-18 22:48:49 +04:00
|
|
|
return Success;
|
2014-02-06 02:49:10 +04:00
|
|
|
}
|
2014-07-07 02:55:38 +04:00
|
|
|
|
|
|
|
ScopedCERTCertList certList;
|
2014-07-18 22:48:49 +04:00
|
|
|
SECStatus srv = ConstructCERTCertListFromReversedDERArray(certArray,
|
|
|
|
certList);
|
|
|
|
if (srv != SECSuccess) {
|
|
|
|
return MapPRErrorCodeToResult(PR_GetError());
|
2014-02-06 02:49:10 +04:00
|
|
|
}
|
2014-07-07 02:55:38 +04:00
|
|
|
|
|
|
|
if (mCheckChainCallback) {
|
|
|
|
if (!mCheckChainCallback->isChainValid) {
|
2014-07-18 22:48:49 +04:00
|
|
|
return Result::FATAL_ERROR_INVALID_ARGS;
|
2014-07-07 02:55:38 +04:00
|
|
|
}
|
|
|
|
PRBool chainOK;
|
2014-07-18 22:48:49 +04:00
|
|
|
srv = (mCheckChainCallback->isChainValid)(
|
2014-07-07 02:55:38 +04:00
|
|
|
mCheckChainCallback->isChainValidArg, certList.get(), &chainOK);
|
2014-07-18 22:48:49 +04:00
|
|
|
if (srv != SECSuccess) {
|
|
|
|
return MapPRErrorCodeToResult(PR_GetError());
|
2014-07-07 02:55:38 +04:00
|
|
|
}
|
|
|
|
if (!chainOK) {
|
2014-07-18 22:48:49 +04:00
|
|
|
return Result::ERROR_KEY_PINNING_FAILURE;
|
2014-07-07 02:55:38 +04:00
|
|
|
}
|
2014-02-06 02:49:10 +04:00
|
|
|
}
|
2014-07-07 02:55:38 +04:00
|
|
|
|
|
|
|
if (mBuiltChain) {
|
|
|
|
*mBuiltChain = certList.forget();
|
|
|
|
}
|
|
|
|
|
2014-07-18 22:48:49 +04:00
|
|
|
return Success;
|
2014-02-06 02:49:10 +04:00
|
|
|
}
|
|
|
|
|
2014-07-18 22:48:49 +04:00
|
|
|
Result
|
2014-07-31 23:17:31 +04:00
|
|
|
NSSCertDBTrustDomain::CheckPublicKey(Input subjectPublicKeyInfo)
|
2014-07-16 03:49:00 +04:00
|
|
|
{
|
|
|
|
return ::mozilla::pkix::CheckPublicKey(subjectPublicKeyInfo);
|
|
|
|
}
|
|
|
|
|
2014-02-10 23:41:12 +04:00
|
|
|
namespace {
|
|
|
|
|
2014-01-21 10:10:33 +04:00
|
|
|
static char*
|
|
|
|
nss_addEscape(const char* string, char quote)
|
|
|
|
{
|
2013-09-20 00:39:36 +04:00
|
|
|
char* newString = 0;
|
2014-05-15 04:46:32 +04:00
|
|
|
size_t escapes = 0, size = 0;
|
2013-09-20 00:39:36 +04:00
|
|
|
const char* src;
|
|
|
|
char* dest;
|
|
|
|
|
|
|
|
for (src = string; *src; src++) {
|
|
|
|
if ((*src == quote) || (*src == '\\')) {
|
|
|
|
escapes++;
|
|
|
|
}
|
|
|
|
size++;
|
|
|
|
}
|
2014-01-21 10:10:33 +04:00
|
|
|
|
2014-05-15 04:46:32 +04:00
|
|
|
newString = (char*) PORT_ZAlloc(escapes + size + 1u);
|
2013-09-20 00:39:36 +04:00
|
|
|
if (!newString) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-01-21 10:10:33 +04:00
|
|
|
|
2013-09-20 00:39:36 +04:00
|
|
|
for (src = string, dest = newString; *src; src++, dest++) {
|
|
|
|
if ((*src == quote) || (*src == '\\')) {
|
|
|
|
*dest++ = '\\';
|
2014-01-21 10:10:33 +04:00
|
|
|
}
|
2013-09-20 00:39:36 +04:00
|
|
|
*dest = *src;
|
|
|
|
}
|
2014-01-21 10:10:33 +04:00
|
|
|
|
2013-09-20 00:39:36 +04:00
|
|
|
return newString;
|
2014-01-21 10:10:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // unnamed namespace
|
|
|
|
|
|
|
|
SECStatus
|
|
|
|
InitializeNSS(const char* dir, bool readOnly)
|
|
|
|
{
|
|
|
|
// The NSS_INIT_NOROOTINIT flag turns off the loading of the root certs
|
|
|
|
// module by NSS_Initialize because we will load it in InstallLoadableRoots
|
|
|
|
// later. It also allows us to work around a bug in the system NSS in
|
|
|
|
// Ubuntu 8.04, which loads any nonexistent "<configdir>/libnssckbi.so" as
|
|
|
|
// "/usr/lib/nss/libnssckbi.so".
|
|
|
|
uint32_t flags = NSS_INIT_NOROOTINIT | NSS_INIT_OPTIMIZESPACE;
|
|
|
|
if (readOnly) {
|
|
|
|
flags |= NSS_INIT_READONLY;
|
|
|
|
}
|
|
|
|
return ::NSS_Initialize(dir, "", "", SECMOD_DB, flags);
|
|
|
|
}
|
|
|
|
|
2014-01-20 13:30:25 +04:00
|
|
|
void
|
|
|
|
DisableMD5()
|
|
|
|
{
|
|
|
|
NSS_SetAlgorithmPolicy(SEC_OID_MD5,
|
|
|
|
0, NSS_USE_ALG_IN_CERT_SIGNATURE | NSS_USE_ALG_IN_CMS_SIGNATURE);
|
|
|
|
NSS_SetAlgorithmPolicy(SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION,
|
|
|
|
0, NSS_USE_ALG_IN_CERT_SIGNATURE | NSS_USE_ALG_IN_CMS_SIGNATURE);
|
|
|
|
NSS_SetAlgorithmPolicy(SEC_OID_PKCS5_PBE_WITH_MD5_AND_DES_CBC,
|
|
|
|
0, NSS_USE_ALG_IN_CERT_SIGNATURE | NSS_USE_ALG_IN_CMS_SIGNATURE);
|
|
|
|
}
|
|
|
|
|
2014-01-21 10:10:33 +04:00
|
|
|
SECStatus
|
|
|
|
LoadLoadableRoots(/*optional*/ const char* dir, const char* modNameUTF8)
|
|
|
|
{
|
|
|
|
PR_ASSERT(modNameUTF8);
|
|
|
|
|
|
|
|
if (!modNameUTF8) {
|
|
|
|
PR_SetError(SEC_ERROR_INVALID_ARGS, 0);
|
|
|
|
return SECFailure;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopedPtr<char, PR_FreeLibraryName> fullLibraryPath(
|
|
|
|
PR_GetLibraryName(dir, "nssckbi"));
|
|
|
|
if (!fullLibraryPath) {
|
|
|
|
return SECFailure;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopedPtr<char, PORT_Free_string> escaped_fullLibraryPath(
|
|
|
|
nss_addEscape(fullLibraryPath.get(), '\"'));
|
|
|
|
if (!escaped_fullLibraryPath) {
|
|
|
|
return SECFailure;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If a module exists with the same name, delete it.
|
|
|
|
int modType;
|
|
|
|
SECMOD_DeleteModule(modNameUTF8, &modType);
|
|
|
|
|
|
|
|
ScopedPtr<char, PR_smprintf_free> pkcs11ModuleSpec(
|
|
|
|
PR_smprintf("name=\"%s\" library=\"%s\"", modNameUTF8,
|
|
|
|
escaped_fullLibraryPath.get()));
|
|
|
|
if (!pkcs11ModuleSpec) {
|
|
|
|
return SECFailure;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopedSECMODModule rootsModule(SECMOD_LoadUserModule(pkcs11ModuleSpec.get(),
|
|
|
|
nullptr, false));
|
|
|
|
if (!rootsModule) {
|
|
|
|
return SECFailure;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rootsModule->loaded) {
|
|
|
|
PR_SetError(PR_INVALID_STATE_ERROR, 0);
|
|
|
|
return SECFailure;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SECSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnloadLoadableRoots(const char* modNameUTF8)
|
|
|
|
{
|
|
|
|
PR_ASSERT(modNameUTF8);
|
|
|
|
ScopedSECMODModule rootsModule(SECMOD_FindModule(modNameUTF8));
|
|
|
|
|
|
|
|
if (rootsModule) {
|
|
|
|
SECMOD_UnloadUserModule(rootsModule.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-09 03:30:59 +04:00
|
|
|
char*
|
|
|
|
DefaultServerNicknameForCert(CERTCertificate* cert)
|
|
|
|
{
|
|
|
|
char* nickname = nullptr;
|
|
|
|
int count;
|
|
|
|
bool conflict;
|
|
|
|
char* servername = nullptr;
|
|
|
|
|
|
|
|
servername = CERT_GetCommonName(&cert->subject);
|
|
|
|
if (!servername) {
|
|
|
|
// Certs without common names are strange, but they do exist...
|
|
|
|
// Let's try to use another string for the nickname
|
|
|
|
servername = CERT_GetOrgUnitName(&cert->subject);
|
|
|
|
if (!servername) {
|
|
|
|
servername = CERT_GetOrgName(&cert->subject);
|
|
|
|
if (!servername) {
|
|
|
|
servername = CERT_GetLocalityName(&cert->subject);
|
|
|
|
if (!servername) {
|
|
|
|
servername = CERT_GetStateName(&cert->subject);
|
|
|
|
if (!servername) {
|
|
|
|
servername = CERT_GetCountryName(&cert->subject);
|
|
|
|
if (!servername) {
|
|
|
|
// We tried hard, there is nothing more we can do.
|
|
|
|
// A cert without any names doesn't really make sense.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
count = 1;
|
|
|
|
while (1) {
|
|
|
|
if (count == 1) {
|
|
|
|
nickname = PR_smprintf("%s", servername);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nickname = PR_smprintf("%s #%d", servername, count);
|
|
|
|
}
|
|
|
|
if (!nickname) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
conflict = SEC_CertNicknameConflict(nickname, &cert->derSubject,
|
|
|
|
cert->dbhandle);
|
|
|
|
if (!conflict) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PR_Free(nickname);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
PR_FREEIF(servername);
|
|
|
|
return nickname;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-07 02:55:38 +04:00
|
|
|
SaveIntermediateCerts(const ScopedCERTCertList& certList)
|
2013-07-09 03:30:59 +04:00
|
|
|
{
|
|
|
|
if (!certList) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isEndEntity = true;
|
|
|
|
for (CERTCertListNode* node = CERT_LIST_HEAD(certList);
|
|
|
|
!CERT_LIST_END(node, certList);
|
|
|
|
node = CERT_LIST_NEXT(node)) {
|
|
|
|
if (isEndEntity) {
|
|
|
|
// Skip the end-entity; we only want to store intermediates
|
|
|
|
isEndEntity = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node->cert->slot) {
|
|
|
|
// This cert was found on a token, no need to remember it in the temp db.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node->cert->isperm) {
|
|
|
|
// We don't need to remember certs already stored in perm db.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have found a signer cert that we want to remember.
|
|
|
|
char* nickname = DefaultServerNicknameForCert(node->cert);
|
|
|
|
if (nickname && *nickname) {
|
|
|
|
ScopedPtr<PK11SlotInfo, PK11_FreeSlot> slot(PK11_GetInternalKeySlot());
|
|
|
|
if (slot) {
|
|
|
|
PK11_ImportCert(slot.get(), node->cert, CK_INVALID_HANDLE,
|
|
|
|
nickname, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PR_FREEIF(nickname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-21 10:10:33 +04:00
|
|
|
} } // namespace mozilla::psm
|