From 6cb8258b419ebfda3b5492992bddbce7f7f432e6 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 27 Sep 2002 23:01:35 +0000 Subject: [PATCH] even better debugging output --- panda/src/downloader/httpClient.cxx | 123 +++++++++++++++++++++++++--- panda/src/downloader/httpClient.h | 10 +++ 2 files changed, 123 insertions(+), 10 deletions(-) diff --git a/panda/src/downloader/httpClient.cxx b/panda/src/downloader/httpClient.cxx index 3b0b251664..8c2e9b1f60 100644 --- a/panda/src/downloader/httpClient.cxx +++ b/panda/src/downloader/httpClient.cxx @@ -109,6 +109,14 @@ make_ctx() { } _ssl_ctx = SSL_CTX_new(SSLv23_client_method()); +#if defined(SSL_097) && !defined(NDEBUG) + // If we have debugging enabled, set a callback that allows us to + // report the SSL messages as they are sent and received. + if (downloader_cat.is_debug()) { + SSL_CTX_set_msg_callback(_ssl_ctx, ssl_msg_callback); + } +#endif + // By default, insist on verifying servers. set_verify_ssl(true); @@ -248,22 +256,16 @@ get_http(const URLSpec &url, const string &body) { //////////////////////////////////////////////////////////////////// BIO *HTTPClient:: get_https(const URLSpec &url, const string &body) { - BIO *sbio = BIO_new_ssl_connect(_ssl_ctx); - SSL *ssl; - BIO_get_ssl(sbio, &ssl); - nassertr(ssl != (SSL *)NULL, NULL); - SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY); - ostringstream server; server << url.get_server() << ":" << url.get_port(); string server_str = server.str(); - BIO_set_conn_hostname(sbio, server_str.c_str()); + BIO *bio = BIO_new_connect((char *)server_str.c_str()); if (downloader_cat.is_debug()) { downloader_cat.debug() << "connecting to " << server_str << "\n"; } - if (BIO_do_connect(sbio) <= 0) { + if (BIO_do_connect(bio) <= 0) { downloader_cat.info() << "Could not contact server " << server_str << "\n"; #ifndef NDEBUG @@ -272,6 +274,14 @@ get_https(const URLSpec &url, const string &body) { return NULL; } + BIO *sbio = BIO_new_ssl(_ssl_ctx, true); + BIO_push(sbio, bio); + + SSL *ssl; + BIO_get_ssl(sbio, &ssl); + nassertr(ssl != (SSL *)NULL, NULL); + SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY); + if (downloader_cat.is_debug()) { downloader_cat.debug() << "performing SSL handshake\n"; @@ -355,9 +365,11 @@ get_https_proxy(const URLSpec &url, const string &body) { << "\r\n"; string request_str = request.str(); +#ifndef NDEBUG if (downloader_cat.is_debug()) { - downloader_cat.debug() << "send:\n" << request_str << "\n"; + show_send(request_str); } +#endif BIO_puts(bio, request_str.c_str()); } @@ -455,10 +467,101 @@ send_get_request(BIO *bio, } string request_str = request.str(); +#ifndef NDEBUG if (downloader_cat.is_debug()) { - downloader_cat.debug() << "send:\n" << request_str << "\n"; + show_send(request_str); } +#endif BIO_puts(bio, request_str.c_str()); } +#ifndef NDEBUG +//////////////////////////////////////////////////////////////////// +// Function: HTTPClient::show_send +// Access: Private, Static +// Description: Writes the outgoing message, one line at a time, to +// the debugging log. +//////////////////////////////////////////////////////////////////// +void HTTPClient:: +show_send(const string &message) { + size_t start = 0; + size_t newline = message.find('\n', start); + while (newline != string::npos) { + downloader_cat.debug() + << "send: " << message.substr(start, newline - start + 1); + start = newline + 1; + newline = message.find('\n', start); + } + + if (start < message.length()) { + downloader_cat.debug() + << "send: " << message.substr(start) << " (no newline)\n"; + } +} +#endif // NDEBUG + +#if defined(SSL_097) && !defined(NDEBUG) +//////////////////////////////////////////////////////////////////// +// Function: HTTPClient::ssl_msg_callback +// Access: Private, Static +// Description: This method is attached as a callback for SSL +// messages only when debug output is enabled. +//////////////////////////////////////////////////////////////////// +void HTTPClient:: +ssl_msg_callback(int write_p, int version, int content_type, + const void *, size_t len, SSL *, void *) { + ostringstream describe; + if (write_p) { + describe << "sent "; + } else { + describe << "received "; + } + switch (version) { + case SSL2_VERSION: + describe << "SSL 2.0 "; + break; + + case SSL3_VERSION: + describe << "SSL 3.0 "; + break; + + case TLS1_VERSION: + describe << "TLS 1.0 "; + break; + + default: + describe << "unknown protocol "; + } + + describe << "message: "; + + if (version != SSL2_VERSION) { + switch (content_type) { + case 20: + describe << "change cipher spec, "; + break; + + case 21: + describe << "alert, "; + break; + + case 22: + describe << "handshake, "; + break; + + case 23: + describe << "application data, "; + break; + + default: + describe << "unknown content type, "; + } + } + + describe << len << " bytes.\n"; + + downloader_cat.debug() << describe.str(); +} +#endif // defined(SSL_097) && !defined(NDEBUG) + #endif // HAVE_SSL diff --git a/panda/src/downloader/httpClient.h b/panda/src/downloader/httpClient.h index 6a1ef93a54..aa09bce27f 100644 --- a/panda/src/downloader/httpClient.h +++ b/panda/src/downloader/httpClient.h @@ -72,6 +72,16 @@ private: const string &path, const string &server, const string &body) const; +#ifndef NDEBUG + static void show_send(const string &message); +#endif + +#if defined(SSL_097) && !defined(NDEBUG) + static void ssl_msg_callback(int write_p, int version, int content_type, + const void *buf, size_t len, SSL *ssl, + void *arg); +#endif + URLSpec _proxy; SSL_CTX *_ssl_ctx; bool _verify_ssl;