14#include <boost/scoped_ptr.hpp>
32 return (
"Access-Request");
34 return (
"Access-Accept");
36 return (
"Access-Reject");
38 return (
"Accounting-Request");
40 return (
"Accounting-Response");
42 return (
"Accounting-Status");
44 return (
"Password-Request");
46 return (
"Password-Ack");
48 return (
"Password-Reject");
50 return (
"Accounting-Message");
52 return (
"Access-Challenge");
54 return (
"Status-Server");
56 return (
"Status-Client");
58 result <<
"Message-Code-" <<
static_cast<unsigned>(code);
59 return (result.str());
64 const vector<uint8_t>& auth,
const string& secret,
80 for (auto const& attr : *other.attributes_) {
81 attributes_->add(attr);
87 const vector<uint8_t>& auth,
111 if (auth.size() != AUTH_VECTOR_LEN) {
120 auth_.resize(AUTH_VECTOR_LEN, 0);
126 if (
auth_.size() != AUTH_VECTOR_LEN) {
133 if (secret.empty()) {
163 vector<uint8_t> binary = attr->toBytes();
164 if (binary.empty()) {
167 if (
buffer_.size() + binary.size() > PW_MAX_MSG_SIZE) {
183 md->final(&
auth_[0], AUTH_VECTOR_LEN);
189 .arg(
static_cast<unsigned>(
code_))
203 if (
buffer_.size() < AUTH_HDR_LEN) {
205 <<
" < " << AUTH_HDR_LEN);
212 auth_.resize(AUTH_VECTOR_LEN);
214 }
else if (
auth_.size() != AUTH_VECTOR_LEN) {
223 <<
" length " <<
length_ <<
" < " << AUTH_HDR_LEN);
225 if (
length_ > PW_MAX_MSG_SIZE) {
227 <<
" length " <<
length_ <<
" > " << PW_MAX_MSG_SIZE);
235 vector<uint8_t> work =
buffer_;
238 md->update(&work[0], work.size());
241 digest.resize(AUTH_VECTOR_LEN);
242 md->final(&
digest[0], AUTH_VECTOR_LEN);
248 auth_.resize(AUTH_VECTOR_LEN);
253 size_t ptr = AUTH_HDR_LEN;
261 const uint8_t type =
buffer_[ptr];
262 const uint8_t len =
buffer_[ptr + 1];
266 <<
static_cast<unsigned>(type) <<
"): length "
267 <<
static_cast<unsigned>(len) <<
", space "
272 <<
static_cast<unsigned>(len) <<
" < 3");
274 vector<uint8_t> binary;
276 memmove(&binary[0], &
buffer_[ptr], binary.size());
291 .arg(
static_cast<unsigned>(
code_))
300 (attr->getValueLen() == 0) ||
301 (
auth_.size() != AUTH_VECTOR_LEN)) {
306 vector<uint8_t> password = attr->toBinary();
307 size_t len = password.size();
308 len = (len + AUTH_VECTOR_LEN - 1) & ~(AUTH_VECTOR_LEN - 1);
309 if (len > AUTH_PASS_LEN) {
312 password.resize(len);
315 for (
size_t i = 0; i < len; i += AUTH_VECTOR_LEN) {
323 to_hash = &password[i - AUTH_VECTOR_LEN];
325 md->update(to_hash, AUTH_VECTOR_LEN);
328 digest.resize(AUTH_VECTOR_LEN);
329 md->final(&
digest[0], AUTH_VECTOR_LEN);
330 for (
size_t j = 0; j < AUTH_VECTOR_LEN; j++) {
331 password[i + j] ^=
digest[j];
333 memset(&
digest[0], 0, AUTH_VECTOR_LEN);
343 (attr->getValueLen() == 0) ||
344 ((attr->getValueLen() % AUTH_VECTOR_LEN) != 0) ||
345 (
auth_.size() != AUTH_VECTOR_LEN)) {
350 vector<uint8_t> password = attr->toBinary();
351 size_t len = password.size();
352 if (len > AUTH_PASS_LEN) {
354 password.resize(len);
360 if (i < AUTH_VECTOR_LEN) {
363 i -= AUTH_VECTOR_LEN;
371 to_hash = &password[i - AUTH_VECTOR_LEN];
373 md->update(to_hash, AUTH_VECTOR_LEN);
376 digest.resize(AUTH_VECTOR_LEN);
377 md->final(&
digest[0], AUTH_VECTOR_LEN);
378 for (
size_t j = 0; j < AUTH_VECTOR_LEN; j++) {
379 password[i + j] ^=
digest[j];
381 memset(&
digest[0], 0, AUTH_VECTOR_LEN);
385 while (password.back() == 0) {
387 if (password.size() == 1) {
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown if a function is called in a prohibited way.
A generic exception that is thrown when an unexpected error condition occurs.
static CryptoLink & getCryptoLink()
Returns a reference to the singleton instance.
static AttrDefs & instance()
Returns a single instance.
static AttributePtr fromBytes(const std::vector< uint8_t > &bytes)
From bytes (wire format).
static AttributePtr fromBinary(const uint8_t type, const std::vector< uint8_t > &value)
From binary with type.
Collection of attributes.
std::vector< uint8_t > auth_
Authenticator: header[4] (16 octets).
void setAuth(const std::vector< uint8_t > &auth)
Set authenticator.
ConstAttributePtr encodeUserPassword(const ConstAttributePtr &attr)
Encode User-Password in an Access-Request.
ConstAttributePtr decodeUserPassword(const ConstAttributePtr &attr)
Decode User-Password in an Access-Request.
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.
std::vector< uint8_t > buffer_
Buffer (message content).
uint8_t code_
Code (useful values in MsgCode): header[0].
void decode()
Decode a message.
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.
virtual ~Message()
Destructor.
void setSecret(const std::string &secret)
Set secret.
void randomIdentifier()
Randomize identifier.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
std::vector< uint8_t > random(size_t len)
Generate random value.
void digest(const void *data, const size_t data_len, const HashAlgorithm hash_algorithm, isc::util::OutputBuffer &result, size_t len)
Create an Hash digest for the given data.
@ PW_USER_PASSWORD
string.
boost::shared_ptr< Attributes > AttributesPtr
Shared pointers to attribute collection.
boost::shared_ptr< const Attribute > ConstAttributePtr
const isc::log::MessageID RADIUS_DECODE_MESSAGE
string msgCodeToText(const uint8_t code)
MsgCode value -> name function.
const int RADIUS_DBG_TRACE
Radius logging levels.
const isc::log::MessageID RADIUS_ENCODE_MESSAGE
isc::log::Logger radius_logger("radius-hooks")
Radius Logger.
Defines the logger used by the top-level component of kea-lfc.