Kea 3.3.3
client_message.h
Go to the documentation of this file.
1// Copyright (C) 2023-2026 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 RADIUS_CLIENT_MESSAGE_H
8#define RADIUS_CLIENT_MESSAGE_H
9
10#include <asiolink/io_address.h>
13#include <tcp/wire_data.h>
14
15#include <cstdint>
16#include <string>
17#include <vector>
18
19namespace isc {
20namespace radius {
21
38
43std::string msgCodeToText(const uint8_t code);
44
46static constexpr size_t AUTH_HDR_LEN = 20;
47
49static constexpr size_t PW_MAX_MSG_SIZE = 4095;
50
52static constexpr size_t AUTH_VECTOR_LEN = 16;
53
55static constexpr size_t AUTH_PASS_LEN = 128;
56
58class Message {
59public:
63 static const std::vector<uint8_t> ZERO_AUTH() {
64 static std::vector<uint8_t> zero(AUTH_VECTOR_LEN, 0);
65 return (zero);
66 }
67
77 Message(const uint8_t code, uint16_t length,
78 const std::vector<uint8_t>& auth,
79 const std::string& secret,
80 const AttributesPtr& attributes);
81
87 Message(const Message& other);
88
96 Message(const std::vector<uint8_t>& buffer,
97 const std::vector<uint8_t>& auth,
98 const std::string& secret);
99
103 virtual ~Message();
104
108 uint8_t getCode() const {
109 return (code_);
110 }
111
115 void setCode(const uint8_t code) {
116 code_ = code;
117 }
118
122 uint8_t getIdentifier() const {
123 return(identifier_);
124 }
125
129 void setIdentifier(const uint8_t identifier) {
130 identifier_ = identifier;
131 }
132
134 void randomIdentifier();
135
139 uint16_t getLength() const {
140 return (length_);
141 }
142
146 void setLength(const uint16_t length) {
147 length_ = length;
148 }
149
153 std::vector<uint8_t> getAuth() const {
154 return (auth_);
155 }
156
160 void setAuth(const std::vector<uint8_t>& auth);
161
163 void zeroAuth();
164
166 void randomAuth();
167
171 std::string getSecret() const {
172 return (secret_);
173 }
174
177 void setSecret(const std::string& secret);
178
183 return (attributes_);
184 }
185
189 void setAttributes(const AttributesPtr& attributes) {
190 attributes_ = attributes;
191 }
192
196 std::vector<uint8_t> getBuffer() const {
197 return (buffer_);
198 }
199
203 void setBuffer(const std::vector<uint8_t>& buffer) {
204 buffer_ = buffer;
205 }
206
211 std::vector<uint8_t> encode();
212
216 void decode();
217
218protected:
224
230
234 void signMessageAuthenticator(size_t ptr);
235
239 void verifyMessageAuthenticator(size_t ptr);
240
242 uint8_t code_;
243
245 uint8_t identifier_;
246
248 uint16_t length_;
249
251 std::vector<uint8_t> auth_;
252
254 std::string secret_;
255
258
260 std::vector<uint8_t> buffer_;
261};
262
264typedef boost::shared_ptr<Message> MessagePtr;
265
266} // end of namespace isc::radius
267} // end of namespace isc
268
269#endif
RADIUS Message.
std::vector< uint8_t > auth_
Authenticator: header[4] (16 octets).
void setAuth(const std::vector< uint8_t > &auth)
Set authenticator.
std::vector< uint8_t > getAuth() const
Get authenticator.
void setLength(const uint16_t length)
Set length.
ConstAttributePtr encodeUserPassword(const ConstAttributePtr &attr)
Encode User-Password in an Access-Request.
void setIdentifier(const uint8_t identifier)
Set identifier.
static const std::vector< uint8_t > ZERO_AUTH()
Build a zero authenticator.
ConstAttributePtr decodeUserPassword(const ConstAttributePtr &attr)
Decode User-Password in an Access-Request.
uint16_t getLength() const
Get length.
void signMessageAuthenticator(size_t ptr)
Encode Message-Authenticator in an Status-Server.
void setCode(const uint8_t code)
Set code.
Message(const uint8_t code, uint16_t length, const std::vector< uint8_t > &auth, const std::string &secret, const AttributesPtr &attributes)
Constructor.
uint8_t identifier_
Identifier (random): header[1].
void randomAuth()
Randomize authenticator.
std::vector< uint8_t > encode()
Encode a message.
uint8_t getCode() const
Get code.
std::vector< uint8_t > buffer_
Buffer (message content).
std::vector< uint8_t > getBuffer() const
Get buffer.
uint8_t code_
Code (useful values in MsgCode): header[0].
uint8_t getIdentifier() const
Get identifier.
void setAttributes(const AttributesPtr &attributes)
Set attributes.
void decode()
Decode a message.
AttributesPtr getAttributes() const
Get attributes.
AttributesPtr attributes_
Attributes: header[20]...
uint16_t length_
Length: header[2] (16 bits, network order).
std::string secret_
Secret (not empty).
void zeroAuth()
Fill authenticator with 0.
std::string getSecret() const
Get secret.
virtual ~Message()
Destructor.
void setBuffer(const std::vector< uint8_t > &buffer)
Set buffer.
void verifyMessageAuthenticator(size_t ptr)
Decode Message-Authenticator in an Status-Server.
void setSecret(const std::string &secret)
Set secret.
void randomIdentifier()
Randomize identifier.
boost::shared_ptr< Attributes > AttributesPtr
Shared pointers to attribute collection.
boost::shared_ptr< const Attribute > ConstAttributePtr
string msgCodeToText(const uint8_t code)
MsgCode value -> name function.
boost::shared_ptr< Message > MessagePtr
Shared pointers to message.
MsgCode
Standard RADIUS message code.
Defines the logger used by the top-level component of kea-lfc.