Kea 3.1.1
client_message.h
Go to the documentation of this file.
1// Copyright (C) 2023-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 RADIUS_CLIENT_MESSAGE_H
8#define RADIUS_CLIENT_MESSAGE_H
9
10#include <client_attribute.h>
12#include <asiolink/io_address.h>
13#include <string>
14#include <vector>
15
16namespace isc {
17namespace radius {
18
35
40std::string msgCodeToText(const uint8_t code);
41
43static constexpr size_t AUTH_HDR_LEN = 20;
44
46static constexpr size_t PW_MAX_MSG_SIZE = 4095;
47
49static constexpr size_t AUTH_VECTOR_LEN = 16;
50
52static constexpr size_t AUTH_PASS_LEN = 128;
53
55class Message {
56public:
60 static const std::vector<uint8_t> ZERO_AUTH() {
61 static std::vector<uint8_t> zero(AUTH_VECTOR_LEN, 0);
62 return (zero);
63 }
64
74 Message(const uint8_t code, uint16_t length,
75 const std::vector<uint8_t>& auth,
76 const std::string& secret,
77 const AttributesPtr& attributes);
78
84 Message(const Message& other);
85
93 Message(const std::vector<uint8_t>& buffer,
94 const std::vector<uint8_t>& auth,
95 const std::string& secret);
96
100 virtual ~Message();
101
105 uint8_t getCode() const {
106 return (code_);
107 }
108
112 void setCode(const uint8_t code) {
113 code_ = code;
114 }
115
119 uint8_t getIdentifier() const {
120 return(identifier_);
121 }
122
126 void setIdentifier(const uint8_t identifier) {
127 identifier_ = identifier;
128 }
129
131 void randomIdentifier();
132
136 uint16_t getLength() const {
137 return (length_);
138 }
139
143 void setLength(const uint16_t length) {
144 length_ = length;
145 }
146
150 std::vector<uint8_t> getAuth() const {
151 return (auth_);
152 }
153
157 void setAuth(const std::vector<uint8_t>& auth);
158
160 void zeroAuth();
161
163 void randomAuth();
164
168 std::string getSecret() const {
169 return (secret_);
170 }
171
174 void setSecret(const std::string& secret);
175
180 return (attributes_);
181 }
182
186 void setAttributes(const AttributesPtr& attributes) {
187 attributes_ = attributes;
188 }
189
193 std::vector<uint8_t> getBuffer() const {
194 return (buffer_);
195 }
196
200 void setBuffer(const std::vector<uint8_t>& buffer) {
201 buffer_ = buffer;
202 }
203
208 std::vector<uint8_t> encode();
209
213 void decode();
214
215protected:
221
227
229 uint8_t code_;
230
232 uint8_t identifier_;
233
235 uint16_t length_;
236
238 std::vector<uint8_t> auth_;
239
241 std::string secret_;
242
245
247 std::vector<uint8_t> buffer_;
248};
249
251typedef boost::shared_ptr<Message> MessagePtr;
252
253} // end of namespace isc::radius
254} // end of namespace isc
255
256#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 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 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.