proxygen
FizzUtil.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #pragma once
10 
11 #include <vector>
12 
15 
19 
20 namespace fizz {
21 
22 class FizzUtil {
23  public:
24  // Read a vector of certs from a file
25  static std::vector<folly::ssl::X509UniquePtr> readChainFile(
26  const std::string& filename);
27 
29  const std::string& filename,
30  const std::string& passwordFilename);
31 
32  // Fizz does not yet support randomized next protocols so we use the highest
33  // weighted list on the first context.
34  static std::vector<std::string> getAlpnsFromNpnList(
35  const std::list<folly::SSLContext::NextProtocolsItem>& list);
36 
38  const std::string& data,
40 
41  // Creates a TicketCipher with given params
42  template <class TicketCipher>
43  static std::unique_ptr<TicketCipher> createTicketCipher(
44  const std::vector<std::string>& oldSecrets,
45  const std::string& currentSecret,
46  const std::vector<std::string>& newSecrets,
47  std::chrono::seconds validity,
48  folly::Optional<std::string> pskContext) {
49  std::vector<folly::ByteRange> ticketSecrets;
50  if (!currentSecret.empty()) {
51  ticketSecrets.push_back(folly::StringPiece(currentSecret));
52  }
53  for (const auto& secret : oldSecrets) {
54  ticketSecrets.push_back(folly::StringPiece(secret));
55  }
56  for (const auto& secret : newSecrets) {
57  ticketSecrets.push_back(folly::StringPiece(secret));
58  }
59  std::unique_ptr<TicketCipher> cipher;
60  if (pskContext.hasValue()) {
61  cipher = std::make_unique<TicketCipher>(std::move(*pskContext));
62  } else {
63  cipher = std::make_unique<TicketCipher>();
64  }
65  cipher->setTicketSecrets(std::move(ticketSecrets));
66  cipher->setValidity(validity);
67  return cipher;
68  }
69 };
70 
71 } // namespace fizz
static folly::ssl::EvpPkeyUniquePtr readPrivateKey(const std::string &filename, const std::string &passwordFilename)
Definition: FizzUtil.cpp:52
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static std::vector< std::string > getAlpnsFromNpnList(const std::list< folly::SSLContext::NextProtocolsItem > &list)
Definition: FizzUtil.cpp:97
static std::unique_ptr< TicketCipher > createTicketCipher(const std::vector< std::string > &oldSecrets, const std::string &currentSecret, const std::vector< std::string > &newSecrets, std::chrono::seconds validity, folly::Optional< std::string > pskContext)
Definition: FizzUtil.h:43
std::unique_ptr< EVP_PKEY, EvpPkeyDeleter > EvpPkeyUniquePtr
static std::vector< folly::ssl::X509UniquePtr > readChainFile(const std::string &filename)
Definition: FizzUtil.cpp:36
CipherSuite cipher
Encoder::MutableCompressedList list
FOLLY_CPP14_CONSTEXPR bool hasValue() const noexcept
Definition: Optional.h:300
Definition: Actions.h:16
static folly::ssl::EvpPkeyUniquePtr decryptPrivateKey(const std::string &data, folly::PasswordInFile *pf)
Definition: FizzUtil.cpp:73
const char * string
Definition: Conv.cpp:212
static constexpr StringPiece secret
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43