#endif
storvector_t convertToISCVector() const override;
- std::string getPubKeyHash() const override;
std::string sign(const std::string& msg) const override;
bool verify(const std::string& msg, const std::string& signature) const override;
std::string getPublicKeyString() const override;
pub.serialize_into(d_pubkey);
}
-std::string DecafED25519DNSCryptoKeyEngine::getPubKeyHash() const
-{
- return this->getPublicKeyString();
-}
-
std::string DecafED25519DNSCryptoKeyEngine::getPublicKeyString() const
{
return string((char*)d_pubkey, DECAF_EDDSA_25519_PUBLIC_BYTES);
#endif
storvector_t convertToISCVector() const override;
- std::string getPubKeyHash() const override;
std::string sign(const std::string& msg) const override;
bool verify(const std::string& msg, const std::string& signature) const override;
std::string getPublicKeyString() const override;
pub.serialize_into(d_pubkey);
}
-std::string DecafED448DNSCryptoKeyEngine::getPubKeyHash() const
-{
- return this->getPublicKeyString();
-}
-
std::string DecafED448DNSCryptoKeyEngine::getPublicKeyString() const
{
return string((char*)d_pubkey, DECAF_EDDSA_448_PUBLIC_BYTES);
[[nodiscard]] virtual bool verify(const std::string& msg, const std::string& signature) const =0;
- [[nodiscard]] virtual std::string getPubKeyHash()const =0;
[[nodiscard]] virtual std::string getPublicKeyString()const =0;
[[nodiscard]] virtual int getBits() const =0;
[[nodiscard]] virtual unsigned int getAlgorithm() const
}
}
+static std::string hashPublicKey(const std::string& pubKey)
+{
+ /* arbitrarily cut off at 64 bytes, the main idea is to save space
+ for very large keys like RSA ones (1024+ bytes) by storing a 20 bytes hash
+ instead */
+ if (pubKey.size() <= 64) {
+ return pubKey;
+ }
+ return pdns_sha1sum(pubKey);
+}
+
static void fillOutRRSIG(DNSSECPrivateKey& dpk, const DNSName& signQName, RRSIGRecordContent& rrc, const sortedRecords_t& toSign)
{
if(!g_signatureCount)
rrc.d_tag = drc.getTag();
rrc.d_algorithm = drc.d_algorithm;
- string msg=getMessageForRRSET(signQName, rrc, toSign); // this is what we will hash & sign
- pair<string, string> lookup(rc->getPubKeyHash(), getLookupKey(msg)); // this hash is a memory saving exercise
+ string msg = getMessageForRRSET(signQName, rrc, toSign); // this is what we will hash & sign
+ pair<string, string> lookup(hashPublicKey(drc.d_key), getLookupKey(msg)); // this hash is a memory saving exercise
bool doCache=true;
if(doCache)
std::string hash(const std::string& hash) const override;
std::string sign(const std::string& hash) const override;
bool verify(const std::string& hash, const std::string& signature) const override;
- std::string getPubKeyHash() const override;
std::string getPublicKeyString() const override;
std::unique_ptr<BIGNUM, void (*)(BIGNUM*)> parse(std::map<std::string, std::string>& stormap, const std::string& key) const;
void fromISCMap(DNSKEYRecordContent& drc, std::map<std::string, std::string>& stormap) override;
return (ret == 1);
}
-
-std::string OpenSSLRSADNSCryptoKeyEngine::getPubKeyHash() const
-{
- const BIGNUM *n, *e, *d;
- RSA_get0_key(d_key.get(), &n, &e, &d);
- std::vector<unsigned char> tmp;
- tmp.resize(std::max(BN_num_bytes(e), BN_num_bytes(n)));
- unsigned char l_hash[SHA_DIGEST_LENGTH];
- SHA_CTX ctx;
-
- int res = SHA1_Init(&ctx);
-
- if (res != 1) {
- throw runtime_error(getName()+" failed to init hash context for generating the public key hash");
- }
-
- int len = BN_bn2bin(e, tmp.data());
- res = SHA1_Update(&ctx, tmp.data(), len);
- if (res != 1) {
- throw runtime_error(getName()+" failed to update hash context for generating the public key hash");
- }
-
- len = BN_bn2bin(n, tmp.data());
- res = SHA1_Update(&ctx, tmp.data(), len);
- if (res != 1) {
- throw runtime_error(getName()+" failed to update hash context for generating the public key hash");
- }
-
- res = SHA1_Final(l_hash, &ctx);
- if (res != 1) {
- throw runtime_error(getName()+" failed to finish hash context for generating the public key hash");
- }
-
- return string((char*)l_hash, sizeof(l_hash));
-}
-
-
std::string OpenSSLRSADNSCryptoKeyEngine::getPublicKeyString() const
{
const BIGNUM *n, *e, *d;
std::string hash(const std::string& hash) const override;
std::string sign(const std::string& hash) const override;
bool verify(const std::string& hash, const std::string& signature) const override;
- std::string getPubKeyHash() const override;
std::string getPublicKeyString() const override;
void fromISCMap(DNSKEYRecordContent& drc, std::map<std::string, std::string>& stormap) override;
void fromPublicKeyString(const std::string& content) override;
return (ret == 1);
}
-std::string OpenSSLECDSADNSCryptoKeyEngine::getPubKeyHash() const
-{
- string pubKey = getPublicKeyString();
- unsigned char l_hash[SHA_DIGEST_LENGTH];
- SHA1((unsigned char*) pubKey.c_str(), pubKey.length(), l_hash);
- return string((char*) l_hash, sizeof(l_hash));
-}
-
std::string OpenSSLECDSADNSCryptoKeyEngine::getPublicKeyString() const
{
std::string binaryPoint;
storvector_t convertToISCVector() const override;
std::string sign(const std::string& msg) const override;
bool verify(const std::string& msg, const std::string& signature) const override;
- std::string getPubKeyHash() const override;
std::string getPublicKeyString() const override;
void fromISCMap(DNSKEYRecordContent& drc, std::map<std::string, std::string>& stormap) override;
void fromPublicKeyString(const std::string& content) override;
return (r == 1);
}
-std::string OpenSSLEDDSADNSCryptoKeyEngine::getPubKeyHash() const
-{
- return this->getPublicKeyString();
-}
-
std::string OpenSSLEDDSADNSCryptoKeyEngine::getPublicKeyString() const
{
string buf;
return d_err;
}
- int DigestKey(std::string& result) {
- auto slot = d_slot->lock();
- CK_MECHANISM mech;
- mech.mechanism = CKM_SHA_1;
-
- DigestInit(*slot, &mech);
-
- if (d_key_type == CKK_RSA) {
- DigestUpdate(*slot, d_modulus);
- DigestUpdate(*slot, d_exponent);
- } else if (d_key_type == CKK_EC || d_key_type == CKK_ECDSA) {
- DigestUpdate(*slot, d_ec_point);
- }
-
- DigestFinal(*slot, result);
-
- return d_err;
- }
-
int DigestFinal(Pkcs11Slot& slot, std::string& result) {
CK_BYTE buffer[1024] = {0};
CK_ULONG buflen = sizeof buffer; // should be enough for most digests
}
};
-std::string PKCS11DNSCryptoKeyEngine::getPubKeyHash() const {
- // find us a public key
- std::shared_ptr<Pkcs11Token> d_slot;
- d_slot = Pkcs11Token::GetToken(d_module, d_slot_id, d_label, d_pub_label);
- if (d_slot->LoggedIn() == false)
- if (d_slot->Login(d_pin) == false)
- throw PDNSException("Not logged in to token");
-
- std::string result;
- if (d_slot->DigestKey(result) == 0) return result;
- throw PDNSException("Could not digest key (maybe it's missing?)");
-};
-
std::string PKCS11DNSCryptoKeyEngine::getPublicKeyString() const {
std::string result("");
std::shared_ptr<Pkcs11Token> d_slot;
bool verify(const std::string& msg, const std::string& signature) const override;
- std::string getPubKeyHash() const override;
-
std::string getPublicKeyString() const override;
int getBits() const override;
#endif
storvector_t convertToISCVector() const override;
- std::string getPubKeyHash() const override;
std::string sign(const std::string& msg) const override;
bool verify(const std::string& msg, const std::string& signature) const override;
std::string getPublicKeyString() const override;
crypto_sign_ed25519_seed_keypair(d_pubkey, d_seckey, seed.get());
}
-std::string SodiumED25519DNSCryptoKeyEngine::getPubKeyHash() const
-{
- return this->getPublicKeyString();
-}
-
std::string SodiumED25519DNSCryptoKeyEngine::getPublicKeyString() const
{
return string((char*)d_pubkey, crypto_sign_ed25519_PUBLICKEYBYTES);
std::string name;
std::string rfcMsgDump;
std::string rfcB64Signature;
- std::string pubKeyHash;
int bits;
uint16_t flags;
uint16_t rfcFlags;
.rfcMsgDump = "",
.rfcB64Signature = "",
- .pubKeyHash = "QH+uURzTHkYZ5MrwNvOrn+BtnL4=",
.bits = 512,
.flags = 256,
.rfcMsgDump = "",
.rfcB64Signature = "",
- .pubKeyHash = "aIQTEsTXwMDIOXPY9e6W1G1AnAk=",
.bits = 256,
.flags = 256,
// https://www.rfc-editor.org/errata_search.php?rfc=8080&eid=4935
.rfcB64Signature = "oL9krJun7xfBOIWcGHi7mag5/hdZrKWw15jPGrHpjQeR"
"AvTdszaPD+QLs3fx8A4M3e23mRZ9VrbpMngwcrqNAg==",
- .pubKeyHash = "l02Woi0iS8Aa25FQkUd9RMzZHJpBoRQwAQEX1SxZJA4=",
.bits = 256,
.flags = 256,
.rfcB64Signature = "3cPAHkmlnxcDHMyg7vFC34l0blBhuG1qpwLmjInI8w1CMB29FkEA"
"IJUA0amxWndkmnBZ6SKiwZSAxGILn/NBtOXft0+Gj7FSvOKxE/07"
"+4RQvE581N3Aj/JtIyaiYVdnYtyMWbSNyGEY2213WKsJlwEA",
- .pubKeyHash = "3kgROaDjrh0H2iuixWBrc8g2EpBBLCdGzHmn+G2MpTPhpj/"
- "OiBVHHSfPodx1FYYUcJKm1MDpJtIA",
.bits = 456,
.flags = 256,
if (!signer.rfcMsgDump.empty() && !signer.rfcB64Signature.empty()) {
checkRR(signer);
}
-
- BOOST_CHECK_EQUAL(Base64Encode(dcke->getPubKeyHash()), signer.pubKeyHash);
}
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables,readability-identifier-length): Boost stuff.