//
-// Open Service Platform
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
#include <unique_ptr.h>
#include <stdlib.h>
+#include <dukgen.h>
+
#include <FBaseSysLog.h>
#include <FBase_StringConverter.h>
#include <FBaseString.h>
#include <FAppPkg_PackageInfoImpl.h>
+#include <FSecSecretKey.h>
#include <FSecCryptoAesCipher.h>
#include <FSecCryptoSha1Hmac.h>
#include <FSecCryptoSha1Hash.h>
#include <FBaseColArrayList.h>
+#include <FBaseColHashMap.h>
+#include <privilege_info.h>
-#include "FSec_DeviceKeyGenerator.h"
#include "FSec_PrivilegeInfo.h"
using namespace Tizen::App;
std::unique_ptr<IEnumerator> pEnum(null);
- r = __privilegeList.Construct();
+ r = __privilegeList.Construct(32, 0.75);
SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "An unexpected system error occurred.");
pEnum.reset(pPrivilegeList->GetEnumeratorN());
while (pEnum->MoveNext() == E_SUCCESS)
{
- String* tempString = static_cast< String* >(pEnum->GetCurrent());
- __privilegeList.Add(new String(*tempString));
+ int ret = PRVMGR_ERR_NONE;
+ char* pPrivilegeLevel = null;
+ std::unique_ptr<char[]> pPrivilegeId(null);
+ String* pTempString = static_cast< String* >(pEnum->GetCurrent());
+
+ pPrivilegeId.reset(_StringConverter::CopyToCharArrayN(*pTempString));
+ SysTryReturnResult(NID_SEC, pPrivilegeId != null, E_SYSTEM, "An unexpected system error occurred.");
+
+ ret = privilege_info_get_external_privilege_level(static_cast<char*>(pPrivilegeId.get()), &pPrivilegeLevel);
+ SysTryReturnResult(NID_SEC, ret == PRVMGR_ERR_NONE, E_SYSTEM, "An unexpected system error occurred.");
+
+ __privilegeList.Add((new String(*pTempString)), (new String(pPrivilegeLevel)));
}
return r;
SysTryReturnResult(NID_SEC, __apiVisibility >= 0, E_SYSTEM, "An unexpected system error occurred.");
std::unique_ptr<IEnumerator> pEnum(null);
- r = __privilegeList.Construct();
+ r = __privilegeList.Construct(32, 0.75);
SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "An unexpected system error occurred.");
pEnum.reset(pPrivilegeList->GetEnumeratorN());
while (pEnum->MoveNext() == E_SUCCESS)
{
- String* tempString = static_cast< String* >(pEnum->GetCurrent());
- __privilegeList.Add(new String(*tempString));
+ int ret = PRVMGR_ERR_NONE;
+ char* pPrivilegeLevel = null;
+ std::unique_ptr<char[]> pPrivilegeId(null);
+ String* pTempString = static_cast< String* >(pEnum->GetCurrent());
+
+ pPrivilegeId.reset(_StringConverter::CopyToCharArrayN(*pTempString));
+ SysTryReturnResult(NID_SEC, pPrivilegeId != null, E_SYSTEM, "An unexpected system error occurred.");
+
+ ret = privilege_info_get_external_privilege_level(static_cast<char*>(pPrivilegeId.get()), &pPrivilegeLevel);
+ SysTryReturnResult(NID_SEC, ret == PRVMGR_ERR_NONE, E_SYSTEM, "An unexpected system error occurred.");
+
+ __privilegeList.Add((new String(*pTempString)), (new String(pPrivilegeLevel)));
}
return r;
r = cipherDec.Construct(L"CBC/128/PKCS7PADDING", CIPHER_DECRYPT);
SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "An unexpected system error occurred.");
- pKey.reset(_DeviceKeyGenerator::GenerateDeviceKeyN(_KEY_LEN));
+ pKey.reset(GetDeviceUniqueKeyN());
SysTryReturnResult(NID_SEC, pKey != null, E_SYSTEM, "An unexpected system error occurred.");
r = cipherDec.SetKey(*pKey.get());
__apiVisibility = visibility;
std::unique_ptr<IEnumerator> pEnum(null);
- r = __privilegeList.Construct();
+ r = __privilegeList.Construct(32, 0.75);
SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "An unexpected system error occurred.");
pEnum.reset(pPrivilegeList->GetEnumeratorN());
while (pEnum->MoveNext() == E_SUCCESS)
{
- String* tempString = static_cast< String* >(pEnum->GetCurrent());
- __privilegeList.Add(new String(*tempString));
+ int ret = PRVMGR_ERR_NONE;
+ char* pPrivilegeLevel = null;
+ std::unique_ptr<char[]> pPrivilegeId(null);
+ String* pTempString = static_cast< String* >(pEnum->GetCurrent());
+
+ pPrivilegeId.reset(_StringConverter::CopyToCharArrayN(*pTempString));
+ SysTryReturnResult(NID_SEC, pPrivilegeId != null, E_SYSTEM, "An unexpected system error occurred.");
+
+ ret = privilege_info_get_external_privilege_level(static_cast<char*>(pPrivilegeId.get()), &pPrivilegeLevel);
+ SysTryReturnResult(NID_SEC, ret == PRVMGR_ERR_NONE, E_SYSTEM, "An unexpected system error occurred.");
+
+ __privilegeList.Add((new String(*pTempString)), (new String(pPrivilegeLevel)));
}
return r;
pPrivilegeInfo->__appId.Append(this->__appId);
memcpy(pPrivilegeInfo->__bitwisePrivilege, this->__bitwisePrivilege, pPrivilegeInfo->__bitwiseLength);
- std::unique_ptr<IEnumerator> pEnum(null);
- r = pPrivilegeInfo->__privilegeList.Construct();
- SysTryReturn(NID_SEC, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred.");
+ std::unique_ptr<IMapEnumerator> pEnum(null);
+ pEnum.reset(this->__privilegeList.GetMapEnumeratorN());
+ SysTryCatch(NID_SEC, pEnum != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred.");
- pEnum.reset(this->__privilegeList.GetEnumeratorN());
- SysTryReturn(NID_SEC, pEnum != null, null, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred.");
+ r = pPrivilegeInfo->__privilegeList.Construct(32, 0.75);
+ SysTryCatch(NID_SEC, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred.");
while (pEnum->MoveNext() == E_SUCCESS)
{
- String* tempString = static_cast< String* >(pEnum->GetCurrent());
- pPrivilegeInfo->__privilegeList.Add(new String(*tempString));
+ String* pTempString = static_cast< String* >(pEnum->GetKey());
+ String* pTempLevel = static_cast< String* >(pEnum->GetValue());
+ pPrivilegeInfo->__privilegeList.Add((new String(*pTempString)), (new String(*pTempLevel)));
}
+ pPrivilegeInfo->__apiVisibility = this->__apiVisibility;
return pPrivilegeInfo;
+
+CATCH:
+
+ SetLastResult(r);
+
+ delete pPrivilegeInfo;
+ return null;
}
result
__apiVisibility = privilegeInfo.__apiVisibility;
- __privilegeList.Construct();
+ std::unique_ptr<IMapEnumerator> pEnum(null);
+ pEnum.reset(privilegeInfo.__privilegeList.GetMapEnumeratorN());
+ SysTryReturnResult(NID_SEC, pEnum != null, E_SYSTEM, "An unexpected system error occurred.");
+
+ r = __privilegeList.Construct(32, 0.75);
+ SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "An unexpected system error occurred.");
- IEnumerator* pEnum = privilegeInfo.__privilegeList.GetEnumeratorN();
while (pEnum->MoveNext() == E_SUCCESS)
{
- String* tempString = static_cast< String* >(pEnum->GetCurrent());
- __privilegeList.Add(new String(*tempString));
+ String* pTempString = static_cast< String* >(pEnum->GetKey());
+ String* pTempLevel = static_cast< String* >(pEnum->GetValue());
+ __privilegeList.Add((new String(*pTempString)), (new String(*pTempLevel)));
}
- delete pEnum;
return r;
}
r = cipherEnc.Construct(L"CBC/128/PKCS7PADDING", CIPHER_ENCRYPT);
SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "An unexpected system error occurred.");
- pKey.reset(_DeviceKeyGenerator::GenerateDeviceKeyN(_KEY_LEN));
+ pKey.reset(GetDeviceUniqueKeyN());
SysTryReturnResult(NID_SEC, pKey != null, E_SYSTEM, "An unexpected system error occurred.");
r = cipherEnc.SetKey(*(pKey.get()));
pHmac.reset(new (std::nothrow) Sha1Hmac());
SysTryReturnResult(NID_SEC, pHmac != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
- pKey.reset(_DeviceKeyGenerator::GenerateDeviceKeyN(_KEY_LEN));
+ pKey.reset(GetDeviceUniqueKeyN());
SysTryReturnResult(NID_SEC, pKey != null, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred.");
r = pHmac->SetKey(*(pKey.get()));
if (__apiVisibility != _API_VISIBILITY_NONE) // To be removed
{
- if (visibilityLevelListTable[privilege][_PRV_API_VER_2_0] > __apiVisibility)
+ if (visibilityLevelListTable[privilege] > __apiVisibility)
{
SysLog(NID_SEC, "Result : FALSE [Visibility]");
return ret;
if (__apiVisibility != _API_VISIBILITY_NONE) // To be removed
{
- if (visibilityLevelListTable[privilege][_PRV_API_VER_2_0] > __apiVisibility)
+ if (visibilityLevelListTable[privilege] > __apiVisibility)
{
return ret;
}
if (validStringFlag)
{
ret = HasPrivilege(privilegeListTable[index].privilege);
-
}
else
{
- ret = __privilegeList.Contains(privilege);
+ ret = __privilegeList.ContainsKey(privilege);
if (ret)
{
+ if (__apiVisibility != _API_VISIBILITY_NONE) // To be removed
+ {
+ const String* pPrivilegeLevel = static_cast< const String* >(__privilegeList.GetValue(privilege));
+ SysTryReturn(NID_SEC, pPrivilegeLevel != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred.");
+
+ int privilegeLevel = GetPrivilegeLevel(*pPrivilegeLevel);
+ if (privilegeLevel > __apiVisibility)
+ {
+ SysLog(NID_SEC, "Result : FALSE [Visibility]");
+ return false;
+ }
+ }
+
SysLog(NID_SEC, "Result : TRUE");
}
else
ByteBuffer input;
std::unique_ptr<IHash> pHash(null);
std::unique_ptr<ByteBuffer> pChecksumByteBuffer(null);
- std::unique_ptr<char> pAppId(null);
+ std::unique_ptr<char[]> pAppId(null);
SysTryReturnResult(NID_SEC, length <= MAX_BITWISE_PRIV_SIZE, E_INVALID_ARG, "The privilege information of %ls is invalid.", appId.GetPointer());
pHmac.reset(new (std::nothrow) Sha1Hmac());
SysTryReturnResult(NID_SEC, pHmac != null, E_OUT_OF_MEMORY, "Memory allocation is failed.");
- pKey.reset(_DeviceKeyGenerator::GenerateDeviceKeyN(_KEY_LEN));
+ pKey.reset(GetDeviceUniqueKeyN());
SysTryReturnResult(NID_SEC, pKey != null, E_SYSTEM, "An unexpected system error occurred.");
r = pHmac->SetKey(*(pKey.get()));
pHmac.reset(new (std::nothrow) Sha1Hmac());
SysTryReturnResult(NID_SEC, pHmac != null, E_OUT_OF_MEMORY, "Memory allocation is failed.");
- pKey.reset(_DeviceKeyGenerator::GenerateDeviceKeyN(_KEY_LEN));
+ pKey.reset(GetDeviceUniqueKeyN());
SysTryReturnResult(NID_SEC, pKey != null, E_SYSTEM, "An unexpected system error occurred.");
r = pHmac->SetKey(*(pKey.get()));
return r;
}
+ISecretKey*
+_PrivilegeInfo::GetDeviceUniqueKeyN(void)
+{
+ result r = E_SUCCESS;
+ ByteBuffer* pTempValue = null;
+ ISecretKey* pKey = null;
+
+ char uniqueInfo[_INFO_LEN] =
+ {
+ 0x09, 0x25, 0x19, 0x87, 0xBF, 0x02, 0x14, 0x19,
+ 0x88, 0xDD, 0x12, 0x30, 0x19, 0x86, 0xAD, 0xED
+ };
+
+ char* pUniqueKey = null;
+ pUniqueKey = GetDeviceUniqueKey(uniqueInfo, _INFO_LEN, _KEY_LEN);
+ SysTryCatch(NID_SEC, pUniqueKey != null, , E_SYSTEM, "[E_SYSTEM] Failed to generate the unique key.");
+
+ pTempValue = new (std::nothrow) ByteBuffer();
+ SysTryCatch(NID_SEC, pTempValue != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
+
+ r = pTempValue->Construct(_KEY_LEN);
+ SysTryCatch(NID_SEC, r == E_SUCCESS, , r, "[%s] Failed to generate device unique key.", GetErrorMessage(r));
+
+ r = pTempValue->SetArray(reinterpret_cast <byte*>(pUniqueKey), 0, _KEY_LEN);
+ SysTryCatch(NID_SEC, r == E_SUCCESS, , r, "[%s] Failed to generate device unique key.", GetErrorMessage(r));
+
+ pTempValue->Flip();
+
+ pKey = new (std::nothrow) SecretKey();
+ SysTryCatch(NID_SEC, pKey != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
+
+ r = pKey->SetKey(*pTempValue);
+ SysTryCatch(NID_SEC, r == E_SUCCESS, , r, "[%s] Failed to generate device unique key.", GetErrorMessage(r));
+
+ if (pUniqueKey != null)
+ {
+ free(pUniqueKey);
+ }
+ delete pTempValue;
+
+ return pKey;
+
+CATCH:
+ if (pUniqueKey != null)
+ {
+ free(pUniqueKey);
+ }
+ delete pTempValue;
+ delete pKey;
+
+ return null;
+}
+
+int
+_PrivilegeInfo::GetPrivilegeLevel(const String& privilegeLevel)
+{
+ if(privilegeLevel.Equals(String(L"platform"), true))
+ {
+ return _API_VISIBILITY_PLATFORM;
+ }
+ else if(privilegeLevel.Equals(String(L"partner"), true))
+ {
+ return _API_VISIBILITY_PARTNER;
+ }
+
+ return _API_VISIBILITY_PUBLIC;
+}
+
}} //Tizen::Security