22 #include <boost/lexical_cast.hpp>
32 if (name == TSIGKey::HMACMD5_NAME()) {
35 if (name == TSIGKey::HMACMD5_SHORT_NAME()) {
38 if (name == TSIGKey::HMACSHA1_NAME()) {
41 if (name == TSIGKey::HMACSHA256_NAME()) {
44 if (name == TSIGKey::HMACSHA224_NAME()) {
47 if (name == TSIGKey::HMACSHA384_NAME()) {
50 if (name == TSIGKey::HMACSHA512_NAME()) {
64 key_name_(key_name), algorithm_name_(algorithm_name),
65 algorithm_(algorithm), digestbits_(digestbits),
71 algorithm_name_ = TSIGKey::HMACMD5_NAME();
73 algorithm_name_.downcase();
78 const void* secret,
size_t secret_len) :
80 key_name_(key_name), algorithm_name_(algorithm_name),
81 algorithm_(algorithm), digestbits_(digestbits),
82 secret_(static_cast<const uint8_t*>(secret),
83 static_cast<const uint8_t*>(secret) + secret_len)
88 algorithm_name_ = TSIGKey::HMACMD5_NAME();
90 algorithm_name_.downcase();
99 TSIGKey::TSIGKey(
const Name& key_name,
const Name& algorithm_name,
100 const void* secret,
size_t secret_len,
101 size_t digestbits ) : impl_(NULL)
103 const HashAlgorithm algorithm = convertAlgorithmName(algorithm_name);
104 if ((secret != NULL && secret_len == 0) ||
105 (secret == NULL && secret_len != 0)) {
107 "TSIGKey secret and its length are inconsistent: " <<
108 key_name <<
":" << algorithm_name);
112 "TSIGKey with unknown algorithm has non empty secret: " <<
113 key_name <<
":" << algorithm_name);
115 if (secret == NULL) {
116 impl_ =
new TSIGKeyImpl(key_name, algorithm_name, algorithm,
119 impl_ =
new TSIGKeyImpl(key_name, algorithm_name, algorithm,
120 digestbits, secret, secret_len);
126 istringstream iss(str);
129 getline(iss, keyname_str,
':');
130 if (iss.fail() || iss.bad() || iss.eof()) {
135 getline(iss, secret_str,
':');
136 if (iss.fail() || iss.bad()) {
142 getline(iss, algo_str,
':');
144 if (iss.fail() || iss.bad()) {
150 getline(iss, dgstbt_str);
152 if (iss.fail() || iss.bad()) {
156 const Name algo_name(algo_str.empty() ?
"hmac-md5.sig-alg.reg.int" :
158 const HashAlgorithm algorithm = convertAlgorithmName(algo_name);
159 size_t digestbits = 0;
161 if (!dgstbt_str.empty()) {
162 digestbits = boost::lexical_cast<
size_t>(dgstbt_str);
164 }
catch (
const boost::bad_lexical_cast&) {
166 "TSIG key with non-numeric digestbits: " << dgstbt_str);
169 vector<uint8_t> secret;
174 "TSIG key with unknown algorithm has non empty secret: "
178 if (secret.empty()) {
183 digestbits, &secret[0], secret.size());
198 if (
this == &source) {
240 return (impl_->
secret_.size());
246 const vector<uint8_t> secret_v(static_cast<const uint8_t*>(
getSecret()),
247 static_cast<const uint8_t*>(
getSecret()) +
252 std::string dgstbt_str = boost::lexical_cast<std::string>(
static_cast<int>(digestbits));
263 static Name alg_name(
"hmac-md5.sig-alg.reg.int");
269 static Name alg_name(
"hmac-md5");
275 static Name alg_name(
"hmac-sha1");
281 static Name alg_name(
"hmac-sha256");
287 static Name alg_name(
"hmac-sha224");
293 static Name alg_name(
"hmac-sha384");
299 static Name alg_name(
"hmac-sha512");
305 static Name alg_name(
"gss-tsig");
324 return (impl_->
keys.size());
329 if (impl_->
keys.insert(
345 TSIGKeyRingImpl::TSIGKeyMap::const_iterator found =
346 impl_->
keys.find(key_name);
347 if (found == impl_->
keys.end()) {
355 TSIGKeyRingImpl::TSIGKeyMap::const_iterator found =
356 impl_->
keys.find(key_name);
357 if (found == impl_->
keys.end() ||
358 (*found).second.getAlgorithmName() != algorithm_name) {
The Name class encapsulates DNS names.
isc::cryptolink::HashAlgorithm getAlgorithm() const
Return the hash algorithm name in the form of cryptolink::HashAlgorithm.
The operation is successful.
const void * getSecret() const
Return the value of the TSIG secret.
TSIGKeyImpl(const Name &key_name, const Name &algorithm_name, isc::cryptolink::HashAlgorithm algorithm, size_t digestbits)
map< Name, TSIGKey > TSIGKeyMap
Result
Result codes of various public methods of TSIGKeyRing.
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
TSIGKey(const Name &key_name, const Name &algorithm_name, const void *secret, size_t secret_len, size_t digestbits=0)
Constructor from key parameters.
TSIGKeyImpl(const Name &key_name, const Name &algorithm_name, isc::cryptolink::HashAlgorithm algorithm, size_t digestbits, const void *secret, size_t secret_len)
A helper structure to represent the search result of TSIGKeyRing::find().
static const Name & HMACSHA224_NAME()
HMAC-SHA256 (RFC4635)
static const Name & HMACSHA1_NAME()
HMAC-SHA1 (RFC4635)
~TSIGKey()
The destructor.
HashAlgorithm
Hash algorithm identifiers.
static const Name & HMACSHA256_NAME()
HMAC-SHA256 (RFC4635)
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
const Name & getAlgorithmName() const
Return the algorithm name.
static const Name & HMACSHA512_NAME()
HMAC-SHA256 (RFC4635)
Result add(const TSIGKey &key)
Add a TSIGKey to the TSIGKeyRing.
static const Name & HMACMD5_NAME()
HMAC-MD5 (RFC2845)
size_t getDigestbits() const
Return the minimum truncated length.
const Name & getKeyName() const
Return the key name.
FindResult find(const Name &key_name) const
Find a TSIGKey for the given name in the TSIGKeyRing.
void decodeBase64(const std::string &input, std::vector< uint8_t > &result)
Decode a text encoded in the base64 format into the original data.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
pair< Name, TSIGKey > NameAndKey
TSIGKey & operator=(const TSIGKey &source)
Assignment operator.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
TSIGKeyRing()
The default constructor.
std::string encodeBase64(const std::vector< uint8_t > &binary)
Encode binary data in the base64 format.
size_t getSecretLength() const
Return the length of the TSIG secret in bytes.
static const Name & HMACMD5_SHORT_NAME()
static const Name & GSSTSIG_NAME()
GSS-TSIG (RFC3645)
~TSIGKeyRing()
The destructor.
The specified key is not found in TSIGKeyRing.
unsigned int size() const
Return the number of keys stored in the TSIGKeyRing.
const isc::cryptolink::HashAlgorithm algorithm_
std::string toText() const
Converts the TSIGKey to a string value.
This value can be used in conversion functions, to be returned when the input is unknown (but a value...
const vector< uint8_t > secret_
Result remove(const Name &key_name)
Remove a TSIGKey for the given name from the TSIGKeyRing.
static const Name & HMACSHA384_NAME()
HMAC-SHA256 (RFC4635)
A key is already stored in TSIGKeyRing.