• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2012 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 #include "net/ssl/ssl_config_service.h"
6 
7 #include <tuple>
8 
9 #include "base/feature_list.h"
10 #include "base/observer_list.h"
11 #include "net/base/features.h"
12 
13 namespace net {
14 
15 namespace {
16 
17 // Checks if the config-service managed fields in two SSLContextConfigs are the
18 // same.
SSLContextConfigsAreEqual(const net::SSLContextConfig & config1,const net::SSLContextConfig & config2)19 bool SSLContextConfigsAreEqual(const net::SSLContextConfig& config1,
20                                const net::SSLContextConfig& config2) {
21   return std::tie(config1.version_min, config1.version_max,
22                   config1.disabled_cipher_suites, config1.post_quantum_enabled,
23                   config1.ech_enabled, config1.insecure_hash_override) ==
24          std::tie(config2.version_min, config2.version_max,
25                   config2.disabled_cipher_suites, config2.post_quantum_enabled,
26                   config2.ech_enabled, config2.insecure_hash_override);
27 }
28 
29 }  // namespace
30 
31 SSLContextConfig::SSLContextConfig() = default;
32 SSLContextConfig::SSLContextConfig(const SSLContextConfig&) = default;
33 SSLContextConfig::SSLContextConfig(SSLContextConfig&&) = default;
34 SSLContextConfig::~SSLContextConfig() = default;
35 SSLContextConfig& SSLContextConfig::operator=(const SSLContextConfig&) =
36     default;
37 SSLContextConfig& SSLContextConfig::operator=(SSLContextConfig&&) = default;
38 
EncryptedClientHelloEnabled() const39 bool SSLContextConfig::EncryptedClientHelloEnabled() const {
40   return ech_enabled &&
41          base::FeatureList::IsEnabled(features::kEncryptedClientHello);
42 }
43 
InsecureHashesInTLSHandshakesEnabled() const44 bool SSLContextConfig::InsecureHashesInTLSHandshakesEnabled() const {
45   return insecure_hash_override.value_or(
46       base::FeatureList::IsEnabled(features::kSHA1ServerSignature));
47 }
48 
SSLConfigService()49 SSLConfigService::SSLConfigService()
50     : observer_list_(base::ObserverListPolicy::EXISTING_ONLY) {}
51 
52 SSLConfigService::~SSLConfigService() = default;
53 
AddObserver(Observer * observer)54 void SSLConfigService::AddObserver(Observer* observer) {
55   observer_list_.AddObserver(observer);
56 }
57 
RemoveObserver(Observer * observer)58 void SSLConfigService::RemoveObserver(Observer* observer) {
59   observer_list_.RemoveObserver(observer);
60 }
61 
NotifySSLContextConfigChange()62 void SSLConfigService::NotifySSLContextConfigChange() {
63   for (auto& observer : observer_list_)
64     observer.OnSSLContextConfigChanged();
65 }
66 
SSLContextConfigsAreEqualForTesting(const SSLContextConfig & config1,const SSLContextConfig & config2)67 bool SSLConfigService::SSLContextConfigsAreEqualForTesting(
68     const SSLContextConfig& config1,
69     const SSLContextConfig& config2) {
70   return SSLContextConfigsAreEqual(config1, config2);
71 }
72 
ProcessConfigUpdate(const SSLContextConfig & old_config,const SSLContextConfig & new_config,bool force_notification)73 void SSLConfigService::ProcessConfigUpdate(const SSLContextConfig& old_config,
74                                            const SSLContextConfig& new_config,
75                                            bool force_notification) {
76   // Do nothing if the configuration hasn't changed.
77   if (!SSLContextConfigsAreEqual(old_config, new_config) || force_notification)
78     NotifySSLContextConfigChange();
79 }
80 
81 }  // namespace net
82