mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-08 22:13:48 +01:00
Merge branch 'upstream-openssl'
This commit is contained in:
commit
895820f14c
7 changed files with 63 additions and 19 deletions
9
HTTP.cpp
9
HTTP.cpp
|
@ -253,21 +253,12 @@ namespace http {
|
||||||
if (pos >= eoh)
|
if (pos >= eoh)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
auto it = headers.find("Host");
|
|
||||||
if (it != headers.end ()) {
|
|
||||||
host = it->second;
|
|
||||||
} else if (version == "HTTP/1.1") {
|
|
||||||
return -1; /* 'Host' header required for HTTP/1.1 */
|
|
||||||
} else if (url.host != "") {
|
|
||||||
host = url.host;
|
|
||||||
}
|
|
||||||
return eoh + strlen(HTTP_EOH);
|
return eoh + strlen(HTTP_EOH);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string HTTPReq::to_string() {
|
std::string HTTPReq::to_string() {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << method << " " << uri << " " << version << CRLF;
|
ss << method << " " << uri << " " << version << CRLF;
|
||||||
ss << "Host: " << host << CRLF;
|
|
||||||
for (auto & h : headers) {
|
for (auto & h : headers) {
|
||||||
ss << h.first << ": " << h.second << CRLF;
|
ss << h.first << ": " << h.second << CRLF;
|
||||||
}
|
}
|
||||||
|
|
1
HTTP.h
1
HTTP.h
|
@ -69,7 +69,6 @@ namespace http {
|
||||||
std::string version;
|
std::string version;
|
||||||
std::string method;
|
std::string method;
|
||||||
std::string uri;
|
std::string uri;
|
||||||
std::string host;
|
|
||||||
|
|
||||||
HTTPReq (): version("HTTP/1.0"), method("GET"), uri("/") {};
|
HTTPReq (): version("HTTP/1.0"), method("GET"), uri("/") {};
|
||||||
|
|
||||||
|
|
|
@ -137,8 +137,24 @@ namespace proxy {
|
||||||
void HTTPReqHandler::SanitizeHTTPRequest(i2p::http::HTTPReq & req)
|
void HTTPReqHandler::SanitizeHTTPRequest(i2p::http::HTTPReq & req)
|
||||||
{
|
{
|
||||||
req.del_header("Referer");
|
req.del_header("Referer");
|
||||||
req.add_header("Connection", "close", true);
|
req.del_header("Via");
|
||||||
req.add_header("User-Agent", "MYOB/6.66 (AN/ON)", true);
|
req.del_header("Forwarded");
|
||||||
|
std::vector<std::string> toErase;
|
||||||
|
for (auto it : req.headers) {
|
||||||
|
if (it.first.compare(0, 12, "X-Forwarded-")) {
|
||||||
|
toErase.push_back(it.first);
|
||||||
|
} else if (it.first.compare(0, 6, "Proxy-")) {
|
||||||
|
toErase.push_back(it.first);
|
||||||
|
} else {
|
||||||
|
/* allow this header */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (auto header : toErase) {
|
||||||
|
req.headers.erase(header);
|
||||||
|
}
|
||||||
|
/* replace headers */
|
||||||
|
req.add_header("Connection", "close", true); /* keep-alive conns not supported yet */
|
||||||
|
req.add_header("User-Agent", "MYOB/6.66 (AN/ON)", true); /* privacy */
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -192,9 +208,28 @@ namespace proxy {
|
||||||
|
|
||||||
std::string dest_host = url.host;
|
std::string dest_host = url.host;
|
||||||
uint16_t dest_port = url.port;
|
uint16_t dest_port = url.port;
|
||||||
/* convert proxy-style http req to ordinary one: */
|
/* set proper 'Host' header in upstream request */
|
||||||
/* 1) replace Host header, 2) make relative url */
|
auto h = req.headers.find("Host");
|
||||||
req.add_header("Host", url.host, true);
|
if (dest_host != "") {
|
||||||
|
/* absolute url, replace 'Host' header */
|
||||||
|
std::string h = dest_host;
|
||||||
|
if (dest_port != 0 && dest_port != 80)
|
||||||
|
h += ":" + std::to_string(dest_port);
|
||||||
|
req.add_header("Host", h, true);
|
||||||
|
} else if (h != req.headers.end()) {
|
||||||
|
/* relative url and 'Host' header provided. transparent proxy mode? */
|
||||||
|
i2p::http::URL u;
|
||||||
|
std::string t = "http://" + h->second;
|
||||||
|
u.parse(t);
|
||||||
|
dest_host = u.host;
|
||||||
|
dest_port = u.port;
|
||||||
|
} else {
|
||||||
|
/* relative url and missing 'Host' header */
|
||||||
|
std::string message = "Can't detect destination host from request";
|
||||||
|
HTTPRequestFailed(message.c_str());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/* make relative url */
|
||||||
url.schema = "";
|
url.schema = "";
|
||||||
url.host = "";
|
url.host = "";
|
||||||
req.uri = url.to_string();
|
req.uri = url.to_string();
|
||||||
|
@ -224,8 +259,10 @@ namespace proxy {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HandleRequest(len))
|
if (HandleRequest(len)) {
|
||||||
|
m_recv_buf.clear();
|
||||||
return; /* request processed */
|
return; /* request processed */
|
||||||
|
}
|
||||||
AsyncSockRead();
|
AsyncSockRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
I2CP.cpp
13
I2CP.cpp
|
@ -15,6 +15,7 @@
|
||||||
#include "LeaseSet.h"
|
#include "LeaseSet.h"
|
||||||
#include "ClientContext.h"
|
#include "ClientContext.h"
|
||||||
#include "Transports.h"
|
#include "Transports.h"
|
||||||
|
#include "Signature.h"
|
||||||
#include "I2CP.h"
|
#include "I2CP.h"
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
|
@ -328,6 +329,12 @@ namespace client
|
||||||
Terminate ();
|
Terminate ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void I2CPSession::ReconfigureSessionMessageHandler (const uint8_t * buf, size_t len)
|
||||||
|
{
|
||||||
|
// TODO: implement actual reconfiguration
|
||||||
|
SendSessionStatusMessage (2); // updated
|
||||||
|
}
|
||||||
|
|
||||||
void I2CPSession::SendSessionStatusMessage (uint8_t status)
|
void I2CPSession::SendSessionStatusMessage (uint8_t status)
|
||||||
{
|
{
|
||||||
uint8_t buf[3];
|
uint8_t buf[3];
|
||||||
|
@ -355,7 +362,10 @@ namespace client
|
||||||
size_t offset = 2;
|
size_t offset = 2;
|
||||||
if (m_Destination)
|
if (m_Destination)
|
||||||
{
|
{
|
||||||
offset += m_Destination->GetIdentity ()->GetSigningPrivateKeyLen (); // skip signing private key
|
offset += i2p::crypto::DSA_PRIVATE_KEY_LENGTH; // skip signing private key
|
||||||
|
// we always assume this field as 20 bytes (DSA) regardless actual size
|
||||||
|
// instead of
|
||||||
|
//offset += m_Destination->GetIdentity ()->GetSigningPrivateKeyLen ();
|
||||||
m_Destination->SetEncryptionPrivateKey (buf + offset);
|
m_Destination->SetEncryptionPrivateKey (buf + offset);
|
||||||
offset += 256;
|
offset += 256;
|
||||||
m_Destination->LeaseSetCreated (buf + offset, len - offset);
|
m_Destination->LeaseSetCreated (buf + offset, len - offset);
|
||||||
|
@ -536,6 +546,7 @@ namespace client
|
||||||
m_MessagesHandlers[I2CP_GET_DATE_MESSAGE] = &I2CPSession::GetDateMessageHandler;
|
m_MessagesHandlers[I2CP_GET_DATE_MESSAGE] = &I2CPSession::GetDateMessageHandler;
|
||||||
m_MessagesHandlers[I2CP_CREATE_SESSION_MESSAGE] = &I2CPSession::CreateSessionMessageHandler;
|
m_MessagesHandlers[I2CP_CREATE_SESSION_MESSAGE] = &I2CPSession::CreateSessionMessageHandler;
|
||||||
m_MessagesHandlers[I2CP_DESTROY_SESSION_MESSAGE] = &I2CPSession::DestroySessionMessageHandler;
|
m_MessagesHandlers[I2CP_DESTROY_SESSION_MESSAGE] = &I2CPSession::DestroySessionMessageHandler;
|
||||||
|
m_MessagesHandlers[I2CP_RECONFIGURE_SESSION_MESSAGE] = &I2CPSession::ReconfigureSessionMessageHandler;
|
||||||
m_MessagesHandlers[I2CP_CREATE_LEASESET_MESSAGE] = &I2CPSession::CreateLeaseSetMessageHandler;
|
m_MessagesHandlers[I2CP_CREATE_LEASESET_MESSAGE] = &I2CPSession::CreateLeaseSetMessageHandler;
|
||||||
m_MessagesHandlers[I2CP_SEND_MESSAGE_MESSAGE] = &I2CPSession::SendMessageMessageHandler;
|
m_MessagesHandlers[I2CP_SEND_MESSAGE_MESSAGE] = &I2CPSession::SendMessageMessageHandler;
|
||||||
m_MessagesHandlers[I2CP_SEND_MESSAGE_EXPIRES_MESSAGE] = &I2CPSession::SendMessageExpiresMessageHandler;
|
m_MessagesHandlers[I2CP_SEND_MESSAGE_EXPIRES_MESSAGE] = &I2CPSession::SendMessageExpiresMessageHandler;
|
||||||
|
|
2
I2CP.h
2
I2CP.h
|
@ -31,6 +31,7 @@ namespace client
|
||||||
const uint8_t I2CP_GET_DATE_MESSAGE = 32;
|
const uint8_t I2CP_GET_DATE_MESSAGE = 32;
|
||||||
const uint8_t I2CP_SET_DATE_MESSAGE = 33;
|
const uint8_t I2CP_SET_DATE_MESSAGE = 33;
|
||||||
const uint8_t I2CP_CREATE_SESSION_MESSAGE = 1;
|
const uint8_t I2CP_CREATE_SESSION_MESSAGE = 1;
|
||||||
|
const uint8_t I2CP_RECONFIGURE_SESSION_MESSAGE = 2;
|
||||||
const uint8_t I2CP_SESSION_STATUS_MESSAGE = 20;
|
const uint8_t I2CP_SESSION_STATUS_MESSAGE = 20;
|
||||||
const uint8_t I2CP_DESTROY_SESSION_MESSAGE = 3;
|
const uint8_t I2CP_DESTROY_SESSION_MESSAGE = 3;
|
||||||
const uint8_t I2CP_REQUEST_VARIABLE_LEASESET_MESSAGE = 37;
|
const uint8_t I2CP_REQUEST_VARIABLE_LEASESET_MESSAGE = 37;
|
||||||
|
@ -113,6 +114,7 @@ namespace client
|
||||||
void GetDateMessageHandler (const uint8_t * buf, size_t len);
|
void GetDateMessageHandler (const uint8_t * buf, size_t len);
|
||||||
void CreateSessionMessageHandler (const uint8_t * buf, size_t len);
|
void CreateSessionMessageHandler (const uint8_t * buf, size_t len);
|
||||||
void DestroySessionMessageHandler (const uint8_t * buf, size_t len);
|
void DestroySessionMessageHandler (const uint8_t * buf, size_t len);
|
||||||
|
void ReconfigureSessionMessageHandler (const uint8_t * buf, size_t len);
|
||||||
void CreateLeaseSetMessageHandler (const uint8_t * buf, size_t len);
|
void CreateLeaseSetMessageHandler (const uint8_t * buf, size_t len);
|
||||||
void SendMessageMessageHandler (const uint8_t * buf, size_t len);
|
void SendMessageMessageHandler (const uint8_t * buf, size_t len);
|
||||||
void SendMessageExpiresMessageHandler (const uint8_t * buf, size_t len);
|
void SendMessageExpiresMessageHandler (const uint8_t * buf, size_t len);
|
||||||
|
|
|
@ -58,7 +58,11 @@ All options below still possible in cmdline, but better write it in config file:
|
||||||
|
|
||||||
* --bob.address= - The address to listen on (BOB command channel)
|
* --bob.address= - The address to listen on (BOB command channel)
|
||||||
* --bob.port= - Port of BOB command channel. Usually 2827. BOB is off if not specified
|
* --bob.port= - Port of BOB command channel. Usually 2827. BOB is off if not specified
|
||||||
* --sam.enabled= - If BOB is enabled. false by default
|
* --bob.enabled= - If BOB is enabled. false by default
|
||||||
|
|
||||||
|
* --i2cp.address= - The address to listen on
|
||||||
|
* --i2cp.port= - Port of I2CP server. Usually 7654. IPCP is off if not specified
|
||||||
|
* --i2cp.enabled= - If I2CP is enabled. false by default. Other services don't requeire I2CP
|
||||||
|
|
||||||
* --i2pcontrol.address= - The address to listen on (I2P control service)
|
* --i2pcontrol.address= - The address to listen on (I2P control service)
|
||||||
* --i2pcontrol.port= - Port of I2P control service. Usually 7650. I2PControl is off if not specified
|
* --i2pcontrol.port= - Port of I2P control service. Usually 7650. I2PControl is off if not specified
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
#define I2P_VERSION_MAJOR 0
|
#define I2P_VERSION_MAJOR 0
|
||||||
#define I2P_VERSION_MINOR 9
|
#define I2P_VERSION_MINOR 9
|
||||||
#define I2P_VERSION_MICRO 25
|
#define I2P_VERSION_MICRO 26
|
||||||
#define I2P_VERSION_PATCH 0
|
#define I2P_VERSION_PATCH 0
|
||||||
#define I2P_VERSION MAKE_VERSION(I2P_VERSION_MAJOR, I2P_VERSION_MINOR, I2P_VERSION_MICRO)
|
#define I2P_VERSION MAKE_VERSION(I2P_VERSION_MAJOR, I2P_VERSION_MINOR, I2P_VERSION_MICRO)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue