mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralsec.git
synced 2025-10-29 09:52:29 +00:00
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
This commit is contained in:
@@ -42,7 +42,7 @@ if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
|
||||
string(REGEX REPLACE "\n$" "" GIT_HASH "${GIT_HASH}")
|
||||
endif()
|
||||
|
||||
add_definitions(-DAWS_CUSTOM_MEMORY_MANAGEMENT)
|
||||
add_definitions(-DAWS_CUSTOM_MEMORY_MANAGEMENT -DBOOST_NO_CXX98_FUNCTION_BASE=1)
|
||||
|
||||
set(BUILD_SHARED_LIBS 1)
|
||||
|
||||
|
||||
@@ -34,6 +34,10 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"strict": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"uuid": {
|
||||
"type": "integer"
|
||||
},
|
||||
@@ -114,6 +118,20 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
"random-password": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"beacon-advertisement": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"device-name": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"device-serial": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"network-id": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -222,6 +240,52 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
}
|
||||
}
|
||||
},
|
||||
"interface.ssid.encryption": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"proto": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"none",
|
||||
"owe",
|
||||
"owe-transition",
|
||||
"psk",
|
||||
"psk2",
|
||||
"psk-mixed",
|
||||
"psk2-radius",
|
||||
"wpa",
|
||||
"wpa2",
|
||||
"wpa-mixed",
|
||||
"sae",
|
||||
"sae-mixed",
|
||||
"wpa3",
|
||||
"wpa3-192",
|
||||
"wpa3-mixed"
|
||||
],
|
||||
"examples": [
|
||||
"psk2"
|
||||
]
|
||||
},
|
||||
"key": {
|
||||
"type": "string",
|
||||
"maxLength": 63,
|
||||
"minLength": 8
|
||||
},
|
||||
"ieee80211w": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"disabled",
|
||||
"optional",
|
||||
"required"
|
||||
],
|
||||
"default": "disabled"
|
||||
},
|
||||
"key-caching": {
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -716,7 +780,8 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"dynamic",
|
||||
"static"
|
||||
"static",
|
||||
"none"
|
||||
],
|
||||
"examples": [
|
||||
"static"
|
||||
@@ -1006,52 +1071,6 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
}
|
||||
]
|
||||
},
|
||||
"interface.ssid.encryption": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"proto": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"none",
|
||||
"owe",
|
||||
"owe-transition",
|
||||
"psk",
|
||||
"psk2",
|
||||
"psk-mixed",
|
||||
"psk2-radius",
|
||||
"wpa",
|
||||
"wpa2",
|
||||
"wpa-mixed",
|
||||
"sae",
|
||||
"sae-mixed",
|
||||
"wpa3",
|
||||
"wpa3-192",
|
||||
"wpa3-mixed"
|
||||
],
|
||||
"examples": [
|
||||
"psk2"
|
||||
]
|
||||
},
|
||||
"key": {
|
||||
"type": "string",
|
||||
"maxLength": 63,
|
||||
"minLength": 8
|
||||
},
|
||||
"ieee80211w": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"disabled",
|
||||
"optional",
|
||||
"required"
|
||||
],
|
||||
"default": "disabled"
|
||||
},
|
||||
"key-caching": {
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"interface.ssid.multi-psk": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -2020,6 +2039,11 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
"decription": "This option allows embedding custom vendor specific IEs inside the beacons of a BSS in AP mode.",
|
||||
"type": "string"
|
||||
},
|
||||
"tip-information-element": {
|
||||
"decription": "The device will broadcast the TIP vendor IE inside its beacons if this option is enabled.",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"fils-discovery-interval": {
|
||||
"type": "integer",
|
||||
"default": 20,
|
||||
@@ -2443,6 +2467,24 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"mode": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"radius",
|
||||
"user"
|
||||
]
|
||||
},
|
||||
"port-filter": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"examples": [
|
||||
{
|
||||
"LAN1": null
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"server-certificate": {
|
||||
"type": "string"
|
||||
},
|
||||
@@ -2454,6 +2496,77 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
"items": {
|
||||
"$ref": "#/$defs/interface.ssid.radius.local-user"
|
||||
}
|
||||
},
|
||||
"radius": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"nas-identifier": {
|
||||
"type": "string"
|
||||
},
|
||||
"auth-server-addr": {
|
||||
"type": "string",
|
||||
"format": "uc-host",
|
||||
"examples": [
|
||||
"192.168.1.10"
|
||||
]
|
||||
},
|
||||
"auth-server-port": {
|
||||
"type": "integer",
|
||||
"maximum": 65535,
|
||||
"minimum": 1024,
|
||||
"examples": [
|
||||
1812
|
||||
]
|
||||
},
|
||||
"auth-server-secret": {
|
||||
"type": "string",
|
||||
"examples": [
|
||||
"secret"
|
||||
]
|
||||
},
|
||||
"acct-server-addr": {
|
||||
"type": "string",
|
||||
"format": "uc-host",
|
||||
"examples": [
|
||||
"192.168.1.10"
|
||||
]
|
||||
},
|
||||
"acct-server-port": {
|
||||
"type": "integer",
|
||||
"maximum": 65535,
|
||||
"minimum": 1024,
|
||||
"examples": [
|
||||
1813
|
||||
]
|
||||
},
|
||||
"acct-server-secret": {
|
||||
"type": "string",
|
||||
"examples": [
|
||||
"secret"
|
||||
]
|
||||
},
|
||||
"coa-server-addr": {
|
||||
"type": "string",
|
||||
"format": "uc-host",
|
||||
"examples": [
|
||||
"192.168.1.10"
|
||||
]
|
||||
},
|
||||
"coa-server-port": {
|
||||
"type": "integer",
|
||||
"maximum": 65535,
|
||||
"minimum": 1024,
|
||||
"examples": [
|
||||
1814
|
||||
]
|
||||
},
|
||||
"coa-server-secret": {
|
||||
"type": "string",
|
||||
"examples": [
|
||||
"secret"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -2777,6 +2890,12 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
}
|
||||
}
|
||||
},
|
||||
"services": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"classifier": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
@@ -3019,6 +3138,24 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
"relay-server": {
|
||||
"type": "string",
|
||||
"format": "uc-ip"
|
||||
},
|
||||
"circuit-id-format": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"vlan-id",
|
||||
"ap-mac",
|
||||
"ssid"
|
||||
],
|
||||
"default": "vlan-id"
|
||||
},
|
||||
"remote-id-format": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"vlan-id",
|
||||
"ap-mac",
|
||||
"ssid"
|
||||
],
|
||||
"default": "ap-mac"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,6 +417,8 @@ namespace OpenWifi::RESTAPI::Errors {
|
||||
|
||||
static const struct msg NotAValidECKey { 1176, "Not a valid Signing Key." };
|
||||
|
||||
static const struct msg NotAValidRadiusPoolType { 1177, "Not a valid RADIUS pool type." };
|
||||
|
||||
static const struct msg SimulationDoesNotExist {
|
||||
7000, "Simulation Instance ID does not exist."
|
||||
};
|
||||
|
||||
@@ -8,6 +8,12 @@
|
||||
#include "framework/AppServiceRegistry.h"
|
||||
#include "framework/utils.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
namespace OpenWifi::Utils {
|
||||
|
||||
bool NormalizeMac(std::string &Mac) {
|
||||
@@ -759,4 +765,101 @@ namespace OpenWifi::Utils {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VerifyRSAKey([[
|
||||
maybe_unused]] const std::string &key) {
|
||||
try {
|
||||
Poco::TemporaryFile F;
|
||||
|
||||
std::ofstream of(F.path().c_str(), std::ios_base::trunc | std::ios_base::out | std::ios_base::binary);
|
||||
of << key;
|
||||
of.close();
|
||||
|
||||
auto Key = Poco::SharedPtr<Poco::Crypto::RSAKey>(
|
||||
new Poco::Crypto::RSAKey("", F.path(),""));
|
||||
return true;
|
||||
} catch (const Poco::Exception &E) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ValidX509Certificate([[
|
||||
maybe_unused]] const std::string &Cert) {
|
||||
try {
|
||||
Poco::TemporaryFile F;
|
||||
std::ofstream of(F.path().c_str(), std::ios_base::trunc | std::ios_base::out | std::ios_base::binary);
|
||||
of << Cert;
|
||||
of.close();
|
||||
|
||||
auto Key = Poco::SharedPtr<Poco::Crypto::X509Certificate>(
|
||||
new Poco::Crypto::X509Certificate(F.path()));
|
||||
return true;
|
||||
} catch (const Poco::Exception &E) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ValidX509Certificate([[
|
||||
maybe_unused]] const std::vector<std::string> &Certs) {
|
||||
auto F = [](const std::string &C) -> bool { return ValidX509Certificate(C); };
|
||||
return std::all_of(Certs.begin(),Certs.end(), F);
|
||||
}
|
||||
|
||||
std::string generateStrongPassword(int minLength, int maxLength, int numDigits, int minLowercase, int minSpecial, int minUppercase) {
|
||||
// Define character sets for each category
|
||||
const std::string lowercaseChars = "abcdefghijklmnopqrstuvwxyz";
|
||||
const std::string uppercaseChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
const std::string digitChars = "0123456789";
|
||||
const std::string specialChars = "!@#$%^&*()_+[]{}|;:,.<>?";
|
||||
|
||||
// Check if parameters are valid
|
||||
if (minLength < 1 || minLength > maxLength || minLowercase + minUppercase + numDigits + minSpecial > maxLength) {
|
||||
return "Invalid parameters";
|
||||
}
|
||||
|
||||
// Initialize random seed
|
||||
std::random_device rd;
|
||||
std::mt19937 g(rd());
|
||||
|
||||
// Initialize the password string
|
||||
std::string password;
|
||||
|
||||
// Generate the required number of each character type
|
||||
for (int i = 0; i < minLowercase; ++i) {
|
||||
password += lowercaseChars[g() % lowercaseChars.length()];
|
||||
}
|
||||
for (int i = 0; i < minUppercase; ++i) {
|
||||
password += uppercaseChars[g() % uppercaseChars.length()];
|
||||
}
|
||||
for (int i = 0; i < numDigits; ++i) {
|
||||
password += digitChars[g() % digitChars.length()];
|
||||
}
|
||||
for (int i = 0; i < minSpecial; ++i) {
|
||||
password += specialChars[g() % specialChars.length()];
|
||||
}
|
||||
|
||||
// Calculate how many more characters are needed
|
||||
int remainingLength = maxLength - (int)password.length();
|
||||
|
||||
// Generate random characters to fill the remaining length
|
||||
for (int i = 0; i < remainingLength; ++i) {
|
||||
int category = g() % 4; // Randomly select a category
|
||||
if (category == 0) {
|
||||
password += lowercaseChars[g() % lowercaseChars.length()];
|
||||
} else if (category == 1) {
|
||||
password += uppercaseChars[g() % uppercaseChars.length()];
|
||||
} else if (category == 2) {
|
||||
password += digitChars[g() % digitChars.length()];
|
||||
} else {
|
||||
password += specialChars[g() % specialChars.length()];
|
||||
}
|
||||
}
|
||||
|
||||
// Shuffle the password to randomize the character order
|
||||
std::shuffle(password.begin(), password.end(),g);
|
||||
|
||||
return password;
|
||||
}
|
||||
|
||||
} // namespace OpenWifi::Utils
|
||||
|
||||
@@ -258,6 +258,10 @@ namespace OpenWifi::Utils {
|
||||
};
|
||||
|
||||
bool CreateX509CSR(const CSRCreationParameters & Parameters, CSRCreationResults & Results);
|
||||
|
||||
std::string generateStrongPassword(int minLength, int maxLength, int numDigits, int minLowercase, int minSpecial, int minUppercase);
|
||||
bool VerifyECKey(const std::string &key);
|
||||
bool VerifyRSAKey(const std::string &key);
|
||||
bool ValidX509Certificate(const std::string &Cert);
|
||||
bool ValidX509Certificate(const std::vector<std::string> &Certs);
|
||||
|
||||
} // namespace OpenWifi::Utils
|
||||
|
||||
Reference in New Issue
Block a user