Kea 2.5.8
option6_auth.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2024 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#include <config.h>
8#include <dhcp/dhcp6.h>
9#include <dhcp/libdhcp++.h>
10#include <dhcp/option6_auth.h>
11#include <dhcp/option_space.h>
13#include <util/io.h>
14#include <util/encode/encode.h>
15
16#include <sstream>
17#include <stdint.h>
18
19using namespace std;
20using namespace isc::util;
21
22namespace isc {
23namespace dhcp {
24
25 Option6Auth::Option6Auth(const uint8_t proto, const uint8_t algo,
26 const uint8_t method, const uint64_t rdm,
27 const std::vector<uint8_t>& info)
28 : Option(Option::V6, D6O_AUTH),
29 protocol_(proto), algorithm_(algo),
30 rdm_method_(method), rdm_value_(rdm),
31 auth_info_(info) {
32}
33
36 return (cloneInternal<Option6Auth>());
37}
38
39void
42 isc_throw(OutOfRange, "Option " << type_ << "Buffer too small for"
43 "packing data");
44 }
45
46 //header = option code + length
47 buf.writeUint16(type_);
48 // length = 11 bytes fixed field length+ length of auth information
49 buf.writeUint16(11 + uint16_t(auth_info_.size()));
50 // protocol 1 byte
52 // algorithm 1 byte
54 // replay detection method
56 // replay detection value
58 // authentication information for reconfig msg
59 // should have zero
60
61 for (auto const& i : auth_info_) {
62 buf.writeUint8(i);
63 }
64}
65
66void
69 isc_throw(OutOfRange, "Option " << type_ << "Buffer too small for"
70 "computing hash input");
71 }
72
73 //header = option code + length
74 buf.writeUint16(type_);
75 // length = 11 bytes fixed field length+ length of auth information
77 // protocol 1 byte
79 // algorithm 1 byte
81 // replay detection method
83 // replay detection value
85 // authentication information for reconfig msg
86 // should have zero
87 for (uint8_t i = 0; i < OPTION6_HASH_MSG_LEN; i++) {
88 buf.writeUint8(0);
89 }
90}
91
92void
95 // throw if it contains length less than minimum size of the auth option
96 if (distance(begin, end) < Option6Auth::OPTION6_AUTH_MIN_LEN) {
97 isc_throw(OutOfRange, "Option " << type_ << " truncated");
98 }
99
100 protocol_ = *begin;
101 begin += sizeof(uint8_t);
102
103 algorithm_ = *begin;
104 begin += sizeof(uint8_t);
105
106 rdm_method_ = *begin;
107 begin += sizeof(uint8_t);
108
109 rdm_value_ = isc::util::readUint64(&(*begin), sizeof(uint64_t));
110 begin += sizeof(uint64_t);
111
112 auth_info_.erase(auth_info_.begin(), auth_info_.end());
113 std::for_each(begin, end, [this](uint8_t msgdata)
114 { auth_info_.push_back(msgdata); });
115}
116
117std::string
118Option6Auth::toText(int indent) const {
119 stringstream output;
120 std::string in(indent, ' '); //base indent
121
122 output << in << "protocol=" << static_cast<int>(protocol_)
123 << ", algorithm=" << static_cast<int>(algorithm_)
124 << ", rdm method=" << static_cast<int>(rdm_method_)
125 << ", rdm value=" << rdm_value_
127
128 return output.str();
129}
130
131} // end namespace dhcp
132} // end namespace isc
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
static const uint8_t OPTION6_HASH_MSG_LEN
Definition: option6_auth.h:31
uint8_t protocol_
keeps protocol type
Definition: option6_auth.h:129
static const uint8_t OPTION6_AUTH_MIN_LEN
Definition: option6_auth.h:30
static const uint8_t OPTION6_HDR
Definition: option6_auth.h:32
uint64_t rdm_value_
keeps replay detection method value
Definition: option6_auth.h:138
uint8_t rdm_method_
keeps replay detection method type
Definition: option6_auth.h:135
virtual std::string toText(int indent=0) const
Provides human readable text representation.
uint8_t algorithm_
keeps hash algorithm value
Definition: option6_auth.h:132
virtual OptionPtr clone() const
Copies this option and returns a pointer to the copy.
Definition: option6_auth.cc:35
std::vector< uint8_t > auth_info_
keeps authentication information
Definition: option6_auth.h:141
void packHashInput(isc::util::OutputBuffer &buf) const
Writes option in wire-format to buf, for computing hash auth info filled with 0 for a length of 128 b...
Definition: option6_auth.cc:67
void pack(isc::util::OutputBuffer &buf, bool check=true) const
Writes option in wire-format to buf, returns pointer to first unused byte after stored option.
Definition: option6_auth.cc:40
Option6Auth(const uint8_t proto, const uint8_t algo, const uint8_t method, const uint64_t rdm, const std::vector< uint8_t > &info)
Constructor, used for auth options while transmitting.
Definition: option6_auth.cc:25
virtual void unpack(OptionBufferConstIter begin, OptionBufferConstIter end)
Parses received buffer.
Definition: option6_auth.cc:93
uint16_t type_
option type (0-255 for DHCPv4, 0-65535 for DHCPv6)
Definition: option.h:590
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:343
void writeUint64(uint64_t data)
Write an unsigned 64-bit integer in host byte order into the buffer in network byte order.
Definition: buffer.h:539
void writeUint8(uint8_t data)
Write an unsigned 8-bit integer into the buffer.
Definition: buffer.h:473
void writeUint16(uint16_t data)
Write an unsigned 16-bit integer in host byte order into the buffer in network byte order.
Definition: buffer.h:498
size_t getCapacity() const
Return the current capacity of the buffer.
Definition: buffer.h:384
@ D6O_AUTH
Definition: dhcp6.h:31
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
@ info
Definition: db_log.h:120
OptionBuffer::const_iterator OptionBufferConstIter
const_iterator for walking over OptionBuffer
Definition: option.h:30
boost::shared_ptr< Option > OptionPtr
Definition: option.h:37
string encodeHex(const vector< uint8_t > &binary)
Encode binary data in the base16 format.
Definition: encode.cc:361
uint64_t readUint64(void const *const buffer, size_t const length)
uint16_t wrapper over readUint.
Definition: io.h:88
Defines the logger used by the top-level component of kea-lfc.