diff options
author | Jack Lloyd <[email protected]> | 2018-03-02 18:39:01 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-03-02 18:39:01 -0500 |
commit | 9208d5ed5207a655babaed93e83768722415f859 (patch) | |
tree | c2b6b103357e18d1c85bd6942a3e6ab93662bd06 /src/lib/pubkey/ec_group | |
parent | 537833f1bef3757adb7d12b5f27a2fa1b8d994b1 (diff) |
Avoid confusing error if invalid EC_Group is used
If an unknown group name was passed it would give a PEM error,
instead of saying unknown group.
Diffstat (limited to 'src/lib/pubkey/ec_group')
-rw-r--r-- | src/lib/pubkey/ec_group/ec_group.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/lib/pubkey/ec_group/ec_group.cpp b/src/lib/pubkey/ec_group/ec_group.cpp index 942e7401a..6064f869c 100644 --- a/src/lib/pubkey/ec_group/ec_group.cpp +++ b/src/lib/pubkey/ec_group/ec_group.cpp @@ -329,10 +329,16 @@ EC_Group::EC_Group(const std::string& str) if(m_data == nullptr) { - // OK try it as PEM ... - secure_vector<uint8_t> ber = PEM_Code::decode_check_label(str, "EC PARAMETERS"); - this->m_data = BER_decode_EC_group(ber.data(), ber.size()); + if(str.size() > 30 && str.substr(0, 29) == "-----BEGIN EC PARAMETERS-----") + { + // OK try it as PEM ... + secure_vector<uint8_t> ber = PEM_Code::decode_check_label(str, "EC PARAMETERS"); + this->m_data = BER_decode_EC_group(ber.data(), ber.size()); + } } + + if(m_data == nullptr) + throw Invalid_Argument("Unknown ECC group '" + str + "'"); } //static |