Remove digest implementation. 89/52989/2
authorBartlomiej Grzelewski <b.grzelewski@samsung.com>
Mon, 30 Nov 2015 15:42:53 +0000 (16:42 +0100)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 1 Dec 2015 08:49:13 +0000 (00:49 -0800)
Change-Id: Ib4c38cae9370e3f39ffb59e9d7602238d178c849

src/CMakeLists.txt
src/manager/service/crypto-logic.cpp
src/manager/service/crypto-logic.h
src/manager/service/digest.cpp [deleted file]
src/manager/service/digest.h [deleted file]
tools/ckm_db_tool/CMakeLists.txt

index ceb976e..99ace29 100644 (file)
@@ -38,7 +38,6 @@ SET(KEY_MANAGER_SOURCES
     ${KEY_MANAGER_PATH}/main/socket-2-id.cpp
     ${KEY_MANAGER_PATH}/service/certificate-store.cpp
     ${KEY_MANAGER_PATH}/service/certificate-config.cpp
-    ${KEY_MANAGER_PATH}/service/digest.cpp
     ${KEY_MANAGER_PATH}/service/file-lock.cpp
     ${KEY_MANAGER_PATH}/service/access-control.cpp
     ${KEY_MANAGER_PATH}/service/ckm-service.cpp
index 6fe6e4e..b5b5959 100644 (file)
@@ -36,7 +36,6 @@
 #include <dpl/log/log.h>
 
 #include <base64.h>
-#include <digest.h>
 #include <crypto-logic.h>
 
 #include <generic-backend/exception.h>
@@ -298,14 +297,5 @@ void CryptoLogic::decBase64(RawBuffer &data)
     data = std::move(decdata);
 }
 
-bool CryptoLogic::equalDigests(RawBuffer &dig1, RawBuffer &dig2)
-{
-    unsigned int dlen = Digest().length();
-
-    if ((dig1.size() != dlen) || (dig2.size() != dlen))
-        return false;
-    return (dig1 == dig2);
-}
-
 } // namespace CKM
 
index 61c582e..aa4a0e8 100644 (file)
@@ -79,7 +79,6 @@ private:
 
     void decBase64(RawBuffer &data);
     void encBase64(RawBuffer &data);
-    bool equalDigests(RawBuffer &dig1, RawBuffer &dig2);
 };
 
 } // namespace CKM
diff --git a/src/manager/service/digest.cpp b/src/manager/service/digest.cpp
deleted file mode 100644 (file)
index 0bec6fc..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (c) 2014 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 <dpl/log/log.h>
-
-#include <openssl/evp.h>
-
-#include <digest.h>
-
-namespace CKM {
-
-Digest::Digest() :
-    m_digest(EVP_MAX_MD_SIZE)
-{
-    m_ctx = nullptr;
-    m_md = EVP_sha1();
-    m_initialized = false;
-    m_finalized = false;
-}
-
-Digest::~Digest()
-{
-    EVP_MD_CTX_destroy(m_ctx);
-}
-
-void Digest::reset()
-{
-    int ret = -1;
-
-    if (m_initialized) {
-        EVP_MD_CTX_destroy(m_ctx);
-        m_ctx = nullptr;
-    }
-
-    m_initialized = false;
-    m_finalized = false;
-    m_ctx = EVP_MD_CTX_create();
-    if (m_ctx == nullptr) {
-    }
-
-    ret = EVP_DigestInit_ex(m_ctx, m_md, NULL);
-    if (ret != 1) {
-        ThrowMsg(Exception::InternalError,
-                 "Failed to create digest context.");
-    }
-    m_digest.clear();
-    m_digest.resize(EVP_MAX_MD_SIZE);
-    m_initialized = true;
-}
-
-void Digest::append(const RawBuffer &data, std::size_t len)
-{
-    int ret = -1;
-
-    if (data.size() == 0) {
-        ThrowMsg(Exception::InternalError, "Empty data.");
-    }
-    if (0 == len)
-        len = data.size();
-    if (m_finalized) {
-        ThrowMsg(Exception::InternalError, "Already finalized.");
-    }
-    if (not m_initialized)
-        reset();
-    ret = EVP_DigestUpdate(m_ctx, data.data(), len);
-    if (ret != 1) {
-        ThrowMsg(Exception::InternalError,
-                 "Failed to calculate digest in openssl.");
-    }
-}
-
-RawBuffer Digest::finalize()
-{
-    int ret = -1;
-    unsigned int dlen;
-
-    if (m_finalized) {
-        ThrowMsg(Exception::InternalError, "Already finalized.");
-    }
-    m_finalized = true;
-    ret = EVP_DigestFinal_ex(m_ctx, m_digest.data(), &dlen);
-    if (ret != 1) {
-        ThrowMsg(Exception::InternalError,
-                 "Failed in digest final in openssl.");
-    }
-    if (dlen != length()) {
-        ThrowMsg(Exception::InternalError, "Invalid digest length.");
-    }
-    if (dlen != EVP_MAX_MD_SIZE)
-        m_digest.resize(dlen);
-    return m_digest;
-}
-
-RawBuffer Digest::get()
-{
-    if (m_finalized)
-        return m_digest;
-    else
-        return RawBuffer();
-}
-
-unsigned int Digest::length()
-{
-    return m_md->md_size;
-}
-
-} // namespace CKM
-
diff --git a/src/manager/service/digest.h b/src/manager/service/digest.h
deleted file mode 100644 (file)
index 519521f..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (c) 2014 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.
- */
-
-#pragma once
-
-#include <dpl/exception.h>
-#include <ckm/ckm-type.h>
-
-#include <noncopyable.h>
-/*
- * Taken from openssl/ossl_typ.h
- */
-struct env_md_ctx_st;
-typedef env_md_ctx_st EVP_MD_CTX;
-struct env_md_st;
-typedef env_md_st EVP_MD;
-
-namespace CKM {
-
-class Digest
-{
-    public:
-        NONCOPYABLE(Digest)
-
-        class Exception
-        {
-            public:
-                DECLARE_EXCEPTION_TYPE(CKM::Exception, Base)
-                DECLARE_EXCEPTION_TYPE(Base, InternalError)
-        };
-        Digest();
-        ~Digest();
-        void append(const RawBuffer &data, std::size_t len = 0);
-        RawBuffer finalize(void);
-        RawBuffer get(void);
-        void reset(void);
-        unsigned int length(void);
-
-    private:
-        EVP_MD_CTX *m_ctx;
-        const EVP_MD *m_md;
-        RawBuffer m_digest;
-        bool m_initialized;
-        bool m_finalized;
-};
-
-} // namespace CKM
-
index 9513b80..309703a 100644 (file)
@@ -43,7 +43,6 @@ SET(CKM_DB_TOOL_SOURCES
     ${KEY_MANAGER_PATH}/main/socket-2-id.cpp
     ${KEY_MANAGER_PATH}/service/certificate-store.cpp
     ${KEY_MANAGER_PATH}/service/certificate-config.cpp
-    ${KEY_MANAGER_PATH}/service/digest.cpp
     ${KEY_MANAGER_PATH}/service/file-lock.cpp
     ${KEY_MANAGER_PATH}/service/access-control.cpp
     ${KEY_MANAGER_PATH}/service/ckm-logic.cpp