]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
pkcs11 create key: error for unknown algos
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Thu, 11 Jun 2020 17:01:19 +0000 (19:01 +0200)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Thu, 11 Jun 2020 17:01:19 +0000 (19:01 +0200)
pdns/pkcs11signers.cc

index 23278b21c53bd012dccd137590bb900f98530633..95fe5654b4f83af389092d9100a3cd67e3cf722f 100644 (file)
@@ -804,7 +804,12 @@ void PKCS11DNSCryptoKeyEngine::create(unsigned int bits) {
 
   std::string pubExp("\000\001\000\001", 4); // 65537
 
-  mech.mechanism = dnssec2cmech[d_algorithm];
+  try {
+    mech.mechanism = dnssec2cmech.at(d_algorithm);
+  } catch (std::out_of_range& e) {
+    throw PDNSException("pkcs11: unsupported algorithm "+std::to_string(d_algorithm)+ " for key pair generation");
+  }
+
   mech.pParameter = NULL;
   mech.ulParameterLen = 0;
 
@@ -839,7 +844,7 @@ void PKCS11DNSCryptoKeyEngine::create(unsigned int bits) {
     pubAttr.push_back(P11KitAttribute(CKA_LABEL, d_pub_label));
     if (d_algorithm == 13) pubAttr.push_back(P11KitAttribute(CKA_ECDSA_PARAMS, ECDSA256_PARAMS));
     else if (d_algorithm == 14) pubAttr.push_back(P11KitAttribute(CKA_ECDSA_PARAMS, ECDSA384_PARAMS));
-    else throw PDNSException("pkcs11: unknown algorithm "+std::to_string(d_algorithm)+" for ECDSA key pair gen");
+    else throw PDNSException("pkcs11: unknown algorithm "+std::to_string(d_algorithm)+" for ECDSA key pair generation");
 
     privAttr.push_back(P11KitAttribute(CKA_CLASS, (unsigned long)CKO_PRIVATE_KEY));
     privAttr.push_back(P11KitAttribute(CKA_KEY_TYPE, (unsigned long)CKK_ECDSA));