mirror of
				https://github.com/Telecominfraproject/wlan-cloud-ucentralsec.git
				synced 2025-10-30 18:27:49 +00:00 
			
		
		
		
	Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
This commit is contained in:
		| @@ -88,7 +88,7 @@ namespace OpenWifi { | ||||
|             uint64_t                    RevocationDate=0; | ||||
|             std::string                 UserId; | ||||
|             if(StorageService()->UserTokenDB().GetToken(CallToken, UI.webtoken, UserId, RevocationDate) && UI.webtoken.refresh_token_==RefreshToken) { | ||||
|                 auto now = OpenWifi::Now(); | ||||
|                 auto now = Utils::Now(); | ||||
|  | ||||
|                 //  Create a new token | ||||
|                 auto NewToken = GenerateTokenHMAC( UI.webtoken.access_token_, CUSTOM); | ||||
| @@ -126,7 +126,7 @@ namespace OpenWifi { | ||||
|             uint64_t                    RevocationDate=0; | ||||
|             std::string                 UserId; | ||||
|             if(StorageService()->SubTokenDB().GetToken(CallToken, UI.webtoken, UserId, RevocationDate) && UI.webtoken.refresh_token_==RefreshToken) { | ||||
|                 auto now = OpenWifi::Now(); | ||||
|                 auto now = Utils::Now(); | ||||
|  | ||||
|                 //  Create a new token | ||||
|                 auto NewToken = GenerateTokenHMAC( UI.webtoken.access_token_, CUSTOM); | ||||
| @@ -162,7 +162,7 @@ namespace OpenWifi { | ||||
|                     poco_debug(Logger(), fmt::format("TokenValidation failed for TID={} Token={}", TID, Utils::SanitizeToken(CallToken))); | ||||
|                     return false; | ||||
|                 } | ||||
|                 auto now=OpenWifi::Now(); | ||||
|                 auto now=Utils::Now(); | ||||
|                 Expired = (WT.created_ + WT.expires_in_) < now; | ||||
|                 if(StorageService()->UserDB().GetUserById(UserId,UInfo.userinfo)) { | ||||
|                     UInfo.webtoken = WT; | ||||
| @@ -227,7 +227,7 @@ namespace OpenWifi { | ||||
|                     poco_debug(Logger(), fmt::format("TokenValidation failed for TID={} Token={}", TID, Utils::SanitizeToken(CallToken))); | ||||
|                     return false; | ||||
|                 } | ||||
|                 auto now=OpenWifi::Now(); | ||||
|                 auto now=Utils::Now(); | ||||
|                 Expired = (WT.created_ + WT.expires_in_) < now; | ||||
|                 if(StorageService()->SubDB().GetUserById(UserId,UInfo.userinfo)) { | ||||
|                     UInfo.webtoken = WT; | ||||
| @@ -314,7 +314,7 @@ namespace OpenWifi { | ||||
|     } | ||||
|  | ||||
|     [[nodiscard]] std::string AuthService::GenerateTokenHMAC(const std::string & UserName, [[maybe_unused]] ACCESS_TYPE Type) { | ||||
|         std::string Identity(UserName + ":" + fmt::format("{}",OpenWifi::Now()) + ":" + std::to_string(rand())); | ||||
|         std::string Identity(UserName + ":" + fmt::format("{}",Utils::Now()) + ":" + std::to_string(rand())); | ||||
|         HMAC_.update(Identity); | ||||
|         return Poco::DigestEngine::digestToHex(HMAC_.digest()); | ||||
|     } | ||||
| @@ -530,14 +530,14 @@ namespace OpenWifi { | ||||
|                     UInfo.webtoken.errorCode = 1; | ||||
|                     return PASSWORD_ALREADY_USED; | ||||
|                 } | ||||
|                 UInfo.userinfo.lastPasswordChange = OpenWifi::Now(); | ||||
|                 UInfo.userinfo.lastPasswordChange = Utils::Now(); | ||||
|                 UInfo.userinfo.changePassword = false; | ||||
|                 UInfo.userinfo.modified = OpenWifi::Now(); | ||||
|                 UInfo.userinfo.modified = Utils::Now(); | ||||
|                 StorageService()->UserDB().UpdateUserInfo(AUTHENTICATION_SYSTEM, UInfo.userinfo.id,UInfo.userinfo); | ||||
|             } | ||||
|  | ||||
|             //  so we have a good password, password up date has taken place if need be, now generate the token. | ||||
|             UInfo.userinfo.lastLogin=OpenWifi::Now(); | ||||
|             UInfo.userinfo.lastLogin=Utils::Now(); | ||||
|             StorageService()->UserDB().SetLastLogin(UInfo.userinfo.id); | ||||
|             CreateToken(UserName, UInfo ); | ||||
|  | ||||
| @@ -575,14 +575,14 @@ namespace OpenWifi { | ||||
|                     UInfo.webtoken.errorCode = 1; | ||||
|                     return PASSWORD_ALREADY_USED; | ||||
|                 } | ||||
|                 UInfo.userinfo.lastPasswordChange = OpenWifi::Now(); | ||||
|                 UInfo.userinfo.lastPasswordChange = Utils::Now(); | ||||
|                 UInfo.userinfo.changePassword = false; | ||||
|                 UInfo.userinfo.modified = OpenWifi::Now(); | ||||
|                 UInfo.userinfo.modified = Utils::Now(); | ||||
|                 StorageService()->SubDB().UpdateUserInfo(AUTHENTICATION_SYSTEM, UInfo.userinfo.id,UInfo.userinfo); | ||||
|             } | ||||
|  | ||||
|             //  so we have a good password, password update has taken place if need be, now generate the token. | ||||
|             UInfo.userinfo.lastLogin=OpenWifi::Now(); | ||||
|             UInfo.userinfo.lastLogin=Utils::Now(); | ||||
|             StorageService()->SubDB().SetLastLogin(UInfo.userinfo.id); | ||||
|             CreateSubToken(UserName, UInfo ); | ||||
|  | ||||
| @@ -715,7 +715,7 @@ namespace OpenWifi { | ||||
|         A.action = OpenWifi::SecurityObjects::LinkActions::VERIFY_EMAIL; | ||||
|         A.userId = UInfo.id; | ||||
|         A.id = MicroServiceCreateUUID(); | ||||
|         A.created = OpenWifi::Now(); | ||||
|         A.created = Utils::Now(); | ||||
|         A.expires = A.created + 24*60*60; | ||||
|         A.userAction = true; | ||||
|         StorageService()->ActionLinksDB().CreateAction(A); | ||||
| @@ -730,7 +730,7 @@ namespace OpenWifi { | ||||
|         A.action = OpenWifi::SecurityObjects::LinkActions::SUB_VERIFY_EMAIL; | ||||
|         A.userId = UInfo.id; | ||||
|         A.id = MicroServiceCreateUUID(); | ||||
|         A.created = OpenWifi::Now(); | ||||
|         A.created = Utils::Now(); | ||||
|         A.expires = A.created + 24*60*60; | ||||
|         A.userAction = false; | ||||
|         StorageService()->ActionLinksDB().CreateAction(A); | ||||
| @@ -750,7 +750,7 @@ namespace OpenWifi { | ||||
|         if(StorageService()->UserTokenDB().GetToken(TToken, WT, UserId, RevocationDate)) { | ||||
|             if(RevocationDate!=0) | ||||
|                 return false; | ||||
|             Expired = (WT.created_ + WT.expires_in_) < OpenWifi::Now(); | ||||
|             Expired = (WT.created_ + WT.expires_in_) < Utils::Now(); | ||||
|             if(StorageService()->UserDB().GetUserById(UserId,UserInfo)) { | ||||
|                 WebToken = WT; | ||||
|                 return true; | ||||
| @@ -769,7 +769,7 @@ namespace OpenWifi { | ||||
|         if(StorageService()->SubTokenDB().GetToken(TToken, WT, UserId, RevocationDate)) { | ||||
|             if(RevocationDate!=0) | ||||
|                 return false; | ||||
|             Expired = (WT.created_ + WT.expires_in_) < OpenWifi::Now(); | ||||
|             Expired = (WT.created_ + WT.expires_in_) < Utils::Now(); | ||||
|             if(StorageService()->SubDB().GetUserById(UserId,UserInfo)) { | ||||
|                 WebToken = WT; | ||||
|                 return true; | ||||
|   | ||||
| @@ -27,7 +27,7 @@ namespace OpenWifi { | ||||
| 						{ | ||||
| 							Poco::Net::WebSocket WS(*Request, *Response); | ||||
| 							auto Id = MicroServiceCreateUUID(); | ||||
| 							UI_WebSocketClientServer()->NewClient(WS,Id,UserInfo_.userinfo.email); | ||||
| 							UI_WebSocketClientServer()->NewClient(WS,Id,UserInfo_.userinfo.email, TransactionId_); | ||||
| 						} | ||||
| 						catch (...) { | ||||
| 							std::cout << "Cannot create websocket client..." << std::endl; | ||||
|   | ||||
| @@ -23,12 +23,12 @@ | ||||
|  | ||||
| namespace OpenWifi { | ||||
|  | ||||
| 	void UI_WebSocketClientServer::NewClient(Poco::Net::WebSocket & WS, const std::string &Id, const std::string &UserName ) { | ||||
| 	void UI_WebSocketClientServer::NewClient(Poco::Net::WebSocket & WS, const std::string &Id, const std::string &UserName, std::uint64_t TID ) { | ||||
|  | ||||
|         std::lock_guard G(LocalMutex_); | ||||
|         auto Client = std::make_unique<UI_WebSocketClientInfo>(WS,Id, UserName); | ||||
|         auto ClientSocket = Client->WS_->impl()->sockfd(); | ||||
|  | ||||
|         TID_ = TID; | ||||
|         Client->WS_->setNoDelay(true); | ||||
|         Client->WS_->setKeepAlive(true); | ||||
|         Client->WS_->setBlocking(false); | ||||
| @@ -233,9 +233,9 @@ namespace OpenWifi { | ||||
| #endif | ||||
| 					if (Tokens.size() == 2 && | ||||
| #if defined(TIP_SECURITY_SERVICE) | ||||
|         			    AuthService()->IsAuthorized(Tokens[1], Client->second->UserInfo_, 0, Expired)) { | ||||
|         			    AuthService()->IsAuthorized(Tokens[1], Client->second->UserInfo_, TID_, Expired)) { | ||||
| #else | ||||
|                         AuthClient()->IsAuthorized(Tokens[1], Client->second->UserInfo_, 0, Expired, Contacted)) { | ||||
|                         AuthClient()->IsAuthorized(Tokens[1], Client->second->UserInfo_, TID_, Expired, Contacted)) { | ||||
| #endif | ||||
|                         Client->second->Authenticated_ = true; | ||||
|                         Client->second->UserName_ = Client->second->UserInfo_.userinfo.email; | ||||
|   | ||||
| @@ -57,7 +57,7 @@ namespace OpenWifi { | ||||
| 		void Stop() override; | ||||
| 		void run() override; | ||||
| 		Poco::Net::SocketReactor & Reactor() { return Reactor_; } | ||||
| 		void NewClient(Poco::Net::WebSocket &WS, const std::string &Id, const std::string &UserName); | ||||
| 		void NewClient(Poco::Net::WebSocket &WS, const std::string &Id, const std::string &UserName, std::uint64_t TID); | ||||
| 		void SetProcessor(UI_WebSocketClientProcessor *F); | ||||
| 		[[nodiscard]] inline bool GeoCodeEnabled() const { return GeoCodeEnabled_; } | ||||
| 		[[nodiscard]] inline std::string GoogleApiKey() const { return GoogleApiKey_; } | ||||
| @@ -113,6 +113,7 @@ namespace OpenWifi { | ||||
| 		NotificationTypeIdVec						NotificationTypes_; | ||||
| 		Poco::JSON::Object							NotificationTypesJSON_; | ||||
| 		std::vector<ClientList::iterator>			ToBeRemoved_; | ||||
|         std::uint64_t                               TID_=0; | ||||
|  | ||||
| 		UI_WebSocketClientServer() noexcept; | ||||
|         void EndConnection(ClientList::iterator Client); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 stephb9959
					stephb9959