1 // Copyright (c) 2012 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.
5 #ifndef NET_QUIC_TEST_TOOLS_CRYPTO_TEST_UTILS_H_
6 #define NET_QUIC_TEST_TOOLS_CRYPTO_TEST_UTILS_H_
12 #include "base/logging.h"
13 #include "base/strings/string_piece.h"
14 #include "net/quic/crypto/crypto_framer.h"
15 #include "net/quic/quic_framer.h"
16 #include "net/quic/quic_protocol.h"
20 class ChannelIDSigner;
26 class QuicCryptoClientStream;
27 class QuicCryptoServerConfig;
28 class QuicCryptoServerStream;
29 class QuicCryptoStream;
34 class PacketSavingConnection;
36 class CryptoTestUtils {
38 // FakeClientOptions bundles together a number of options for configuring
39 // HandshakeWithFakeClient.
40 struct FakeClientOptions {
43 // If dont_verify_certs is true then no ProofVerifier is set on the client.
44 // Thus no certificates will be requested or checked.
45 bool dont_verify_certs;
47 // If channel_id_enabled is true then the client will attempt to send a
48 // ChannelID. The key will be the same as is returned by
49 // ChannelIDSigner's |GetKeyForHostname|.
50 bool channel_id_enabled;
53 // returns: the number of client hellos that the client sent.
54 static int HandshakeWithFakeServer(PacketSavingConnection* client_conn,
55 QuicCryptoClientStream* client);
57 // returns: the number of client hellos that the client sent.
58 static int HandshakeWithFakeClient(PacketSavingConnection* server_conn,
59 QuicCryptoServerStream* server,
60 const FakeClientOptions& options);
62 // SetupCryptoServerConfigForTest configures |config| and |crypto_config|
63 // with sensible defaults for testing.
64 static void SetupCryptoServerConfigForTest(
65 const QuicClock* clock,
68 QuicCryptoServerConfig* crypto_config);
70 // CommunicateHandshakeMessages moves messages from |a| to |b| and back until
71 // |a|'s handshake has completed.
72 static void CommunicateHandshakeMessages(PacketSavingConnection* a_conn,
74 PacketSavingConnection* b_conn,
77 // Returns the value for the tag |tag| in the tag value map of |message|.
78 static std::string GetValueForTag(const CryptoHandshakeMessage& message,
81 // Returns a |ProofSource| that serves up test certificates.
82 static ProofSource* ProofSourceForTesting();
84 // Returns a |ProofVerifier| that uses the QUIC testing root CA.
85 static ProofVerifier* ProofVerifierForTesting();
87 // MockCommonCertSets returns a CommonCertSets that contains a single set with
88 // hash |hash|, consisting of the certificate |cert| at index |index|.
89 static CommonCertSets* MockCommonCertSets(base::StringPiece cert,
93 // ParseTag returns a QuicTag from parsing |tagstr|. |tagstr| may either be
94 // in the format "EXMP" (i.e. ASCII format), or "#11223344" (an explicit hex
95 // format). It CHECK fails if there's a parse error.
96 static QuicTag ParseTag(const char* tagstr);
98 // Message constructs a handshake message from a variable number of
99 // arguments. |message_tag| is passed to |ParseTag| and used as the tag of
100 // the resulting message. The arguments are taken in pairs and NULL
101 // terminated. The first of each pair is the tag of a tag/value and is given
102 // as an argument to |ParseTag|. The second is the value of the tag/value
103 // pair and is either a hex dump, preceeded by a '#', or a raw value.
107 // "NOCE", "#11223344",
108 // "SNI", "www.example.com",
110 static CryptoHandshakeMessage Message(const char* message_tag, ...);
112 // BuildMessage is the same as |Message|, but takes the variable arguments
113 // explicitly. TODO(rtenneti): Investigate whether it'd be better for
114 // Message() and BuildMessage() to return a CryptoHandshakeMessage* pointer
115 // instead, to avoid copying the return value.
116 static CryptoHandshakeMessage BuildMessage(const char* message_tag,
119 // ChannelIDSignerForTesting returns a ChannelIDSigner that generates keys
120 // deterministically based on the hostname given in the Sign call.
121 static ChannelIDSigner* ChannelIDSignerForTesting();
124 static void CompareClientAndServerKeys(QuicCryptoClientStream* client,
125 QuicCryptoServerStream* server);
132 #endif // NET_QUIC_TEST_TOOLS_CRYPTO_TEST_UTILS_H_