Switch to sqlcipher library
[platform/core/security/key-manager.git] / tests / encryption-scheme / scheme-test.cpp
index 04319a2..bfaaef9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2015 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015-2020 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.
@@ -818,10 +818,10 @@ size_t SchemeTest::CountObjects()
 
 void SchemeTest::RestoreDb()
 {
+       m_db.reset();
        restoreFile("key-7654");
        restoreFile("db-key-7654");
        restoreFile("db-7654");
-       m_db.reset();
        m_directAccessEnabled = false;
 }
 
@@ -863,8 +863,15 @@ void SchemeTest::EnableDirectDbAccess()
        auto wrappedDatabaseDEK = fs.getDBDEK();
        RawBuffer key = keyProvider.getPureDEK(wrappedDatabaseDEK);
 
-       m_db.reset(new DB::Crypto(fs.getDBPath(), key));
+       m_db.reset(new DB::Crypto(fs.getLegacyDBPath(), fs.getDBPath(), key));
        m_directAccessEnabled = true;
+
+       // Legacy db files of the form db-$uid are incompatible with upstream sqlcipher.
+       // DB::Crypto(...) converts them to db0-$uid upstream-compatible, then deletes them.
+       // This function runs DB::Crypto(...) as root so db0-$uid are root-owned.
+       // However, database files need to be accessible to USER_NAME/GROUP_NAME (ex. ReadAll()).
+       // Thus the need to fix up ownership, much like restoreFile() does.
+       BOOST_REQUIRE(!chown(RW_DATA_DIR "/db0-7654", getUid(USER_NAME), getGid(GROUP_NAME)));
 }
 
 void SchemeTest::SignVerifyItem(const Item &itemPrv, const Item &itemPub)