-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create pure virtual Factory interface
Summary: `fizz::Factory` is used by other parts of Fizz to allow customization of various components that Fizz may need to construct while servicing a handshake. However, `fizz::Factory` as it currently stands is not a pure inteface -- the current implementation tightly couples OpenSSL (e.g. `makeAead`). Introduce a new class `IFactory` that is meant to represent the interface of Factory. Later diffs will merge OpenSSLFactory and Factory together. Reviewed By: mingtaoy Differential Revision: D50714194 fbshipit-source-id: afef019d4943d284c7b8410cdf30f6d6d0365d61
- Loading branch information
1 parent
7e124c6
commit 5c92af0
Showing
2 changed files
with
104 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright (c) 2018-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include <fizz/protocol/Types.h> | ||
#include <fizz/record/Types.h> | ||
#include <folly/io/async/AsyncTransportCertificate.h> | ||
|
||
namespace fizz { | ||
|
||
class Aead; | ||
class EncryptedReadRecordLayer; | ||
class EncryptedWriteRecordLayer; | ||
class HandshakeContext; | ||
class KeyDerivation; | ||
class KeyExchange; | ||
class KeyScheduler; | ||
class PeerCert; | ||
class PlaintextReadRecordLayer; | ||
class PlaintextWriteRecordLayer; | ||
|
||
/** | ||
* This class instantiates various objects to facilitate testing. | ||
*/ | ||
class IFactory { | ||
public: | ||
enum class KeyExchangeMode { Server, Client }; | ||
|
||
virtual ~IFactory() = default; | ||
|
||
virtual std::unique_ptr<PlaintextReadRecordLayer> | ||
makePlaintextReadRecordLayer() const = 0; | ||
|
||
virtual std::unique_ptr<PlaintextWriteRecordLayer> | ||
makePlaintextWriteRecordLayer() const = 0; | ||
|
||
virtual std::unique_ptr<EncryptedReadRecordLayer> | ||
makeEncryptedReadRecordLayer(EncryptionLevel encryptionLevel) const = 0; | ||
|
||
virtual std::unique_ptr<EncryptedWriteRecordLayer> | ||
makeEncryptedWriteRecordLayer(EncryptionLevel encryptionLevel) const = 0; | ||
|
||
virtual std::unique_ptr<KeyScheduler> makeKeyScheduler( | ||
CipherSuite cipher) const = 0; | ||
|
||
virtual std::unique_ptr<KeyDerivation> makeKeyDeriver( | ||
CipherSuite cipher) const = 0; | ||
|
||
virtual std::unique_ptr<HandshakeContext> makeHandshakeContext( | ||
CipherSuite cipher) const = 0; | ||
|
||
virtual std::unique_ptr<KeyExchange> makeKeyExchange( | ||
NamedGroup group, | ||
KeyExchangeMode mode) const = 0; | ||
|
||
[[nodiscard]] virtual std::unique_ptr<Aead> makeAead( | ||
CipherSuite cipher) const = 0; | ||
|
||
[[nodiscard]] virtual Random makeRandom() const = 0; | ||
|
||
[[nodiscard]] virtual uint32_t makeTicketAgeAdd() const = 0; | ||
|
||
[[nodiscard]] virtual std::unique_ptr<folly::IOBuf> makeRandomBytes( | ||
size_t count) const = 0; | ||
|
||
virtual std::shared_ptr<PeerCert> makePeerCert( | ||
CertificateEntry certEntry, | ||
bool /*leaf*/) const = 0; | ||
|
||
[[nodiscard]] virtual std::shared_ptr<folly::AsyncTransportCertificate> | ||
makeIdentityOnlyCert(std::string ident) const = 0; | ||
|
||
[[nodiscard]] virtual std::string getHkdfPrefix() const = 0; | ||
}; | ||
} // namespace fizz |