1 // Copyright 2012 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 #ifdef UNSAFE_BUFFERS_BUILD 6 // TODO(crbug.com/40284755): Remove this and spanify to fix the errors. 7 #pragma allow_unsafe_buffers 8 #endif 9 10 // Dumps the contents of a QUIC crypto handshake message in a human readable 11 // format. 12 // 13 // Usage: crypto_message_printer_bin <hex of message> 14 15 #include <iostream> 16 17 #include "base/command_line.h" 18 #include "base/strings/string_number_conversions.h" 19 #include "net/third_party/quiche/src/quiche/quic/core/crypto/crypto_framer.h" 20 21 using quic::Perspective; 22 using std::cerr; 23 using std::cout; 24 using std::endl; 25 26 namespace net { 27 28 class CryptoMessagePrinter : public quic::CryptoFramerVisitorInterface { 29 public: 30 explicit CryptoMessagePrinter() = default; 31 OnHandshakeMessage(const quic::CryptoHandshakeMessage & message)32 void OnHandshakeMessage( 33 const quic::CryptoHandshakeMessage& message) override { 34 cout << message.DebugString() << endl; 35 } 36 OnError(quic::CryptoFramer * framer)37 void OnError(quic::CryptoFramer* framer) override { 38 cerr << "Error code: " << framer->error() << endl; 39 cerr << "Error details: " << framer->error_detail() << endl; 40 } 41 42 }; 43 44 } // namespace net 45 main(int argc,char * argv[])46int main(int argc, char* argv[]) { 47 base::CommandLine::Init(argc, argv); 48 49 if (argc != 1) { 50 cerr << "Usage: " << argv[0] << " <hex of message>\n"; 51 return 1; 52 } 53 54 net::CryptoMessagePrinter printer; 55 quic::CryptoFramer framer; 56 framer.set_visitor(&printer); 57 framer.set_process_truncated_messages(true); 58 std::string input; 59 if (!base::HexStringToString(argv[1], &input) || 60 !framer.ProcessInput(input)) { 61 return 1; 62 } 63 if (framer.InputBytesRemaining() != 0) { 64 cerr << "Input partially consumed. " << framer.InputBytesRemaining() 65 << " bytes remaining." << endl; 66 return 2; 67 } 68 return 0; 69 } 70