Skip to content

Commit 3f4455b

Browse files
committed
Use same cert pinning on redirects
IB-8937 Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent 426562d commit 3f4455b

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

src/crypto/Connect.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ using namespace std;
5656

5757

5858

59-
Connect::Connect(const string &_url, string _method, int _timeout, const vector<X509Cert> &certs, const string &userAgentData, const string &version)
60-
: method(std::move(_method))
59+
Connect::Connect(const string &_url, string_view _method, int _timeout, vector<X509Cert> _certs, string _userAgentData, string_view _version)
60+
: method(_method)
61+
, userAgentData(std::move(_userAgentData))
62+
, version(_version)
63+
, certs(std::move(_certs))
6164
, timeout(_timeout)
6265
{
6366
DEBUG("Connecting to URL: %s", _url.c_str());
@@ -128,6 +131,9 @@ Connect::Connect(const string &_url, string _method, int _timeout, const vector<
128131
SSL_CTX_set_options(ssl.get(), options);
129132
#endif
130133
SSL_CTX_set_quiet_shutdown(ssl.get(), 1);
134+
// TLS peer verification is performed only when pinned certificates are provided.
135+
// Without pinning, content-level crypto covers integrity: OCSP responses are signed
136+
// by the responder cert, TSA responses are CMS-signed, and TSL uses known public keys.
131137
if(!certs.empty())
132138
{
133139
SSL_CTX_set_verify(ssl.get(), SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, nullptr);
@@ -159,7 +165,7 @@ Connect::Connect(const string &_url, string _method, int _timeout, const vector<
159165
}
160166
}
161167

162-
BIO_printf(d, "%s %s HTTP/%s\r\n", method.c_str(), path.c_str(), version.c_str());
168+
BIO_printf(d, "%.*s %s HTTP/%.*s\r\n", STR_VIEW_FMT(method), path.c_str(), STR_VIEW_FMT(version));
163169
addHeader("Connection", "close");
164170
if(port == "80" || port == "443")
165171
addHeader("Host", host);
@@ -305,7 +311,7 @@ Connect::Result Connect::exec(initializer_list<pair<string_view,string_view>> he
305311
return r;
306312
string &location = r.headers["location"];
307313
string url = location.find("://") != string::npos ? std::move(location) : baseurl + location;
308-
Connect c(url, method, timeout);
314+
Connect c(url, method, timeout, std::move(certs), std::move(userAgentData), version);
309315
c.recursive = recursive + 1;
310316
return c.exec(headers);
311317
}

src/crypto/Connect.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ class Connect
6060
}
6161
};
6262

63-
Connect(const std::string &url, std::string method = "POST",
64-
int timeout = 0, const std::vector<X509Cert> &certs = {}, const std::string &userAgentData = {},
65-
const std::string &version = "1.1");
63+
Connect(const std::string &url, std::string_view method = "POST",
64+
int timeout = 0, std::vector<X509Cert> certs = {}, std::string userAgentData = {},
65+
std::string_view version = "1.1");
6666
~Connect();
6767
inline Result exec(std::initializer_list<std::pair<std::string_view,std::string_view>> headers,
6868
const std::vector<unsigned char> &data)
@@ -79,7 +79,9 @@ class Connect
7979
void sendProxyAuth();
8080
static std::string decompress(const std::string &encoding, const std::string &data) ;
8181

82-
std::string baseurl, method;
82+
std::string baseurl, userAgentData;
83+
std::string_view method, version;
84+
std::vector<X509Cert> certs;
8385
BIO *d = nullptr;
8486
std::shared_ptr<SSL_CTX> ssl;
8587
int timeout;

0 commit comments

Comments
 (0)