diff options
26 files changed, 52 insertions, 39 deletions
@@ -4,6 +4,9 @@ Release Notes Version 1.11.35, Not Yet Released ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +* Rename Public_Key::x509_subject_public_key, which does not return a + X.509 SubjectPublicKey, to public_key_bits. Add a new non-virtual function + Public_Key::subject_public_key which does exactly that. (GH #685) Version 1.11.34, 2016-11-28 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/lib/ffi/ffi.cpp b/src/lib/ffi/ffi.cpp index 3a943378d..4727c0763 100644 --- a/src/lib/ffi/ffi.cpp +++ b/src/lib/ffi/ffi.cpp @@ -998,7 +998,7 @@ int botan_pubkey_fingerprint(botan_pubkey_t key, const char* hash_fn, { return BOTAN_FFI_DO(Botan::Public_Key, key, k, { std::unique_ptr<Botan::HashFunction> h(Botan::HashFunction::create(hash_fn)); - return write_vec_output(out, out_len, h->process(k.x509_subject_public_key())); + return write_vec_output(out, out_len, h->process(k.public_key_bits())); }); } diff --git a/src/lib/prov/openssl/openssl_rsa.cpp b/src/lib/prov/openssl/openssl_rsa.cpp index 77f74fab6..21822a627 100644 --- a/src/lib/prov/openssl/openssl_rsa.cpp +++ b/src/lib/prov/openssl/openssl_rsa.cpp @@ -44,7 +44,7 @@ class OpenSSL_RSA_Encryption_Operation : public PK_Ops::Encryption OpenSSL_RSA_Encryption_Operation(const RSA_PublicKey& rsa, int pad, size_t pad_overhead) : m_openssl_rsa(nullptr, ::RSA_free), m_padding(pad) { - const std::vector<byte> der = rsa.x509_subject_public_key(); + const std::vector<byte> der = rsa.public_key_bits(); const byte* der_ptr = der.data(); m_openssl_rsa.reset(::d2i_RSAPublicKey(nullptr, &der_ptr, der.size())); if(!m_openssl_rsa) @@ -143,7 +143,7 @@ class OpenSSL_RSA_Verification_Operation : public PK_Ops::Verification_with_EMSA PK_Ops::Verification_with_EMSA(emsa), m_openssl_rsa(nullptr, ::RSA_free) { - const std::vector<byte> der = rsa.x509_subject_public_key(); + const std::vector<byte> der = rsa.public_key_bits(); const byte* der_ptr = der.data(); m_openssl_rsa.reset(::d2i_RSAPublicKey(nullptr, &der_ptr, der.size())); } diff --git a/src/lib/prov/pkcs11/p11_ecc_key.cpp b/src/lib/prov/pkcs11/p11_ecc_key.cpp index 52f98b079..527daceaf 100644 --- a/src/lib/prov/pkcs11/p11_ecc_key.cpp +++ b/src/lib/prov/pkcs11/p11_ecc_key.cpp @@ -106,7 +106,7 @@ size_t PKCS11_EC_PrivateKey::key_length() const return m_domain_params.get_order().bits(); } -std::vector<byte> PKCS11_EC_PrivateKey::x509_subject_public_key() const +std::vector<byte> PKCS11_EC_PrivateKey::public_key_bits() const { return unlock(EC2OSP(public_point(), PointGFp::COMPRESSED)); } diff --git a/src/lib/prov/pkcs11/p11_ecc_key.h b/src/lib/prov/pkcs11/p11_ecc_key.h index 0a222cb79..69e612c33 100644 --- a/src/lib/prov/pkcs11/p11_ecc_key.h +++ b/src/lib/prov/pkcs11/p11_ecc_key.h @@ -201,7 +201,7 @@ class BOTAN_DLL PKCS11_EC_PrivateKey : public virtual Private_Key, // Private_Key methods - std::vector<byte> x509_subject_public_key() const override; + std::vector<byte> public_key_bits() const override; std::size_t key_length() const override; diff --git a/src/lib/prov/tpm/tpm.cpp b/src/lib/prov/tpm/tpm.cpp index 0c2f9353e..b3a846d4e 100644 --- a/src/lib/prov/tpm/tpm.cpp +++ b/src/lib/prov/tpm/tpm.cpp @@ -349,7 +349,7 @@ AlgorithmIdentifier TPM_PrivateKey::algorithm_identifier() const AlgorithmIdentifier::USE_NULL_PARAM); } -std::vector<byte> TPM_PrivateKey::x509_subject_public_key() const +std::vector<byte> TPM_PrivateKey::public_key_bits() const { return DER_Encoder() .start_cons(SEQUENCE) diff --git a/src/lib/prov/tpm/tpm.h b/src/lib/prov/tpm/tpm.h index 804d42e70..f776f09e7 100644 --- a/src/lib/prov/tpm/tpm.h +++ b/src/lib/prov/tpm/tpm.h @@ -154,7 +154,7 @@ class BOTAN_DLL TPM_PrivateKey : public Private_Key AlgorithmIdentifier algorithm_identifier() const override; - std::vector<byte> x509_subject_public_key() const override; + std::vector<byte> public_key_bits() const override; secure_vector<byte> pkcs8_private_key() const override; diff --git a/src/lib/pubkey/curve25519/curve25519.cpp b/src/lib/pubkey/curve25519/curve25519.cpp index dd97e1f1d..8c2628934 100644 --- a/src/lib/pubkey/curve25519/curve25519.cpp +++ b/src/lib/pubkey/curve25519/curve25519.cpp @@ -58,7 +58,7 @@ Curve25519_PublicKey::Curve25519_PublicKey(const AlgorithmIdentifier&, size_check(m_public.size(), "public key"); } -std::vector<byte> Curve25519_PublicKey::x509_subject_public_key() const +std::vector<byte> Curve25519_PublicKey::public_key_bits() const { return DER_Encoder() .start_cons(SEQUENCE) diff --git a/src/lib/pubkey/curve25519/curve25519.h b/src/lib/pubkey/curve25519/curve25519.h index 40d9d81da..f48bb117d 100644 --- a/src/lib/pubkey/curve25519/curve25519.h +++ b/src/lib/pubkey/curve25519/curve25519.h @@ -25,7 +25,7 @@ class BOTAN_DLL Curve25519_PublicKey : public virtual Public_Key AlgorithmIdentifier algorithm_identifier() const override; - std::vector<byte> x509_subject_public_key() const override; + std::vector<byte> public_key_bits() const override; std::vector<byte> public_value() const { return m_public; } diff --git a/src/lib/pubkey/dl_algo/dl_algo.cpp b/src/lib/pubkey/dl_algo/dl_algo.cpp index f5c6ddabb..8457a61ac 100644 --- a/src/lib/pubkey/dl_algo/dl_algo.cpp +++ b/src/lib/pubkey/dl_algo/dl_algo.cpp @@ -29,7 +29,7 @@ AlgorithmIdentifier DL_Scheme_PublicKey::algorithm_identifier() const m_group.DER_encode(group_format())); } -std::vector<byte> DL_Scheme_PublicKey::x509_subject_public_key() const +std::vector<byte> DL_Scheme_PublicKey::public_key_bits() const { return DER_Encoder().encode(m_y).get_contents_unlocked(); } diff --git a/src/lib/pubkey/dl_algo/dl_algo.h b/src/lib/pubkey/dl_algo/dl_algo.h index 7e90bc3b7..c24c921a8 100644 --- a/src/lib/pubkey/dl_algo/dl_algo.h +++ b/src/lib/pubkey/dl_algo/dl_algo.h @@ -23,7 +23,7 @@ class BOTAN_DLL DL_Scheme_PublicKey : public virtual Public_Key AlgorithmIdentifier algorithm_identifier() const override; - std::vector<byte> x509_subject_public_key() const override; + std::vector<byte> public_key_bits() const override; /** * Get the DL domain parameters of this key. diff --git a/src/lib/pubkey/ecc_key/ecc_key.cpp b/src/lib/pubkey/ecc_key/ecc_key.cpp index ea2bb48e9..95427c487 100644 --- a/src/lib/pubkey/ecc_key/ecc_key.cpp +++ b/src/lib/pubkey/ecc_key/ecc_key.cpp @@ -55,7 +55,7 @@ AlgorithmIdentifier EC_PublicKey::algorithm_identifier() const return AlgorithmIdentifier(get_oid(), DER_domain()); } -std::vector<byte> EC_PublicKey::x509_subject_public_key() const +std::vector<byte> EC_PublicKey::public_key_bits() const { return unlock(EC2OSP(public_point(), PointGFp::COMPRESSED)); } diff --git a/src/lib/pubkey/ecc_key/ecc_key.h b/src/lib/pubkey/ecc_key/ecc_key.h index 375c8e85c..e6e5a3029 100644 --- a/src/lib/pubkey/ecc_key/ecc_key.h +++ b/src/lib/pubkey/ecc_key/ecc_key.h @@ -55,7 +55,7 @@ class BOTAN_DLL EC_PublicKey : public virtual Public_Key AlgorithmIdentifier algorithm_identifier() const override; - std::vector<byte> x509_subject_public_key() const override; + std::vector<byte> public_key_bits() const override; bool check_key(RandomNumberGenerator& rng, bool strong) const override; diff --git a/src/lib/pubkey/gost_3410/gost_3410.cpp b/src/lib/pubkey/gost_3410/gost_3410.cpp index ed01450c8..d10ad0575 100644 --- a/src/lib/pubkey/gost_3410/gost_3410.cpp +++ b/src/lib/pubkey/gost_3410/gost_3410.cpp @@ -15,7 +15,7 @@ namespace Botan { -std::vector<byte> GOST_3410_PublicKey::x509_subject_public_key() const +std::vector<byte> GOST_3410_PublicKey::public_key_bits() const { const BigInt x = public_point().get_affine_x(); const BigInt y = public_point().get_affine_y(); diff --git a/src/lib/pubkey/gost_3410/gost_3410.h b/src/lib/pubkey/gost_3410/gost_3410.h index c844e0fab..a80b41fc7 100644 --- a/src/lib/pubkey/gost_3410/gost_3410.h +++ b/src/lib/pubkey/gost_3410/gost_3410.h @@ -46,7 +46,7 @@ class BOTAN_DLL GOST_3410_PublicKey : public virtual EC_PublicKey AlgorithmIdentifier algorithm_identifier() const override; - std::vector<byte> x509_subject_public_key() const override; + std::vector<byte> public_key_bits() const override; size_t message_parts() const override { return 2; } diff --git a/src/lib/pubkey/mce/mceliece.h b/src/lib/pubkey/mce/mceliece.h index 2c4f38c33..884f40083 100644 --- a/src/lib/pubkey/mce/mceliece.h +++ b/src/lib/pubkey/mce/mceliece.h @@ -40,7 +40,7 @@ class BOTAN_DLL McEliece_PublicKey : public virtual Public_Key size_t key_length() const override; size_t estimated_strength() const override; - std::vector<byte> x509_subject_public_key() const override; + std::vector<byte> public_key_bits() const override; bool check_key(RandomNumberGenerator&, bool) const override { return true; } diff --git a/src/lib/pubkey/mce/mceliece_key.cpp b/src/lib/pubkey/mce/mceliece_key.cpp index 93ce41fb2..502665820 100644 --- a/src/lib/pubkey/mce/mceliece_key.cpp +++ b/src/lib/pubkey/mce/mceliece_key.cpp @@ -69,7 +69,7 @@ AlgorithmIdentifier McEliece_PublicKey::algorithm_identifier() const return AlgorithmIdentifier(get_oid(), std::vector<byte>()); } -std::vector<byte> McEliece_PublicKey::x509_subject_public_key() const +std::vector<byte> McEliece_PublicKey::public_key_bits() const { return DER_Encoder() .start_cons(SEQUENCE) diff --git a/src/lib/pubkey/pk_keys.cpp b/src/lib/pubkey/pk_keys.cpp index 3b843cea3..d21ff484a 100644 --- a/src/lib/pubkey/pk_keys.cpp +++ b/src/lib/pubkey/pk_keys.cpp @@ -14,6 +14,16 @@ namespace Botan { +std::vector<byte> Public_Key::subject_public_key() const + { + return DER_Encoder() + .start_cons(SEQUENCE) + .encode(algorithm_identifier()) + .encode(public_key_bits(), BIT_STRING) + .end_cons() + .get_contents_unlocked(); + } + /* * Default OID access */ diff --git a/src/lib/pubkey/pk_keys.h b/src/lib/pubkey/pk_keys.h index 613fbb7dd..6a5f4fc64 100644 --- a/src/lib/pubkey/pk_keys.h +++ b/src/lib/pubkey/pk_keys.h @@ -74,9 +74,14 @@ class BOTAN_DLL Public_Key virtual AlgorithmIdentifier algorithm_identifier() const = 0; /** + * @return BER encoded public key bits + */ + virtual std::vector<byte> public_key_bits() const = 0; + + /** * @return X.509 subject key encoding for this key object */ - virtual std::vector<byte> x509_subject_public_key() const = 0; + std::vector<byte> subject_public_key() const; // Internal or non-public declarations follow diff --git a/src/lib/pubkey/rsa/rsa.cpp b/src/lib/pubkey/rsa/rsa.cpp index 4302aa88a..039627806 100644 --- a/src/lib/pubkey/rsa/rsa.cpp +++ b/src/lib/pubkey/rsa/rsa.cpp @@ -41,7 +41,7 @@ AlgorithmIdentifier RSA_PublicKey::algorithm_identifier() const AlgorithmIdentifier::USE_NULL_PARAM); } -std::vector<byte> RSA_PublicKey::x509_subject_public_key() const +std::vector<byte> RSA_PublicKey::public_key_bits() const { return DER_Encoder() .start_cons(SEQUENCE) diff --git a/src/lib/pubkey/rsa/rsa.h b/src/lib/pubkey/rsa/rsa.h index f576a5f07..83b43a9ad 100644 --- a/src/lib/pubkey/rsa/rsa.h +++ b/src/lib/pubkey/rsa/rsa.h @@ -41,7 +41,7 @@ class BOTAN_DLL RSA_PublicKey : public virtual Public_Key AlgorithmIdentifier algorithm_identifier() const override; - std::vector<byte> x509_subject_public_key() const override; + std::vector<byte> public_key_bits() const override; /** * @return public modulus diff --git a/src/lib/pubkey/x509_key.cpp b/src/lib/pubkey/x509_key.cpp index f4cfe805e..f1db29bc4 100644 --- a/src/lib/pubkey/x509_key.cpp +++ b/src/lib/pubkey/x509_key.cpp @@ -18,12 +18,8 @@ namespace X509 { std::vector<byte> BER_encode(const Public_Key& key) { - return DER_Encoder() - .start_cons(SEQUENCE) - .encode(key.algorithm_identifier()) - .encode(key.x509_subject_public_key(), BIT_STRING) - .end_cons() - .get_contents_unlocked(); + // keeping it around for compat + return key.subject_public_key(); } /* @@ -31,7 +27,7 @@ std::vector<byte> BER_encode(const Public_Key& key) */ std::string PEM_encode(const Public_Key& key) { - return PEM_Code::encode(X509::BER_encode(key), + return PEM_Code::encode(key.subject_public_key(), "PUBLIC KEY"); } diff --git a/src/lib/pubkey/xmss/xmss_publickey.h b/src/lib/pubkey/xmss/xmss_publickey.h index b8aa8d920..23c8032c2 100644 --- a/src/lib/pubkey/xmss/xmss_publickey.h +++ b/src/lib/pubkey/xmss/xmss_publickey.h @@ -216,13 +216,12 @@ class BOTAN_DLL XMSS_PublicKey : public virtual Public_Key } /** - * Currently x509 is not suppoerted for XMSS. x509_subject_public_key() - * returns a raw byte sequence as defined in [1]. This method acts as - * alias for raw_public_key(). + * Returns a raw byte sequence as defined in [1]. + * This method acts as an alias for raw_public_key(). * - * @return raw non x509 compliant public key. + * @return raw public key bits. **/ - virtual std::vector<byte> x509_subject_public_key() const override + virtual std::vector<byte> public_key_bits() const override { return raw_public_key(); } diff --git a/src/lib/pubkey/xmss/xmss_wots_addressed_publickey.h b/src/lib/pubkey/xmss/xmss_wots_addressed_publickey.h index a07b0b803..74e686f9f 100644 --- a/src/lib/pubkey/xmss/xmss_wots_addressed_publickey.h +++ b/src/lib/pubkey/xmss/xmss_wots_addressed_publickey.h @@ -82,9 +82,9 @@ class XMSS_WOTS_Addressed_PublicKey : public virtual Public_Key return m_pub_key.estimated_strength(); } - virtual std::vector<byte> x509_subject_public_key() const override + virtual std::vector<byte> public_key_bits() const override { - return m_pub_key.x509_subject_public_key(); + return m_pub_key.public_key_bits(); } protected: diff --git a/src/lib/pubkey/xmss/xmss_wots_publickey.h b/src/lib/pubkey/xmss/xmss_wots_publickey.h index afb0ac847..4f414de27 100644 --- a/src/lib/pubkey/xmss/xmss_wots_publickey.h +++ b/src/lib/pubkey/xmss/xmss_wots_publickey.h @@ -261,9 +261,9 @@ class BOTAN_DLL XMSS_WOTS_PublicKey : virtual public Public_Key return m_wots_params.estimated_strength(); } - virtual std::vector<byte> x509_subject_public_key() const override + virtual std::vector<byte> public_key_bits() const override { - throw Not_Implemented("No x509 key format defined for XMSS-WOTS."); + throw Not_Implemented("No key format defined for XMSS-WOTS"); } bool operator==(const XMSS_WOTS_PublicKey& key) diff --git a/src/tests/test_mceliece.cpp b/src/tests/test_mceliece.cpp index 1d581e938..26a404c13 100644 --- a/src/tests/test_mceliece.cpp +++ b/src/tests/test_mceliece.cpp @@ -62,7 +62,7 @@ class McEliece_Keygen_Encrypt_Test : public Text_Based_Test Test::Result result("McEliece keygen"); - result.test_eq("public key fingerprint", hash_bytes(mce_priv.x509_subject_public_key()), fprint_pub); + result.test_eq("public key fingerprint", hash_bytes(mce_priv.public_key_bits()), fprint_pub); result.test_eq("private key fingerprint", hash_bytes(mce_priv.pkcs8_private_key()), fprint_priv); rng.clear(); @@ -130,7 +130,7 @@ class McEliece_Tests : public Test if(!hash) throw Test_Error("Hash " + hash_algo + " not available"); - hash->update(key.x509_subject_public_key()); + hash->update(key.public_key_bits()); return Botan::hex_encode(hash->final()); } @@ -153,7 +153,7 @@ class McEliece_Tests : public Test Botan::McEliece_PrivateKey sk1(Test::rng(), param_sets[i].code_length, t); const Botan::McEliece_PublicKey& pk1 = sk1; - const std::vector<byte> pk_enc = pk1.x509_subject_public_key(); + const std::vector<byte> pk_enc = pk1.public_key_bits(); const Botan::secure_vector<byte> sk_enc = sk1.pkcs8_private_key(); Botan::McEliece_PublicKey pk(pk_enc); |