From: KyungwooNoh Date: Mon, 24 Jun 2013 05:09:47 +0000 (+0900) Subject: remove _DeviceKeyGenerator class X-Git-Tag: submit/tizen_2.2/20130714.152805~79 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=06a5fb972c467fb93d41f9b18ed6f1432cfd8813;p=framework%2Fosp%2Fappfw.git remove _DeviceKeyGenerator class Change-Id: Iab70eb52196f32233e4b708a662414bdf575be7f Signed-off-by: KyungwooNoh --- diff --git a/src/security/CMakeLists.txt b/src/security/CMakeLists.txt index 1c1a1e4..abdbc2d 100755 --- a/src/security/CMakeLists.txt +++ b/src/security/CMakeLists.txt @@ -74,8 +74,6 @@ SET (${this_target}_SOURCE_FILES FSecDhKeyParameters.cpp FSecKeaKeyParameters.cpp FSecRsaKeyConverter.cpp - FSec_DeviceKeyGenerator.cpp - #FSec_DeviceKeyGeneratorMessage.cpp FSecAccessController.cpp FSec_AccessController.cpp FSec_PrivilegeCache.cpp diff --git a/src/security/FSec_DeviceKeyGenerator.cpp b/src/security/FSec_DeviceKeyGenerator.cpp deleted file mode 100644 index 3d3933c..0000000 --- a/src/security/FSec_DeviceKeyGenerator.cpp +++ /dev/null @@ -1,221 +0,0 @@ -// -// Copyright (c) 2012 Samsung Electronics Co., Ltd. -// -// 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 FSec_DeviceKeyGenerator.cpp - * @brief This file contains the implementation of DeviceKeyGenerator class. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace Tizen::Base; -using namespace Tizen::Base::Utility; -using namespace Tizen::Security::Crypto; - - -namespace Tizen { namespace Security -{ - -static const int _HASH_LEN = 20; - -_DeviceKeyGenerator::_DeviceKeyGenerator(void) -{ - -} - -_DeviceKeyGenerator::~_DeviceKeyGenerator(void) -{ - -} - -ISecretKey* -_DeviceKeyGenerator::GenerateDeviceKeyN(int keySize) -{ - result r = E_SUCCESS; - String deviceInfo; - ByteBuffer deviceInfoBuffer; - std::unique_ptr pHashValue(null); - std::unique_ptr pKey(null); - ByteBuffer* pTempValue = null; - ByteBuffer* pTempInfoBuffer = null; - Sha1Hash hash; - int count = 0; - char* pDeviceInfo = null; - - SysLog(NID_SEC, "GenerateDeviceKeyN called."); - - SysTryReturn(NID_SEC, keySize > 0, null, E_INVALID_ARG, - "[E_INVALID_ARG] The device key size MUST be a valid integer greater than 0."); - deviceInfo.Append(L"1234567890abcdefghijklmnopqrstuvwxyz"); - if (keySize % _HASH_LEN == 0) - { - count = keySize / _HASH_LEN; - } - else - { - count = keySize / _HASH_LEN + 1; - } - - pHashValue.reset(new (std::nothrow) ByteBuffer()); - SysTryReturn(NID_SEC, pHashValue != null, null, r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory."); - r = pHashValue->Construct(count * _HASH_LEN); - SysTryReturn(NID_SEC, r == E_SUCCESS, null, r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory."); - - pDeviceInfo = _StringConverter::CopyToCharArrayN(deviceInfo); - deviceInfoBuffer.Construct(deviceInfo.GetLength()); - r = deviceInfoBuffer.SetArray(reinterpret_cast (pDeviceInfo), 0, deviceInfo.GetLength()); - SysTryCatch(NID_SEC, r == E_SUCCESS, , r, "[%s] A system error has occurred.", GetErrorMessage(r)); - deviceInfoBuffer.Flip(); - - for (int i = 0; i < count; i++) - { - if (i == 0) - { - pTempValue = hash.GetHashN(deviceInfoBuffer); - } - else - { - pTempValue = hash.GetHashN(*pTempInfoBuffer); - } - SysTryCatch(NID_SEC, pTempValue != null, , GetLastResult(), "[%s] Failed to generate hash code.", - GetErrorMessage(GetLastResult())); - - if (pTempInfoBuffer != null) - delete pTempInfoBuffer; - pTempInfoBuffer = new (std::nothrow) ByteBuffer(); - r = pTempInfoBuffer->Construct(*pTempValue); - delete pTempValue; - SysTryCatch(NID_SEC, r == E_SUCCESS, , r, "[%s] A system error has occurred.", GetErrorMessage(r)); - r = pHashValue->CopyFrom(*pTempInfoBuffer); - SysTryCatch(NID_SEC, r == E_SUCCESS, , r, "[%s] A system error has occurred.", GetErrorMessage(r)); - } - - pHashValue->Flip(); - pHashValue->SetLimit(keySize); - pKey.reset(new (std::nothrow) SecretKey()); - SysTryCatch(NID_SEC, pKey != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory."); - r = pKey->SetKey(*(pHashValue.get())); - SysTryCatch(NID_SEC, r == E_SUCCESS, , r, "[%s] Failed to generate device unique key.", GetErrorMessage(r)); - -CATCH: - SetLastResult(r); - delete[] pDeviceInfo; - delete pTempInfoBuffer; - - return pKey.release(); -} - -ISecretKey* -_DeviceKeyGenerator::GenerateDeviceKeyN(String& appId, int keySize) -{ - result r = E_SUCCESS; - String deviceInfo; - ByteBuffer deviceInfoBuffer; - std::unique_ptr pHashValue(null); - std::unique_ptr pHmacKey(null); - std::unique_ptr pSecretKey(null); - std::unique_ptr pKey(null); - ByteBuffer* pTempValue = null; - ByteBuffer* pTempInfoBuffer = null; - Sha1Hmac hmac; - int count = 0; - char* pDeviceInfo = null; - - SysLog(NID_SEC, "GenerateDeviceKeyN called."); - - SysTryReturn(NID_SEC, keySize > 0 && appId.GetLength() > 0, null, E_INVALID_ARG, - "[E_INVALID_ARG] The device key size MUST be a valid integer greater than 0."); - -//ToDo -//Add slp API - - deviceInfo.Append(L"1234567890abcdefghijklmnopqrstuvwxyz"); - if (keySize % _HASH_LEN == 0) - { - count = keySize / _HASH_LEN; - } - else - { - count = keySize / _HASH_LEN + 1; - } - - pHashValue.reset(new (std::nothrow) ByteBuffer()); - SysTryReturn(NID_SEC, pHashValue != null, null, r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory."); - r = pHashValue->Construct(count * _HASH_LEN); - SysTryCatch(NID_SEC, r == E_SUCCESS, , r, "[%s] A system error has occurred.", GetErrorMessage(r)); - - pDeviceInfo = _StringConverter::CopyToCharArrayN(deviceInfo); - deviceInfoBuffer.Construct(deviceInfo.GetLength()); - r = deviceInfoBuffer.SetArray(reinterpret_cast (pDeviceInfo), 0, deviceInfo.GetLength()); - SysTryCatch(NID_SEC, r == E_SUCCESS, , r, "[%s] A system error has occurred.", GetErrorMessage(r)); - deviceInfoBuffer.Flip(); - - pHmacKey.reset(StringUtil::StringToUtf8N(appId)); - - pSecretKey.reset(new (std::nothrow) SecretKey()); - r = pSecretKey->SetKey(*(pHmacKey.get())); - SysTryCatch(NID_SEC, r == E_SUCCESS, , r, "[%s] A system error has occurred.", GetErrorMessage(r)); - hmac.SetKey(*(pSecretKey.get())); - - for (int i = 0; i < count; i++) - { - if (i == 0) - { - pTempValue = hmac.GetHmacN(deviceInfoBuffer); - } - else - { - pTempValue = hmac.GetHmacN(*pTempInfoBuffer); - } - SysTryCatch(NID_SEC, pTempValue != null, , GetLastResult(), "[%s] Failed to generate hash code.", - GetErrorMessage(GetLastResult())); - - if (pTempInfoBuffer != null) - delete pTempInfoBuffer; - pTempInfoBuffer = new (std::nothrow) ByteBuffer(); - r = pTempInfoBuffer->Construct(*pTempValue); - delete pTempValue; - SysTryCatch(NID_SEC, r == E_SUCCESS, , r, "[%s] A system error has occurred.", GetErrorMessage(r)); - r = pHashValue->CopyFrom(*pTempInfoBuffer); - SysTryCatch(NID_SEC, r == E_SUCCESS, , r, "[%s] A system error has occurred.", GetErrorMessage(r)); - } - - pHashValue->Flip(); - pHashValue->SetLimit(keySize); - pKey.reset(new (std::nothrow) SecretKey()); - SysTryCatch(NID_SEC, pKey != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory."); - r = pKey->SetKey(*(pHashValue.get())); - SysTryCatch(NID_SEC, r == E_SUCCESS, , r, "[%s] Failed to generate device unique key.", GetErrorMessage(r)); - -CATCH: - SetLastResult(r); - delete[] pDeviceInfo; - delete pTempInfoBuffer; - - return pKey.release(); -} - -} //Tizen::Security -} //Osp diff --git a/src/security/inc/FSec_DeviceKeyGenerator.h b/src/security/inc/FSec_DeviceKeyGenerator.h deleted file mode 100644 index f27b43e..0000000 --- a/src/security/inc/FSec_DeviceKeyGenerator.h +++ /dev/null @@ -1,76 +0,0 @@ -// -// Copyright (c) 2012 Samsung Electronics Co., Ltd. -// -// 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 FSec_DeviceKey.h - * @brief This is the header file for the %_DeviceKey class. - * - * This header file contains the declarations of the %_DeviceKey class. - */ -#ifndef _FSEC_INTERNAL_DEVICE_KEY_GENERATOR_H_ -#define _FSEC_INTERNAL_DEVICE_KEY_GENERATOR_H_ - -#include - -namespace Tizen { namespace Base -{ -class String; -class ByteBuffer; -}} - - -namespace Tizen { namespace Security -{ -class ISecretKey; - -/** - * @class _DeviceKeyGenerator - * @brief This class generates a device unique key. - * @since 2.1 - * - * The %_DeviceKeyGenerator class generates a device unique key. - * - */ - - -class _OSP_EXPORT_ _DeviceKeyGenerator -{ -public: - /** - * Gets a device unique key. - * - * @since 2.1 - * @return The device unique key - * @param[in] keySize The size of device unique key. - * @exception E_SUCCESS The method is successful. - * @exception E_OUT_OF_MEMORY The memory is insufficient. - * @exception E_SYSTEM A system error has occurred. - * - * @remarks The specific error code can be accessed using the GetLastResult() method. - */ - static ISecretKey* GenerateDeviceKeyN(int keySize); - static ISecretKey* GenerateDeviceKeyN(Tizen::Base::String& appId, int keySize); - -private: - _DeviceKeyGenerator(void); - ~_DeviceKeyGenerator(void); - _DeviceKeyGenerator(const _DeviceKeyGenerator& value); - _DeviceKeyGenerator& operator =(const _DeviceKeyGenerator& value); - -}; //_DeviceKeyGenerator -}} - -#endif // _FSEC_INTERNAL_DEVICE_KEY_GENERATOR_H_