Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CA certificate path customization for HTTPS connections #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/uid2client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "keyparser.h"
#include "uid2encryption.h"
#include "version.h"

#include <cstdlib> // For getenv
#include <uid2/uid2client.h>

#include <mutex>
Expand All @@ -27,7 +27,16 @@ struct UID2Client::Impl {
{
macaron::Base64::Decode(secretKey, this->secretKey_);

if (endpoint_.find("https") != 0) {
if (endpoint_.find("https") == 0) {
// Check if the CA_CERT_FILE_PATH/CA_CERT_DIR_PATH environment variables are set
const char* caCertFilePath = std::getenv("CA_CERT_FILE_PATH");
const char* caCertDirPath = std::getenv("CA_CERT_DIR_PATH");

// Use CA_CERT_FILE_PATH/CA_CERT_DIR_PATH if set, otherwise fallback to the default path
httpClient_.set_ca_cert_path(caCertFilePath ? caCertFilePath : "/etc/ssl/certs/ca-certificates.crt",
caCertDirPath ? caCertDirPath : "/etc/ssl/certs/");
httpClient_.enable_server_certificate_verification(true);
} else {
// TODO: non-https endpoint warning
}

Expand Down