1 // Copyright 2017 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_CERT_INTERNAL_TRUST_STORE_MAC_H_ 6 #define NET_CERT_INTERNAL_TRUST_STORE_MAC_H_ 7 8 #include <CoreFoundation/CoreFoundation.h> 9 10 #include "net/base/net_export.h" 11 #include "net/cert/internal/platform_trust_store.h" 12 #include "third_party/boringssl/src/pki/trust_store.h" 13 14 namespace net { 15 16 // TrustStoreMac is an implementation of bssl::TrustStore which uses macOS 17 // keychain to find trust anchors for path building. Trust state is cached, so a 18 // single TrustStoreMac instance should be created and used for all 19 // verifications of a given policy. TrustStoreMac objects are threadsafe and 20 // methods may be called from multiple threads simultaneously. It is the owner's 21 // responsibility to ensure the TrustStoreMac object outlives any threads 22 // accessing it. 23 class NET_EXPORT TrustStoreMac : public PlatformTrustStore { 24 public: 25 // NOTE: When updating this enum, also update ParamToTrustImplType in 26 // system_trust_store.cc 27 enum class TrustImplType { 28 // Values 1, 2, and 3 were used for implementation strategies that have 29 // since been removed. 30 kUnknown = 0, 31 kDomainCacheFullCerts = 4, 32 kKeychainCacheFullCerts = 5, 33 }; 34 35 // Creates a TrustStoreMac which will find anchors that are trusted for 36 // |policy_oid|. For list of possible policy values, see: 37 // https://developer.apple.com/reference/security/1667150-certificate_key_and_trust_servic/1670151-standard_policies_for_specific_c?language=objc 38 // |impl| selects which internal implementation is used for checking trust 39 // settings. 40 TrustStoreMac(CFStringRef policy_oid, TrustImplType impl); 41 42 TrustStoreMac(const TrustStoreMac&) = delete; 43 TrustStoreMac& operator=(const TrustStoreMac&) = delete; 44 45 ~TrustStoreMac() override; 46 47 // Initializes the trust cache, if it isn't already initialized. 48 void InitializeTrustCache() const; 49 50 // bssl::TrustStore implementation: 51 void SyncGetIssuersOf(const bssl::ParsedCertificate* cert, 52 bssl::ParsedCertificateList* issuers) override; 53 bssl::CertificateTrust GetTrust(const bssl::ParsedCertificate* cert) override; 54 55 // net::PlatformTrustStore implementation: 56 std::vector<net::PlatformTrustStore::CertWithTrust> GetAllUserAddedCerts() 57 override; 58 59 private: 60 class TrustImpl; 61 class TrustImplDomainCacheFullCerts; 62 class TrustImplKeychainCacheFullCerts; 63 64 std::unique_ptr<TrustImpl> trust_cache_; 65 }; 66 67 } // namespace net 68 69 #endif // NET_CERT_INTERNAL_TRUST_STORE_MAC_H_ 70