Implement key retrieval in encryption service
[platform/core/security/key-manager.git] / src / manager / service / encryption-logic.cpp
index 5baac5b..2fd733c 100644 (file)
@@ -44,7 +44,7 @@ void EncryptionLogic::Crypt(const CryptoRequest& request)
 
     // request key
     try {
-        m_service.RequestKey(request.cred, request.name, request.label);
+        m_service.RequestKey(request);
     } catch (...) {
         LogError("Key request failed");
         m_requests.erase(request.msgId);
@@ -52,4 +52,31 @@ void EncryptionLogic::Crypt(const CryptoRequest& request)
     }
 }
 
+void EncryptionLogic::KeyRetrieved(MsgKeyResponse response)
+{
+    auto it = m_requests.find(response.id);
+    if (it == m_requests.end()) {
+        LogError("No matching request found"); // nothing we can do
+        return;
+    }
+    CryptoRequest req = std::move(it->second);
+    m_requests.erase(it);
+
+    if (response.error != CKM_API_SUCCESS) {
+        LogError("Attempt to retrieve key failed with error: " << response.error);
+        m_service.RespondToClient(req, response.error);
+        return;
+    }
+
+    if (!response.key) {
+        LogError("Retrieved key is empty");
+        m_service.RespondToClient(req, CKM_API_ERROR_SERVER_ERROR);
+        return;
+    }
+
+    // TODO encrypt/decrypt
+    LogError("Encryption/decryption not yet supported");
+    m_service.RespondToClient(req, CKM_API_ERROR_SERVER_ERROR);
+}
+
 } /* namespace CKM */