• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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 #ifndef NET_SSL_SSL_CONNECTION_STATUS_FLAGS_H_
6 #define NET_SSL_SSL_CONNECTION_STATUS_FLAGS_H_
7 
8 namespace net {
9 
10 // Status flags for SSLInfo::connection_status.
11 enum {
12   // The lower 16 bits are reserved for the TLS ciphersuite id.
13   SSL_CONNECTION_CIPHERSUITE_SHIFT = 0,
14   SSL_CONNECTION_CIPHERSUITE_MASK = 0xffff,
15 
16   // The next two bits are reserved for the compression used.
17   SSL_CONNECTION_COMPRESSION_SHIFT = 16,
18   SSL_CONNECTION_COMPRESSION_MASK = 3,
19 
20   // We fell back to an older protocol version for this connection.
21   SSL_CONNECTION_VERSION_FALLBACK = 1 << 18,
22 
23   // The server doesn't support the renegotiation_info extension. If this bit
24   // is not set then either the extension isn't supported, or we don't have any
25   // knowledge either way. (The latter case will occur when we use an SSL
26   // library that doesn't report it, like SChannel.)
27   SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION = 1 << 19,
28 
29   // The next three bits are reserved for the SSL version.
30   SSL_CONNECTION_VERSION_SHIFT = 20,
31   SSL_CONNECTION_VERSION_MASK = 7,
32 
33   // 1 << 31 (the sign bit) is reserved so that the SSL connection status will
34   // never be negative.
35 };
36 
37 // NOTE: the SSL version enum constants must be between 0 and
38 // SSL_CONNECTION_VERSION_MASK, inclusive.
39 enum {
40   SSL_CONNECTION_VERSION_UNKNOWN = 0,  // Unknown SSL version.
41   SSL_CONNECTION_VERSION_SSL2 = 1,
42   SSL_CONNECTION_VERSION_SSL3 = 2,
43   SSL_CONNECTION_VERSION_TLS1 = 3,
44   SSL_CONNECTION_VERSION_TLS1_1 = 4,
45   SSL_CONNECTION_VERSION_TLS1_2 = 5,
46   SSL_CONNECTION_VERSION_MAX,
47 };
48 COMPILE_ASSERT(SSL_CONNECTION_VERSION_MAX - 1 <= SSL_CONNECTION_VERSION_MASK,
49                SSL_CONNECTION_VERSION_MASK_too_small);
50 
SSLConnectionStatusToCipherSuite(int connection_status)51 inline int SSLConnectionStatusToCipherSuite(int connection_status) {
52   return (connection_status >> SSL_CONNECTION_CIPHERSUITE_SHIFT) &
53          SSL_CONNECTION_CIPHERSUITE_MASK;
54 }
55 
SSLConnectionStatusToVersion(int connection_status)56 inline int SSLConnectionStatusToVersion(int connection_status) {
57   return (connection_status >> SSL_CONNECTION_VERSION_SHIFT) &
58          SSL_CONNECTION_VERSION_MASK;
59 }
60 
61 }  // namespace net
62 
63 #endif  // NET_SSL_SSL_CONNECTION_STATUS_FLAGS_H_
64