Skip to content

Commit 9e7f7bf

Browse files
committed
cURL - https use pem in bin dir OpenSSL / no generate
1 parent 334402f commit 9e7f7bf

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

libs/openFrameworks/utils/ofURLFileLoader.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ using std::string;
1616

1717
#define MAX_POSTFIELDS_SIZE (1024 * 1024)
1818

19-
#define NO_OPENSSL 1
2019
#include <openssl/evp.h>
2120
#include <openssl/pem.h>
2221
#include <openssl/x509.h>
@@ -25,10 +24,9 @@ using std::string;
2524
#include <iostream>
2625
#include <fstream>
2726

28-
#if !defined(NO_OPENSSL)
29-
#define CERTIFICATE_FILE "cacert.pem"
30-
#define PRIVATE_KEY_FILE "cacert.key"
31-
#endif
27+
#define CERTIFICATE_FILE "cacert.pem"
28+
#define PRIVATE_KEY_FILE "cacert.key"
29+
3230
#endif
3331

3432
int ofHttpRequest::nextID = 0;
@@ -51,10 +49,8 @@ class ofURLFileLoaderImpl : public ofThread, public ofBaseURLFileLoader {
5149
void remove(int id);
5250
void clear();
5351
void stop();
54-
#if !defined(NO_OPENSSL)
5552
bool checkValidCertifcate(const std::string& cert_file);
5653
void createSSLCertificate();
57-
#endif
5854
ofHttpResponse handleRequest(const ofHttpRequest & request);
5955
int handleRequestAsync(const ofHttpRequest & request); // returns id
6056

@@ -134,8 +130,9 @@ void ofURLFileLoaderImpl::stop() {
134130
curl_global_cleanup();
135131
}
136132

137-
#if !defined(NO_OPENSSL)
133+
138134
bool ofURLFileLoaderImpl::checkValidCertifcate(const std::string & cert_file) {
135+
#if !defined(NO_OPENSSL)
139136
try {
140137
FILE * fp = fopen(cert_file.c_str(), "r");
141138
if (!fp) return false;
@@ -154,10 +151,12 @@ bool ofURLFileLoaderImpl::checkValidCertifcate(const std::string & cert_file) {
154151
ofLogError("ofURLFileLoader") << "Unknown error occurred in checkValidCertifcate.";
155152
return false;
156153
}
154+
#endif
157155
}
158156

159157

160158
void ofURLFileLoaderImpl::createSSLCertificate() {
159+
#if !defined(NO_OPENSSL)
161160
try {
162161
EVP_PKEY * pkey = nullptr;
163162
X509 * x509 = nullptr;
@@ -233,8 +232,9 @@ void ofURLFileLoaderImpl::createSSLCertificate() {
233232
} catch (...) {
234233
ofLogError("ofURLFileLoader") << "Unknown error occurred in createSSLCertificate.";
235234
}
236-
}
237235
#endif
236+
}
237+
238238

239239

240240
void ofURLFileLoaderImpl::threadedFunction() {
@@ -317,19 +317,13 @@ ofHttpResponse ofURLFileLoaderImpl::handleRequest(const ofHttpRequest & request)
317317
}
318318
}
319319
if(version->features & CURL_VERSION_SSL) {
320-
#if !defined(NO_OPENSSL)
321320
const std::string certPath = ofToDataPath(CERTIFICATE_FILE, true);
322321
if (ofFile::doesFileExist(certPath) && checkValidCertifcate(certPath)) {
323-
ofLogVerbose("ofURLFileLoader") << "SSL valid certificate found at " << certPath;
324-
} else {
325-
ofLogVerbose("ofURLFileLoader") << "SSL certificate not found - generating";
326-
createSSLCertificate();
322+
curl_easy_setopt(curl.get(), CURLOPT_CAINFO, certPath.c_str());
327323
}
328-
curl_easy_setopt(curl.get(), CURLOPT_CAINFO, certPath.c_str());
329324
#ifndef TARGET_WIN32
330325
curl_easy_setopt(curl.get(), CURLOPT_CAPATH, ofToDataPath("./", true).c_str());
331326
#endif
332-
#endif
333327
curl_easy_setopt(curl.get(), CURLOPT_SSL_VERIFYPEER, false);
334328
curl_easy_setopt(curl.get(), CURLOPT_SSL_VERIFYHOST, 2L);
335329
}

0 commit comments

Comments
 (0)