From c5f0be126e3d795cf7e520bf3944f75998b0555e Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 15 Feb 2015 23:03:04 -0500 Subject: [PATCH] client hello for HTTPS --- Reseed.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ Reseed.h | 6 ++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/Reseed.cpp b/Reseed.cpp index 219d18e7..de854fab 100644 --- a/Reseed.cpp +++ b/Reseed.cpp @@ -491,6 +491,53 @@ namespace data } LogPrint (eLogInfo, numCertificates, " certificates loaded"); } + + std::string Reseeder::HttpsRequest (const std::string& address) + { + static uint8_t clientHello[] = + { + 0x16, // handshake + 0x03, 0x02, // version (TSL 1.2) + 0x00, 0x2F, // length of handshake + // handshake + 0x01, // client hello + 0x00, 0x00, 0x2B, // length of client hello + // client hello + 0x03, 0x02, // highest version supported (TSL 1.2) + 0x01, 0x01, 0x01, 0x01, // date, can be anything + 0x74, 0x55, 0x18, 0x36, 0x42, 0x05, 0xC1, 0xDD, 0x4A, 0x21, 0x80, 0x80, 0xEC, 0x37, + 0x11, 0x93, 0x16, 0xF4, 0x66, 0x00, 0x12, 0x67, 0xAB, 0xBA, 0xFF, 0x29, 0x13, 0x9E, // 28 random bytes + 0x00, // session id length + 0x00, 0x04, // chiper suites length + 0x00, 0x00, // NULL_WITH_NULL_NULL + 0x00, 0x35, // RSA_WITH_AES_256_CBC_SHA + 0x01, // compression methods length + 0x00 // no complression + }; + + i2p::util::http::url u(address); + boost::asio::ip::tcp::iostream site; + site.connect(u.host_, "443"); + if (site.good ()) + { + // send ClientHello + site.write ((char *)clientHello, sizeof (clientHello)); + // read ServerHello + uint8_t type; + site.read ((char *)&type, 1); + uint16_t version; + site.read ((char *)&version, 2); + uint16_t length; + site.read ((char *)&length, 2); + length = be16toh (length); + char * serverHello = new char[length]; + site.read (serverHello, length); + delete[] serverHello; + } + else + LogPrint (eLogError, "Can't connect to ", address); + return ""; + } } } diff --git a/Reseed.h b/Reseed.h index 3857d057..c2f32c5b 100644 --- a/Reseed.h +++ b/Reseed.h @@ -24,7 +24,9 @@ namespace data int ReseedNowSU3 (); void LoadCertificates (); - + + std::string HttpsRequest (const std::string& address); // TODO: move to private section + private: void LoadCertificate (const std::string& filename); @@ -34,7 +36,7 @@ namespace data int ProcessSU3Stream (std::istream& s); bool FindZipDataDescriptor (std::istream& s); - + private: std::map m_SigningKeys;