mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralsec.git
synced 2025-11-01 11:17:51 +00:00
Hardening SMS code.
This commit is contained in:
@@ -20,39 +20,26 @@ namespace OpenWifi {
|
|||||||
bool MFAServer::StartMFAChallenge(const SecurityObjects::UserInfoAndPolicy &UInfo, Poco::JSON::Object &ChallengeStart) {
|
bool MFAServer::StartMFAChallenge(const SecurityObjects::UserInfoAndPolicy &UInfo, Poco::JSON::Object &ChallengeStart) {
|
||||||
std::lock_guard G(Mutex_);
|
std::lock_guard G(Mutex_);
|
||||||
|
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
CleanCache();
|
CleanCache();
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
|
|
||||||
if(!MethodEnabled(UInfo.userinfo.userTypeProprietaryInfo.mfa.method))
|
if(!MethodEnabled(UInfo.userinfo.userTypeProprietaryInfo.mfa.method))
|
||||||
return false;
|
return false;
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
|
|
||||||
std::string Challenge = MakeChallenge();
|
std::string Challenge = MakeChallenge();
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
std::string uuid = MicroService::instance().CreateUUID();
|
std::string uuid = MicroService::instance().CreateUUID();
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
uint64_t Created = std::time(nullptr);
|
uint64_t Created = std::time(nullptr);
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
|
|
||||||
ChallengeStart.set("uuid",uuid);
|
ChallengeStart.set("uuid",uuid);
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
ChallengeStart.set("created", Created);
|
ChallengeStart.set("created", Created);
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
ChallengeStart.set("method", UInfo.userinfo.userTypeProprietaryInfo.mfa.method);
|
ChallengeStart.set("method", UInfo.userinfo.userTypeProprietaryInfo.mfa.method);
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
|
|
||||||
Cache_[uuid] = MFACacheEntry{ .UInfo = UInfo, .Answer=Challenge, .Created=Created, .Method=UInfo.userinfo.userTypeProprietaryInfo.mfa.method };
|
Cache_[uuid] = MFACacheEntry{ .UInfo = UInfo, .Answer=Challenge, .Created=Created, .Method=UInfo.userinfo.userTypeProprietaryInfo.mfa.method };
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
return SendChallenge(UInfo, UInfo.userinfo.userTypeProprietaryInfo.mfa.method, Challenge);
|
return SendChallenge(UInfo, UInfo.userinfo.userTypeProprietaryInfo.mfa.method, Challenge);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MFAServer::SendChallenge(const SecurityObjects::UserInfoAndPolicy &UInfo, const std::string &Method, const std::string &Challenge) {
|
bool MFAServer::SendChallenge(const SecurityObjects::UserInfoAndPolicy &UInfo, const std::string &Method, const std::string &Challenge) {
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
if(Method=="sms" && SMSSender()->Enabled() && !UInfo.userinfo.userTypeProprietaryInfo.mobiles.empty()) {
|
if(Method=="sms" && SMSSender()->Enabled() && !UInfo.userinfo.userTypeProprietaryInfo.mobiles.empty()) {
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
std::string Message = "This is your login code: " + Challenge + " Please enter this in your login screen.";
|
std::string Message = "This is your login code: " + Challenge + " Please enter this in your login screen.";
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
return SMSSender()->Send(UInfo.userinfo.userTypeProprietaryInfo.mobiles[0].number, Message);
|
return SMSSender()->Send(UInfo.userinfo.userTypeProprietaryInfo.mobiles[0].number, Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,33 +40,27 @@ namespace OpenWifi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SMS_provider_aws::Send(const std::string &PhoneNumber, const std::string &Message) {
|
bool SMS_provider_aws::Send(const std::string &PhoneNumber, const std::string &Message) {
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
if(!Running_)
|
if(!Running_)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
try {
|
||||||
Aws::SNS::SNSClient sns(AwsCreds_,AwsConfig_);
|
Aws::SNS::SNSClient sns(AwsCreds_,AwsConfig_);
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
Aws::SNS::Model::PublishRequest psms_req;
|
Aws::SNS::Model::PublishRequest psms_req;
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
psms_req.SetMessage(Message.c_str());
|
psms_req.SetMessage(Message.c_str());
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
psms_req.SetPhoneNumber(PhoneNumber.c_str());
|
psms_req.SetPhoneNumber(PhoneNumber.c_str());
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
|
|
||||||
auto psms_out = sns.Publish(psms_req);
|
auto psms_out = sns.Publish(psms_req);
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
if (psms_out.IsSuccess()) {
|
if (psms_out.IsSuccess()) {
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
Logger_.debug(Poco::format("SMS sent to %s",PhoneNumber));
|
Logger_.debug(Poco::format("SMS sent to %s",PhoneNumber));
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
std::string ErrMsg{psms_out.GetError().GetMessage()};
|
std::string ErrMsg{psms_out.GetError().GetMessage()};
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
|
||||||
Logger_.debug(Poco::format("SMS NOT sent to %s: %s",PhoneNumber, ErrMsg));
|
Logger_.debug(Poco::format("SMS NOT sent to %s: %s",PhoneNumber, ErrMsg));
|
||||||
std::cout << __func__ << " : " << __LINE__ << std::endl;
|
return false;
|
||||||
|
} catch (...) {
|
||||||
|
|
||||||
|
}
|
||||||
|
Logger_.debug(Poco::format("SMS NOT sent to %s: failure in SMS service",PhoneNumber));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user