NSSCertDBTrustDomain.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef NSSCertDBTrustDomain_h
  6. #define NSSCertDBTrustDomain_h
  7. #include "CertVerifier.h"
  8. #include "ScopedNSSTypes.h"
  9. #include "mozilla/BasePrincipal.h"
  10. #include "nsICertBlocklist.h"
  11. #include "nsString.h"
  12. #include "pkix/pkixtypes.h"
  13. #include "secmodt.h"
  14. namespace mozilla { namespace psm {
  15. enum class ValidityCheckingMode {
  16. CheckingOff = 0,
  17. CheckForEV = 1,
  18. };
  19. // Policy options for matching id-Netscape-stepUp with id-kp-serverAuth (for CA
  20. // certificates only):
  21. // * Always match: the step-up OID is considered equivalent to serverAuth
  22. // * Match before 23 August 2016: the OID is considered equivalent if the
  23. // certificate's notBefore is before 23 August 2016
  24. // * Match before 23 August 2015: similarly, but for 23 August 2015
  25. // * Never match: the OID is never considered equivalent to serverAuth
  26. enum class NetscapeStepUpPolicy : uint32_t {
  27. AlwaysMatch = 0,
  28. MatchBefore23August2016 = 1,
  29. MatchBefore23August2015 = 2,
  30. NeverMatch = 3,
  31. };
  32. SECStatus InitializeNSS(const nsACString& dir, bool readOnly,
  33. bool loadPKCS11Modules);
  34. void DisableMD5();
  35. extern const char BUILTIN_ROOTS_MODULE_DEFAULT_NAME[];
  36. // The dir parameter is the path to the directory containing the NSS builtin
  37. // roots module. Usually this is the same as the path to the other NSS shared
  38. // libraries. If it is null then the (library) path will be searched.
  39. //
  40. // The modNameUTF8 parameter should usually be
  41. // BUILTIN_ROOTS_MODULE_DEFAULT_NAME.
  42. SECStatus LoadLoadableRoots(/*optional*/ const char* dir,
  43. const char* modNameUTF8);
  44. void UnloadLoadableRoots(const char* modNameUTF8);
  45. nsresult DefaultServerNicknameForCert(const CERTCertificate* cert,
  46. /*out*/ nsCString& nickname);
  47. void SaveIntermediateCerts(const UniqueCERTCertList& certList);
  48. class NSSCertDBTrustDomain : public mozilla::pkix::TrustDomain
  49. {
  50. public:
  51. typedef mozilla::pkix::Result Result;
  52. enum OCSPFetching {
  53. NeverFetchOCSP = 0,
  54. FetchOCSPForDVSoftFail = 1,
  55. FetchOCSPForDVHardFail = 2,
  56. FetchOCSPForEV = 3,
  57. LocalOnlyOCSPForEV = 4,
  58. };
  59. NSSCertDBTrustDomain(SECTrustType certDBTrustType, OCSPFetching ocspFetching,
  60. OCSPCache& ocspCache, void* pinArg,
  61. CertVerifier::OcspGetConfig ocspGETConfig,
  62. uint32_t certShortLifetimeInDays,
  63. unsigned int minRSABits,
  64. ValidityCheckingMode validityCheckingMode,
  65. CertVerifier::SHA1Mode sha1Mode,
  66. NetscapeStepUpPolicy netscapeStepUpPolicy,
  67. const NeckoOriginAttributes& originAttributes,
  68. UniqueCERTCertList& builtChain);
  69. virtual Result FindIssuer(mozilla::pkix::Input encodedIssuerName,
  70. IssuerChecker& checker,
  71. mozilla::pkix::Time time) override;
  72. virtual Result GetCertTrust(mozilla::pkix::EndEntityOrCA endEntityOrCA,
  73. const mozilla::pkix::CertPolicyId& policy,
  74. mozilla::pkix::Input candidateCertDER,
  75. /*out*/ mozilla::pkix::TrustLevel& trustLevel)
  76. override;
  77. virtual Result CheckSignatureDigestAlgorithm(
  78. mozilla::pkix::DigestAlgorithm digestAlg,
  79. mozilla::pkix::EndEntityOrCA endEntityOrCA,
  80. mozilla::pkix::Time notBefore) override;
  81. virtual Result CheckRSAPublicKeyModulusSizeInBits(
  82. mozilla::pkix::EndEntityOrCA endEntityOrCA,
  83. unsigned int modulusSizeInBits) override;
  84. virtual Result VerifyRSAPKCS1SignedDigest(
  85. const mozilla::pkix::SignedDigest& signedDigest,
  86. mozilla::pkix::Input subjectPublicKeyInfo) override;
  87. virtual Result CheckECDSACurveIsAcceptable(
  88. mozilla::pkix::EndEntityOrCA endEntityOrCA,
  89. mozilla::pkix::NamedCurve curve) override;
  90. virtual Result VerifyECDSASignedDigest(
  91. const mozilla::pkix::SignedDigest& signedDigest,
  92. mozilla::pkix::Input subjectPublicKeyInfo) override;
  93. virtual Result DigestBuf(mozilla::pkix::Input item,
  94. mozilla::pkix::DigestAlgorithm digestAlg,
  95. /*out*/ uint8_t* digestBuf,
  96. size_t digestBufLen) override;
  97. virtual Result CheckValidityIsAcceptable(
  98. mozilla::pkix::Time notBefore, mozilla::pkix::Time notAfter,
  99. mozilla::pkix::EndEntityOrCA endEntityOrCA,
  100. mozilla::pkix::KeyPurposeId keyPurpose) override;
  101. virtual Result NetscapeStepUpMatchesServerAuth(
  102. mozilla::pkix::Time notBefore,
  103. /*out*/ bool& matches) override;
  104. virtual Result CheckRevocation(
  105. mozilla::pkix::EndEntityOrCA endEntityOrCA,
  106. const mozilla::pkix::CertID& certID,
  107. mozilla::pkix::Time time,
  108. mozilla::pkix::Duration validityDuration,
  109. /*optional*/ const mozilla::pkix::Input* stapledOCSPResponse,
  110. /*optional*/ const mozilla::pkix::Input* aiaExtension,
  111. /*optional*/ const mozilla::pkix::Input* sctExtension)
  112. override;
  113. virtual Result IsChainValid(const mozilla::pkix::DERArray& certChain,
  114. mozilla::pkix::Time time,
  115. const mozilla::pkix::CertPolicyId& requiredPolicy) override;
  116. virtual void NoteAuxiliaryExtension(
  117. mozilla::pkix::AuxiliaryExtension extension,
  118. mozilla::pkix::Input extensionData) override;
  119. // Resets the OCSP stapling status and SCT lists accumulated during
  120. // the chain building.
  121. void ResetAccumulatedState();
  122. CertVerifier::OCSPStaplingStatus GetOCSPStaplingStatus() const
  123. {
  124. return mOCSPStaplingStatus;
  125. }
  126. // SCT lists (see Certificate Transparency) extracted during
  127. // certificate verification. Note that the returned Inputs are invalidated
  128. // the next time a chain is built and by ResetAccumulatedState method
  129. // (and when the TrustDomain object is destroyed).
  130. mozilla::pkix::Input GetSCTListFromCertificate() const;
  131. mozilla::pkix::Input GetSCTListFromOCSPStapling() const;
  132. private:
  133. enum EncodedResponseSource {
  134. ResponseIsFromNetwork = 1,
  135. ResponseWasStapled = 2
  136. };
  137. Result VerifyAndMaybeCacheEncodedOCSPResponse(
  138. const mozilla::pkix::CertID& certID, mozilla::pkix::Time time,
  139. uint16_t maxLifetimeInDays, mozilla::pkix::Input encodedResponse,
  140. EncodedResponseSource responseSource, /*out*/ bool& expired);
  141. const SECTrustType mCertDBTrustType;
  142. const OCSPFetching mOCSPFetching;
  143. OCSPCache& mOCSPCache; // non-owning!
  144. void* mPinArg; // non-owning!
  145. const CertVerifier::OcspGetConfig mOCSPGetConfig;
  146. const uint32_t mCertShortLifetimeInDays;
  147. const unsigned int mMinRSABits;
  148. ValidityCheckingMode mValidityCheckingMode;
  149. CertVerifier::SHA1Mode mSHA1Mode;
  150. NetscapeStepUpPolicy mNetscapeStepUpPolicy;
  151. const NeckoOriginAttributes& mOriginAttributes;
  152. UniqueCERTCertList& mBuiltChain; // non-owning
  153. nsCOMPtr<nsICertBlocklist> mCertBlocklist;
  154. CertVerifier::OCSPStaplingStatus mOCSPStaplingStatus;
  155. // Certificate Transparency data extracted during certificate verification
  156. UniqueSECItem mSCTListFromCertificate;
  157. UniqueSECItem mSCTListFromOCSPStapling;
  158. };
  159. } } // namespace mozilla::psm
  160. #endif // NSSCertDBTrustDomain_h