2017
[folly.git] / folly / io / async / ssl / TLSDefinitions.h
1 /*
2  * Copyright 2017 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #pragma once
18
19 #include <folly/io/Cursor.h>
20 #include <folly/io/IOBuf.h>
21 #include <map>
22 #include <vector>
23
24 namespace folly {
25 namespace ssl {
26
27 // http://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml
28 enum class TLSExtension : uint16_t {
29   SERVER_NAME = 0,
30   MAX_FRAGMENT_LENGTH = 1,
31   CLIENT_CERTIFICATE_URL = 2,
32   TRUSTED_CA_KEYS = 3,
33   TRUNCATED_HMAC = 4,
34   STATUS_REQUEST = 5,
35   USER_MAPPING = 6,
36   CLIENT_AUTHZ = 7,
37   SERVER_AUTHZ = 8,
38   CERT_TYPE = 9,
39   SUPPORTED_GROUPS = 10,
40   EC_POINT_FORMATS = 11,
41   SRP = 12,
42   SIGNATURE_ALGORITHMS = 13,
43   USE_SRTP = 14,
44   HEARTBEAT = 15,
45   APPLICATION_LAYER_PROTOCOL_NEGOTIATION = 16,
46   STATUS_REQUEST_V2 = 17,
47   SIGNED_CERTIFICATE_TIMESTAMP = 18,
48   CLIENT_CERTIFICATE_TYPE = 19,
49   SERVER_CERTIFICATE_TYPE = 20,
50   PADDING = 21,
51   ENCRYPT_THEN_MAC = 22,
52   EXTENDED_MASTER_SECRET = 23,
53   SESSION_TICKET = 35,
54   SUPPORTED_VERSIONS = 43,
55   // Facebook-specific, not IANA assigned yet
56   TLS_CACHED_INFO_FB = 60001,
57   // End Facebook-specific
58   RENEGOTIATION_INFO = 65281
59 };
60
61 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-18
62 enum class HashAlgorithm : uint8_t {
63   NONE = 0,
64   MD5 = 1,
65   SHA1 = 2,
66   SHA224 = 3,
67   SHA256 = 4,
68   SHA384 = 5,
69   SHA512 = 6
70 };
71
72 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-16
73 enum class SignatureAlgorithm : uint8_t {
74   ANONYMOUS = 0,
75   RSA = 1,
76   DSA = 2,
77   ECDSA = 3
78 };
79
80 struct ClientHelloInfo {
81   folly::IOBufQueue clientHelloBuf_;
82   uint8_t clientHelloMajorVersion_;
83   uint8_t clientHelloMinorVersion_;
84   std::vector<uint16_t> clientHelloCipherSuites_;
85   std::vector<uint8_t> clientHelloCompressionMethods_;
86   std::vector<TLSExtension> clientHelloExtensions_;
87   std::vector<std::pair<HashAlgorithm, SignatureAlgorithm>> clientHelloSigAlgs_;
88   std::vector<uint16_t> clientHelloSupportedVersions_;
89 };
90
91 } // ssl
92 } // folly