############################# 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
SET_TARGET_PROPERTIES(${TARGET_WEBAPPENC} PROPERTIES
SOVERSION ${SO_VERSION}
VERSION ${VERSION}
+ COMPILE_FLAGS "-D_GNU_SOURCE"
)
TARGET_LINK_LIBRARIES(${TARGET_WEBAPPENC}
* @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>
#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;
}
}
/*
- * 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.
* @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
#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,
#ifdef __cplusplus
}
#endif
-#endif /* __TIZEN_CORE_WAE_CRYPTO_SERVICE_H */
+#endif /* __TIZEN_CORE_WAE_CRYPTO_SERVICE_H */
/*
- * 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.
* @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];
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);
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));
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) {
return ret;
}
-int load_preloaded_app_deks(int reload)
+int load_preloaded_app_deks(bool reload)
{
int ret = WAE_ERROR_NONE;
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) {
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) {
/*
- * 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.
* @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
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();
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 */
#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);
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;
}
// 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;
_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);