Regarding the issue of the root certificate being unable to verify the certificate,
JamesLebron opened this issue · 3 comments
Dear author, hello.
I have encountered some issues regarding certificate-related functionality, particularly regarding the problem of root certificate verification for certificates.
-
Currently, I have two certificates: 1.pem (containing certificate A) and 2.pem (containing certificates B and C). The complete certificate chain is A/B/C (with C being the top-level CA).
-
When I attempt to verify 1.pem using 2.pem (root), I receive a failure result (from the return value of the Certificate::verify function in Certificate.cpp).
-
I have tried swapping the order of certificates B and C in 2.pem, but I still receive a failure result (from the return value of the Certificate::verify function in Certificate.cpp).
-
In the same operating system and environment, I have tried using the openssl command for verification:
openssl verify -CAfile 2.pem 1.pem
I have tried both swapping and not swapping the order of certificates B and C in 2.pem, and in both cases, the verification succeeds.
Dear author, could you please provide me with some suggestions for modification?
Below is the PEM content of the certificates:
[1.pem]
-----BEGIN CERTIFICATE-----
MIIGfzCCBOegAwIBAgIRAP90I3tYvw8Yh0nkJvGU0qwwDQYJKoZIhvcNAQEMBQAw
WTELMAkGA1UEBhMCQ04xJTAjBgNVBAoTHFRydXN0QXNpYSBUZWNobm9sb2dpZXMs
IEluYy4xIzAhBgNVBAMTGlRydXN0QXNpYSBSU0EgRFYgVExTIENBIEcyMB4XDTIz
MDgwMTAwMDAwMFoXDTI0MDgzMDIzNTk1OVowGjEYMBYGA1UEAxMPd3lldmNoYXJn
ZXIuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArCXBTauJGBG1
ZI/eoR5OAPIXCGd9stkFbAaNRTsqmJ3JjoZve8u0xvl9r2sw4Ya9YoyYN5+Sxbvr
awu2jUeYOTG8k30lcw9vpB/k/btsvNuWBDJRklj9LKgzbmBrXFHBSmVPlen7SFu4
nttZctlIrGWByete9jn69y5UArlOGw6mXYBDromIcbH0Dw36uCTzGXFqQt03VWjC
tInUaX9WiLdELvUjZZPXYNq+RiXAzNGtNK9rNZJky7wqjOD4i3PLi9zfEeqG75ti
kIcwC4qFhli6Dz/EmaObwe1868caG+rS+DFO4mf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2P2N7Sw4ScDV7oL8kCAwEAAaOBwDCBvTAdBgNVHQ4EFgQU
oBEKIz6W8Qfs4q8p74Klf9AwpLQwDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQF
MAMBAf8wewYDVR0fBHQwcjA4oDagNIYyaHR0cDovL2NybC5jb21vZG9jYS5jb20v
QUFBQ2VydGlmaWNhdGVTZXJ2aWNlcy5jcmwwNqA0oDKGMGh0dHA6Ly9jcmwuY29t
b2RvLm5ldC9BQUFDZXJ0aWZpY2F0ZVNlcnZpY2VzLmNybDANBgkqhkiG9w0BAQUF
AAOCAQEACFb8AvCb6P+k+tZ7xkSAzk/ExfYAWMymtrwUSWgEdujm7l3sAg9g1o1Q
GE8mTgHj5rCl7r+8dFRBv/38ErjHT1r0iWAFf2C3BUrz9vHCv8S5dIa2LX1rzNLz
Rt0vxuBqw8M0Ayx9lt1awg6nCpnBBYurDC/zXDrPbDdVCYfeU0BsWO/8tqtlbgT2
G9w84FoVxp7Z8VlIMCFlA2zs6SFz7JsDoeA3raAVGI/6ugLOpyypEBMs1OUIJqsi
l2D4kF501KKaU73yqWjgom7C12yxow+ev+to51byrvLjKzg6CYG1a4XXvi3tPxq3
smPi9WIsgtRqAEFQ8TmDn5XpNpaYbg==
-----END CERTIFICATE-----
Hello,
I just made the following test with your certificates and everything was fine, the verification was successful :
Certificate cert(std::filesystem::path("1.pem"));
CHECK(cert.isValid());
Certificate ca_certs(std::filesystem::path("2.pem"));
CHECK(ca_certs.isValid());
CHECK(cert.verify(ca_certs.certificateChain()));
How did you make your verification using the Certificate
class?
Dear author, hello.
-
I used the approach you provided, "constructing a Certificate from a file path," and the result was consistent with yours. The verification passed.
-
Therefore, I continued to investigate and found that the problem lies in the following code: DefaultChargePointEventsHandler::checkFirmwareSigningCertificate.
ocpp::types::UpdateFirmwareStatusEnumType DefaultChargePointEventsHandler::checkFirmwareSigningCertificate(
const ocpp::x509::Certificate& signing_certificate)
{
UpdateFirmwareStatusEnumType ret = UpdateFirmwareStatusEnumType::InvalidCertificate;
cout << "Check of firmware signing certificate requested : subject = " << signing_certificate.subjectString()
<< " - issuer = " << signing_certificate.issuerString() << endl;
// Load all installed Manufacturer CA certificates
std::vector<Certificate> ca_certificates;
for (auto const& dir_entry : std::filesystem::directory_iterator{m_working_dir})
{
if (!dir_entry.is_directory())
{
std::string filename = dir_entry.path().filename().string();
if (ocpp::helpers::startsWith(filename, "fw_") && ocpp::helpers::endsWith(filename, ".pem"))
{
ca_certificates.emplace_back(dir_entry.path());
}
}
}
if (!ca_certificates.empty())
{
// Check signing certificate
if (signing_certificate.verify(ca_certificates))
{
ret = UpdateFirmwareStatusEnumType::Accepted;
}
}
else
{
cout << "No manufacturer CA installed" << endl;
}
return ret;
}
- I made the following modifications to the code, and the verification passed.
if (!ca_certificates.empty())
{
bool verify_result = false;
// Check signing certificate
for (auto cer : ca_certificates)
{
verify_result = signing_certificate.verify(cer.certificateChain());
if (verify_result)
{
ret = UpdateFirmwareStatusEnumType::Accepted;
break;
}
}
}
else
{
LOG_DEBUG << "No manufacturer CA installed";
}
However, I have encountered another issue, which I will submit to you as a new issue later. Could you please provide some guidance?