From 4ea2f0ebe530415109e408cb96f81cc0a0b6b3f7 Mon Sep 17 00:00:00 2001 From: Kyungwook Tak Date: Fri, 15 Jul 2016 11:52:13 +0900 Subject: Use stdbool instead of macro for boolean Change-Id: I6d95a582cd8d2ec52adb314a167bd42dd386ac0b Signed-off-by: Kyungwook Tak --- srcs/CMakeLists.txt | 1 + srcs/crypto_service.c | 11 +++++------ srcs/crypto_service.h | 12 ++++-------- srcs/key_handler.c | 36 +++++++++++++++++++++++------------- srcs/key_handler.h | 33 ++++++++------------------------- srcs/wae_initializer.c | 5 +++-- 6 files changed, 44 insertions(+), 54 deletions(-) (limited to 'srcs') diff --git a/srcs/CMakeLists.txt b/srcs/CMakeLists.txt index e94a7d4..9eb766c 100644 --- a/srcs/CMakeLists.txt +++ b/srcs/CMakeLists.txt @@ -18,6 +18,7 @@ ADD_LIBRARY(${TARGET_WEBAPPENC} SHARED ${WEB_APP_ENC_SOURCES}) SET_TARGET_PROPERTIES(${TARGET_WEBAPPENC} PROPERTIES SOVERSION ${SO_VERSION} VERSION ${VERSION} + COMPILE_FLAGS "-D_GNU_SOURCE" ) TARGET_LINK_LIBRARIES(${TARGET_WEBAPPENC} diff --git a/srcs/crypto_service.c b/srcs/crypto_service.c index eb1fc20..1c52cc5 100644 --- a/srcs/crypto_service.c +++ b/srcs/crypto_service.c @@ -19,7 +19,9 @@ * @version 1.0 * @brief provides encryption and decription operations. */ +#include "crypto_service.h" +#include #include #include #include @@ -34,20 +36,17 @@ #define AES_256_KEY_SIZE 32 -#define WAE_FALSE 0 -#define WAE_TRUE 1 - static unsigned char AES_CBC_IV[16] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x08, 0x39, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}; -static int __initialized = WAE_FALSE; +static bool __initialized = false; void _initialize() { - if(__initialized != WAE_TRUE) { + if(!__initialized) { ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); - __initialized = WAE_TRUE; + __initialized = true; } } diff --git a/srcs/crypto_service.h b/srcs/crypto_service.h index c49c34b..fcdb0fe 100644 --- a/srcs/crypto_service.h +++ b/srcs/crypto_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016 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. @@ -17,11 +17,8 @@ * @file crypto_service.h * @author Dongsun Lee (ds73.lee@samsung.com) * @version 1.0 - * @brief a header for key manupulatation. + * @brief provides encryption and decription operations. */ - - - #ifndef __TIZEN_CORE_WAE_CRYPTO_SERVICE_H #define __TIZEN_CORE_WAE_CRYPTO_SERVICE_H @@ -31,9 +28,8 @@ extern "C" { #include - int encrypt_app_dek(const unsigned char* rsaPublicKey, size_t pubKeyLen, - const unsigned char* dek, const int dekLen, + const unsigned char* dek, size_t dekLen, unsigned char** encryptedDek, size_t* encryptedDekLen); int decrypt_app_dek(const unsigned char* rsaPrivateKey, size_t priKeyLen, @@ -53,5 +49,5 @@ int decrypt_aes_cbc(const unsigned char* pKey, size_t keyLen, #ifdef __cplusplus } #endif -#endif /* __TIZEN_CORE_WAE_CRYPTO_SERVICE_H */ +#endif /* __TIZEN_CORE_WAE_CRYPTO_SERVICE_H */ diff --git a/srcs/key_handler.c b/srcs/key_handler.c index 714be0f..bf98c5d 100644 --- a/srcs/key_handler.c +++ b/srcs/key_handler.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016 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. @@ -17,25 +17,35 @@ * @file key_handler.c * @author Dongsun Lee (ds73.lee@samsung.com) * @version 1.0 - * @brief a header for key manupulatation. + * @brief Key manupulatation. */ +#include "key_handler.h" #include #include #include #include #include + #include +#include + #include "wae_log.h" #include "web_app_enc.h" -#include "key_handler.h" #include "crypto_service.h" -#include - +#define RANDOM_FILE "/dev/urandom" +#define WRT_INSTALLER_LABEL "/User" #define APP_DEK_KEK_PRIKEY_PASSWORD "wae_appdek_kek_1q2w3e4r" +#define APP_DEK_ALIAS_PFX "APP_DEK_" +#define APP_DEK_LOADING_DONE_ALIAS "APP_DEKS_LOADING_FINISHED" +#define APP_DEK_FILE_PFX "WAE_APP_DEK" +#define APP_DEK_KEK_ALIAS "WAE_APP_DEK_KEK" -#define WRT_INSTALLER_LABEL "/User" +#define DEK_LEN 32 +#define MAX_ALIAS_LEN 256 +#define MAX_PKGID_LEN 256 +#define MAX_CACHE_SIZE 100 typedef struct _dek_cache_element{ char pkgId[MAX_PKGID_LEN]; @@ -139,10 +149,10 @@ int _get_random(size_t length, unsigned char* random) return WAE_ERROR_NONE; } -void _get_alias(const char* pPkgId, wae_app_type_e appType, int forSave, char* alias, size_t buff_len) +void _get_alias(const char* pPkgId, wae_app_type_e appType, bool forSave, char* alias, size_t buff_len) { if(appType == WAE_DOWNLOADED_NORMAL_APP) { - if(forSave == WAE_TRUE) { + if(forSave) { snprintf(alias, buff_len, "%s%s", APP_DEK_ALIAS_PFX, pPkgId); @@ -208,7 +218,7 @@ int _add_dek_to_key_manager(const char* pPkgId, wae_app_type_e appType, const un policy.extractable = true; // save app_dek in key_manager - _get_alias(pPkgId, appType, WAE_TRUE, alias, sizeof(alias)); + _get_alias(pPkgId, appType, true, alias, sizeof(alias)); // even if it fails to remove, ignore it. ret = _to_wae_error( ckmc_remove_alias(alias)); @@ -367,7 +377,7 @@ int get_app_dek(const char* pPkgId, wae_app_type_e appType, unsigned char** ppDe cached_dek = _get_app_dek_from_cache(pPkgId); if(cached_dek == NULL) { // get APP_DEK from system database - _get_alias(pPkgId, appType, WAE_FALSE, alias, sizeof(alias)); + _get_alias(pPkgId, appType, false, alias, sizeof(alias)); ret = _to_wae_error(ckmc_get_data(alias, password, &pDekBuffer)); if(ret != WAE_ERROR_NONE) { @@ -641,7 +651,7 @@ int _clear_app_deks_loaded() return ret; } -int load_preloaded_app_deks(int reload) +int load_preloaded_app_deks(bool reload) { int ret = WAE_ERROR_NONE; @@ -661,7 +671,7 @@ int load_preloaded_app_deks(int reload) int error_during_loading = 0; - if(reload != WAE_TRUE) { + if(!reload) { // check if all deks were already loaded into key-manager. ret = _get_app_deks_loaded(); if(ret == WAE_ERROR_NONE) { @@ -765,7 +775,7 @@ int remove_app_dek(const char* pPkgId, wae_app_type_e appType) int ret = CKMC_ERROR_NONE; char alias[MAX_ALIAS_LEN] = {0,}; - _get_alias(pPkgId, appType, WAE_TRUE, alias,sizeof(alias)); + _get_alias(pPkgId, appType, true, alias,sizeof(alias)); ret = _to_wae_error(ckmc_remove_alias(alias)); if(ret != WAE_ERROR_NONE) { diff --git a/srcs/key_handler.h b/srcs/key_handler.h index a417fdd..2d3af65 100644 --- a/srcs/key_handler.h +++ b/srcs/key_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016 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. @@ -17,11 +17,8 @@ * @file key_handler.h * @author Dongsun Lee (ds73.lee@samsung.com) * @version 1.0 - * @brief a header for key manupulatation. + * @brief Key manupulatation. */ - - - #ifndef __TIZEN_CORE_WAE_KEY_HANDLER_H #define __TIZEN_CORE_WAE_KEY_HANDLER_H @@ -29,32 +26,19 @@ extern "C" { #endif +#include #include #include "web_app_enc.h" -#define APP_DEK_ALIAS_PFX "APP_DEK_" -#define APP_DEK_LOADING_DONE_ALIAS "APP_DEKS_LOADING_FINISHED" - -#define DEK_LEN 32 -#define MAX_ALIAS_LEN 256 -#define MAX_PKGID_LEN 256 #define MAX_PATH_LEN 512 -#define MAX_CACHE_SIZE 100 - - -#define RANDOM_FILE "/dev/urandom" -#define APP_DEK_FILE_PFX "WAE_APP_DEK" -#define APP_DEK_KEK_ALIAS "WAE_APP_DEK_KEK" - -#define WAE_TRUE 1 -#define WAE_FALSE 0 +/* functions with "_" prefix are internal static functions but declared here for testing */ void _initialize_cache(); unsigned char* _get_app_dek_from_cache(const char* pkgId); void _add_app_dek_to_cache(const char* pkgId, unsigned char* dek); void _remove_app_dek_from_cache(const char* pkgId); int _get_random(size_t length, unsigned char* random); -void _get_alias(const char* pPkgId, wae_app_type_e appType, int forSave, char* alias, size_t buff_len); +void _get_alias(const char* pPkgId, wae_app_type_e appType, bool forSave, char* alias, size_t buff_len); void _get_dek_kek_alias(char* alias, size_t buff_len); void _get_dek_loading_done_alias(char* alias, size_t buff_len); const char* _get_dek_kek_pub_key_path(); @@ -67,21 +51,20 @@ int _read_encrypted_app_dek_from_file(const char* pPkgId, unsigned char** encryp int _write_encrypted_app_dek_to_file(const char* pPkgId, const unsigned char* encrypted_app_dek, size_t len); int _read_from_file(const char* path, unsigned char** data, size_t* len); int _write_to_file(const char* path, const unsigned char* data, size_t len); -int _get_app_dek_kek_from_key_manager(unsigned char** ppDekKek, size_t* kekLen); int _get_app_deks_loaded(); int _set_app_deks_loaded(); int _clear_app_deks_loaded(); +/* functions for interface */ int get_app_dek(const char* pPkgId, wae_app_type_e appType, unsigned char** ppDek, size_t *dekLen); int create_app_dek(const char* pPkgId, wae_app_type_e appType, unsigned char** ppDek, size_t *dekLen); int get_preloaded_app_dek(const char* pPkgId, unsigned char** ppDek, size_t* dekLen); int create_preloaded_app_dek(const char* pPkgId, unsigned char** ppDek, size_t *dekLen); -int load_preloaded_app_deks(int reload); +int load_preloaded_app_deks(bool reload); int remove_app_dek(const char* pPkgId, wae_app_type_e appType); - #ifdef __cplusplus } #endif -#endif /* __TIZEN_CORE_WAE_KEY_HANDLER_H */ +#endif /* __TIZEN_CORE_WAE_KEY_HANDLER_H */ diff --git a/srcs/wae_initializer.c b/srcs/wae_initializer.c index 011c8a0..4022f48 100644 --- a/srcs/wae_initializer.c +++ b/srcs/wae_initializer.c @@ -23,15 +23,16 @@ #include "key_handler.h" #include "web_app_enc.h" #include "wae_log.h" + #include int main(int argc, char* argv[]) { int ret = WAE_ERROR_NONE; - int reload = WAE_FALSE; + bool reload = false; if(argc == 2 && strcmp(argv[1], "--reload")==0) { - reload = WAE_TRUE; + reload = true; } ret = load_preloaded_app_deks(reload); -- cgit v1.2.3