Add classes for Trust Zone backend. 12/39612/4
authorBartlomiej Grzelewski <b.grzelewski@samsung.com>
Tue, 19 May 2015 15:18:30 +0000 (17:18 +0200)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Mon, 25 May 2015 16:28:27 +0000 (18:28 +0200)
Change-Id: I84d0fc46e0026e83903ead87285fb6f9fb5754db

src/CMakeLists.txt
src/manager/crypto/platform/decider.cpp
src/manager/crypto/platform/decider.h
src/manager/crypto/tz-backend/key.cpp [new file with mode: 0644]
src/manager/crypto/tz-backend/key.h [new file with mode: 0644]
src/manager/crypto/tz-backend/store.cpp [new file with mode: 0644]
src/manager/crypto/tz-backend/store.h [new file with mode: 0644]

index b245860..a114f40 100644 (file)
@@ -52,6 +52,8 @@ SET(KEY_MANAGER_SOURCES
     ${KEY_MANAGER_PATH}/crypto/sw-backend/store.cpp
     ${KEY_MANAGER_PATH}/crypto/sw-backend/crypto-service.cpp
     ${KEY_MANAGER_PATH}/crypto/platform/decider.cpp
+    ${KEY_MANAGER_PATH}/crypto/tz-backend/key.cpp
+    ${KEY_MANAGER_PATH}/crypto/tz-backend/store.cpp
     )
 
 # -fPIE and -pie flag is added for ASLR
index aad14b8..7a985bf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *  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.
 #include <platform/decider.h>
 
 #include <sw-backend/store.h>
+#include <tz-backend/store.h>
 
 namespace CKM {
 namespace Crypto {
 
 Decider::Decider()
   : m_swStore(new SW::Store(CryptoBackend::OpenSSL))
+  , m_tzStore(new TZ::Store(CryptoBackend::TrustZone))
 {}
 
-GStore& Decider::getStore(const Token &) {
-    // This the place where we should choose backend bases on token information.
-    if (!m_swStore) {
-        LogError("No backend available.");
-        ThrowMsg(CKM::Crypto::Exception::Base, "No backend available.");
-    }
-    return *m_swStore;
+GStore& Decider::getStore(const Token &token) {
+    return getStore(token.backendId);
 };
 
-CryptoBackend Decider::chooseCryptoBackend(DataType, const Policy &) const {
+GStore& Decider::getStore(CryptoBackend cryptoBackend) {
+    GStore *gStore = NULL;
+    if (cryptoBackend == CryptoBackend::OpenSSL)
+        gStore = m_swStore.get();
+    if (cryptoBackend == CryptoBackend::TrustZone)
+        gStore = m_tzStore.get();
+
+    if (gStore)
+        return *gStore;
+
+    LogError("Backend not available. BackendId: " << (int)cryptoBackend);
+    ThrowMsg(CKM::Crypto::Exception::Base,
+             "Backend not available. BackendId: " << (int)cryptoBackend);
+}
+
+CryptoBackend Decider::chooseCryptoBackend(DataType dataType, const Policy &policy) const {
+// The list of items that MUST be support by OpenSSL
+    if (dataType.isCertificate())
+        return CryptoBackend::OpenSSL;
+
+    if (dataType.isBinaryData())
+        return CryptoBackend::OpenSSL;
+
+    if (policy.extractable)
+        return CryptoBackend::OpenSSL;
+
+//  This is the place where we can use trust zone backend
+//  Examples:
+//
+//  if (dataType.isKeyPrivate())
+//      return CryptoBackend::TrustZone;
+
+// This item does not met Trust Zone requirements. Let's use software backend
     return CryptoBackend::OpenSSL;
 }
 
index 17a00aa..c14a743 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *  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.
@@ -39,8 +39,11 @@ public:
     CryptoBackend chooseCryptoBackend(DataType data, const Policy &policy) const;
 
     virtual ~Decider(){}
-private:
+protected:
+    GStore& getStore(CryptoBackend id);
+
     std::unique_ptr<GStore> m_swStore;
+    std::unique_ptr<GStore> m_tzStore;
 };
 
 } // Crypto
diff --git a/src/manager/crypto/tz-backend/key.cpp b/src/manager/crypto/tz-backend/key.cpp
new file mode 100644 (file)
index 0000000..1ebeec6
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ *  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
+ */
+/*
+ * @file       key.cpp
+ * @author     Bartłomiej Grzelewski (b.grzelewski@samsung.com)
+ * @version    1.0
+ */
+namespace CKM {
+namespace Crypto {
+namespace TZ {
+
+} // namespace TZ
+} // namespace Crypto
+} // namespace CKM
+
diff --git a/src/manager/crypto/tz-backend/key.h b/src/manager/crypto/tz-backend/key.h
new file mode 100644 (file)
index 0000000..c911cf8
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ *  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
+ */
+/*
+ * @file       key.h
+ * @author     Bartłomiej Grzelewski (b.grzelewski@samsung.com)
+ * @version    1.0
+ */
+#pragma once
+
+#include <generic-backend/gkey.h>
+
+namespace CKM {
+namespace Crypto {
+namespace TZ {
+
+class SKey : public GKey {
+public:
+    SKey(){}
+    virtual ~SKey(){}
+protected:
+};
+
+class AKey : public GKey {
+public:
+    AKey(){}
+    virtual ~AKey(){}
+protected:
+};
+
+} // namespace TZ
+} // namespace Crypto
+} // namespace CKM
+
diff --git a/src/manager/crypto/tz-backend/store.cpp b/src/manager/crypto/tz-backend/store.cpp
new file mode 100644 (file)
index 0000000..0cf6ffe
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ *  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
+ */
+/*
+ * @file       store.cpp
+ * @author     Bartłomiej Grzelewski (b.grzelewski@samsung.com)
+ * @version    1.0
+ */
+#include <dpl/log/log.h>
+
+#include <generic-backend/exception.h>
+#include <tz-backend/key.h>
+#include <tz-backend/store.h>
+
+namespace CKM {
+namespace Crypto {
+namespace TZ {
+
+Store::Store(CryptoBackend backendId)
+  : GStore(backendId)
+{}
+
+GKeyShPtr Store::getKey(const Token &) {
+    LogError("Trust zone backend is not implemented!");
+    ThrowMsg(Exception::Base, "Trust zone backend is not implemented!");
+}
+
+Token Store::import(DataType, const RawBuffer &) {
+    LogError("Trust zone backend is not implemented!");
+    ThrowMsg(Exception::Base, "Trust zone backend is not implemented!");
+}
+
+} // namespace TZ
+} // namespace Crypto
+} // namespace CKM
+
diff --git a/src/manager/crypto/tz-backend/store.h b/src/manager/crypto/tz-backend/store.h
new file mode 100644 (file)
index 0000000..d2e29de
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ *  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
+ */
+/*
+ * @file       store.h
+ * @author     Bartłomiej Grzelewski (b.grzelewski@samsung.com)
+ * @version    1.0
+ */
+#pragma once
+
+#include <generic-backend/gkey.h>
+#include <generic-backend/gstore.h>
+
+namespace CKM {
+namespace Crypto {
+namespace TZ {
+
+class Store : public GStore {
+public:
+    explicit Store(CryptoBackend backendId);
+
+    virtual GKeyShPtr getKey(const Token &token);
+    virtual Token import(DataType dataType, const RawBuffer &buffer);
+    virtual void destroy(const Token &){}
+};
+
+} // namespace TZ
+} // namespace Crypto
+} // namespace CKM
+