[CryptoLogic] Fix func name and set max schema version 06/105906/3 accepted/tizen/common/20161227.192124 accepted/tizen/ivi/20161226.131245 accepted/tizen/mobile/20161226.131146 accepted/tizen/tv/20161226.131212 accepted/tizen/wearable/20161226.131222 submit/tizen/20161226.013211
authorKyungwook Tak <k.tak@samsung.com>
Tue, 20 Dec 2016 04:10:16 +0000 (13:10 +0900)
committerKyungwook Tak <k.tak@samsung.com>
Tue, 20 Dec 2016 05:00:24 +0000 (14:00 +0900)
Change function name: CLEAR_FLAG => CLEAR_FLAGS

Define maximum variable of schema version available.
To changing encryption schema bitmask from int to std::bitset
makes some backward compatability issue because it resides in
DB::Row::encryptionScheme as int already which is in DB.
But std::bitset cannot support converting to int (only ulong & ulong
long) so it's hard to use.

Change-Id: Ia27ec252f67c61fece9b34b1458724476b653b77
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
src/manager/service/crypto-logic.cpp
src/manager/service/crypto-logic.h

index 9951e9c..536783c 100644 (file)
@@ -144,7 +144,7 @@ void CryptoLogic::encryptRow(DB::Row &row)
                crow.iv = generateRandIV();
 
        key = m_keyMap[row.ownerLabel];
-       CLEAR_FLAG(crow.encryptionScheme);
+       CLEAR_FLAGS(crow.encryptionScheme);
        SET_FLAG(ENCR_APPKEY, crow.encryptionScheme);
 
        auto dataPair = Crypto::SW::Internals::encryptDataAesGcm(key, crow.data,
index 707b070..fab4cf9 100644 (file)
@@ -24,6 +24,7 @@
 #include <map>
 #include <ckm/ckm-type.h>
 #include <db-crypto.h>
+#include <exception.h>
 
 namespace CKM {
 
@@ -63,13 +64,20 @@ public:
 
 private:
        // Encryption scheme flags (enable/disable specific encryption type, multiple choice)
-       static const int ENCR_BASE64 =   1 << 0;
-       static const int ENCR_APPKEY =   1 << 1;
+       static const int ENCR_BASE64   = 1 << 0;
+       static const int ENCR_APPKEY   = 1 << 1;
        static const int ENCR_PASSWORD = 1 << 2;
 
        static const int ENCR_ORDER_OFFSET = 24;
 
-       static inline void CLEAR_FLAG(int &encryptionScheme) {
+       /*
+        *  available maximum encryption version.
+        *     This limitation is from bitset which is in DB::Row::encryptionScheme(int).
+        *     24bit is used for schema flag and upper 7 bit is for schema version.
+        */
+       static const int ENCRYPTION_V_MAX = 128;
+
+       static inline void CLEAR_FLAGS(int &encryptionScheme) {
                encryptionScheme = 0;
        }
 
@@ -81,7 +89,11 @@ private:
                return encryptionScheme & fieldId;
        }
 
-       static inline void SET_ENCRYPTION_VERSION(int version, int &encryptionScheme) {
+       static void SET_ENCRYPTION_VERSION(int version, int &encryptionScheme) {
+               if (version >= ENCRYPTION_V_MAX)
+                       ThrowErr(Exc::InputParam,
+                               "encryption schema version is bigger than max: ", version);
+
                encryptionScheme |= (version << ENCR_ORDER_OFFSET);
        }