963cad27af76d5d99780390754b27e7eb34516a5
[folly.git] / folly / io / async / SSLOptions.h
1 /*
2  * Copyright 2004-present 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/Format.h>
20 #include <folly/io/async/SSLContext.h>
21
22 #include <glog/logging.h>
23
24 namespace folly {
25 namespace ssl {
26
27 struct SSLCommonOptions {
28   /**
29    * Return the cipher list recommended for this options configuration.
30    */
31   static const std::vector<std::string>& getCipherList();
32
33   /**
34    * Return the list of signature algorithms recommended for this options
35    * configuration.
36    */
37   static const std::vector<std::string>& getSignatureAlgorithms();
38
39   /**
40    * Set common parameters on a client SSL context, for example,
41    * ciphers, signature algorithms, verification options, and client EC curves.
42    * @param ctx The SSL Context to which to apply the options.
43    */
44   static void setClientOptions(SSLContext& ctx);
45 };
46
47 template <typename TSSLOptions>
48 void setCipherSuites(SSLContext& ctx) {
49   try {
50     ctx.setCipherList(TSSLOptions::getCipherList());
51   } catch (std::runtime_error const& e) {
52     LOG(DFATAL) << exceptionStr(e);
53   }
54 }
55
56 template <typename TSSLOptions>
57 void setSignatureAlgorithms(SSLContext& ctx) {
58   try {
59     ctx.setSignatureAlgorithms(TSSLOptions::getSignatureAlgorithms());
60   } catch (std::runtime_error const& e) {
61     LOG(DFATAL) << exceptionStr(e);
62   }
63 }
64
65 } // namespace ssl
66 } // namespace folly