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: */
|
2012-10-27 11:11:35 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
2016-05-06 00:56:36 +03:00
|
|
|
#ifndef CertVerifier_h
|
|
|
|
#define CertVerifier_h
|
2012-10-27 11:11:35 +04:00
|
|
|
|
2016-02-09 21:14:27 +03:00
|
|
|
#include "BRNameMatchingPolicy.h"
|
2017-01-09 09:22:28 +03:00
|
|
|
#include "CTPolicyEnforcer.h"
|
2016-08-11 13:41:50 +03:00
|
|
|
#include "CTVerifyResult.h"
|
2014-03-13 00:08:48 +04:00
|
|
|
#include "OCSPCache.h"
|
2018-06-18 12:31:47 +03:00
|
|
|
#include "RootCertificateTelemetryUtils.h"
|
2014-07-07 02:55:38 +04:00
|
|
|
#include "ScopedNSSTypes.h"
|
2016-02-09 21:14:27 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2017-04-01 01:21:40 +03:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2016-08-11 13:41:50 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2017-06-03 08:35:51 +03:00
|
|
|
#include "nsString.h"
|
2018-10-02 15:59:34 +03:00
|
|
|
#include "mozpkix/pkixtypes.h"
|
2012-10-27 11:11:35 +04:00
|
|
|
|
2016-11-23 09:56:20 +03:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#pragma warning(push)
|
|
|
|
// Silence "RootingAPI.h(718): warning C4324: 'js::DispatchWrapper<T>':
|
|
|
|
// structure was padded due to alignment specifier with [ T=void * ]"
|
|
|
|
#pragma warning(disable : 4324)
|
|
|
|
#endif /* defined(_MSC_VER) */
|
|
|
|
#include "mozilla/BasePrincipal.h"
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#pragma warning(pop) /* popping the pragma in this file */
|
|
|
|
#endif /* defined(_MSC_VER) */
|
|
|
|
|
2016-08-11 13:41:50 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace ct {
|
|
|
|
|
2017-01-09 09:22:28 +03:00
|
|
|
// Including the headers of the classes below would bring along all of their
|
|
|
|
// dependent headers and force us to export them in moz.build.
|
|
|
|
// Just forward-declare the classes here instead.
|
2016-08-11 13:41:50 +03:00
|
|
|
class MultiLogCTVerifier;
|
2017-01-09 09:22:28 +03:00
|
|
|
class CTDiversityPolicy;
|
2016-08-11 13:41:50 +03:00
|
|
|
|
|
|
|
} // namespace ct
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2012-10-27 11:11:35 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace psm {
|
|
|
|
|
2016-10-31 12:05:13 +03:00
|
|
|
typedef mozilla::pkix::Result Result;
|
|
|
|
|
2015-02-25 02:48:05 +03:00
|
|
|
// These values correspond to the CERT_CHAIN_KEY_SIZE_STATUS telemetry.
|
|
|
|
enum class KeySizeStatus {
|
|
|
|
NeverChecked = 0,
|
|
|
|
LargeMinimumSucceeded = 1,
|
|
|
|
CompatibilityRisk = 2,
|
|
|
|
AlreadyBad = 3,
|
|
|
|
};
|
|
|
|
|
2016-01-13 23:50:42 +03:00
|
|
|
// These values correspond to the CERT_CHAIN_SHA1_POLICY_STATUS telemetry.
|
|
|
|
enum class SHA1ModeResult {
|
2015-07-09 09:22:29 +03:00
|
|
|
NeverChecked = 0,
|
2016-01-13 23:50:42 +03:00
|
|
|
SucceededWithoutSHA1 = 1,
|
2016-09-15 01:11:15 +03:00
|
|
|
SucceededWithImportedRoot = 2,
|
|
|
|
SucceededWithImportedRootOrSHA1Before2016 = 3,
|
2016-01-13 23:50:42 +03:00
|
|
|
SucceededWithSHA1 = 4,
|
|
|
|
Failed = 5,
|
2015-07-09 09:22:29 +03:00
|
|
|
};
|
|
|
|
|
2018-02-28 02:04:51 +03:00
|
|
|
// Whether or not we are enforcing one of our CA distrust policies. For context,
|
|
|
|
// see Bug 1437754 and Bug 1409257.
|
2018-05-08 01:46:22 +03:00
|
|
|
enum DistrustedCAPolicy : uint32_t {
|
|
|
|
Permit = 0b0000,
|
|
|
|
DistrustSymantecRoots = 0b0001,
|
|
|
|
DistrustSymantecRootsRegardlessOfDate = 0b0010,
|
2018-02-28 02:04:51 +03:00
|
|
|
};
|
2018-05-08 01:46:22 +03:00
|
|
|
|
|
|
|
// Bitmask by nsNSSComponent to check for wholly-invalid values; be sure to
|
|
|
|
// update this to account for new entries in DistrustedCAPolicy.
|
|
|
|
const uint32_t DistrustedCAPolicyMaxAllowedValueMask = 0b0011;
|
2018-02-28 02:04:51 +03:00
|
|
|
|
2016-05-06 02:11:11 +03:00
|
|
|
enum class NetscapeStepUpPolicy : uint32_t;
|
|
|
|
|
2015-08-21 17:14:08 +03:00
|
|
|
class PinningTelemetryInfo {
|
|
|
|
public:
|
2018-06-18 12:31:47 +03:00
|
|
|
PinningTelemetryInfo()
|
|
|
|
: certPinningResultBucket(0), rootBucket(ROOT_CERTIFICATE_UNKNOWN) {
|
|
|
|
Reset();
|
|
|
|
}
|
2017-02-14 03:47:43 +03:00
|
|
|
|
2015-08-21 17:14:08 +03:00
|
|
|
// Should we accumulate pinning telemetry for the result?
|
|
|
|
bool accumulateResult;
|
2018-06-18 12:31:47 +03:00
|
|
|
Maybe<Telemetry::HistogramID> certPinningResultHistogram;
|
2015-08-21 17:14:08 +03:00
|
|
|
int32_t certPinningResultBucket;
|
|
|
|
// Should we accumulate telemetry for the root?
|
|
|
|
bool accumulateForRoot;
|
|
|
|
int32_t rootBucket;
|
|
|
|
|
|
|
|
void Reset() {
|
|
|
|
accumulateForRoot = false;
|
|
|
|
accumulateResult = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-11 13:41:50 +03:00
|
|
|
class CertificateTransparencyInfo {
|
|
|
|
public:
|
2018-06-18 12:31:47 +03:00
|
|
|
CertificateTransparencyInfo()
|
|
|
|
: enabled(false),
|
|
|
|
policyCompliance(mozilla::ct::CTPolicyCompliance::Unknown) {
|
|
|
|
Reset();
|
|
|
|
}
|
2017-02-14 03:47:43 +03:00
|
|
|
|
2016-08-11 13:41:50 +03:00
|
|
|
// Was CT enabled?
|
|
|
|
bool enabled;
|
|
|
|
// Verification result of the processed SCTs.
|
|
|
|
mozilla::ct::CTVerifyResult verifyResult;
|
2017-01-09 09:22:28 +03:00
|
|
|
// Connection compliance to the CT Policy.
|
|
|
|
mozilla::ct::CTPolicyCompliance policyCompliance;
|
2016-08-11 13:41:50 +03:00
|
|
|
|
2017-01-09 09:22:28 +03:00
|
|
|
void Reset();
|
2016-08-11 13:41:50 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class NSSCertDBTrustDomain;
|
|
|
|
|
2012-10-27 11:11:35 +04:00
|
|
|
class CertVerifier {
|
|
|
|
public:
|
|
|
|
typedef unsigned int Flags;
|
2014-01-17 23:04:09 +04:00
|
|
|
// XXX: FLAG_LOCAL_ONLY is ignored in the classic verification case
|
2012-10-27 11:11:35 +04:00
|
|
|
static const Flags FLAG_LOCAL_ONLY;
|
2014-01-17 23:04:09 +04:00
|
|
|
// Don't perform fallback DV validation on EV validation failure.
|
2014-01-25 01:57:35 +04:00
|
|
|
static const Flags FLAG_MUST_BE_EV;
|
2015-11-13 19:49:08 +03:00
|
|
|
// TLS feature request_status should be ignored
|
|
|
|
static const Flags FLAG_TLS_IGNORE_STATUS_REQUEST;
|
2012-10-27 11:11:35 +04:00
|
|
|
|
2014-12-12 10:22:35 +03:00
|
|
|
// These values correspond to the SSL_OCSP_STAPLING telemetry.
|
|
|
|
enum OCSPStaplingStatus {
|
|
|
|
OCSP_STAPLING_NEVER_CHECKED = 0,
|
|
|
|
OCSP_STAPLING_GOOD = 1,
|
|
|
|
OCSP_STAPLING_NONE = 2,
|
|
|
|
OCSP_STAPLING_EXPIRED = 3,
|
|
|
|
OCSP_STAPLING_INVALID = 4,
|
|
|
|
};
|
|
|
|
|
2012-10-27 11:11:35 +04:00
|
|
|
// *evOidPolicy == SEC_OID_UNKNOWN means the cert is NOT EV
|
2013-12-07 01:42:44 +04:00
|
|
|
// Only one usage per verification is supported.
|
2016-10-10 10:44:41 +03:00
|
|
|
mozilla::pkix::Result VerifyCert(
|
|
|
|
CERTCertificate* cert, SECCertificateUsage usage,
|
|
|
|
mozilla::pkix::Time time, void* pinArg, const char* hostname,
|
|
|
|
/*out*/ UniqueCERTCertList& builtChain, Flags flags = 0,
|
|
|
|
/*optional in*/ const SECItem* stapledOCSPResponse = nullptr,
|
|
|
|
/*optional in*/ const SECItem* sctsFromTLS = nullptr,
|
2017-01-12 19:38:48 +03:00
|
|
|
/*optional in*/ const OriginAttributes& originAttributes =
|
|
|
|
OriginAttributes(),
|
2016-10-10 10:44:41 +03:00
|
|
|
/*optional out*/ SECOidTag* evOidPolicy = nullptr,
|
|
|
|
/*optional out*/ OCSPStaplingStatus* ocspStaplingStatus = nullptr,
|
|
|
|
/*optional out*/ KeySizeStatus* keySizeStatus = nullptr,
|
|
|
|
/*optional out*/ SHA1ModeResult* sha1ModeResult = nullptr,
|
|
|
|
/*optional out*/ PinningTelemetryInfo* pinningTelemetryInfo = nullptr,
|
|
|
|
/*optional out*/ CertificateTransparencyInfo* ctInfo = nullptr);
|
|
|
|
|
|
|
|
mozilla::pkix::Result VerifySSLServerCert(
|
2016-04-20 11:14:22 +03:00
|
|
|
const UniqueCERTCertificate& peerCert,
|
2013-09-28 06:53:36 +04:00
|
|
|
/*optional*/ const SECItem* stapledOCSPResponse,
|
2016-08-11 13:41:50 +03:00
|
|
|
/*optional*/ const SECItem* sctsFromTLS, mozilla::pkix::Time time,
|
2017-06-03 08:35:51 +03:00
|
|
|
/*optional*/ void* pinarg, const nsACString& hostname,
|
2016-05-06 00:56:36 +03:00
|
|
|
/*out*/ UniqueCERTCertList& builtChain,
|
2016-01-13 23:50:42 +03:00
|
|
|
/*optional*/ bool saveIntermediatesInPermanentDatabase = false,
|
|
|
|
/*optional*/ Flags flags = 0,
|
2017-01-12 19:38:48 +03:00
|
|
|
/*optional*/ const OriginAttributes& originAttributes =
|
|
|
|
OriginAttributes(),
|
2014-12-12 10:22:35 +03:00
|
|
|
/*optional out*/ SECOidTag* evOidPolicy = nullptr,
|
2015-02-25 02:48:05 +03:00
|
|
|
/*optional out*/ OCSPStaplingStatus* ocspStaplingStatus = nullptr,
|
2015-07-09 09:22:29 +03:00
|
|
|
/*optional out*/ KeySizeStatus* keySizeStatus = nullptr,
|
2016-01-13 23:50:42 +03:00
|
|
|
/*optional out*/ SHA1ModeResult* sha1ModeResult = nullptr,
|
2016-08-11 13:41:50 +03:00
|
|
|
/*optional out*/ PinningTelemetryInfo* pinningTelemetryInfo = nullptr,
|
|
|
|
/*optional out*/ CertificateTransparencyInfo* ctInfo = nullptr);
|
2013-07-09 03:30:59 +04:00
|
|
|
|
2014-09-25 22:08:36 +04:00
|
|
|
enum PinningMode {
|
2014-02-06 02:49:10 +04:00
|
|
|
pinningDisabled = 0,
|
|
|
|
pinningAllowUserCAMITM = 1,
|
2014-05-20 00:04:40 +04:00
|
|
|
pinningStrict = 2,
|
|
|
|
pinningEnforceTestMode = 3
|
2014-02-06 02:49:10 +04:00
|
|
|
};
|
|
|
|
|
2015-09-11 21:52:30 +03:00
|
|
|
enum class SHA1Mode {
|
|
|
|
Allowed = 0,
|
|
|
|
Forbidden = 1,
|
2016-09-15 01:11:15 +03:00
|
|
|
// There used to be a policy that only allowed SHA1 for certificates issued
|
|
|
|
// before 2016. This is no longer available. If a user has selected this
|
|
|
|
// policy in about:config, it now maps to Forbidden.
|
|
|
|
UsedToBeBefore2016ButNowIsForbidden = 2,
|
2016-01-13 23:50:42 +03:00
|
|
|
ImportedRoot = 3,
|
2016-09-15 01:11:15 +03:00
|
|
|
ImportedRootOrBefore2016 = 4,
|
2015-09-11 21:52:30 +03:00
|
|
|
};
|
|
|
|
|
2015-05-28 23:29:13 +03:00
|
|
|
enum OcspDownloadConfig { ocspOff = 0, ocspOn = 1, ocspEVOnly = 2 };
|
2015-01-23 08:17:00 +03:00
|
|
|
enum OcspStrictConfig { ocspRelaxed = 0, ocspStrict };
|
2012-10-27 11:11:35 +04:00
|
|
|
|
2016-08-11 13:41:50 +03:00
|
|
|
enum class CertificateTransparencyMode {
|
|
|
|
Disabled = 0,
|
|
|
|
TelemetryOnly = 1,
|
|
|
|
};
|
|
|
|
|
bug 1456489 - prevent making OCSP requests on the main thread r=fkiefer,jcj
OCSP requests cannot be performed on the main thread. If we were to wait for a
response from the network, we would be blocking the main thread for an
unnaceptably long time. If we were to spin the event loop while waiting (which
is what we do currently), other parts of the code that assume this will never
happen (which is essentially all of them) can break.
As of bug 867473, no certificate verification happens on the main thread, so no
OCSP requests happen on the main thread. Given this, we can go ahead and
prohibit such requests.
Incidentally, this gives us an opportunity to improve the current OCSP
implementation, which has a few drawbacks (the largest of which is that it's
unclear that its ownership model is implemented correctly).
This also removes OCSP GET support. Due to recent OCSP server implementations
(namely, the ability to cache OCSP POST request responses), OCSP GET is not a
compelling technology to pursue. Furthermore, continued support presents a
maintenance burden.
MozReview-Commit-ID: 4ACDY09nCBA
--HG--
extra : rebase_source : 072564adf1836720e147b8250afca7cebe4dbf62
2018-04-23 19:09:35 +03:00
|
|
|
CertVerifier(OcspDownloadConfig odc, OcspStrictConfig osc,
|
2017-04-01 01:21:40 +03:00
|
|
|
mozilla::TimeDuration ocspTimeoutSoft,
|
|
|
|
mozilla::TimeDuration ocspTimeoutHard,
|
|
|
|
uint32_t certShortLifetimeInDays, PinningMode pinningMode,
|
2016-05-06 02:11:11 +03:00
|
|
|
SHA1Mode sha1Mode, BRNameMatchingPolicy::Mode nameMatchingMode,
|
2016-08-11 13:41:50 +03:00
|
|
|
NetscapeStepUpPolicy netscapeStepUpPolicy,
|
2018-02-28 02:04:51 +03:00
|
|
|
CertificateTransparencyMode ctMode,
|
|
|
|
DistrustedCAPolicy distrustedCAPolicy);
|
2012-10-27 11:11:35 +04:00
|
|
|
~CertVerifier();
|
|
|
|
|
2014-03-13 00:08:48 +04:00
|
|
|
void ClearOCSPCache() { mOCSPCache.Clear(); }
|
|
|
|
|
2015-05-28 23:29:13 +03:00
|
|
|
const OcspDownloadConfig mOCSPDownloadConfig;
|
2012-10-27 11:11:35 +04:00
|
|
|
const bool mOCSPStrict;
|
2017-04-01 01:21:40 +03:00
|
|
|
const mozilla::TimeDuration mOCSPTimeoutSoft;
|
|
|
|
const mozilla::TimeDuration mOCSPTimeoutHard;
|
2015-04-07 02:10:28 +03:00
|
|
|
const uint32_t mCertShortLifetimeInDays;
|
2014-09-25 22:08:36 +04:00
|
|
|
const PinningMode mPinningMode;
|
2015-09-11 21:52:30 +03:00
|
|
|
const SHA1Mode mSHA1Mode;
|
2016-02-09 21:14:27 +03:00
|
|
|
const BRNameMatchingPolicy::Mode mNameMatchingMode;
|
2016-05-06 02:11:11 +03:00
|
|
|
const NetscapeStepUpPolicy mNetscapeStepUpPolicy;
|
2016-08-11 13:41:50 +03:00
|
|
|
const CertificateTransparencyMode mCTMode;
|
2018-02-28 02:04:51 +03:00
|
|
|
const DistrustedCAPolicy mDistrustedCAPolicy;
|
2014-02-10 23:41:12 +04:00
|
|
|
|
|
|
|
private:
|
2014-03-13 00:08:48 +04:00
|
|
|
OCSPCache mOCSPCache;
|
2016-01-13 23:50:42 +03:00
|
|
|
|
2017-01-09 09:22:28 +03:00
|
|
|
// We only have a forward declarations of these classes (see above)
|
|
|
|
// so we must allocate dynamically.
|
2016-08-11 13:41:50 +03:00
|
|
|
UniquePtr<mozilla::ct::MultiLogCTVerifier> mCTVerifier;
|
2017-01-09 09:22:28 +03:00
|
|
|
UniquePtr<mozilla::ct::CTDiversityPolicy> mCTDiversityPolicy;
|
2016-08-11 13:41:50 +03:00
|
|
|
|
|
|
|
void LoadKnownCTLogs();
|
2017-01-09 09:22:28 +03:00
|
|
|
mozilla::pkix::Result VerifyCertificateTransparencyPolicy(
|
2016-08-11 13:41:50 +03:00
|
|
|
NSSCertDBTrustDomain& trustDomain, const UniqueCERTCertList& builtChain,
|
|
|
|
mozilla::pkix::Input sctsFromTLS, mozilla::pkix::Time time,
|
|
|
|
/*optional out*/ CertificateTransparencyInfo* ctInfo);
|
|
|
|
|
2016-01-13 23:50:42 +03:00
|
|
|
// Returns true if the configured SHA1 mode is more restrictive than the given
|
|
|
|
// mode. SHA1Mode::Forbidden is more restrictive than any other mode except
|
2016-09-15 01:11:15 +03:00
|
|
|
// Forbidden. Next is ImportedRoot, then ImportedRootOrBefore2016, then
|
|
|
|
// Allowed. (A mode is never more restrictive than itself.)
|
2016-01-13 23:50:42 +03:00
|
|
|
bool SHA1ModeMoreRestrictiveThanGivenMode(SHA1Mode mode);
|
2012-10-27 11:11:35 +04:00
|
|
|
};
|
|
|
|
|
2016-03-05 04:06:33 +03:00
|
|
|
mozilla::pkix::Result IsCertBuiltInRoot(CERTCertificate* cert, bool& result);
|
2014-09-25 22:18:56 +04:00
|
|
|
mozilla::pkix::Result CertListContainsExpectedKeys(
|
|
|
|
const CERTCertList* certList, const char* hostname,
|
|
|
|
mozilla::pkix::Time time, CertVerifier::PinningMode pinningMode);
|
2014-09-03 22:44:08 +04:00
|
|
|
|
2012-10-27 11:11:35 +04:00
|
|
|
} // namespace psm
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2016-05-06 00:56:36 +03:00
|
|
|
#endif // CertVerifier_h
|