Skip to content

Commit 6cd4859

Browse files
Merge pull request #54 from ynput/develop
0.1.5 release
2 parents a233d01 + 824c91b commit 6cd4859

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/AyonCppApi/AyonCppApi.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ AyonApi::AyonApi(const std::optional<std::string> &logFilePos,
168168
if (!ayonSSLPath.empty()) {
169169
m_log->info(m_log->key("AyonApi"), "Using AYON_SSL_CERT_PATH: {}", ayonSSLPath);
170170
m_ayonServer->set_ca_cert_path(ayonSSLPath.c_str());
171+
m_caCertPath = ayonSSLPath;
171172
} else {
172173
m_log->warn(m_log->key("AyonApi"), "No AYON_SSL_CERT_PATH set, trying to get OpenSSL dir");
173174
try {
@@ -681,6 +682,25 @@ AyonApi::serialCorePost(const std::string &endPoint,
681682
while (retries <= m_maxCallRetries) {
682683
try {
683684
response = m_ayonServer->Post(endPoint, headers, Payload, "application/json");
685+
if (!response) {
686+
auto err = response.error();
687+
m_log->warn("AyonApi::serialCorePost response is null: {}", httplib::to_string(err));
688+
if (err == httplib::Error::SSLServerVerification) {
689+
if (m_caCertPath.empty() || !std::filesystem::exists(m_caCertPath) ||
690+
!std::filesystem::is_regular_file(m_caCertPath)) {
691+
m_log->error("AyonApi::serialCorePost SSL verification failed and cert path is invalid: '{}' - not retrying", m_caCertPath);
692+
return "";
693+
}
694+
m_log->warn("AyonApi::serialCorePost SSL verification failed with a valid cert path present - rebuilding client and retrying");
695+
m_ayonServer = std::make_unique<httplib::Client>(m_serverUrl);
696+
m_ayonServer->set_keep_alive(true);
697+
m_ayonServer->set_ca_cert_path(m_caCertPath.c_str());
698+
m_ayonServer->enable_server_certificate_verification(true);
699+
}
700+
retries++;
701+
std::this_thread::sleep_for(std::chrono::milliseconds(m_retryWait));
702+
continue;
703+
}
684704
responseStatus = response->status;
685705
retries++;
686706

@@ -853,6 +873,7 @@ AyonApi::setSSL() {
853873
if (std::filesystem::exists(envCertFile)) {
854874
m_log->info("Using cert based on env variable (SSL_CERT_FILE): {}", envCertFile);
855875
m_ayonServer->set_ca_cert_path(envCertFile);
876+
m_caCertPath = envCertFile;
856877
return;
857878
}
858879
}
@@ -864,6 +885,7 @@ AyonApi::setSSL() {
864885
if (std::filesystem::exists(certFileCLI)) {
865886
m_log->info("Using cert based on CLI var: {}", certFileCLI);
866887
m_ayonServer->set_ca_cert_path(certFileCLI.c_str());
888+
m_caCertPath = certFileCLI;
867889
return;
868890
}
869891

@@ -874,6 +896,7 @@ AyonApi::setSSL() {
874896
if (std::filesystem::exists(certFileSSLEAY)) {
875897
m_log->info("Using cert based on SSLEAY_DIR: {}", certFileSSLEAY);
876898
m_ayonServer->set_ca_cert_path(certFileSSLEAY.c_str());
899+
m_caCertPath = certFileSSLEAY;
877900
return;
878901
}
879902

@@ -913,6 +936,7 @@ AyonApi::setSSL() {
913936
if (std::filesystem::exists(certPath)) {
914937
m_log->info("Using bundled certificate (via library path): {}", certPath);
915938
m_ayonServer->set_ca_cert_path(certPath.c_str());
939+
m_caCertPath = certPath;
916940
return;
917941
}
918942

src/AyonCppApi/AyonCppApi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ class AyonApi {
202202
// Core Dependencies
203203
std::unique_ptr<httplib::Client> m_ayonServer;
204204
std::shared_ptr<AyonLogger> m_log;
205+
// Path to the CA cert bundle actually in use, recorded so a client
206+
// can be rebuilt with the same configuration after a verification
207+
// failure, without re-running cert path discovery.
208+
std::string m_caCertPath;
205209

206210
// Configuration from Constructor
207211
const std::string m_authKey;

0 commit comments

Comments
 (0)