1 // Copyright 2017 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_QUIC_MOCK_DECRYPTER_H_ 6 #define NET_QUIC_MOCK_DECRYPTER_H_ 7 8 #include <cstddef> 9 #include <cstdint> 10 11 #include "base/compiler_specific.h" 12 #include "net/base/net_export.h" 13 #include "net/third_party/quiche/src/quiche/quic/core/crypto/quic_decrypter.h" 14 #include "net/third_party/quiche/src/quiche/quic/core/quic_types.h" 15 16 namespace net { 17 18 // A MockDecrypter is a QuicDecrypter that strips the last 12 bytes of 19 // ciphertext (which should be zeroes, but are ignored), and returns the 20 // remaining ciphertext untouched and ignores the associated data. This is used 21 // to allow fuzzing to mutate plaintext packets. 22 class MockDecrypter : public quic::QuicDecrypter { 23 public: 24 explicit MockDecrypter(quic::Perspective perspective); 25 26 MockDecrypter(const MockDecrypter&) = delete; 27 MockDecrypter& operator=(const MockDecrypter&) = delete; 28 29 ~MockDecrypter() override = default; 30 31 // QuicCrypter implementation 32 bool SetKey(std::string_view key) override; 33 bool SetNoncePrefix(std::string_view nonce_prefix) override; 34 bool SetIV(std::string_view iv) override; 35 bool SetHeaderProtectionKey(std::string_view key) override; 36 size_t GetKeySize() const override; 37 size_t GetIVSize() const override; 38 size_t GetNoncePrefixSize() const override; 39 40 // QuicDecrypter implementation 41 bool SetPreliminaryKey(std::string_view key) override; 42 bool SetDiversificationNonce( 43 const quic::DiversificationNonce& nonce) override; 44 bool DecryptPacket(uint64_t packet_number, 45 std::string_view associated_data, 46 std::string_view ciphertext, 47 char* output, 48 size_t* output_length, 49 size_t max_output_length) override; 50 std::string GenerateHeaderProtectionMask( 51 quic::QuicDataReader* sample_reader) override; 52 uint32_t cipher_id() const override; 53 quic::QuicPacketCount GetIntegrityLimit() const override; 54 std::string_view GetKey() const override; 55 std::string_view GetNoncePrefix() const override; 56 }; 57 58 } // namespace net 59 60 #endif // NET_QUIC_MOCK_DECRYPTER_H_ 61