From: Bartlomiej Grzelewski Date: Tue, 1 Jul 2014 15:59:42 +0000 (+0200) Subject: You may extract public key from CertificateImpl now. X-Git-Tag: accepted/tizen/common/20140925.172038~98 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=36140c23a44769697f44082e9c9cf9314c0c5e64;p=platform%2Fcore%2Fsecurity%2Fkey-manager.git You may extract public key from CertificateImpl now. Change-Id: I3c0ed204e2622b0e8a6ca4be5c39f91d6c009def --- diff --git a/src/manager/common/certificate-impl.cpp b/src/manager/common/certificate-impl.cpp index 56362d3..3e446ef 100644 --- a/src/manager/common/certificate-impl.cpp +++ b/src/manager/common/certificate-impl.cpp @@ -23,6 +23,7 @@ #include +#include #include #include @@ -125,6 +126,20 @@ bool CertificateImpl::empty() const { return m_x509 == NULL; } +GenericKey::EvpShPtr CertificateImpl::getEvpShPtr() const { + return GenericKey::EvpShPtr(X509_get_pubkey(m_x509), EVP_PKEY_free); +} + +GenericKey CertificateImpl::getGenericKey() const { + GenericKey::EvpShPtr evp(X509_get_pubkey(m_x509), EVP_PKEY_free); + if (EVP_PKEY_type(evp->type) == EVP_PKEY_RSA) + return GenericKey(evp, KeyType::KEY_RSA_PUBLIC); + if (EVP_PKEY_type(evp->type) == EVP_PKEY_EC) + return GenericKey(evp, KeyType::KEY_ECDSA_PUBLIC); + LogError("Unsupported key type in certificate."); + return GenericKey(); +} + CertificateImpl::~CertificateImpl() { LogDebug("free cert start ptr: " << (void*)m_x509); X509_free(m_x509); diff --git a/src/manager/common/certificate-impl.h b/src/manager/common/certificate-impl.h index ca182c3..d364056 100644 --- a/src/manager/common/certificate-impl.h +++ b/src/manager/common/certificate-impl.h @@ -25,6 +25,8 @@ #include #include +#include + extern "C" { struct x509_st; typedef struct x509_st X509; @@ -44,6 +46,9 @@ public: RawBuffer getDER() const; bool empty() const; + GenericKey::EvpShPtr getEvpShPtr() const; + GenericKey getGenericKey() const; + X509* getX509() const; virtual ~CertificateImpl();