mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
fixed crash if can't connect to a reseed
This commit is contained in:
parent
cb9f78540a
commit
43f8ec46cc
33
Reseed.cpp
33
Reseed.cpp
@ -500,17 +500,22 @@ namespace data
|
||||
if (u.port_ == 80) u.port_ = 443;
|
||||
TlsSession session (u.host_, u.port_);
|
||||
|
||||
// send request
|
||||
std::stringstream ss;
|
||||
ss << "GET " << u.path_ << " HTTP/1.1\r\nHost: " << u.host_
|
||||
<< "\r\nAccept: */*\r\n" << "User-Agent: Wget/1.11.4\r\n" << "Connection: close\r\n\r\n";
|
||||
session.Send ((uint8_t *)ss.str ().c_str (), ss.str ().length ());
|
||||
if (session.IsEstablished ())
|
||||
{
|
||||
// send request
|
||||
std::stringstream ss;
|
||||
ss << "GET " << u.path_ << " HTTP/1.1\r\nHost: " << u.host_
|
||||
<< "\r\nAccept: */*\r\n" << "User-Agent: Wget/1.11.4\r\n" << "Connection: close\r\n\r\n";
|
||||
session.Send ((uint8_t *)ss.str ().c_str (), ss.str ().length ());
|
||||
|
||||
// read response
|
||||
std::stringstream rs;
|
||||
while (session.Receive (rs))
|
||||
;
|
||||
return i2p::util::http::GetHttpContent (rs);
|
||||
// read response
|
||||
std::stringstream rs;
|
||||
while (session.Receive (rs))
|
||||
;
|
||||
return i2p::util::http::GetHttpContent (rs);
|
||||
}
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------
|
||||
@ -622,13 +627,11 @@ namespace data
|
||||
|
||||
|
||||
TlsSession::TlsSession (const std::string& host, int port):
|
||||
m_Cipher (nullptr)
|
||||
m_IsEstablished (false), m_Cipher (nullptr)
|
||||
{
|
||||
m_Site.connect(host, boost::lexical_cast<std::string>(port));
|
||||
if (m_Site.good ())
|
||||
{
|
||||
Handshake ();
|
||||
}
|
||||
else
|
||||
LogPrint (eLogError, "Can't connect to ", host, ":", port);
|
||||
}
|
||||
@ -693,7 +696,9 @@ namespace data
|
||||
LogPrint (eLogError, "Unexpected handshake type ", (int)serverHello[0]);
|
||||
uint8_t sessionIDLen = serverHello[38]; // 6 + 32
|
||||
char * cipherSuite = serverHello + 39 + sessionIDLen;
|
||||
if (cipherSuite[1] != 0x3D && cipherSuite[1] != 0x35 && cipherSuite[1] != 0x05)
|
||||
if (cipherSuite[1] == 0x3D || cipherSuite[1] == 0x35 || cipherSuite[1] == 0x05)
|
||||
m_IsEstablished = true;
|
||||
else
|
||||
LogPrint (eLogError, "Unsupported cipher ", (int)cipherSuite[0], ",", (int)cipherSuite[1]);
|
||||
// read Certificate
|
||||
m_Site.read ((char *)&type, 1);
|
||||
|
2
Reseed.h
2
Reseed.h
@ -69,6 +69,7 @@ namespace data
|
||||
~TlsSession ();
|
||||
void Send (const uint8_t * buf, size_t len);
|
||||
bool Receive (std::ostream& rs);
|
||||
bool IsEstablished () const { return m_IsEstablished; };
|
||||
|
||||
private:
|
||||
|
||||
@ -82,6 +83,7 @@ namespace data
|
||||
|
||||
private:
|
||||
|
||||
bool m_IsEstablished;
|
||||
boost::asio::ip::tcp::iostream m_Site;
|
||||
CryptoPP::SHA256 m_FinishedHash;
|
||||
uint8_t m_MasterSecret[64]; // actual size is 48, but must be multiple of 32
|
||||
|
Loading…
x
Reference in New Issue
Block a user