Kea 3.1.9
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 <client_attribute.h>
12#include <asiolink/io_address.h>
13#include <tcp/wire_data.h>
14#include <string>
15#include <vector>
16
17namespace isc {
18namespace radius {
19
36
41std::string msgCodeToText(const uint8_t code);
42
44static constexpr size_t AUTH_HDR_LEN = 20;
45
47static constexpr size_t PW_MAX_MSG_SIZE = 4095;
48
50static constexpr size_t AUTH_VECTOR_LEN = 16;
51
53static constexpr size_t AUTH_PASS_LEN = 128;
54
56class Message {
57public:
61 static const std::vector<uint8_t> ZERO_AUTH() {
62 static std::vector<uint8_t> zero(AUTH_VECTOR_LEN, 0);
63 return (zero);
64 }
65
75 Message(const uint8_t code, uint16_t length,
76 const std::vector<uint8_t>& auth,
77 const std::string& secret,
78 const AttributesPtr& attributes);
79
85 Message(const Message& other);
86
94 Message(const std::vector<uint8_t>& buffer,
95 const std::vector<uint8_t>& auth,
96 const std::string& secret);
97
101 virtual ~Message();
102
106 uint8_t getCode() const {
107 return (code_);
108 }
109
113 void setCode(const uint8_t code) {
114 code_ = code;
115 }
116
120 uint8_t getIdentifier() const {
121 return(identifier_);
122 }
123
127 void setIdentifier(const uint8_t identifier) {
128 identifier_ = identifier;
129 }
130
132 void randomIdentifier();
133
137 uint16_t getLength() const {
138 return (length_);
139 }
140
144 void setLength(const uint16_t length) {
145 length_ = length;
146 }
147
151 std::vector<uint8_t> getAuth() const {
152 return (auth_);
153 }
154
158 void setAuth(const std::vector<uint8_t>& auth);
159
161 void zeroAuth();
162
164 void randomAuth();
165
169 std::string getSecret() const {
170 return (secret_);
171 }
172
175 void setSecret(const std::string& secret);
176
181 return (attributes_);
182 }
183
187 void setAttributes(const AttributesPtr& attributes) {
188 attributes_ = attributes;
189 }
190
194 std::vector<uint8_t> getBuffer() const {
195 return (buffer_);
196 }
197
201 void setBuffer(const std::vector<uint8_t>& buffer) {
202 buffer_ = buffer;
203 }
204
209 std::vector<uint8_t> encode();
210
214 void decode();
215
216protected:
222
228
232 void signMessageAuthenticator(size_t ptr);
233
237 void verifyMessageAuthenticator(size_t ptr);
238
240 uint8_t code_;
241
243 uint8_t identifier_;
244
246 uint16_t length_;
247
249 std::vector<uint8_t> auth_;
250
252 std::string secret_;
253
256
258 std::vector<uint8_t> buffer_;
259};
260
262typedef boost::shared_ptr<Message> MessagePtr;
263
264} // end of namespace isc::radius
265} // end of namespace isc
266
267#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.