QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 | // 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> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 11 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13 | #include "net/third_party/quiche/src/quic/core/crypto/crypto_framer.h" |
| 14 | #include "net/third_party/quiche/src/quic/core/quic_utils.h" |
dmcardle | 904ef18 | 2019-12-13 08:34:33 -0800 | [diff] [blame] | 15 | #include "net/third_party/quiche/src/common/platform/api/quiche_text_utils.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 16 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 17 | using std::cerr; |
| 18 | using std::cout; |
| 19 | using std::endl; |
| 20 | |
| 21 | namespace quic { |
| 22 | |
| 23 | class 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 | |
| 37 | int main(int argc, char* argv[]) { |
rch | 1b3be2a | 2019-04-29 15:46:36 -0700 | [diff] [blame] | 38 | 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 team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 45 | |
| 46 | quic::CryptoMessagePrinter printer; |
| 47 | quic::CryptoFramer framer; |
| 48 | framer.set_visitor(&printer); |
| 49 | framer.set_process_truncated_messages(true); |
dmcardle | 904ef18 | 2019-12-13 08:34:33 -0800 | [diff] [blame] | 50 | std::string input = quiche::QuicheTextUtils::HexDecode(messages[0]); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 51 | 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 | } |