Kea 3.1.1
gss_tsig_cfg.h
Go to the documentation of this file.
1// Copyright (C) 2021-2025 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef GSS_TSIG_CFG_H
8#define GSS_TSIG_CFG_H
9
10#include <asiodns/io_fetch.h>
11#include <cc/cfg_to_element.h>
12#include <cc/simple_parser.h>
13#include <cc/user_context.h>
14#include <d2srv/d2_cfg_mgr.h>
15
16#include <boost/shared_ptr.hpp>
17#include <boost/multi_index_container.hpp>
18#include <boost/multi_index/hashed_index.hpp>
19#include <boost/multi_index/mem_fun.hpp>
20#include <boost/multi_index/random_access_index.hpp>
21
22#include <list>
23#include <map>
24#include <memory>
25#include <set>
26#include <sstream>
27#include <vector>
28
29namespace isc {
30namespace gss_tsig {
31
34public:
37
45 static const std::list<std::string> STAT_NAMES;
46
55 DnsServer(const std::string& id,
56 const std::set<std::string>& domains,
57 const isc::asiolink::IOAddress& ip_address,
59
63 virtual ~DnsServer();
64
66 virtual void resetStats();
67
71 std::string getID() const {
72 return (id_);
73 }
74
78 void setID(const std::string& id) {
79 id_ = id;
80 }
81
86 return (ip_address_);
87 }
88
93 return (timer_);
94 }
95
99 uint16_t getPort() const {
100 return (port_);
101 }
102
107 return (server_infos_);
108 }
109
114 server_infos_.push_back(server_info);
115 }
116
119 server_infos_.clear();
120 }
121
130
134 const std::string& getServerPrincipal() const {
135 return (server_principal_);
136 }
137
141 void setServerPrincipal(const std::string& server_principal) {
142 server_principal_ = server_principal;
143 }
144
148 const std::string& getKeyNameSuffix() const {
149 return (key_name_suffix_);
150 }
151
155 void setKeyNameSuffix(const std::string& key_name_suffix) {
156 key_name_suffix_ = key_name_suffix;
158 }
159
167 void buildKeyNameSuffix();
168
176 void checkKeyNameSuffix();
177
181 const std::string& getClientPrincipal() const {
182 return (cred_principal_);
183 }
184
188 void setClientPrincipal(const std::string& cred_principal) {
189 cred_principal_ = cred_principal;
190 }
191
195 uint32_t getKeyLifetime() const {
196 return (tkey_lifetime_);
197 }
198
202 bool getGssReplayFlag() const {
203 return (gss_replay_flag_);
204 }
205
209 void setGssReplayFlag(bool flag) {
210 gss_replay_flag_ = flag;
211 }
212
216 bool getGssSequenceFlag() const {
217 return (gss_sequence_flag_);
218 }
219
223 void setGssSequenceFlag(bool flag) {
224 gss_sequence_flag_ = flag;
225 }
226
230 void setKeyLifetime(uint32_t tkey_lifetime) {
231 tkey_lifetime_ = tkey_lifetime;
232 }
233
237 uint32_t getRekeyInterval() const {
238 return (rekey_interval_);
239 }
240
244 void setRekeyInterval(uint32_t rekey_interval) {
245 rekey_interval_ = rekey_interval;
246 }
247
251 uint32_t getRetryInterval() const {
252 return (retry_interval_);
253 }
254
258 void setRetryInterval(uint32_t retry_interval) {
259 retry_interval_ = retry_interval;
260 }
261
266 return (tkey_proto_);
267 }
268
273 tkey_proto_ = tkey_proto;
274 }
275
279 bool getFallback() const {
280 return (fallback_);
281 }
282
286 void setFallback(bool fallback) {
287 fallback_ = fallback;
288 }
289
293 uint32_t getExchangeTimeout() const {
294 return (exchange_timeout_);
295 }
296
301 void setExchangeTimeout(uint32_t exchange_timeout) {
302 exchange_timeout_ = exchange_timeout;
303 }
304
312
316 static constexpr size_t DEFAULT_KEY_LIFETIME = 3600;
317
321 static constexpr size_t DEFAULT_REKEY_INTERVAL = 2700;
322
326 static constexpr size_t DEFAULT_RETRY_INTERVAL = 120;
327
331 static constexpr size_t DEFAULT_EXCHANGE_TIMEOUT = 3000;
332
333private:
335 void initStats();
336
338 void removeStats();
339
344 void buildServerInfo(isc::d2::DdnsDomainPtr d2_dns_domain);
345
347 std::string id_;
348
350 std::set<std::string> domains_;
351
353 isc::asiolink::IOAddress ip_address_;
354
356 uint16_t port_;
357
359 isc::d2::DnsServerInfoStorage server_infos_;
360
362 std::string server_principal_;
363
365 std::string key_name_suffix_;
366
368 std::string cred_principal_;
369
371 bool gss_replay_flag_;
372
374 bool gss_sequence_flag_;
375
377 uint32_t tkey_lifetime_;
378
380 uint32_t rekey_interval_;
381
383 uint32_t retry_interval_;
384
387
389 bool fallback_;
390
392 uint32_t exchange_timeout_;
393
396};
397
399typedef boost::shared_ptr<DnsServer> DnsServerPtr;
400
403
405struct DnsServerIdTag { };
406
408typedef boost::multi_index_container<
409 // Multi index container holding pointers to the DNS servers.
411 // The following holds all indexes.
412 boost::multi_index::indexed_by<
413 // First index allows the random access (vector).
414 boost::multi_index::random_access<
415 boost::multi_index::tag<DnsServerIndexTag>
416 >,
417 // Second index allows the id access.
418 boost::multi_index::hashed_unique<
419 boost::multi_index::tag<DnsServerIdTag>,
420 boost::multi_index::const_mem_fun<DnsServer, std::string,
422 >
423 >
425
427typedef std::map<isc::d2::DnsServerInfoPtr, DnsServerPtr> DnsServerRevMap;
428
431public:
434
436 GssTsigCfg();
437
439 virtual ~GssTsigCfg();
440
445 return (servers_);
446 }
447
453 void addServer(DnsServerPtr server) {
454 servers_.push_back(server);
455 }
456
461 return (servers_rev_map_);
462 }
463
468 DnsServerPtr getServer(const isc::d2::DnsServerInfoPtr& server_info) const;
469
474 DnsServerPtr getServer(const std::string& id) const;
475
478 servers_.clear();
479 servers_rev_map_.clear();
480 }
481
486
490 const std::string& getClientKeyTab() const {
491 return (client_keytab_);
492 }
493
497 void setClientKeyTab(const std::string& client_keytab) {
498 client_keytab_ = client_keytab;
499 }
500
504 const std::string& getCredsCache() const {
505 return (creds_cache_);
506 }
507
511 void setCredsCache(const std::string& creds_cache) {
512 creds_cache_ = creds_cache;
513 }
514
520
524 uint32_t getMaxKeyLifetime() const {
525 return (max_tkey_lifetime_);
526 }
527
531 void setMaxKeyLifetime(uint32_t max_tkey_lifetime) {
532 max_tkey_lifetime_ = max_tkey_lifetime;
533 }
534
535private:
537 DnsServerList servers_;
538
540 DnsServerRevMap servers_rev_map_;
541
543 std::string client_keytab_;
544
546 std::string creds_cache_;
547
549 uint32_t max_tkey_lifetime_;
550};
551
552} // end of namespace isc::gss_tsig
553} // end of namespace isc
554
555#endif // GSS_TSIG_CFG_H
Protocol
Protocol to use on the fetch.
Definition io_fetch.h:36
static const uint32_t STANDARD_DNS_PORT
defines DNS standard port value
Definition d2_config.h:436
GSS-TSIG hook configuration for a server.
static const std::list< std::string > STAT_NAMES
Server TKEY exchange statistics names.
uint32_t getRekeyInterval() const
Get the rekey interval.
void setKeyLifetime(uint32_t tkey_lifetime)
Set the TKEY lifetime.
void checkKeyNameSuffix()
Check and fix the GSS-TSIG key name suffix.
void setKeyNameSuffix(const std::string &key_name_suffix)
Set the GSS-TSIG key name suffix.
static const isc::data::SimpleKeywords SERVER_PARAMETERS
This table defines all server parameters.
const std::string & getServerPrincipal() const
Get the DNS server principal.
void setExchangeTimeout(uint32_t exchange_timeout)
Set the TKEY exchange timeout.
virtual void resetStats()
Reset statistics.
void setServerPrincipal(const std::string &server_principal)
Set the DNS server principal.
void clearServerInfos()
Clear the server info list.
uint16_t getPort() const
Get the server port.
virtual ~DnsServer()
Destructor.
uint32_t getExchangeTimeout() const
Get the TKEY exchange timeout.
const isc::d2::DnsServerInfoStorage & getServerInfos() const
Get the server info list.
bool getFallback() const
Get the fallback flag.
const std::string & getClientPrincipal() const
Get the client/credentials principal.
DnsServer(const std::string &id, const std::set< std::string > &domains, const isc::asiolink::IOAddress &ip_address, uint16_t port=isc::d2::DnsServerInfo::STANDARD_DNS_PORT)
Constructor.
void buildKeyNameSuffix()
Build the GSS-TSIG key name suffix.
isc::asiodns::IOFetch::Protocol getKeyProto() const
Get the TKEY protocol.
std::string getID() const
Get the ID.
void addServerInfo(isc::d2::DnsServerInfoPtr server_info)
Add a server info to the list.
void setID(const std::string &id)
Set the ID.
static constexpr size_t DEFAULT_REKEY_INTERVAL
The rekey timer interval (expressed in seconds).
void setClientPrincipal(const std::string &cred_principal)
Set the client/credentials principal.
isc::data::ElementPtr toElement() const
Unparse a DNS server object.
void setRetryInterval(uint32_t retry_interval)
Set the retry interval.
const isc::asiolink::IOAddress & getIpAddress() const
Get the server IP address.
void setGssReplayFlag(bool flag)
Set the GSS (anti) replay flag.
const std::string & getKeyNameSuffix() const
Get the GSS-TSIG key name suffix.
bool getGssReplayFlag() const
Get the GSS (anti) replay flag.
uint32_t getRetryInterval() const
Get the retry interval.
void setRekeyInterval(uint32_t rekey_interval)
Set the rekey interval.
void setKeyProto(isc::asiodns::IOFetch::Protocol tkey_proto)
Set the TKEY protocol.
static constexpr size_t DEFAULT_KEY_LIFETIME
The default TKEY lifetime (expressed in seconds).
static constexpr size_t DEFAULT_EXCHANGE_TIMEOUT
The default TKEY exchange timeout (expressed in milliseconds).
bool getGssSequenceFlag() const
Get the GSS sequence flag.
static constexpr size_t DEFAULT_RETRY_INTERVAL
The retry timer interval (expressed in seconds).
void buildServerInfo(isc::d2::D2CfgContextPtr d2_config)
Convert the list of DNS domains to the server info list.
isc::asiolink::IntervalTimerPtr & getTimer()
Get timer used to rekey or to retry on error.
void setGssSequenceFlag(bool flag)
Set the GSS sequence flag.
void setFallback(bool fallback)
Set the fallback flag.
uint32_t getKeyLifetime() const
Get the TKEY lifetime.
const std::string & getCredsCache() const
Get the credentials cache specification.
const DnsServerList & getServerList() const
Get the DNS server list.
uint32_t getMaxKeyLifetime() const
Get the maximum TKEY lifetime.
virtual ~GssTsigCfg()
Destructor.
DnsServerPtr getServer(const isc::d2::DnsServerInfoPtr &server_info) const
Get the DNS server from a server info.
const std::string & getClientKeyTab() const
Get the client key table specification.
void setClientKeyTab(const std::string &client_keytab)
Set the client key table specification.
void setCredsCache(const std::string &creds_cache)
Set the credentials cache specification.
const DnsServerRevMap & getServerRevMap() const
Get the DNS server reverse map.
void buildServerRevMap(isc::d2::D2CfgContextPtr d2_config)
Build the reverse map.
void clearServers()
Clear the DNS server list and reverse map.
void configure(isc::data::ConstElementPtr params)
Configure.
static const isc::data::SimpleKeywords GLOBAL_PARAMETERS
This table defines all global parameters.
void setMaxKeyLifetime(uint32_t max_tkey_lifetime)
Set the maximum TKEY lifetime.
void addServer(DnsServerPtr server)
Add a DNS server to the list.
boost::shared_ptr< DdnsDomain > DdnsDomainPtr
Defines a pointer for DdnsDomain instances.
Definition d2_config.h:624
boost::shared_ptr< DnsServerInfo > DnsServerInfoPtr
Defines a pointer for DnsServerInfo instances.
Definition d2_config.h:554
std::vector< DnsServerInfoPtr > DnsServerInfoStorage
Defines a storage container for DnsServerInfo pointers.
Definition d2_config.h:557
boost::shared_ptr< D2CfgContext > D2CfgContextPtr
Pointer to a configuration context.
Definition d2_cfg_mgr.h:26
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
std::map< std::string, isc::data::Element::types > SimpleKeywords
This specifies all accepted keywords with their types.
std::map< isc::d2::DnsServerInfoPtr, DnsServerPtr > DnsServerRevMap
A map of DNS server info and DNS server.
boost::shared_ptr< DnsServer > DnsServerPtr
A pointer to a DNS server.
boost::multi_index_container< DnsServerPtr, boost::multi_index::indexed_by< boost::multi_index::random_access< boost::multi_index::tag< DnsServerIndexTag > >, boost::multi_index::hashed_unique< boost::multi_index::tag< DnsServerIdTag >, boost::multi_index::const_mem_fun< DnsServer, std::string, &DnsServer::getID > > > > DnsServerList
A list of DNS server.
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.
Base class for user context.
Tag for the id access index for searching DNS server.
Tag for the random access index for searching DNS server.