cf803d10357be1a37e321980108458442a44218a
[folly.git] / folly / io / async / ssl / TLSDefinitions.h
1 /*
2  * Copyright 2016 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 <openssl/ssl.h>
23 #include <openssl/tls1.h>
24 #include <vector>
25
26 namespace folly {
27 namespace ssl {
28
29 // http://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml
30 enum class TLSExtension : uint16_t {
31   SERVER_NAME = 0,
32   MAX_FRAGMENT_LENGTH = 1,
33   CLIENT_CERTIFICATE_URL = 2,
34   TRUSTED_CA_KEYS = 3,
35   TRUNCATED_HMAC = 4,
36   STATUS_REQUEST = 5,
37   USER_MAPPING = 6,
38   CLIENT_AUTHZ = 7,
39   SERVER_AUTHZ = 8,
40   CERT_TYPE = 9,
41   SUPPORTED_GROUPS = 10,
42   EC_POINT_FORMATS = 11,
43   SRP = 12,
44   SIGNATURE_ALGORITHMS = 13,
45   USE_SRTP = 14,
46   HEARTBEAT = 15,
47   APPLICATION_LAYER_PROTOCOL_NEGOTIATION = 16,
48   STATUS_REQUEST_V2 = 17,
49   SIGNED_CERTIFICATE_TIMESTAMP = 18,
50   CLIENT_CERTIFICATE_TYPE = 19,
51   SERVER_CERTIFICATE_TYPE = 20,
52   PADDING = 21,
53   ENCRYPT_THEN_MAC = 22,
54   EXTENDED_MASTER_SECRET = 23,
55   SESSION_TICKET = 35,
56   // Facebook-specific, not IANA assigned yet
57   TLS_CACHED_INFO_FB = 60001,
58   // End Facebook-specific
59   RENEGOTIATION_INFO = 65281
60 };
61
62 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-18
63 enum class HashAlgorithm : uint8_t {
64   NONE = 0,
65   MD5 = 1,
66   SHA1 = 2,
67   SHA224 = 3,
68   SHA256 = 4,
69   SHA384 = 5,
70   SHA512 = 6
71 };
72
73 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-16
74 enum class SignatureAlgorithm : uint8_t {
75   ANONYMOUS = 0,
76   RSA = 1,
77   DSA = 2,
78   ECDSA = 3
79 };
80
81 struct ClientHelloInfo {
82   folly::IOBufQueue clientHelloBuf_;
83   uint8_t clientHelloMajorVersion_;
84   uint8_t clientHelloMinorVersion_;
85   std::vector<uint16_t> clientHelloCipherSuites_;
86   std::vector<uint8_t> clientHelloCompressionMethods_;
87   std::vector<TLSExtension> clientHelloExtensions_;
88   std::vector<std::pair<HashAlgorithm, SignatureAlgorithm>> clientHelloSigAlgs_;
89 };
90
91 } // ssl
92 } // folly