From aa79e39575a1496d52dcb18c899d81cc4238c62d Mon Sep 17 00:00:00 2001 From: John Date: Wed, 5 Jun 2024 12:18:54 +0300 Subject: [PATCH] Fixed a potentially bad optional access (#79) Signed-off-by: AssemblyJohn --- lib/evse_security/evse_security.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/evse_security/evse_security.cpp b/lib/evse_security/evse_security.cpp index 4daf761..1c4ca3a 100644 --- a/lib/evse_security/evse_security.cpp +++ b/lib/evse_security/evse_security.cpp @@ -710,9 +710,22 @@ OCSPRequestDataList EvseSecurity::get_v2g_ocsp_request_data() { return OCSPRequestDataList(); } - std::vector chain = std::move( - X509CertificateBundle(secc_key_pair.info.value().certificate.value(), EncodingFormat::PEM).split()); - return get_ocsp_request_data_internal(this->ca_bundle_path_map.at(CaCertificateType::V2G), chain); + std::vector chain; + + if (secc_key_pair.info.value().certificate.has_value()) { + chain = std::move( + X509CertificateBundle(secc_key_pair.info.value().certificate.value(), EncodingFormat::PEM).split()); + } else if (secc_key_pair.info.value().certificate_single.has_value()) { + chain = std::move( + X509CertificateBundle(secc_key_pair.info.value().certificate_single.value(), EncodingFormat::PEM) + .split()); + } else { + EVLOG_error << "Could not load v2g ocsp cache leaf chain!"; + } + + if (!chain.empty()) { + return get_ocsp_request_data_internal(this->ca_bundle_path_map.at(CaCertificateType::V2G), chain); + } } catch (const CertificateLoadException& e) { EVLOG_error << "Could not get v2g ocsp cache, certificate load failure: " << e.what(); }