blob: f5584adad551efeb2bb459283df98fe4bc6456bf [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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// Dumps the contents of a QUIC crypto handshake message in a human readable
6// format.
7//
8// Usage: crypto_message_printer_bin <hex of message>
9
10#include <iostream>
vasilvv872e7a32019-03-12 16:42:44 -070011#include <string>
QUICHE teama6ef0a62019-03-07 20:34:33 -050012
QUICHE teama6ef0a62019-03-07 20:34:33 -050013#include "net/third_party/quiche/src/quic/core/crypto/crypto_framer.h"
14#include "net/third_party/quiche/src/quic/core/quic_utils.h"
dmcardle904ef182019-12-13 08:34:33 -080015#include "net/third_party/quiche/src/common/platform/api/quiche_text_utils.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050016
QUICHE teama6ef0a62019-03-07 20:34:33 -050017using std::cerr;
18using std::cout;
19using std::endl;
20
21namespace quic {
22
23class CryptoMessagePrinter : public ::quic::CryptoFramerVisitorInterface {
24 public:
25 void OnHandshakeMessage(const CryptoHandshakeMessage& message) override {
26 cout << message.DebugString() << endl;
27 }
28
29 void OnError(CryptoFramer* framer) override {
30 cerr << "Error code: " << framer->error() << endl;
31 cerr << "Error details: " << framer->error_detail() << endl;
32 }
33};
34
35} // namespace quic
36
37int main(int argc, char* argv[]) {
rch1b3be2a2019-04-29 15:46:36 -070038 const char* usage = "Usage: crypto_message_printer <hex>";
39 std::vector<std::string> messages =
40 quic::QuicParseCommandLineFlags(usage, argc, argv);
41 if (messages.size() != 1) {
42 quic::QuicPrintCommandLineFlagHelp(usage);
43 exit(0);
44 }
QUICHE teama6ef0a62019-03-07 20:34:33 -050045
46 quic::CryptoMessagePrinter printer;
47 quic::CryptoFramer framer;
48 framer.set_visitor(&printer);
49 framer.set_process_truncated_messages(true);
dmcardle904ef182019-12-13 08:34:33 -080050 std::string input = quiche::QuicheTextUtils::HexDecode(messages[0]);
QUICHE teama6ef0a62019-03-07 20:34:33 -050051 if (!framer.ProcessInput(input)) {
52 return 1;
53 }
54 if (framer.InputBytesRemaining() != 0) {
55 cerr << "Input partially consumed. " << framer.InputBytesRemaining()
56 << " bytes remaining." << endl;
57 return 2;
58 }
59 return 0;
60}