SSLOptions.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2017-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. #include <folly/io/async/SSLOptions.h>
  17. #include <folly/Format.h>
  18. #include <glog/logging.h>
  19. namespace folly {
  20. namespace ssl {
  21. namespace ssl_options_detail {
  22. void logDfatal(std::exception const& e) {
  23. LOG(DFATAL) << exceptionStr(e);
  24. }
  25. } // namespace ssl_options_detail
  26. constexpr std::array<const char*, 12> SSLCommonOptions::kCipherList;
  27. constexpr std::array<const char*, 8> SSLCommonOptions::kSignatureAlgorithms;
  28. constexpr std::array<const char*, 12> SSLServerOptions::kCipherList;
  29. void SSLCommonOptions::setClientOptions(SSLContext& ctx) {
  30. #ifdef SSL_MODE_HANDSHAKE_CUTTHROUGH
  31. ctx.enableFalseStart();
  32. #endif
  33. X509VerifyParam param(X509_VERIFY_PARAM_new());
  34. X509_VERIFY_PARAM_set_flags(param.get(), X509_V_FLAG_X509_STRICT);
  35. try {
  36. ctx.setX509VerifyParam(param);
  37. } catch (std::runtime_error const& e) {
  38. LOG(DFATAL) << exceptionStr(e);
  39. }
  40. try {
  41. ctx.setClientECCurvesList({"P-256", "P-384"});
  42. } catch (std::runtime_error const& e) {
  43. LOG(DFATAL) << exceptionStr(e);
  44. }
  45. setCipherSuites<SSLCommonOptions>(ctx);
  46. setSignatureAlgorithms<SSLCommonOptions>(ctx);
  47. }
  48. } // namespace ssl
  49. } // namespace folly