aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey/ec_group
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-03-02 18:39:01 -0500
committerJack Lloyd <[email protected]>2018-03-02 18:39:01 -0500
commit9208d5ed5207a655babaed93e83768722415f859 (patch)
treec2b6b103357e18d1c85bd6942a3e6ab93662bd06 /src/lib/pubkey/ec_group
parent537833f1bef3757adb7d12b5f27a2fa1b8d994b1 (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.cpp12
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