From 8f38360ef7391ebe213a4e7ff1812dd3309c93fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Mon, 21 Sep 2009 14:52:09 +0000 Subject: [PATCH] new certificate attribute get methods --- src/openssl.hxx | 65 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/src/openssl.hxx b/src/openssl.hxx index 9166198..578c91b 100644 --- a/src/openssl.hxx +++ b/src/openssl.hxx @@ -286,9 +286,68 @@ namespace openssl { c); return std::string((char*)c, SHA_DIGEST_LENGTH); } - //! Get label. - std::string label() const { - return std::string(); + //! Get common name. + std::string commonName() const { + X509_NAME *name(X509_get_subject_name(_x509)); + ASN1_STRING* cn + (X509_NAME_ENTRY_get_data + (X509_NAME_get_entry + (name, X509_NAME_get_index_by_NID(name, NID_commonName, -1)))); + return std::string((char*)M_ASN1_STRING_data(cn), + M_ASN1_STRING_length(cn)); + } + //! Get country name. + std::string countryName() const { + X509_NAME *name(X509_get_subject_name(_x509)); + ASN1_STRING* cn + (X509_NAME_ENTRY_get_data + (X509_NAME_get_entry + (name, X509_NAME_get_index_by_NID(name, NID_countryName, -1)))); + return std::string((char*)M_ASN1_STRING_data(cn), + M_ASN1_STRING_length(cn)); + } + //! Get locality name. + std::string localityName() const { + X509_NAME *name(X509_get_subject_name(_x509)); + ASN1_STRING* cn + (X509_NAME_ENTRY_get_data + (X509_NAME_get_entry + (name, X509_NAME_get_index_by_NID(name, NID_localityName, -1)))); + return std::string((char*)M_ASN1_STRING_data(cn), + M_ASN1_STRING_length(cn)); + } + //! Get state or province name. + std::string stateOrProvinceName() const { + X509_NAME *name(X509_get_subject_name(_x509)); + ASN1_STRING* cn + (X509_NAME_ENTRY_get_data + (X509_NAME_get_entry + (name, X509_NAME_get_index_by_NID + (name, NID_stateOrProvinceName, -1)))); + return std::string((char*)M_ASN1_STRING_data(cn), + M_ASN1_STRING_length(cn)); + } + //! Get organization name. + std::string organizationName() const { + X509_NAME *name(X509_get_subject_name(_x509)); + ASN1_STRING* cn + (X509_NAME_ENTRY_get_data + (X509_NAME_get_entry + (name, X509_NAME_get_index_by_NID + (name, NID_organizationName, -1)))); + return std::string((char*)M_ASN1_STRING_data(cn), + M_ASN1_STRING_length(cn)); + } + //! Get organizational unit name. + std::string organizationalUnitName() const { + X509_NAME *name(X509_get_subject_name(_x509)); + ASN1_STRING* cn + (X509_NAME_ENTRY_get_data + (X509_NAME_get_entry + (name, X509_NAME_get_index_by_NID + (name, NID_organizationalUnitName, -1)))); + return std::string((char*)M_ASN1_STRING_data(cn), + M_ASN1_STRING_length(cn)); } private: ::X509* _x509;