Drop all encryption requests upon disconnection 51/292951/7
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 17 May 2023 12:35:13 +0000 (14:35 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Mon, 5 Jun 2023 14:05:26 +0000 (16:05 +0200)
If client disconnects before finishing the request the request should
be removed from the map.

Change-Id: I7bb0fa71b12f0a07bac5e62e5191bd9729829bfe

src/manager/service/encryption-logic.cpp
src/manager/service/encryption-logic.h
src/manager/service/encryption-service.cpp
src/manager/service/encryption-service.h

index e3cf1d6..6698317 100644 (file)
@@ -54,6 +54,16 @@ void EncryptionLogic::Crypt(const CryptoRequest &request)
        }
 }
 
+void EncryptionLogic::DropRequests(const ConnectionID& connectionID)
+{
+       for (auto it = m_requestsMap.begin(); it != m_requestsMap.end();) {
+               if (it->second.conn.counter == connectionID.counter)
+                       it = m_requestsMap.erase(it);
+               else
+                       it++;
+       }
+}
+
 void EncryptionLogic::KeyRetrieved(MsgKeyResponse response)
 {
        auto it = m_requestsMap.find(response.id);
index 7ae1e00..65c9d0d 100644 (file)
@@ -37,7 +37,7 @@ public:
 
        void Crypt(const CryptoRequest &request);
        void KeyRetrieved(MsgKeyResponse response);
-
+       void DropRequests(const ConnectionID& connectionID);
 private:
        IEncryptionService &m_service;
 
index f642870..d254be4 100644 (file)
@@ -152,4 +152,12 @@ void EncryptionService::CustomHandle(const SecurityEvent &/*event*/)
        LogError("This should not happend! SecurityEvent was called on EncryptionService!");
 }
 
+void EncryptionService::CustomHandle(const CloseEvent &event)
+{
+       // call the default handler
+       ThreadService::Handle(event);
+
+       m_logic.DropRequests(event.connectionID);
+}
+
 } /* namespace CKM */
index 264b0fc..27a007f 100644 (file)
@@ -55,6 +55,13 @@ public:
                });
        }
 
+       virtual void Event(const CloseEvent &event)
+       {
+               CreateEvent([this, event]() {
+                       this->CustomHandle(event);
+               });
+       }
+
        void Start();
        void Stop();
 
@@ -62,6 +69,7 @@ protected:
        // CustomHandle is used to bypass security check
        void CustomHandle(const ReadEvent &event);
        void CustomHandle(const SecurityEvent &event);
+       void CustomHandle(const CloseEvent &event);
 
 private:
        virtual void SetCommManager(CommMgr *manager);