From fdd68b17f3c48f31ab39cad322d66cf84ce37356 Mon Sep 17 00:00:00 2001 From: Guenter Obiltschnig Date: Thu, 25 Feb 2016 22:15:32 +0100 Subject: [PATCH] added X509Certificate::equals() --- Crypto/include/Poco/Crypto/X509Certificate.h | 8 ++++++++ Crypto/src/X509Certificate.cpp | 8 ++++++++ Crypto/testsuite/src/CryptoTest.cpp | 5 +++++ 3 files changed, 21 insertions(+) diff --git a/Crypto/include/Poco/Crypto/X509Certificate.h b/Crypto/include/Poco/Crypto/X509Certificate.h index 72d39ca0c..f4e09cdbf 100644 --- a/Crypto/include/Poco/Crypto/X509Certificate.h +++ b/Crypto/include/Poco/Crypto/X509Certificate.h @@ -130,6 +130,14 @@ public: /// Returns true if verification against the issuer certificate /// was successful, false otherwise. + bool equals(const X509Certificate& otherCertificate) const; + /// Checks whether the certificate is equal to + /// the other certificate, by comparing the hashes + /// of both certificates. + /// + /// Returns true if both certificates are identical, + /// otherwise false. + const X509* certificate() const; /// Returns the underlying OpenSSL certificate. diff --git a/Crypto/src/X509Certificate.cpp b/Crypto/src/X509Certificate.cpp index f2263dcfd..0137c6bfc 100644 --- a/Crypto/src/X509Certificate.cpp +++ b/Crypto/src/X509Certificate.cpp @@ -284,4 +284,12 @@ bool X509Certificate::issuedBy(const X509Certificate& issuerCertificate) const } +bool X509Certificate::equals(const X509Certificate& otherCertificate) const +{ + X509* pCert = const_cast(_pCert); + X509* pOtherCert = const_cast(otherCertificate.certificate()); + return X509_cmp(pCert, pOtherCert) == 0; +} + + } } // namespace Poco::Crypto diff --git a/Crypto/testsuite/src/CryptoTest.cpp b/Crypto/testsuite/src/CryptoTest.cpp index cfc9e67f3..7072a8632 100644 --- a/Crypto/testsuite/src/CryptoTest.cpp +++ b/Crypto/testsuite/src/CryptoTest.cpp @@ -304,6 +304,11 @@ void CryptoTest::testCertificate() // fails with recent OpenSSL versions: // assert (cert.issuedBy(cert)); + + std::istringstream otherCertStream(APPINF_PEM); + X509Certificate otherCert(otherCertStream); + + assert (cert.equals(otherCert)); }