Add database 32/64-bit compatibility check
authorJan Wojtkowski <j.wojtkowski@samsung.com>
Mon, 7 Oct 2024 12:35:41 +0000 (14:35 +0200)
committerDariusz Michaluk <d.michaluk@samsung.com>
Wed, 16 Oct 2024 11:53:30 +0000 (13:53 +0200)
* Reading a 64bit database on 32bit architecture
  and reading a 32bit database on 64bit architecture
  should work after the fix

Change-Id: Ibe9b23fc0b9dcf374707822aa72b31cca2c31563

misc/encryption_scheme/CMakeLists.txt
misc/encryption_scheme/db-key-32bit [new file with mode: 0644]
misc/encryption_scheme/db-key-64bit [new file with mode: 0644]
misc/encryption_scheme/db0-32bit [new file with mode: 0644]
misc/encryption_scheme/db0-64bit [new file with mode: 0644]
misc/encryption_scheme/key-32bit [new file with mode: 0644]
misc/encryption_scheme/key-64bit [new file with mode: 0644]
misc/encryption_scheme/scheme-test.cpp
misc/encryption_scheme/scheme-test.h
misc/encryption_scheme/test_encryption-scheme.cpp

index 25d101cd85b93fcec5ebe58c300b52cde4b56fff..c44b47bb0d9088831ea2efa3eecc0ec679349fbb 100644 (file)
@@ -90,6 +90,12 @@ INSTALL(
         db-7654
         db-key-7654
         key-7654
+        db0-64bit
+        db-key-64bit
+        key-64bit
+        db0-32bit
+        db-key-32bit
+        key-32bit
     DESTINATION ${MISC_DIR}
 )
 
diff --git a/misc/encryption_scheme/db-key-32bit b/misc/encryption_scheme/db-key-32bit
new file mode 100644 (file)
index 0000000..afda22f
Binary files /dev/null and b/misc/encryption_scheme/db-key-32bit differ
diff --git a/misc/encryption_scheme/db-key-64bit b/misc/encryption_scheme/db-key-64bit
new file mode 100644 (file)
index 0000000..666b53b
Binary files /dev/null and b/misc/encryption_scheme/db-key-64bit differ
diff --git a/misc/encryption_scheme/db0-32bit b/misc/encryption_scheme/db0-32bit
new file mode 100644 (file)
index 0000000..dabb065
Binary files /dev/null and b/misc/encryption_scheme/db0-32bit differ
diff --git a/misc/encryption_scheme/db0-64bit b/misc/encryption_scheme/db0-64bit
new file mode 100644 (file)
index 0000000..5cc4221
Binary files /dev/null and b/misc/encryption_scheme/db0-64bit differ
diff --git a/misc/encryption_scheme/key-32bit b/misc/encryption_scheme/key-32bit
new file mode 100644 (file)
index 0000000..b84121b
Binary files /dev/null and b/misc/encryption_scheme/key-32bit differ
diff --git a/misc/encryption_scheme/key-64bit b/misc/encryption_scheme/key-64bit
new file mode 100644 (file)
index 0000000..7222c6f
Binary files /dev/null and b/misc/encryption_scheme/key-64bit differ
index 416634af554051c0e7e6cf22436e1598bc9851ee..4bfa3dec8478d29791f835b53da2f9ea87eb0390 100644 (file)
@@ -333,15 +333,13 @@ gid_t getGid(const char *name)
        return grp.gr_gid;
 }
 
-void restoreFile(const string &filename)
+void restoreFileInternal(const string& sourcePath, const string& targetPath)
 {
-       static uid_t CKM_UID = getUid(USER_NAME);
-       static gid_t CKM_GID = getGid(GROUP_NAME);
-       string sourcePath = string(MISC_DIR) + "/" + filename;
-       string targetPath = string(RW_DATA_DIR) + "/" + filename;
-
        int err, ret;
 
+       static const uid_t CKM_UID = getUid(USER_NAME);
+       static const gid_t CKM_GID = getGid(GROUP_NAME);
+
        int sourceFd = TEMP_FAILURE_RETRY(open(sourcePath.c_str(), O_RDONLY));
        err = errno;
        BOOST_REQUIRE_MESSAGE(sourceFd > 0,
@@ -374,6 +372,22 @@ void restoreFile(const string &filename)
        BOOST_REQUIRE_MESSAGE(ret != -1, "fsync() failed: " << GetErrnoString(err));
 }
 
+void restoreFile(const string &filename)
+{
+       string sourcePath = string(MISC_DIR) + "/" + filename;
+       string targetPath = string(RW_DATA_DIR) + "/" + filename;
+
+       restoreFileInternal(sourcePath, targetPath);
+}
+
+void restoreFile(const string &filename, const string &replaced_filename)
+{
+       string sourcePath = string(MISC_DIR) + "/" + filename;
+       string targetPath = string(RW_DATA_DIR) + "/" + replaced_filename;
+
+       restoreFileInternal(sourcePath, targetPath);
+}
+
 void generateRandom(size_t random_bytes, unsigned char *output)
 {
        if (random_bytes <= 0 || !output)
@@ -824,6 +838,24 @@ void SchemeTest::RestoreDb()
        m_directAccessEnabled = false;
 }
 
+void SchemeTest::RestoreDb32()
+{
+       m_db.reset();
+       restoreFile("key-32bit", "key-7654");
+       restoreFile("db-key-32bit", "db-key-7654");
+       restoreFile("db0-32bit", "db0-7654");
+       m_directAccessEnabled = false;
+}
+
+void SchemeTest::RestoreDb64()
+{
+       m_db.reset();
+       restoreFile("key-64bit", "key-7654");
+       restoreFile("db-key-64bit", "db-key-7654");
+       restoreFile("db0-64bit", "db0-7654");
+       m_directAccessEnabled = false;
+}
+
 void SchemeTest::CheckSchemeVersion(const ItemFilter &filter, int version)
 {
        EnableDirectDbAccess();
index 7679de476dd3acda48ae77d80ff6aeabad3afcbf..f109cdb4742d388176e079b9b0a85c1d0dbec179 100644 (file)
@@ -115,6 +115,8 @@ public:
        void RemoveAll();
        size_t CountObjects();
        void RestoreDb();
+       void RestoreDb32();
+       void RestoreDb64();
        void CheckSchemeVersion(const ItemFilter &filter, int version);
 
 private:
index d12916915f05cd7ec16e8744ba80e6c9b65cb290..0ffbfcd10d904149ce737b496b6e254c09b127ad 100644 (file)
@@ -233,4 +233,18 @@ POSITIVE_TEST_CASE(T220_CreateChain)
        test.CheckSchemeVersion(filter2, NEW_ENC_SCHEME);
 }
 
+POSITIVE_TEST_CASE(T320_Check64bitDatabaseRead)
+{
+       SchemeTest test;
+       test.RestoreDb64();
+       test.ReadAll();
+}
+
+POSITIVE_TEST_CASE(T320_Check32bitDatabaseRead)
+{
+       SchemeTest test;
+       test.RestoreDb32();
+       test.ReadAll();
+}
+
 BOOST_AUTO_TEST_SUITE_END()