Add key-manager to manage device key and password 99/95999/6
authorSungbae Yoo <sungbae.yoo@samsung.com>
Mon, 7 Nov 2016 09:14:02 +0000 (18:14 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Thu, 10 Nov 2016 07:12:24 +0000 (16:12 +0900)
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Change-Id: I75c5a6c9722c183db36fde2936b71351dad331cf

server/CMakeLists.txt
server/external-encryption.cpp
server/internal-encryption.cpp
server/key-manager/key-generator.cpp
server/key-manager/key-generator.h
server/key-manager/key-manager.cpp [new file with mode: 0644]
server/key-manager/key-manager.h [new file with mode: 0644]
server/key-manager/key-store.cpp [new file with mode: 0644]
server/key-manager/key-store.h [new file with mode: 0644]
server/key-manager/keystore.cpp [deleted file]
server/key-manager/keystore.h [deleted file]

index 1560574d4d5d538f1b1f909236e47e93db624aa8..6a6f5c3b484e79a8cb741c742ce58aebc157461f 100644 (file)
@@ -21,7 +21,8 @@ SET(SERVER_SRCS       main.cpp
                                engine/ext4-engine.cpp
                                engine/dmcrypt-engine.cpp
                                engine/ecryptfs-engine.cpp
-                               key-manager/keystore.cpp
+                               key-manager/key-store.cpp
+                               key-manager/key-manager.cpp
                                key-manager/key-generator.cpp
 )
 
index e5381192abf81565baf6bb0353a604b69f1d8ac1..a9e380020387fcd78330ab18e044454461865c9c 100644 (file)
@@ -17,8 +17,7 @@
 #include <klay/audit/logger.h>
 
 #include "engine/ecryptfs-engine.h"
-#include "key-manager/keystore.h"
-#include "key-manager/key-generator.h"
+#include "key-manager/key-manager.h"
 
 #include "rmi/external-encryption.h"
 
index a4956e3ae0bffb372f0bec1b0af2ac5b0effbaf9..6978dfc4d74460d591e26fff3204653a3783b9f8 100644 (file)
@@ -17,8 +17,7 @@
 #include <klay/audit/logger.h>
 
 #include "engine/dmcrypt-engine.h"
-#include "key-manager/keystore.h"
-#include "key-manager/key-generator.h"
+#include "key-manager/key-manager.h"
 
 #include "rmi/internal-encryption.h"
 
index ccb5934824e1df89b22ba6c9f3b4d27a8867d5ce..aad4128074209ddc78acd77c99bd2deb2ce74923 100644 (file)
@@ -22,7 +22,8 @@
 
 namespace ode {
 
-KeyGenerator::KeyGenerator()
+KeyGenerator::KeyGenerator(int size) :
+       keySize(size)
 {
 }
 
index 5a1a4b60354a2c902ececda73da9c3acfeb1092a..b5b0d1a5a14aa376edd19030a918940f072346ad 100644 (file)
@@ -23,7 +23,7 @@ namespace ode {
 
 class KeyGenerator final {
 public:
-       KeyGenerator();
+       KeyGenerator(int size);
        KeyGenerator(const KeyGenerator&) = delete;
        KeyGenerator(KeyGenerator&&) = delete;
        ~KeyGenerator();
@@ -37,6 +37,9 @@ public:
        const data AES(const data& in1, const data& in2);
        const data HMAC(const data& original, const data& key);
        const data RNG();
+
+private:
+       int keySize;
 };
 
 } // namespace ode
diff --git a/server/key-manager/key-manager.cpp b/server/key-manager/key-manager.cpp
new file mode 100644 (file)
index 0000000..6333c4a
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ *  Copyright (c) 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.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+#include "key-manager.h"
+
+namespace ode {
+
+KeyManager::KeyManager(const std::string& storeName) :
+       store(storeName), keyGen(store.getKeySize())
+{
+}
+
+KeyManager::~KeyManager()
+{
+}
+
+bool KeyManager::isInitialized()
+{
+       return store.isInitialized();
+}
+
+void KeyManager::initPassword(const KeyManager::data& password)
+{
+       data salt, edk, emk;
+       data mk, dek;
+
+       salt = keyGen.RNG();
+       mk = keyGen.PBKDF(password, salt);
+       dek = keyGen.RNG();
+
+       edk = keyGen.AES(dek, mk);
+       emk = keyGen.HMAC(mk, edk);
+
+       store.setSalt(salt);
+       store.setEDK(edk);
+       store.setEMK(emk);
+}
+
+void KeyManager::changePassword(const KeyManager::data& old_password,
+                                                               const KeyManager::data& new_password)
+{
+       data salt, edk, emk;
+       data mk, dek;
+
+       salt = store.getSalt();
+       edk = store.getEDK();
+
+       mk = keyGen.PBKDF(old_password, salt);
+       dek = keyGen.AES(edk, mk);
+
+       salt = keyGen.RNG();
+       mk = keyGen.PBKDF(new_password, salt);
+       edk = keyGen.AES(dek, mk);
+       emk = keyGen.HMAC(mk, edk);
+
+       store.setSalt(salt);
+       store.setEDK(edk);
+       store.setEMK(emk);
+}
+
+bool KeyManager::verifyPassword(const KeyManager::data& password)
+{
+       data salt, edk, emk;
+       data mk;
+
+       salt = store.getSalt();
+       edk = store.getEDK();
+       emk = store.getEMK();
+
+       mk = keyGen.PBKDF(password, salt);
+
+       if (emk == keyGen.HMAC(mk, edk)) {
+               return true;
+       } else {
+               return false;
+       }
+}
+
+KeyManager::data KeyManager::getDEK(const KeyManager::data& password)
+{
+       data salt, edk;
+       data mk;
+
+       salt = store.getSalt();
+       edk = store.getEDK();
+
+       mk = keyGen.PBKDF(password, salt);
+
+       return keyGen.AES(edk, mk);
+}
+
+} // namespace ode
diff --git a/server/key-manager/key-manager.h b/server/key-manager/key-manager.h
new file mode 100644 (file)
index 0000000..299de31
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ *  Copyright (c) 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.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#ifndef __KEY_MANAGER_H__
+#define __KEY_MANAGER_H__
+
+#include "key-store.h"
+#include "key-generator.h"
+
+namespace ode {
+
+class KeyManager final {
+public:
+       KeyManager(const std::string& storeName);
+       KeyManager(const KeyManager&) = delete;
+       KeyManager(KeyManager&&) = delete;
+       ~KeyManager();
+
+       KeyManager& operator=(const KeyManager&) = delete;
+       KeyManager& operator=(KeyManager&&) = delete;
+
+       typedef std::vector<unsigned char> data;
+
+       bool isInitialized();
+
+       void initPassword(const data& password);
+       void changePassword(const data& old_password, const data& new_password);
+       bool verifyPassword(const data& password);
+       data getDEK(const data& password);
+
+private:
+       KeyStore store;
+       KeyGenerator keyGen;
+};
+
+} // namespace ode
+
+#endif // __KEY_MANAGER_H__
diff --git a/server/key-manager/key-store.cpp b/server/key-manager/key-store.cpp
new file mode 100644 (file)
index 0000000..98b9d52
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ *  Copyright (c) 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.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+#include <klay/filesystem.h>
+#include <klay/audit/logger.h>
+
+#include "key-store.h"
+
+#define FOOTER_FILE_PATH "/opt/etc/.ode_footer"
+#define KEY_SIZE       (256 / 8)
+
+namespace ode {
+
+KeyStore::KeyStore(const std::string& name) :
+       file(FOOTER_FILE_PATH)
+{
+}
+
+KeyStore::~KeyStore()
+{
+}
+
+size_t KeyStore::getKeySize() const
+{
+       return KEY_SIZE;
+}
+
+bool KeyStore::isInitialized()
+{
+       //TODO
+
+       return false;
+}
+
+KeyStore::data KeyStore::getEDK()
+{
+       data ret;
+
+       //TODO
+
+       return ret;
+}
+
+KeyStore::data KeyStore::getEMK()
+{
+       data ret;
+
+       //TODO
+
+       return ret;
+}
+
+KeyStore::data KeyStore::getSalt()
+{
+       data ret;
+
+       //TODO
+
+       return ret;
+}
+
+void KeyStore::setEDK(const KeyStore::data& key)
+{
+       //TODO
+}
+
+void KeyStore::setEMK(const KeyStore::data& key)
+{
+       //TODO
+}
+
+void KeyStore::setSalt(const KeyStore::data& key)
+{
+       //TODO
+}
+
+} // namespace ode
diff --git a/server/key-manager/key-store.h b/server/key-manager/key-store.h
new file mode 100644 (file)
index 0000000..125accd
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ *  Copyright (c) 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.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#ifndef __KEY_STORE_H__
+#define __KEY_STORE_H__
+
+#include <vector>
+#include <string>
+
+#include <klay/filesystem.h>
+
+namespace ode {
+
+class KeyStore final {
+public:
+       KeyStore(const std::string& name);
+       KeyStore(const KeyStore&) = delete;
+       KeyStore(KeyStore&&) = delete;
+       ~KeyStore();
+
+       KeyStore& operator=(const KeyStore&) = delete;
+       KeyStore& operator=(KeyStore&&) = delete;
+
+       size_t getKeySize() const;
+
+       bool isInitialized();
+
+       typedef std::vector<unsigned char> data;
+
+       data getEDK();
+       data getEMK();
+       data getSalt();
+
+       void setEDK(const data& key);
+       void setEMK(const data& key);
+       void setSalt(const data& key);
+
+private:
+       runtime::File file;
+       int index;
+};
+
+} // namespace ode
+
+#endif // __KEY_STORE_H__
diff --git a/server/key-manager/keystore.cpp b/server/key-manager/keystore.cpp
deleted file mode 100644 (file)
index 20de6de..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- *  Copyright (c) 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.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-#include <klay/filesystem.h>
-#include <klay/audit/logger.h>
-
-#include "keystore.h"
-
-namespace ode {
-
-KeyStore::KeyStore(const std::string& name) :
-       file(name)
-{
-}
-
-KeyStore::~KeyStore()
-{
-}
-
-KeyStore::data KeyStore::getEncryptedDeviceKey()
-{
-       data ret;
-
-       //TODO
-
-       return ret;
-}
-
-KeyStore::data KeyStore::getEncryptedMasterKey()
-{
-       data ret;
-
-       //TODO
-
-       return ret;
-}
-
-void KeyStore::setEncryptedDeviceKey(const KeyStore::data& key)
-{
-       //TODO
-}
-
-void KeyStore::setEncryptedMasterKey(const KeyStore::data& key)
-{
-       //TODO
-}
-
-} // namespace ode
diff --git a/server/key-manager/keystore.h b/server/key-manager/keystore.h
deleted file mode 100644 (file)
index d6d0e5e..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- *  Copyright (c) 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.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-
-#ifndef __KEY_STORAGE_H__
-#define __KEY_STORAGE_H__
-
-#include <vector>
-#include <string>
-
-#include <klay/filesystem.h>
-
-namespace ode {
-
-class KeyStore final {
-public:
-       KeyStore(const std::string& name);
-       KeyStore(const KeyStore&) = delete;
-       KeyStore(KeyStore&&) = delete;
-       ~KeyStore();
-
-       KeyStore& operator=(const KeyStore&) = delete;
-       KeyStore& operator=(KeyStore&&) = delete;
-
-       typedef std::vector<unsigned char> data;
-
-       data getEncryptedDeviceKey();
-       data getEncryptedMasterKey();
-
-       void setEncryptedDeviceKey(const data& key);
-       void setEncryptedMasterKey(const data& key);
-
-private:
-       runtime::File file;
-};
-
-} // namespace ode
-
-#endif // __KEY_STORAGE_H__