Encryption service calls proper encryption/decryption methods 83/41883/6
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 18 Jun 2015 14:24:20 +0000 (16:24 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 26 Jun 2015 13:23:59 +0000 (15:23 +0200)
[Feature] Encryption srevice development
[Solution] After key is retrieved it is used to perform encryption/decryption
of data and return the result to the client.

[Verification] Run ckm-tests --group=CKM_ENCRYPTION_DECRYPTION.
TED_1250_gcm_aad may fail.

Change-Id: Iaff45ac05df0470eabf3164c6fb427c68c9ef1a5

src/manager/crypto/generic-backend/gkey.h
src/manager/service/ckm-logic.cpp
src/manager/service/encryption-logic.cpp

index 530842d..b06926d 100644 (file)
@@ -57,6 +57,7 @@ public:
 };
 
 typedef std::unique_ptr<GKey> GKeyUPtr;
+typedef std::shared_ptr<GKey> GKeyShPtr;
 
 } // namespace Crypto
 } // namespace CKM
index 35e9613..a173cd7 100644 (file)
@@ -517,9 +517,6 @@ int CKMLogic::getKeyForService(
         if (retCode == CKM_API_SUCCESS)
             key = m_decider.getStore(row).getKey(row);
         return retCode;
-    } catch (const KeyProvider::Exception::Base &e) {
-        LogError("KeyProvider failed with error: " << e.GetMessage());
-        return CKM_API_ERROR_SERVER_ERROR;
     } catch (const DB::Crypto::Exception::Base &e) {
         LogError("DB::Crypto failed with message: " << e.GetMessage());
         return CKM_API_ERROR_DB_ERROR;
index 2fd733c..a2bad2b 100644 (file)
@@ -74,9 +74,20 @@ void EncryptionLogic::KeyRetrieved(MsgKeyResponse response)
         return;
     }
 
-    // TODO encrypt/decrypt
-    LogError("Encryption/decryption not yet supported");
-    m_service.RespondToClient(req, CKM_API_ERROR_SERVER_ERROR);
+    // encrypt/decrypt
+    try {
+        RawBuffer output;
+        if (req.command == EncryptionCommand::ENCRYPT)
+            output = response.key->encrypt(req.cas, req.input);
+        else
+            output = response.key->decrypt(req.cas, req.input);
+        m_service.RespondToClient(req, CKM_API_SUCCESS, output);
+    } catch (const Exc::Exception& ex) {
+        m_service.RespondToClient(req, ex.error());
+    } catch (...) {
+        LogError("Uncaught exception from encrypt/decrypt.");
+        m_service.RespondToClient(req, CKM_API_ERROR_SERVER_ERROR);
+    }
 }
 
 } /* namespace CKM */