mirror of
https://bitbucket.org/theswgsource/src-1.2.git
synced 2026-01-15 23:04:24 -05:00
make cert pinning work (currently only for our 30 year lasting cloudflare cert, can enable others later)
This commit is contained in:
18
external/3rd/library/webAPI/webAPI.cpp
vendored
18
external/3rd/library/webAPI/webAPI.cpp
vendored
@@ -17,9 +17,6 @@
|
||||
|
||||
#include "webAPI.h"
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/bio.h>
|
||||
|
||||
using namespace StellaBellum;
|
||||
|
||||
webAPI::webAPI(std::string endpoint, std::string userAgent) : uri(endpoint), userAgent(userAgent), statusCode(0) {}
|
||||
@@ -124,8 +121,8 @@ bool webAPI::fetch(const int &getPost, const int &mimeType) // 0 for json 1 for
|
||||
res = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback); // place the data into readBuffer using writeCallback
|
||||
res = curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); // specify readBuffer as the container for data
|
||||
res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
|
||||
|
||||
switch (getPost) {
|
||||
|
||||
switch (getPost) {
|
||||
case HTTP::GET:
|
||||
res = curl_easy_setopt(curl, CURLOPT_URL, std::string(uri + "?" + sRequest).c_str());
|
||||
break;
|
||||
@@ -137,10 +134,13 @@ bool webAPI::fetch(const int &getPost, const int &mimeType) // 0 for json 1 for
|
||||
}
|
||||
|
||||
if (uri.find("stellabellum") != std::string::npos) {
|
||||
res = curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, "PEM");
|
||||
res = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
|
||||
res = curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, *webAPI::sslctx_function);
|
||||
}
|
||||
// the public one will verify but since this is pinned we don't care about the CA
|
||||
res = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
|
||||
// cloudflare public: ***REMOVED***
|
||||
// cloudflare private: ***REMOVED***
|
||||
res = curl_easy_setopt(curl, CURLOPT_PINNEDPUBLICKEY, vxENCRYPT("***REMOVED***").decrypt());
|
||||
}
|
||||
|
||||
if (res == CURLE_OK) {
|
||||
res = curl_easy_perform(curl); // make the request!
|
||||
|
||||
57
external/3rd/library/webAPI/webAPI.h
vendored
57
external/3rd/library/webAPI/webAPI.h
vendored
@@ -25,8 +25,6 @@
|
||||
#else
|
||||
|
||||
#include <unordered_map>
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <curl/curl.h>
|
||||
|
||||
#endif
|
||||
@@ -115,61 +113,6 @@ namespace StellaBellum {
|
||||
|
||||
// json processor - string to json
|
||||
bool processJSON();
|
||||
|
||||
// our ssl cert
|
||||
inline static CURLcode sslctx_function(CURL *curl, void *sslctx, void *parm) {
|
||||
X509_STORE *store;
|
||||
X509 *cert = NULL;
|
||||
BIO *bio;
|
||||
|
||||
char * ctx = "-----BEGIN CERTIFICATE-----\n"\
|
||||
"MIIEojCCA4qgAwIBAgIUJ88p38SKi9SeyVOF0AQne1O6Vs4wDQYJKoZIhvcNAQEL\n"\
|
||||
"BQAwgYsxCzAJBgNVBAYTAlVTMRkwFwYDVQQKExBDbG91ZEZsYXJlLCBJbmMuMTQw\n"\
|
||||
"MgYDVQQLEytDbG91ZEZsYXJlIE9yaWdpbiBTU0wgQ2VydGlmaWNhdGUgQXV0aG9y\n"\
|
||||
"aXR5MRYwFAYDVQQHEw1TYW4gRnJhbmNpc2NvMRMwEQYDVQQIEwpDYWxpZm9ybmlh\n"\
|
||||
"MB4XDTE2MTIzMTA1MDcwMFoXDTMxMTIyODA1MDcwMFowYjEZMBcGA1UEChMQQ2xv\n"\
|
||||
"dWRGbGFyZSwgSW5jLjEdMBsGA1UECxMUQ2xvdWRGbGFyZSBPcmlnaW4gQ0ExJjAk\n"\
|
||||
"BgNVBAMTHUNsb3VkRmxhcmUgT3JpZ2luIENlcnRpZmljYXRlMIIBIjANBgkqhkiG\n"\
|
||||
"9w0BAQEFAA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/CsF89dkvU+zksP4wzJAMvGiB8Tmc8bKWmIfBnusj3D\n"\
|
||||
"npbKvZL2ch+hwY4SZspJLoKJ4iz5wWSHihwNYxm+KGsJpt2moV15gAuObmDg7nu6\n"\
|
||||
"owOLXtbf62tQOXnXee2peBN1JX/mCHKUSL1mu+wJXjitBEgXJRGSnZl4IGv/m8Q5\n"\
|
||||
"KDeA44tJg2f/le+MertWN/+aTYhK8exu4v/7SaEJHNCwbXCJICg=\n"\
|
||||
"-----END CERTIFICATE-----\n";
|
||||
|
||||
bio = BIO_new_mem_buf(ctx, -1);
|
||||
PEM_read_bio_X509(bio, &cert, 0, NULL);
|
||||
if (cert == NULL) {
|
||||
printf("cert is null");
|
||||
return CURLE_FAILED_INIT;
|
||||
}
|
||||
|
||||
store = SSL_CTX_get_cert_store((SSL_CTX *) sslctx);
|
||||
|
||||
if (X509_STORE_add_cert(store, cert) == 0) {
|
||||
printf("couldn't store cert");
|
||||
return CURLE_FAILED_INIT;
|
||||
}
|
||||
|
||||
X509_free(cert);
|
||||
BIO_free(bio);
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
protected:
|
||||
// http response code (200, 404, etc)
|
||||
long statusCode;
|
||||
|
||||
Reference in New Issue
Block a user