Skip to content

Commit

Permalink
https://telecominfraproject.atlassian.net/browse/WIFI-12692
Browse files Browse the repository at this point in the history
Signed-off-by: stephb9959 <[email protected]>
  • Loading branch information
stephb9959 committed Oct 20, 2023
1 parent ba6c657 commit 8a69089
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
9 changes: 4 additions & 5 deletions src/RADIUS_Destination.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace OpenWifi {
}
} else if ((Utils::Now() - LastKeepAlive) > Pool_.radsecKeepAlive) {
RADIUS::RadiusOutputPacket P(Pool_.authConfig.servers[ServerIndex_].radsecSecret);
P.MakeStatusMessage();
P.MakeStatusMessage(Pool_.authConfig.servers[ServerIndex_].name);
poco_trace(Logger_, fmt::format("{}: Keep-Alive message.", Pool_.authConfig.servers[ServerIndex_].name));
Socket_->sendBytes(P.Data(), P.Len());
LastKeepAlive = Utils::Now();
Expand Down Expand Up @@ -115,6 +115,7 @@ namespace OpenWifi {

try {
auto NumberOfReceivedBytes = Socket_->receiveBytes(Buffer, sizeof(Buffer));
std::string ReplySource;
if (NumberOfReceivedBytes >= 20) {
RADIUS::RadiusPacket P(Buffer, NumberOfReceivedBytes);
if (P.IsAuthentication()) {
Expand All @@ -125,11 +126,9 @@ namespace OpenWifi {
P.PacketType(), NumberOfReceivedBytes));
AP_WS_Server()->SendRadiusAuthenticationData(SerialNumber, Buffer,
NumberOfReceivedBytes);
} else if(P.IsStatusMessageReply()) {
DBGLINE
} else if(P.IsStatusMessageReply(ReplySource)) {
poco_debug(Logger_,
fmt::format("{}: Keepalive message received.", SerialNumber));
DBGLINE
fmt::format("{}: Keepalive message received.", ReplySource));
} else {
poco_debug(Logger_, "AUTH packet dropped.");
}
Expand Down
20 changes: 12 additions & 8 deletions src/RADIUS_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,17 +429,20 @@ namespace OpenWifi::RADIUS {
P_.code == RADIUS::CoA_ACK || P_.code == RADIUS::CoA_NAK);
}

inline bool IsStatusMessageReply() {
inline bool IsStatusMessageReply(std::string &ReplySource) {
std::string Result;
for (const auto &attribute : Attrs_) {
if (attribute.type == RADIUS::Attributes::PROXY_STATE) {
DBGLINE
std::string Attr33;
// format is serial:IP:port:interface
Attr33.assign((const char *)(const char *)&P_.attributes[attribute.pos],
attribute.len);
DBGLINE
return Attr33 == "status";
auto Parts = Poco::StringTokenizer(Attr33, ":");
if(Parts.count() == 2) {
ReplySource = Parts[1];
return true;
}
return false;
}
}
DBGLINE
Expand Down Expand Up @@ -1003,12 +1006,13 @@ namespace OpenWifi::RADIUS {
public:
explicit RadiusOutputPacket(const std::string &Secret) : Secret_(Secret) {}

inline void MakeStatusMessage() {
inline void MakeStatusMessage(const std::string &Source) {
P_.code = RADIUS::Status_Server;
P_.identifier = std::rand() & 0x00ff;
MakeRadiusAuthenticator(P_.authenticator);
unsigned char MessageAuthenticator[16]{0};
AddAttribute(RADIUS::Attributes::PROXY_STATE, 6, (const unsigned char *)"status" );
std::string FullSource = "status:" + Source;
AddAttribute(RADIUS::Attributes::PROXY_STATE, FullSource.size(), (const unsigned char *)FullSource.c_str());
AddAttribute(RADIUS::Attributes::MESSAGE_AUTHENTICATOR, sizeof(MessageAuthenticator),
MessageAuthenticator);
// int PktLen = 1 + 1 + 2 + 16 + 1 + 1 + 16 ;
Expand All @@ -1019,9 +1023,9 @@ namespace OpenWifi::RADIUS {
Poco::HMACEngine<Poco::MD5Engine> H(Secret_);
H.update((const unsigned char *)&P_, PktLen);
auto digest = H.digest();
int p = 0;
int p = 0, offset = (int)FullSource.size() + 2 ;
for (const auto &i : digest)
P_.attributes[8 + 1 + 1 + p++] = i;
P_.attributes[offset + 1 + 1 + p++] = i;
}

inline void AddAttribute(unsigned char attr, uint8_t len, const unsigned char *data) {
Expand Down

0 comments on commit 8a69089

Please sign in to comment.