From 38aa86de2a4288658e9fad09433c78a23a3dcfc1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Thu, 29 Dec 2016 11:19:27 -0500
Subject: [PATCH] crypto/crl: add getIssuerName, getIssuerUID

---
 include/opendht/crypto.h |  6 ++++++
 src/crypto.cpp           | 26 ++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/include/opendht/crypto.h b/include/opendht/crypto.h
index efee4c0c..3d4f4d52 100644
--- a/include/opendht/crypto.h
+++ b/include/opendht/crypto.h
@@ -213,6 +213,12 @@ public:
      */
     Blob getNumber() const;
 
+    /** Read CRL issuer Common Name (CN) */
+    std::string getIssuerName() const;
+
+    /** Read CRL issuer User ID (UID) */
+    std::string getIssuerUID() const;
+
     time_point getUpdateTime() const;
     time_point getNextUpdateTime() const;
 
diff --git a/src/crypto.cpp b/src/crypto.cpp
index c320136c..0c91d885 100644
--- a/src/crypto.cpp
+++ b/src/crypto.cpp
@@ -962,6 +962,32 @@ RevocationList::revoke(const Certificate& crt, std::chrono::system_clock::time_p
         throw CryptoException(std::string("Can't revoke certificate: ") + gnutls_strerror(err));
 }
 
+static std::string
+getCRLIssuerDN(gnutls_x509_crl_t cert, const char* oid)
+{
+    std::string dn;
+    dn.resize(512);
+    size_t dn_sz = dn.size();
+    int ret = gnutls_x509_crl_get_issuer_dn_by_oid(cert, oid, 0, 0, &(*dn.begin()), &dn_sz);
+    if (ret != GNUTLS_E_SUCCESS)
+        return {};  
+    dn.resize(dn_sz);
+    return dn;
+}
+
+std::string
+RevocationList::getIssuerName() const
+{
+    return getCRLIssuerDN(crl, GNUTLS_OID_X520_COMMON_NAME);
+}
+
+/** Read CRL issuer User ID (UID) */
+std::string
+RevocationList::getIssuerUID() const
+{
+    return getCRLIssuerDN(crl, GNUTLS_OID_LDAP_UID);
+}
+
 RevocationList::time_point
 RevocationList::getNextUpdateTime() const
 {
-- 
GitLab