summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyungwook Tak <k.tak@samsung.com>2016-07-15 11:52:13 +0900
committerKyungwook Tak <k.tak@samsung.com>2016-07-15 11:53:01 +0900
commit4ea2f0ebe530415109e408cb96f81cc0a0b6b3f7 (patch)
tree4308c9fd81955e079567979dc4c3a8f48f032c12
parent6f18da83631e06509b2f14a729c7b6ac05aa4046 (diff)
downloadlibwebappenc-4ea2f0ebe530415109e408cb96f81cc0a0b6b3f7.tar.gz
libwebappenc-4ea2f0ebe530415109e408cb96f81cc0a0b6b3f7.tar.bz2
libwebappenc-4ea2f0ebe530415109e408cb96f81cc0a0b6b3f7.zip
Use stdbool instead of macro for boolean
Change-Id: I6d95a582cd8d2ec52adb314a167bd42dd386ac0b Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
-rw-r--r--CMakeLists.txt8
-rw-r--r--srcs/CMakeLists.txt1
-rw-r--r--srcs/crypto_service.c11
-rw-r--r--srcs/crypto_service.h12
-rw-r--r--srcs/key_handler.c36
-rw-r--r--srcs/key_handler.h33
-rw-r--r--srcs/wae_initializer.c5
-rw-r--r--tests/wae_tests.c12
8 files changed, 54 insertions, 64 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c9fec0e..31e000b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -31,13 +31,13 @@ INCLUDE(FindPkgConfig)
############################# compiler flags ##################################
-SET(CMAKE_C_FLAGS_PROFILING "-g -O0 -pg -Wp,-U_FORTIFY_SOURCE")
+SET(CMAKE_C_FLAGS_PROFILING "-g -std=c99 -O0 -pg -Wp,-U_FORTIFY_SOURCE")
SET(CMAKE_CXX_FLAGS_PROFILING "-g -std=c++0x -O0 -pg -Wp,-U_FORTIFY_SOURCE")
-SET(CMAKE_C_FLAGS_DEBUG "-g -O0 -ggdb -Wp,-U_FORTIFY_SOURCE")
+SET(CMAKE_C_FLAGS_DEBUG "-g -std=c99 -O0 -ggdb -Wp,-U_FORTIFY_SOURCE")
SET(CMAKE_CXX_FLAGS_DEBUG "-g -std=c++0x -O0 -ggdb -Wp,-U_FORTIFY_SOURCE")
-SET(CMAKE_C_FLAGS_RELEASE "-g -O2")
+SET(CMAKE_C_FLAGS_RELEASE "-g -std=c99 -O2")
SET(CMAKE_CXX_FLAGS_RELEASE "-g -std=c++0x -O2")
-SET(CMAKE_C_FLAGS_CCOV "-g -O2 --coverage")
+SET(CMAKE_C_FLAGS_CCOV "-g -std=c99 -O2 --coverage")
SET(CMAKE_CXX_FLAGS_CCOV "-g -std=c++0x -O2 --coverage")
# If supported for the target machine, emit position-independent code,suitable
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 <stdbool.h>
#include <openssl/evp.h>
#include <openssl/rand.h>
#include <openssl/crypto.h>
@@ -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 <stddef.h>
-
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <unistd.h>
+
#include <ckmc/ckmc-manager.h>
+#include <tzplatform_config.h>
+
#include "wae_log.h"
#include "web_app_enc.h"
-#include "key_handler.h"
#include "crypto_service.h"
-#include <tzplatform_config.h>
-
+#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 <stdbool.h>
#include <stddef.h>
#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 <stdio.h>
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);
diff --git a/tests/wae_tests.c b/tests/wae_tests.c
index a40b301..abaf4aa 100644
--- a/tests/wae_tests.c
+++ b/tests/wae_tests.c
@@ -336,16 +336,16 @@ int wae_tc_get_alias()
const char* pkgId = "TEST_PKG_ID";
char alias[256] = {0, };
- _get_alias(pkgId, WAE_DOWNLOADED_NORMAL_APP, WAE_TRUE, alias, sizeof(alias));
+ _get_alias(pkgId, WAE_DOWNLOADED_NORMAL_APP, true, alias, sizeof(alias));
FPRINTF("...pkgid=%s, alias for normal for save. app=%s\n", pkgId, alias);
- _get_alias(pkgId, WAE_DOWNLOADED_NORMAL_APP, WAE_FALSE, alias, sizeof(alias));
+ _get_alias(pkgId, WAE_DOWNLOADED_NORMAL_APP, false, alias, sizeof(alias));
FPRINTF("...pkgid=%s, alias for normal for get. app=%s\n", pkgId, alias);
- _get_alias(pkgId, WAE_DOWNLOADED_GLOBAL_APP, WAE_TRUE, alias, sizeof(alias));
+ _get_alias(pkgId, WAE_DOWNLOADED_GLOBAL_APP, true, alias, sizeof(alias));
FPRINTF("...pkgid=%s, alias for global app=%s\n", pkgId, alias);
- _get_alias(pkgId, WAE_PRELOADED_APP, WAE_TRUE, alias, sizeof(alias));
+ _get_alias(pkgId, WAE_PRELOADED_APP, true, alias, sizeof(alias));
FPRINTF("...pkgid=%s, alias for preloaded app=%s\n", pkgId, alias);
return ret;
@@ -644,7 +644,7 @@ int wae_tc_load_preloaded_app_deks()
}
// load_preloaded_app_deks
- ret = load_preloaded_app_deks(WAE_TRUE);
+ ret = load_preloaded_app_deks(true);
if(ret != WAE_ERROR_NONE) {
FPRINTF("...FAIL: load_preloaded_app_deks. ret=%d\n", ret);
goto error;
@@ -752,7 +752,7 @@ int _wae_tc_encrypt_decrypt_web_app(wae_app_type_e appType)
_remove_app_dek_from_cache(pkgId);
if(appType == WAE_PRELOADED_APP) {
- load_preloaded_app_deks(WAE_TRUE);
+ load_preloaded_app_deks(true);
}
ret = wae_decrypt_web_application(pkgId, appType, encrypted, encLen, &decrypted, &decLen);