Skip to content

Commit

Permalink
decoder now adds packet type and auth vector to output VPs
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Nov 9, 2019
1 parent 59472ce commit 427f211
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/protocols/radius/attrs.h
Expand Up @@ -30,6 +30,8 @@ RCSIDH(radius_attrs_h, "$Id$")
extern fr_dict_t const *dict_freeradius;
extern fr_dict_t const *dict_radius;

extern fr_dict_attr_t const *attr_packet_type;
extern fr_dict_attr_t const *attr_packet_authentication_vector;
extern fr_dict_attr_t const *attr_raw_attribute;
extern fr_dict_attr_t const *attr_chap_challenge;
extern fr_dict_attr_t const *attr_chargeable_user_identity;
Expand Down
4 changes: 4 additions & 0 deletions src/protocols/radius/base.c
Expand Up @@ -46,6 +46,8 @@ fr_dict_autoload_t libfreeradius_radius_dict[] = {
{ NULL }
};

fr_dict_attr_t const *attr_packet_type;
fr_dict_attr_t const *attr_packet_authentication_vector;
fr_dict_attr_t const *attr_raw_attribute;
fr_dict_attr_t const *attr_chap_challenge;
fr_dict_attr_t const *attr_chargeable_user_identity;
Expand All @@ -56,6 +58,8 @@ fr_dict_attr_t const *attr_vendor_specific;

extern fr_dict_attr_autoload_t libfreeradius_radius_dict_attr[];
fr_dict_attr_autoload_t libfreeradius_radius_dict_attr[] = {
{ .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_radius },
{ .out = &attr_packet_authentication_vector, .name = "Packet-Authentication-Vector", .type = FR_TYPE_OCTETS, .dict = &dict_radius },
{ .out = &attr_raw_attribute, .name = "Raw-Attribute", .type = FR_TYPE_OCTETS, .dict = &dict_freeradius },
{ .out = &attr_chap_challenge, .name = "CHAP-Challenge", .type = FR_TYPE_OCTETS, .dict = &dict_radius },
{ .out = &attr_chargeable_user_identity, .name = "Chargeable-User-Identity", .type = FR_TYPE_OCTETS, .dict = &dict_radius },
Expand Down
35 changes: 30 additions & 5 deletions src/protocols/radius/decode.c
Expand Up @@ -1639,16 +1639,41 @@ static int decode_test_ctx(void **out, TALLOC_CTX *ctx)

static ssize_t fr_radius_decode_proto(TALLOC_CTX *ctx, VALUE_PAIR **vps, uint8_t const *data, size_t data_len, void *proto_ctx)
{
ssize_t rcode;
size_t packet_len = data_len;
fr_radius_ctx_t *test_ctx = talloc_get_type_abort(proto_ctx, fr_radius_ctx_t);
decode_fail_t reason;
fr_cursor_t cursor;
VALUE_PAIR *vp;

if (!fr_radius_ok(data, &packet_len, 200, false, NULL)) return -1;
if (!fr_radius_ok(data, &packet_len, 200, false, &reason)) {
return -1;
}

*vps = NULL;
fr_cursor_init(&cursor, vps);

/*
* Decode the header
*/
vp = fr_pair_afrom_da(ctx, attr_packet_type);
if (!vp) {
fr_strerror_printf("Failed creating Packet-Type");
return -1;
}
vp->vp_uint32 = data[0];
fr_cursor_append(&cursor, vp);

rcode = fr_radius_decode(ctx, data, packet_len, test_ctx->vector - 4, /* decode adds 4 to this */
test_ctx->secret, talloc_array_length(test_ctx->secret) - 1, vps);
vp = fr_pair_afrom_da(ctx, attr_packet_authentication_vector);
if (!vp) {
fr_strerror_printf("Failed creating Packet-Authentication-Vector");
return -1;
}
(void) fr_pair_value_memcpy(vp, data + 4, 16, true);
fr_cursor_append(&cursor, vp);
vp = fr_cursor_tail(&cursor);

return rcode;
return fr_radius_decode(ctx, data, packet_len, test_ctx->vector - 4, /* decode adds 4 to this */
test_ctx->secret, talloc_array_length(test_ctx->secret) - 1, &vp->next);
}

/*
Expand Down

0 comments on commit 427f211

Please sign in to comment.