diff options
author | Jack Lloyd <[email protected]> | 2018-03-05 16:22:07 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-03-05 16:22:07 -0500 |
commit | 65d81676334a80829ab756725873ed62dc852c6b (patch) | |
tree | 0f46600287366a6f3055d1f2721cfdc12eb8663e | |
parent | 22ca08fca54ea9f3ae5691bb3e4e3625b7441b5d (diff) |
Add X509_Certificate::subject_public_key_info
Fixes #277
-rw-r--r-- | src/lib/x509/x509cert.cpp | 13 | ||||
-rw-r--r-- | src/lib/x509/x509cert.h | 6 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/lib/x509/x509cert.cpp b/src/lib/x509/x509cert.cpp index 66921ed66..d47021247 100644 --- a/src/lib/x509/x509cert.cpp +++ b/src/lib/x509/x509cert.cpp @@ -32,6 +32,7 @@ struct X509_Certificate_Data X509_Time m_not_before; X509_Time m_not_after; std::vector<uint8_t> m_subject_public_key_bits; + std::vector<uint8_t> m_subject_public_key_bits_seq; std::vector<uint8_t> m_subject_public_key_bitstring; std::vector<uint8_t> m_subject_public_key_bitstring_sha1; AlgorithmIdentifier m_subject_public_key_algid; @@ -186,6 +187,8 @@ std::unique_ptr<X509_Certificate_Data> parse_x509_cert_body(const X509_Object& o data->m_subject_public_key_bits.assign(public_key.bits(), public_key.bits() + public_key.length()); + data->m_subject_public_key_bits_seq = ASN1::put_in_sequence(data->m_subject_public_key_bits); + BER_Decoder(data->m_subject_public_key_bits) .decode(data->m_subject_public_key_algid) .decode(data->m_subject_public_key_bitstring, BIT_STRING); @@ -280,8 +283,7 @@ std::unique_ptr<X509_Certificate_Data> parse_x509_cert_body(const X509_Object& o try { - std::unique_ptr<Public_Key> pub_key( - X509::load_key(ASN1::put_in_sequence(data->m_subject_public_key_bits))); + std::unique_ptr<Public_Key> pub_key(X509::load_key(data->m_subject_public_key_bits_seq)); Certificate_Status_Code sig_status = obj.verify_signature(*pub_key); @@ -375,6 +377,11 @@ const std::vector<uint8_t>& X509_Certificate::subject_public_key_bits() const return data().m_subject_public_key_bits; } +const std::vector<uint8_t>& X509_Certificate::subject_public_key_info() const + { + return data().m_subject_public_key_bits_seq; + } + const std::vector<uint8_t>& X509_Certificate::subject_public_key_bitstring() const { return data().m_subject_public_key_bitstring; @@ -632,7 +639,7 @@ std::unique_ptr<Public_Key> X509_Certificate::load_subject_public_key() const { try { - return std::unique_ptr<Public_Key>(X509::load_key(ASN1::put_in_sequence(this->subject_public_key_bits()))); + return std::unique_ptr<Public_Key>(X509::load_key(subject_public_key_info())); } catch(std::exception& e) { diff --git a/src/lib/x509/x509cert.h b/src/lib/x509/x509cert.h index 637efd569..34be10e68 100644 --- a/src/lib/x509/x509cert.h +++ b/src/lib/x509/x509cert.h @@ -70,6 +70,12 @@ class BOTAN_PUBLIC_API(2,0) X509_Certificate : public X509_Object const std::vector<uint8_t>& subject_public_key_bits() const; /** + * Get the SubjectPublicKeyInfo associated with this certificate. + * @return subject public key info of this certificate + */ + const std::vector<uint8_t>& subject_public_key_info() const; + + /** * Return the algorithm identifier of the public key */ const AlgorithmIdentifier& subject_public_key_algo() const; |