From a09bbf5f06a9ed2f5011999c0a6eef78b9e1ca56 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 12 Jul 2015 20:40:32 +0100 Subject: [PATCH] Rename a couple of Certificate methods and add accessors for organization and organizational unit name. --- src/certificates.cc | 18 +++++++++++++++++- src/certificates.h | 8 ++++++-- src/decrypted_kdm.cc | 2 +- src/encrypted_kdm.cc | 2 +- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/certificates.cc b/src/certificates.cc index cc443746..e5acdd25 100644 --- a/src/certificates.cc +++ b/src/certificates.cc @@ -211,13 +211,29 @@ Certificate::subject () const } string -Certificate::common_name () const +Certificate::subject_common_name () const { DCP_ASSERT (_certificate); return get_name_part (X509_get_subject_name (_certificate), NID_commonName); } +string +Certificate::subject_organization_name () const +{ + DCP_ASSERT (_certificate); + + return get_name_part (X509_get_subject_name (_certificate), NID_organizationName); +} + +string +Certificate::subject_organizational_unit_name () const +{ + DCP_ASSERT (_certificate); + + return get_name_part (X509_get_subject_name (_certificate), NID_organizationalUnitName); +} + string Certificate::serial () const { diff --git a/src/certificates.h b/src/certificates.h index 0cc52396..2ece6f78 100644 --- a/src/certificates.h +++ b/src/certificates.h @@ -59,10 +59,14 @@ public: Certificate& operator= (Certificate const &); std::string certificate (bool with_begin_end = false) const; - std::string issuer () const; std::string serial () const; + + std::string issuer () const; + std::string subject () const; - std::string common_name () const; + std::string subject_common_name () const; + std::string subject_organization_name () const; + std::string subject_organizational_unit_name () const; X509* x509 () const { return _certificate; diff --git a/src/decrypted_kdm.cc b/src/decrypted_kdm.cc index 9a9a1694..62058fee 100644 --- a/src/decrypted_kdm.cc +++ b/src/decrypted_kdm.cc @@ -260,7 +260,7 @@ DecryptedKDM::encrypt (shared_ptr signer, Certificate recipient, F keys.push_back (lines.str ()); } - string device_list_description = recipient.common_name (); + string device_list_description = recipient.subject_common_name (); if (device_list_description.find (".") != string::npos) { device_list_description = device_list_description.substr (device_list_description.find (".") + 1); } diff --git a/src/encrypted_kdm.cc b/src/encrypted_kdm.cc index fe96250f..948e26a5 100644 --- a/src/encrypted_kdm.cc +++ b/src/encrypted_kdm.cc @@ -524,7 +524,7 @@ EncryptedKDM::EncryptedKDM ( kre.not_valid_before = not_valid_before; kre.not_valid_after = not_valid_after; kre.authorized_device_info.device_list_identifier = make_uuid (); - string n = recipient.common_name (); + string n = recipient.subject_common_name (); if (n.find (".") != string::npos) { n = n.substr (n.find (".") + 1); } -- 2.30.2