Add checking return value
[platform/core/security/ode.git] / server / key-server.cpp
index 4ab6541..2e6d55c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2015-2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015 - 2019 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.
@@ -63,6 +63,8 @@ KeyServer::~KeyServer()
 
 int KeyServer::isInitialized(const std::string& dev)
 {
+       RequestLifetime rl(server);
+
        if (dev.empty())
                return error::InvalidParameter;
 
@@ -73,6 +75,8 @@ int KeyServer::init(const std::string& dev,
                                        const std::string& password,
                                        int params)
 {
+       RequestLifetime rl(server);
+
        BinaryData dummy;
        return initAndGet(dev, password, params, dummy);
 }
@@ -97,6 +101,8 @@ int KeyServer::initAndGet(const std::string& dev,
 
 int KeyServer::remove(const std::string& dev, const std::string& password)
 {
+       RequestLifetime rl(server);
+
        if (dev.empty() || password.empty())
                return error::InvalidParameter;
 
@@ -114,6 +120,8 @@ int KeyServer::changePassword(const std::string& dev,
                                                          const std::string& curPassword,
                                                          const std::string& newPassword)
 {
+       RequestLifetime rl(server);
+
        if (dev.empty() || curPassword.empty() || newPassword.empty())
                return error::InvalidParameter;
 
@@ -134,12 +142,31 @@ int KeyServer::changePassword(const std::string& dev,
        ek.encrypt(key, newPassword);
 
        FileFooter::write(dev, ek.serialize());
+
+       UpgradeSupport::removeUpgradeFlag();
+
+       return error::None;
+}
+
+int KeyServer::changePassword2(const std::string& dev,
+                                                          const BinaryData& masterKey,
+                                                          const std::string& newPassword)
+{
+       if (dev.empty() || masterKey.empty() || newPassword.empty())
+               return error::InvalidParameter;
+
+       std::lock_guard<std::mutex> lock(footerLock);
+       EncryptedKey ek(masterKey, newPassword);
+
+       FileFooter::write(dev, ek.serialize());
        return error::None;
 }
 
 int KeyServer::verifyPassword(const std::string& dev,
                                                          const std::string& password)
 {
+       RequestLifetime rl(server);
+
        if (dev.empty() || password.empty())
                return error::InvalidParameter;
 
@@ -171,6 +198,8 @@ void KeyServer::removePassword(const std::string& dev)
 int KeyServer::storeMasterKey(const std::string& dev,
                                                          const std::string& password)
 {
+       RequestLifetime rl(server);
+
        if (dev.empty() || password.empty())
                return error::InvalidParameter;
 
@@ -193,6 +222,8 @@ int KeyServer::storeMasterKey(const std::string& dev,
 
 int KeyServer::removeMasterKey(const std::string& dev)
 {
+       RequestLifetime rl(server);
+
        if (dev.empty())
                return error::InvalidParameter;
 
@@ -214,6 +245,8 @@ int KeyServer::internalGet(const std::string& dev,
                return error::NoSuchFile;
        }
 
+       UpgradeSupport::removeUpgradeFlag();
+
        EncryptedKey ek(FileFooter::read(dev));
 
        key = ek.decrypt(password);