1 // Copyright 2018 The Chromium Authors. All rights reserved.
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 "services/network/ssl_config_type_converter.h"
6 
7 #include "base/logging.h"
8 
9 namespace mojo {
10 
MojoSSLVersionToNetSSLVersion(network::mojom::SSLVersion mojo_version)11 int MojoSSLVersionToNetSSLVersion(network::mojom::SSLVersion mojo_version) {
12   switch (mojo_version) {
13     case network::mojom::SSLVersion::kTLS1:
14       return net::SSL_PROTOCOL_VERSION_TLS1;
15     case network::mojom::SSLVersion::kTLS11:
16       return net::SSL_PROTOCOL_VERSION_TLS1_1;
17     case network::mojom::SSLVersion::kTLS12:
18       return net::SSL_PROTOCOL_VERSION_TLS1_2;
19     case network::mojom::SSLVersion::kTLS13:
20       return net::SSL_PROTOCOL_VERSION_TLS1_3;
21   }
22   NOTREACHED();
23   return net::SSL_PROTOCOL_VERSION_TLS1_3;
24 }
25 
MojoSSLConfigToSSLContextConfig(const network::mojom::SSLConfigPtr & mojo_config)26 net::SSLContextConfig MojoSSLConfigToSSLContextConfig(
27     const network::mojom::SSLConfigPtr& mojo_config) {
28   net::SSLContextConfig net_config;
29 
30   net_config.version_min =
31       MojoSSLVersionToNetSSLVersion(mojo_config->version_min);
32   net_config.version_min_warn =
33       MojoSSLVersionToNetSSLVersion(mojo_config->version_min_warn);
34   net_config.version_max =
35       MojoSSLVersionToNetSSLVersion(mojo_config->version_max);
36   DCHECK_LE(net_config.version_min, net_config.version_max);
37 
38   net_config.disabled_cipher_suites = mojo_config->disabled_cipher_suites;
39   net_config.tls13_hardening_for_local_anchors_enabled =
40       mojo_config->tls13_hardening_for_local_anchors_enabled;
41   return net_config;
42 }
43 
MojoSSLConfigToCertVerifierConfig(const network::mojom::SSLConfigPtr & mojo_config)44 net::CertVerifier::Config MojoSSLConfigToCertVerifierConfig(
45     const network::mojom::SSLConfigPtr& mojo_config) {
46   net::CertVerifier::Config net_config;
47   net_config.enable_rev_checking = mojo_config->rev_checking_enabled;
48   net_config.require_rev_checking_local_anchors =
49       mojo_config->rev_checking_required_local_anchors;
50   net_config.enable_sha1_local_anchors =
51       mojo_config->sha1_local_anchors_enabled;
52   net_config.disable_symantec_enforcement =
53       mojo_config->symantec_enforcement_disabled;
54 
55   return net_config;
56 }
57 
58 }  // namespace mojo
59