Remove warnings and performance problems reported by cppcheck.
[platform/core/security/key-manager.git] / src / manager / service / ckm-service.cpp
index 0631ddd..63095bb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -54,8 +54,8 @@ void CKMService::Stop() {
 GenericSocketService::ServiceDescriptionVector CKMService::GetServiceDescription()
 {
     return ServiceDescriptionVector {
-        {SERVICE_SOCKET_CKM_CONTROL, "key-manager::api-control", SOCKET_ID_CONTROL},
-        {SERVICE_SOCKET_CKM_STORAGE, "key-manager::api-storage", SOCKET_ID_STORAGE}
+        {SERVICE_SOCKET_CKM_CONTROL, "http://tizen.org/privilege/keymanager.admin", SOCKET_ID_CONTROL},
+        {SERVICE_SOCKET_CKM_STORAGE, "http://tizen.org/privilege/keymanager", SOCKET_ID_STORAGE}
     };
 }
 
@@ -65,9 +65,12 @@ void CKMService::SetCommManager(CommMgr *manager)
     Register(*manager);
 }
 
+// CKMService does not support security check
+// so 3rd parameter is not used
 bool CKMService::ProcessOne(
     const ConnectionID &conn,
-    ConnectionInfo &info)
+    ConnectionInfo &info,
+    bool /*allowed*/)
 {
     LogDebug ("process One");
     RawBuffer response;
@@ -167,11 +170,18 @@ RawBuffer CKMService::ProcessStorage(Credentials &cred, MessageBuffer &buffer)
     int tmpDataType = 0;
     Name name;
     Label label, accessorLabel;
-    std::string user;
 
     buffer.Deserialize(command);
     buffer.Deserialize(msgID);
 
+    // This is a workaround solution for locktype=None in Tizen 2.2.1
+    // When locktype is None, lockscreen app doesn't interfere with unlocking process.
+    // Therefor lockscreen app cannot notify unlock events to key-manager when locktype is None.
+    // So, to unlock user data when lock type is None, key-manager always try to unlock user data with null password.
+    // Even if the result is fail, it will be ignored.
+    Password nullPassword("");
+    m_logic->unlockUserKey(cred.clientUid, nullPassword);
+
     LogDebug("Process storage. Command: " << command);
 
     switch(static_cast<LogicCommand>(command)) {
@@ -299,7 +309,7 @@ RawBuffer CKMService::ProcessStorage(Credentials &cred, MessageBuffer &buffer)
             RawBuffer certificate;
             RawBufferVector untrustedVector;
             RawBufferVector trustedVector;
-            bool systemCerts;
+            bool systemCerts = false;
             buffer.Deserialize(certificate, untrustedVector, trustedVector, systemCerts);
             return m_logic->getCertificateChain(
                 cred,
@@ -314,7 +324,7 @@ RawBuffer CKMService::ProcessStorage(Credentials &cred, MessageBuffer &buffer)
             RawBuffer certificate;
             LabelNameVector untrustedVector;
             LabelNameVector trustedVector;
-            bool systemCerts;
+            bool systemCerts = false;
             buffer.Deserialize(certificate, untrustedVector, trustedVector, systemCerts);
             return m_logic->getCertificateChain(
                 cred,
@@ -401,5 +411,16 @@ void CKMService::ProcessMessage(MsgKeyRequest msg)
     }
 }
 
+void CKMService::CustomHandle(const ReadEvent &event) {
+    LogDebug("Read event");
+    auto &info = m_connectionInfoMap[event.connectionID.counter];
+    info.buffer.Push(event.rawBuffer);
+    while(ProcessOne(event.connectionID, info, true));
+}
+
+void CKMService::CustomHandle(const SecurityEvent & /*event*/) {
+    LogError("This should not happend! SecurityEvent was called on CKMService!");
+}
+
 } // namespace CKM