proxygen
KeyScheduler.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 
12 #include <fizz/crypto/aead/Aead.h>
13 #include <folly/Optional.h>
14 
15 namespace fizz {
16 
17 enum class EarlySecrets {
22 };
23 
25 
27 
29 
33 class KeyScheduler {
34  public:
35  explicit KeyScheduler(std::unique_ptr<KeyDerivation> deriver)
36  : deriver_(std::move(deriver)) {}
37  virtual ~KeyScheduler() = default;
38 
42  virtual void deriveEarlySecret(folly::ByteRange psk);
43 
47  virtual void deriveHandshakeSecret();
48 
53  virtual void deriveHandshakeSecret(folly::ByteRange ecdhe);
54 
58  virtual void deriveMasterSecret();
59 
64  virtual void deriveAppTrafficSecrets(folly::ByteRange transcript);
65 
69  virtual void clearMasterSecret();
70 
75  virtual uint32_t clientKeyUpdate();
76 
81  virtual uint32_t serverKeyUpdate();
82 
86  virtual std::vector<uint8_t> getSecret(
88  folly::ByteRange transcript) const;
89  virtual std::vector<uint8_t> getSecret(
91  folly::ByteRange transcript) const;
92  virtual std::vector<uint8_t> getSecret(
93  MasterSecrets s,
94  folly::ByteRange transcript) const;
95  virtual std::vector<uint8_t> getSecret(AppTrafficSecrets s) const;
96 
100  virtual TrafficKey getTrafficKey(
101  folly::ByteRange trafficSecret,
102  size_t keyLength,
103  size_t ivLength) const;
104 
109  virtual Buf getResumptionSecret(
110  folly::ByteRange resumptionMasterSecret,
111  folly::ByteRange ticketNonce) const;
112 
113  private:
114  struct EarlySecret {
115  std::vector<uint8_t> secret;
116  };
118  std::vector<uint8_t> secret;
119  };
120  struct MasterSecret {
121  std::vector<uint8_t> secret;
122  };
124  std::vector<uint8_t> client;
125  uint32_t clientGeneration{0};
126  std::vector<uint8_t> server;
127  uint32_t serverGeneration{0};
128  };
129 
133 
134  std::unique_ptr<KeyDerivation> deriver_;
135 };
136 } // namespace fizz
AppTrafficSecrets
Definition: KeyScheduler.h:28
folly::Optional< boost::variant< EarlySecret, HandshakeSecret, MasterSecret > > secret_
Definition: KeyScheduler.h:131
folly::Optional< AppTrafficSecret > appTrafficSecret_
Definition: KeyScheduler.h:132
KeyScheduler(std::unique_ptr< KeyDerivation > deriver)
Definition: KeyScheduler.h:35
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
STL namespace.
std::unique_ptr< KeyDerivation > deriver_
Definition: KeyScheduler.h:134
EarlySecrets
Definition: KeyScheduler.h:17
MasterSecrets
Definition: KeyScheduler.h:26
std::vector< uint8_t > secret
Definition: KeyScheduler.h:115
Definition: Actions.h:16
HandshakeSecrets
Definition: KeyScheduler.h:24
std::unique_ptr< folly::IOBuf > Buf
Definition: Types.h:22
static set< string > s
std::vector< uint8_t > secret
Definition: KeyScheduler.h:118
std::vector< uint8_t > secret
Definition: KeyScheduler.h:121