+++ /dev/null
-//
-// 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 <unique_ptr.h>
-#include <FBaseResult.h>
-#include <FBaseErrors.h>
-#include <FBaseUtilStringUtil.h>
-#include <FSecCryptoSha1Hash.h>
-#include <FSecCryptoSha1Hmac.h>
-#include <FSecSecretKey.h>
-#include <FBaseSysLog.h>
-#include <FBase_StringConverter.h>
-#include <FSec_DeviceKeyGenerator.h>
-
-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 <ByteBuffer> pHashValue(null);
- std::unique_ptr <ISecretKey> 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 <byte*>(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 <ByteBuffer> pHashValue(null);
- std::unique_ptr <ByteBuffer> pHmacKey(null);
- std::unique_ptr <ISecretKey> pSecretKey(null);
- std::unique_ptr <ISecretKey> 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 <byte*>(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
+++ /dev/null
-//
-// 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 <FOspConfig.h>
-
-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_