xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/core/handshaker_delegate_interface.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright (c) 2019 The Chromium Authors. All rights reserved.
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 QUICHE_QUIC_CORE_HANDSHAKER_DELEGATE_INTERFACE_H_
6 #define QUICHE_QUIC_CORE_HANDSHAKER_DELEGATE_INTERFACE_H_
7 
8 #include "quiche/quic/core/crypto/transport_parameters.h"
9 #include "quiche/quic/core/quic_types.h"
10 #include "quiche/quic/core/quic_versions.h"
11 
12 namespace quic {
13 
14 class QuicDecrypter;
15 class QuicEncrypter;
16 
17 // Pure virtual class to get notified when particular handshake events occurred.
18 class QUICHE_EXPORT HandshakerDelegateInterface {
19  public:
~HandshakerDelegateInterface()20   virtual ~HandshakerDelegateInterface() {}
21 
22   // Called when new decryption key of |level| is available. Returns true if
23   // decrypter is set successfully, otherwise, returns false.
24   virtual bool OnNewDecryptionKeyAvailable(
25       EncryptionLevel level, std::unique_ptr<QuicDecrypter> decrypter,
26       bool set_alternative_decrypter, bool latch_once_used) = 0;
27 
28   // Called when new encryption key of |level| is available.
29   virtual void OnNewEncryptionKeyAvailable(
30       EncryptionLevel level, std::unique_ptr<QuicEncrypter> encrypter) = 0;
31 
32   // Called to set default encryption level to |level|. Only used in QUIC
33   // crypto.
34   virtual void SetDefaultEncryptionLevel(EncryptionLevel level) = 0;
35 
36   // Called when both 1-RTT read and write keys are available. Only used in TLS
37   // handshake.
38   virtual void OnTlsHandshakeComplete() = 0;
39 
40   // Called on the client side when handshake state change to
41   // HANDSHAKE_CONFIRMED. Only used in TLS handshake.
42   virtual void OnTlsHandshakeConfirmed() = 0;
43 
44   // Called to discard old decryption keys to stop processing packets of
45   // encryption |level|.
46   virtual void DiscardOldDecryptionKey(EncryptionLevel level) = 0;
47 
48   // Called to discard old encryption keys (and neuter obsolete data).
49   // TODO(fayang): consider to combine this with DiscardOldDecryptionKey.
50   virtual void DiscardOldEncryptionKey(EncryptionLevel level) = 0;
51 
52   // Called to neuter ENCRYPTION_INITIAL data (without discarding initial keys).
53   virtual void NeuterUnencryptedData() = 0;
54 
55   // Called to neuter data of HANDSHAKE_DATA packet number space. Only used in
56   // QUIC crypto. This is called 1) when a client switches to forward secure
57   // encryption level and 2) a server successfully processes a forward secure
58   // packet.
59   virtual void NeuterHandshakeData() = 0;
60 
61   // Called when 0-RTT data is rejected by the server. This is only called in
62   // TLS handshakes and only called on clients.
63   virtual void OnZeroRttRejected(int reason) = 0;
64 
65   // Fills in |params| with values from the delegate's QuicConfig.
66   // Returns whether the operation succeeded.
67   virtual bool FillTransportParameters(TransportParameters* params) = 0;
68 
69   // Read |params| and apply the values to the delegate's QuicConfig.
70   // On failure, returns a QuicErrorCode and saves a detailed error in
71   // |error_details|.
72   virtual QuicErrorCode ProcessTransportParameters(
73       const TransportParameters& params, bool is_resumption,
74       std::string* error_details) = 0;
75 
76   // Called at the end of an handshake operation callback.
77   virtual void OnHandshakeCallbackDone() = 0;
78 
79   // Whether a packet flusher is currently attached.
80   virtual bool PacketFlusherAttached() const = 0;
81 
82   // Get the QUIC version currently in use. tls_handshaker needs this to pass
83   // to crypto_utils to apply version-dependent HKDF labels.
84   virtual ParsedQuicVersion parsed_version() const = 0;
85 
86   // Called after an ClientHelloInner is encrypted and sent as a client.
87   virtual void OnEncryptedClientHelloSent(
88       absl::string_view client_hello) const = 0;
89 
90   // Called after an ClientHelloInner is received and decrypted as a server.
91   virtual void OnEncryptedClientHelloReceived(
92       absl::string_view client_hello) const = 0;
93 };
94 
95 }  // namespace quic
96 
97 #endif  // QUICHE_QUIC_CORE_HANDSHAKER_DELEGATE_INTERFACE_H_
98