-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incoming packet validation and header data.
- Loading branch information
Showing
10 changed files
with
265 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
# Python virtual env | ||
/venv | ||
|
||
# VSOutput | ||
**/.vs/** | ||
**/out/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# LibAAA a Bare-Bone C radius packet library | ||
|
||
The following pages will explain the usage of the libaaa library. The lib is composed out of the following components: | ||
|
||
- `libaaa_pg`: C-API for packet generation | ||
- `libaaa_pr`: C-API for packet reading/parsing | ||
- `libaaa::packet_generator`: C++ OOP wrapper for packet generation | ||
- `libaaa::packet_reader`: C++ OOP wrapper for packet reading/parsing |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include "libaaa_test.h" | ||
|
||
class libaaa_pr_test : public ::testing::Test | ||
{ | ||
protected: | ||
virtual void SetUp() override | ||
{ | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "pr_facade.h" | ||
|
||
class pr_header_data : public libaaa_pr_test {}; | ||
|
||
TEST_F(pr_header_data, extract) | ||
{ | ||
// Expected values | ||
uint8_t expected_code = 22; | ||
uint8_t expected_id = 111; | ||
uint8_t expected_authenticator[] = { | ||
0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A, 0x8A, | ||
0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B, 0x8B, | ||
}; | ||
|
||
// Target values | ||
uint8_t code = 0; | ||
uint8_t id = 0; | ||
uint8_t authenticator[16]; | ||
memset(authenticator, 0x0, 16); | ||
|
||
// Retrieve packet | ||
uint8_t packet[] = { | ||
22, 111, // Code, ID | ||
0, 20, // Length | ||
0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A, 0x8A, // Authenticator | ||
0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B, 0x8B, // ... | ||
}; | ||
|
||
libaaa_pr_get_packet_details(packet, &code, &id, (char*)authenticator); | ||
|
||
EXPECT_EQ(code, expected_code); | ||
EXPECT_EQ(id, expected_id); | ||
ASSERT_THAT(authenticator, PacketCheck(expected_authenticator, 16)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include "pr_facade.h" | ||
|
||
class pr_validation : public libaaa_pr_test {}; | ||
|
||
TEST_F(pr_validation, size_invalid) | ||
{ | ||
// Retrieve packet | ||
uint8_t packet[] = { | ||
0, 0, 0, 0, | ||
}; | ||
|
||
EXPECT_EQ(libaaa_pr_validate_packet(packet, 4), LIBAAA_PACKET_INVALID_LENGTH); | ||
} | ||
|
||
TEST_F(pr_validation, header_valid) | ||
{ | ||
// Retrieve packet | ||
uint8_t packet[] = { | ||
1, 2, // Code, ID | ||
0, 20, // Length | ||
0, 0, 0, 0, 0, 0, 0, 0, // Authenticator | ||
0, 0, 0, 0, 0, 0, 0, 0, // ... | ||
}; | ||
|
||
EXPECT_EQ(libaaa_pr_validate_packet(packet, 20), LIBAAA_OK); | ||
} | ||
|
||
TEST_F(pr_validation, header_valid_padding) | ||
{ | ||
// Retrieve packet | ||
uint8_t packet[] = { | ||
1, 2, // Code, ID | ||
0, 20, // Length | ||
0, 0, 0, 0, 0, 0, 0, 0, // Authenticator | ||
0, 0, 0, 0, 0, 0, 0, 0, // ... | ||
0, 0, 0, 0, 0, 0, 0, 0, | ||
0, 0, 0, 0, | ||
}; | ||
|
||
EXPECT_EQ(libaaa_pr_validate_packet(packet, 32), LIBAAA_OK); | ||
} | ||
|
||
TEST_F(pr_validation, header_invalid) | ||
{ | ||
// Retrieve packet | ||
uint8_t packet[] = { | ||
160, 2, // Code, ID | ||
0, 20, // Length | ||
0, 0, 0, 0, 0, 0, 0, 0, // Authenticator | ||
0, 0, 0, 0, 0, 0, 0, 0, // ... | ||
}; | ||
|
||
EXPECT_EQ(libaaa_pr_validate_packet(packet, 20), LIBAAA_PACKET_VALIDATION_FAILED); | ||
} | ||
|
||
TEST_F(pr_validation, attribute_valid) | ||
{ | ||
// Retrieve packet | ||
uint8_t packet[] = { | ||
1, 2, // Code, ID | ||
0, 22, // Length | ||
0, 0, 0, 0, 0, 0, 0, 0, // Authenticator | ||
0, 0, 0, 0, 0, 0, 0, 0, // ... | ||
5, 2, | ||
}; | ||
|
||
EXPECT_EQ(libaaa_pr_validate_packet(packet, 22), LIBAAA_OK); | ||
} | ||
|
||
TEST_F(pr_validation, attribute_invalid) | ||
{ | ||
// Retrieve packet | ||
uint8_t packet[] = { | ||
1, 2, // Code, ID | ||
0, 22, // Length | ||
0, 0, 0, 0, 0, 0, 0, 0, // Authenticator | ||
0, 0, 0, 0, 0, 0, 0, 0, // ... | ||
5, 0, | ||
}; | ||
|
||
EXPECT_EQ(libaaa_pr_validate_packet(packet, 22), LIBAAA_PACKET_INVALID_BODY); | ||
} | ||
|
||
TEST_F(pr_validation, attribute_header_missmatch) | ||
{ | ||
// Retrieve packet | ||
uint8_t packet[] = { | ||
1, 2, // Code, ID | ||
0, 22, // Length | ||
0, 0, 0, 0, 0, 0, 0, 0, // Authenticator | ||
0, 0, 0, 0, 0, 0, 0, 0, // ... | ||
5, 5, 0, 0, 0, // <-- Valid attributes but invalid header size | ||
}; | ||
|
||
EXPECT_EQ(libaaa_pr_validate_packet(packet, 25), LIBAAA_PACKET_INVALID_BODY); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters