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

Fixed an issue with certificate directory support #20

Merged
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
29 changes: 26 additions & 3 deletions lib/evse_security/evse_security.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,17 +507,29 @@ void EvseSecurity::update_ocsp_cache(const CertificateHashData& certificate_hash
}
}
} catch (const CertificateLoadException& e) {
EVLOG_error << "Could update ocsp cache, certificate load failure!";
EVLOG_error << "Could not update ocsp cache, certificate load failure!";
}
}

bool EvseSecurity::is_ca_certificate_installed(CaCertificateType certificate_type) {
try {
X509Wrapper(this->ca_bundle_path_map.at(certificate_type), EncodingFormat::PEM);
return true;
X509CertificateBundle bundle(this->ca_bundle_path_map.at(certificate_type), EncodingFormat::PEM);

// Search for a valid self-signed root
auto& hierarchy = bundle.get_certficate_hierarchy();

// Get all roots and search for a valid self-signed
for (auto& root : hierarchy.get_hierarchy()) {
if (root.certificate.is_selfsigned() && root.certificate.is_valid())
return true;
}
} catch (const CertificateLoadException& e) {
EVLOG_error << "Could not load ca certificate type:"
<< conversions::ca_certificate_type_to_string(certificate_type);
return false;
AssemblyJohn marked this conversation as resolved.
Show resolved Hide resolved
}

return false;
}

std::string EvseSecurity::generate_certificate_signing_request(LeafCertificateType certificate_type,
Expand Down Expand Up @@ -648,6 +660,17 @@ std::string EvseSecurity::get_verify_file(CaCertificateType certificate_type) {
EVLOG_debug << "Requesting certificate file: [" << conversions::ca_certificate_type_to_string(certificate_type)
<< "] file:" << verify_file.get_path();

// If we are using a directory, search for the first valid root file
if (verify_file.is_using_directory()) {
auto& hierarchy = verify_file.get_certficate_hierarchy();

// Get all roots and search for a valid self-signed
for (auto& root : hierarchy.get_hierarchy()) {
if (root.certificate.is_selfsigned() && root.certificate.is_valid())
return root.certificate.get_file().value_or("");
}
}
Comment on lines +664 to +672
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: In case there are multiple roots, this interface is probably not adequate. We would need to be able to return a list of certificates somehow.


return verify_file.get_path().string();
}

Expand Down