summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDongsun Lee <ds73.lee@samsung.com>2015-08-13 07:35:58 (GMT)
committerDongsun Lee <ds73.lee@samsung.com>2015-08-13 07:39:51 (GMT)
commit671aefceb8f5249194c2abfc1bdeddb7d16a7631 (patch)
tree46f5e1e555980a34bfb5eade99257886416a7fcc
parent391c9b75f18989c2778c0cc804a4eddb38a3f050 (diff)
downloadlibwebappenc-accepted/tizen/tv/20150820.115853.zip
libwebappenc-accepted/tizen/tv/20150820.115853.tar.gz
libwebappenc-accepted/tizen/tv/20150820.115853.tar.bz2
Change-Id: Ic9a60b295bff13bb59c1c6990dfbad569e92c267 Signed-off-by: Dongsun Lee <ds73.lee@samsung.com>
-rw-r--r--include/web_app_enc.h26
-rw-r--r--srcs/key_handler.c32
-rw-r--r--srcs/key_handler.h11
-rw-r--r--srcs/web_app_enc.c49
-rw-r--r--tests/wae_tests.c235
5 files changed, 213 insertions, 140 deletions
diff --git a/include/web_app_enc.h b/include/web_app_enc.h
index 2e31a3c..68a1fd9 100644
--- a/include/web_app_enc.h
+++ b/include/web_app_enc.h
@@ -31,6 +31,10 @@ extern "C" {
*/
+/**
+ * @brief WAE Errors.
+ * @since_tizen 3.0
+ */
typedef enum
{
WAE_ERROR_NONE = 0x00, /**< Successful */
@@ -46,11 +50,22 @@ typedef enum
} wae_error_e;
/**
+ * @brief Application Type.
+ * @since_tizen 3.0
+ */
+typedef enum
+{
+ WAE_DOWNLOADED_NORMAL_APP = 0, /**< Downloaded Normal Application*/
+ WAE_DOWNLOADED_GLOBAL_APP = 1, /**< Downloaded Global Application*/
+ WAE_PRELOADED_APP = 2 /**< Preloaded Application*/
+} wae_app_type_e;
+
+/**
* @brief Encrypts web application data with internal key(APP DEK: Application Data Encryption Key).
*
* @since_tizen 3.0
* @param[in] pPkgId The package id of an application.
- * @param[in] isPreloaded True(!=0) if the application is preloaded, otherwise false(==0).
+ * @param[in] appType The application type.
* @param[in] pData The data block to be encrypted.
* @param[in] dataLen The length of the data block.
* @param[out] ppEncryptedData The data block contaning encrypted data block. Memory allocated for ppEncryptedData. Has to be freed by free() function.
@@ -66,14 +81,14 @@ typedef enum
*
* @see wae_decrypt_web_application()
*/
-int wae_encrypt_web_application(const char* pPkgId, int isPreloaded, const unsigned char* pData, size_t dataLen, unsigned char** ppEncryptedData, size_t* pEncDataLen);
+int wae_encrypt_web_application(const char* pPkgId, wae_app_type_e appType, const unsigned char* pData, size_t dataLen, unsigned char** ppEncryptedData, size_t* pEncDataLen);
/**
* @brief Encrypts web application data with internal key.
*
* @since_tizen 3.0
* @param[in] pPkgId The package id of an application.
- * @param[in] isPreloaded True(!=0) if the application is preloaded, otherwise false(==0).
+ * @param[in] appType The application type.
* @param[in] pData The data block to be decrypted.
* @param[in] dataLen The length of the data block.
* @param[out] ppDecryptedData Data block contaning decrypted data block. Memory allocated for ppEncryptedData. Has to be freed by free() function.
@@ -89,13 +104,14 @@ int wae_encrypt_web_application(const char* pPkgId, int isPreloaded, const unsig
*
* @see wae_encrypt_web_application()
*/
-int wae_decrypt_web_application(const char* pPkgId, int isPreloaded, const unsigned char* pData, size_t dataLen, unsigned char** ppDecryptedData, size_t* pDecDataLen);
+int wae_decrypt_web_application(const char* pPkgId, wae_app_type_e appType, const unsigned char* pData, size_t dataLen, unsigned char** ppDecryptedData, size_t* pDecDataLen);
/**
* @brief Remove a APP DEK(Application Data Encryption Key) used for encrytpion and decryption of a web application.
*
* @since_tizen 3.0
* @param[in] pPkgId The package id of an application.
+ * @param[in] appType The application type.
*
* @return #WAE_ERROR_NONE on success, otherwise a negative error value
* @retval #WAE_ERROR_INVALID_PARAMETER Invalid input parameter
@@ -105,7 +121,7 @@ int wae_decrypt_web_application(const char* pPkgId, int isPreloaded, const unsig
* @retval #WAE_ERROR_UNKNOWN Failed with unknown reason
*
*/
-int wae_remove_app_dek(const char* pPkgId);
+int wae_remove_app_dek(const char* pPkgId, wae_app_type_e appType);
/**
diff --git a/srcs/key_handler.c b/srcs/key_handler.c
index 4ec4e5c..304d94b 100644
--- a/srcs/key_handler.c
+++ b/srcs/key_handler.c
@@ -138,13 +138,19 @@ int _get_random(size_t length, unsigned char* random)
return WAE_ERROR_NONE;
}
-void _get_alias(const char* pPkgId, char* alias, size_t buff_len)
+void _get_alias(const char* pPkgId, wae_app_type_e appType, char* alias, size_t buff_len)
{
- snprintf(alias, buff_len, "%s%s%s%s",
+ if(appType == WAE_DOWNLOADED_NORMAL_APP) {
+ snprintf(alias, buff_len, "%s%s",
+ APP_DEK_ALIAS_PFX,
+ pPkgId);
+ }else { // system alias
+ snprintf(alias, buff_len, "%s%s%s%s",
ckmc_label_shared_owner,
ckmc_label_name_separator,
APP_DEK_ALIAS_PFX,
pPkgId);
+ }
}
void _get_dek_kek_alias(char* alias, size_t buff_len)
@@ -178,7 +184,7 @@ const char* _get_dek_store_path()
return tzplatform_mkpath3(TZ_SYS_SHARE, "wae", "app_dek");
}
-int _add_dek_to_key_manager(const char* pPkgId, const unsigned char* pDek, size_t len)
+int _add_dek_to_key_manager(const char* pPkgId, wae_app_type_e appType, const unsigned char* pDek, size_t len)
{
int ret = WAE_ERROR_NONE;
char alias[MAX_ALIAS_LEN] = {0,};
@@ -192,14 +198,14 @@ int _add_dek_to_key_manager(const char* pPkgId, const unsigned char* pDek, size_
policy.extractable = true;
// save app_dek in key_manager
- _get_alias(pPkgId, alias, sizeof(alias));
+ _get_alias(pPkgId, appType, alias, sizeof(alias));
// even if it fails to remove, ignore it.
ret = _to_wae_error( ckmc_remove_alias(alias));
ret = _to_wae_error(ckmc_save_data(alias, buff, policy));
if(ret != WAE_ERROR_NONE) {
- WAE_SLOGE("Fail to add APP_DEK to key-manager. pkgId=%s, ret=%d", pPkgId, ret);
+ WAE_SLOGE("Fail to add APP_DEK to key-manager. pkgId=%s, alias=%s, ret=%d", pPkgId, alias, ret);
goto error;
}
@@ -324,7 +330,7 @@ error:
return ret;
}
-int get_app_dek(const char* pPkgId, unsigned char** ppDek, size_t* dekLen)
+int get_app_dek(const char* pPkgId, wae_app_type_e appType, unsigned char** ppDek, size_t* dekLen)
{
int ret = WAE_ERROR_NONE;
@@ -338,11 +344,11 @@ int get_app_dek(const char* pPkgId, unsigned char** ppDek, size_t* dekLen)
cached_dek = _get_app_dek_from_cache(pPkgId);
if(cached_dek == NULL) {
// get APP_DEK from system database
- _get_alias(pPkgId, alias, sizeof(alias));
+ _get_alias(pPkgId, appType, alias, sizeof(alias));
ret = _to_wae_error(ckmc_get_data(alias, password, &pDekBuffer));
if(ret != WAE_ERROR_NONE) {
- WAE_SLOGE("Fail to get APP_DEK from key-manager. alias=%s, ret=%d", alias, ret);
+ WAE_SLOGI("Fail to get APP_DEK from key-manager. alias=%s, ret=%d", alias, ret);
goto error;
}
}
@@ -367,7 +373,7 @@ error:
return ret;
}
-int create_app_dek(const char* pPkgId, 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 ret = WAE_ERROR_NONE;
unsigned char *dek= NULL;
@@ -385,7 +391,7 @@ int create_app_dek(const char* pPkgId, unsigned char** ppDek, size_t* dekLen)
}
// save app_dek in key_manager
- ret = _add_dek_to_key_manager(pPkgId, dek, DEK_LEN);
+ ret = _add_dek_to_key_manager(pPkgId, appType, dek, DEK_LEN);
if(ret != WAE_ERROR_NONE) {
goto error;
}
@@ -691,7 +697,7 @@ int load_preloaded_app_deks(int reload)
}
// save app_dek in key_manager
- ret = _add_dek_to_key_manager(pkgId, app_dek, app_dek_len);
+ ret = _add_dek_to_key_manager(pkgId, WAE_PRELOADED_APP, app_dek, app_dek_len);
// free temp objects
free(app_dek);
free(encrypted_app_dek);
@@ -724,12 +730,12 @@ error:
}
-int remove_app_dek(const char* pPkgId)
+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, alias,sizeof(alias));
+ _get_alias(pPkgId, appType, 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 c855241..c786964 100644
--- a/srcs/key_handler.h
+++ b/srcs/key_handler.h
@@ -30,6 +30,7 @@ extern "C" {
#endif
#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"
@@ -53,13 +54,13 @@ 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, char* alias, size_t buff_len);
+void _get_alias(const char* pPkgId, wae_app_type_e appType, 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();
const char* _get_dek_kek_pri_key_path();
const char* _get_dek_store_path();
-int _add_dek_to_key_manager(const char* pPkgId, const unsigned char* pDek, size_t len);
+int _add_dek_to_key_manager(const char* pPkgId, wae_app_type_e appType, const unsigned char* pDek, size_t len);
int _get_preloaded_app_dek_file_path(const char* pPkgId, char *path);
int _extract_pkg_id_from_file_name(const char* fileName, char* pkgId);
int _read_encrypted_app_dek_from_file(const char* pPkgId, unsigned char** encrypted_app_dek, size_t*len);
@@ -71,12 +72,12 @@ int _get_app_deks_loaded();
int _set_app_deks_loaded();
int _clear_app_deks_loaded();
-int get_app_dek(const char* pPkgId, unsigned char** ppDek, size_t *dekLen);
-int create_app_dek(const char* pPkgId, unsigned char** ppDek, size_t *dekLen);
+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 remove_app_dek(const char* pPkgId);
+int remove_app_dek(const char* pPkgId, wae_app_type_e appType);
#ifdef __cplusplus
diff --git a/srcs/web_app_enc.c b/srcs/web_app_enc.c
index 7bc8484..39865bc 100644
--- a/srcs/web_app_enc.c
+++ b/srcs/web_app_enc.c
@@ -29,7 +29,7 @@
#include "wae_log.h"
-int _wae_encrypt_downloaded_web_application(const char* pPkgId,
+int _wae_encrypt_downloaded_web_application(const char* pPkgId, wae_app_type_e appType,
const unsigned char* pData, size_t dataLen,
unsigned char** ppEncryptedData, size_t* pEncDataLen)
{
@@ -55,9 +55,9 @@ int _wae_encrypt_downloaded_web_application(const char* pPkgId,
// get APP_DEK.
// if not exists, create APP_DEK
- ret = get_app_dek(pPkgId, &pDek, &dekLen);
+ ret = get_app_dek(pPkgId, appType, &pDek, &dekLen);
if(ret == WAE_ERROR_NO_KEY) {
- ret = create_app_dek(pPkgId, &pDek, &dekLen);
+ ret = create_app_dek(pPkgId, appType, &pDek, &dekLen);
}
if(ret != WAE_ERROR_NONE) {
goto error;
@@ -76,7 +76,7 @@ error:
return ret;
}
-int _wae_decrypt_downloaded_web_application(const char* pPkgId,
+int _wae_decrypt_downloaded_web_application(const char* pPkgId, wae_app_type_e appType,
const unsigned char* pData, size_t dataLen,
unsigned char** ppDecryptedData, size_t* pDecDataLen)
{
@@ -100,7 +100,7 @@ int _wae_decrypt_downloaded_web_application(const char* pPkgId,
goto error;
}
- ret = get_app_dek(pPkgId, &pDek, &dekLen);
+ ret = get_app_dek(pPkgId, appType, &pDek, &dekLen);
if(ret != WAE_ERROR_NONE) {
goto error;
}
@@ -163,51 +163,56 @@ error:
return ret;
}
-int _wae_decrypt_preloaded_web_application(const char* pPkgId,
+int _wae_decrypt_preloaded_web_application(const char* pPkgId, wae_app_type_e appType,
const unsigned char* pData, size_t dataLen,
unsigned char** ppDecryptedData, size_t* pDecDataLen)
{
// same with the decryption of downloaded web application
- return _wae_decrypt_downloaded_web_application(pPkgId, pData, dataLen, ppDecryptedData, pDecDataLen);
+ return _wae_decrypt_downloaded_web_application(pPkgId, appType,
+ pData, dataLen, ppDecryptedData, pDecDataLen);
}
-int wae_encrypt_web_application(const char* pPkgId,int isPreloaded,
+int wae_encrypt_web_application(const char* pPkgId, wae_app_type_e appType,
const unsigned char* pData, size_t dataLen,
unsigned char** ppEncryptedData, size_t* pEncDataLen)
{
int ret = WAE_ERROR_NONE;
- if(isPreloaded)
- ret = _wae_encrypt_preloaded_web_application(pPkgId, pData, dataLen, ppEncryptedData, pEncDataLen);
+ if(appType == WAE_PRELOADED_APP)
+ ret = _wae_encrypt_preloaded_web_application(pPkgId,
+ pData, dataLen, ppEncryptedData, pEncDataLen);
else
- ret = _wae_encrypt_downloaded_web_application(pPkgId, pData, dataLen, ppEncryptedData, pEncDataLen);
+ ret = _wae_encrypt_downloaded_web_application(pPkgId, appType,
+ pData, dataLen, ppEncryptedData, pEncDataLen);
- WAE_SLOGI("Encrypt Web App. pkgId=%s, isPreloaded=%d, dataLen=%d, ret=%d",
- pPkgId, isPreloaded, dataLen, ret);
+ WAE_SLOGI("Encrypt Web App. pkgId=%s, appType=%d, dataLen=%d, ret=%d",
+ pPkgId, appType, dataLen, ret);
return ret;
}
-int wae_decrypt_web_application(const char* pPkgId, int isPreloaded,
+int wae_decrypt_web_application(const char* pPkgId, wae_app_type_e appType,
const unsigned char* pData, size_t dataLen,
unsigned char** ppDecryptedData, size_t* pDecDataLen)
{
int ret = WAE_ERROR_NONE;
- if(isPreloaded)
- ret = _wae_decrypt_preloaded_web_application(pPkgId, pData, dataLen, ppDecryptedData, pDecDataLen);
+ if(appType == WAE_PRELOADED_APP)
+ ret = _wae_decrypt_preloaded_web_application(pPkgId, appType,
+ pData, dataLen, ppDecryptedData, pDecDataLen);
else
- ret =_wae_decrypt_downloaded_web_application(pPkgId, pData, dataLen, ppDecryptedData, pDecDataLen);
+ ret = _wae_decrypt_downloaded_web_application(pPkgId, appType,
+ pData, dataLen, ppDecryptedData, pDecDataLen);
- WAE_SLOGI("Decrypt Web App. pkgId=%s, isPreloaded=%d, dataLen=%d, ret=%d",
- pPkgId, isPreloaded, dataLen, ret);
+ WAE_SLOGI("Decrypt Web App. pkgId=%s, appType=%d, dataLen=%d, ret=%d",
+ pPkgId, appType, dataLen, ret);
return ret;
}
-int wae_remove_app_dek(const char* pPkgId)
+int wae_remove_app_dek(const char* pPkgId, wae_app_type_e appType)
{
int ret = WAE_ERROR_NONE;
- ret = remove_app_dek(pPkgId);
- WAE_SLOGI("Remove APP DEK. pkgId=%s, ret=%d", pPkgId, ret);
+ ret = remove_app_dek(pPkgId, appType);
+ WAE_SLOGI("Remove APP DEK. pkgId=%s, appType=%d, ret=%d", pPkgId, appType, ret);
return ret;
}
diff --git a/tests/wae_tests.c b/tests/wae_tests.c
index 18527d0..2710f98 100644
--- a/tests/wae_tests.c
+++ b/tests/wae_tests.c
@@ -334,16 +334,21 @@ int wae_tc_get_alias()
int ret = WAE_ERROR_NONE;
const char* pkgId = "TEST_PKG_ID";
- char sys_alias[256] = {0, };
+ char alias[256] = {0, };
- _get_alias(pkgId, sys_alias, sizeof(sys_alias));
+ _get_alias(pkgId, WAE_DOWNLOADED_NORMAL_APP, alias, sizeof(alias));
+ FPRINTF("...pkgid=%s, alias for normal app=%s\n", pkgId, alias);
- FPRINTF("...pkgid=%s, system alias=%s\n", pkgId, sys_alias);
+ _get_alias(pkgId, WAE_DOWNLOADED_GLOBAL_APP, alias, sizeof(alias));
+ FPRINTF("...pkgid=%s, alias for global app=%s\n", pkgId, alias);
+
+ _get_alias(pkgId, WAE_PRELOADED_APP, alias, sizeof(alias));
+ FPRINTF("...pkgid=%s, alias for preloaded app=%s\n", pkgId, alias);
return ret;
}
-int wae_tc_add_get_remove_dek()
+int _wae_tc_add_get_remove_dek(wae_app_type_e appType)
{
int ret = WAE_ERROR_NONE;
@@ -356,15 +361,15 @@ int wae_tc_add_get_remove_dek()
ret = _get_random(dekLen, dek);
- remove_app_dek(pkgId);
+ remove_app_dek(pkgId, appType);
- ret = _add_dek_to_key_manager(pkgId, dek, dekLen);
+ ret = _add_dek_to_key_manager(pkgId, appType, dek, dekLen);
if(ret != WAE_ERROR_NONE) {
FPRINTF("...FAIL: _add_dek_to_key_manager. ret=%d\n", ret);
goto error;
}
- ret = get_app_dek(pkgId, &storedDek, &storedDekLen);
+ ret = get_app_dek(pkgId, appType, &storedDek, &storedDekLen);
if(ret != WAE_ERROR_NONE) {
FPRINTF("...FAIL: get_app_dek. ret=%d\n", ret);
goto error;
@@ -376,13 +381,13 @@ int wae_tc_add_get_remove_dek()
goto error;
}
- ret = remove_app_dek(pkgId);
+ ret = remove_app_dek(pkgId, appType);
if(ret != WAE_ERROR_NONE) {
FPRINTF("...FAIL: remove_app_dek. ret=%d\n", ret);
goto error;
}
- ret = get_app_dek(pkgId, &storedDek, &storedDekLen);
+ ret = get_app_dek(pkgId, appType, &storedDek, &storedDekLen);
if(ret == WAE_ERROR_NONE) {
ret = WAE_ERROR_UNKNOWN;
FPRINTF("...FAIL: APP DEK still exists in key_manager.\n");
@@ -397,6 +402,21 @@ error:
return ret;
}
+int wae_tc_add_get_remove_dek_for_normal_app()
+{
+ return _wae_tc_add_get_remove_dek(WAE_DOWNLOADED_NORMAL_APP);
+}
+
+int wae_tc_add_get_remove_dek_for_global_app()
+{
+ return _wae_tc_add_get_remove_dek(WAE_DOWNLOADED_GLOBAL_APP);
+}
+
+int wae_tc_add_get_remove_dek_for_preloaded_app()
+{
+ return _wae_tc_add_get_remove_dek(WAE_PRELOADED_APP);
+}
+
int wae_tc_get_preloaded_app_dek_file_path()
{
int ret = WAE_ERROR_NONE;
@@ -404,10 +424,10 @@ int wae_tc_get_preloaded_app_dek_file_path()
const char *pkgId = "test_pkg";
const char *expectedPath = tzplatform_mkpath4(TZ_SYS_SHARE,
"wae", "app_dek", "WAE_APP_DEK_test_pkg.adek");
- char path[100];
+ char path[256];
- ret = _get_preloaded_app_dek_file_path(pkgId, path);
FPRINTF("...expected path : %s\n", expectedPath);
+ ret = _get_preloaded_app_dek_file_path(pkgId, path);
FPRINTF("...returned path : %s\n", path);
if(ret != WAE_ERROR_NONE || strncmp(expectedPath, path, strlen(expectedPath)) != 0) {
@@ -473,7 +493,7 @@ error:
}
-int wae_tc_create_app_dek()
+int _wae_tc_create_app_dek(wae_app_type_e appType)
{
int ret = WAE_ERROR_NONE;
@@ -484,15 +504,15 @@ int wae_tc_create_app_dek()
size_t storedDekLen = 0;
unsigned char* storedDek = NULL;
- remove_app_dek(pkgId);
+ remove_app_dek(pkgId, appType);
- ret = create_app_dek(pkgId, &dek, &dekLen);
+ ret = create_app_dek(pkgId, appType, &dek, &dekLen);
if(ret != WAE_ERROR_NONE) {
FPRINTF("...FAIL: create_app_dek. ret=%d\n", ret);
goto error;
}
- ret = get_app_dek(pkgId, &storedDek, &storedDekLen);
+ ret = get_app_dek(pkgId, appType, &storedDek, &storedDekLen);
if(ret != WAE_ERROR_NONE) {
ret = WAE_ERROR_KEY_MANAGER;
FPRINTF("...FAIL: get_app_dek. ret=%d\n", ret);
@@ -507,7 +527,7 @@ int wae_tc_create_app_dek()
goto error;
}
- remove_app_dek(pkgId);
+ remove_app_dek(pkgId, appType);
ret = WAE_ERROR_NONE;
error:
@@ -518,6 +538,21 @@ error:
return ret;
}
+int wae_tc_create_app_dek_for_normal_app()
+{
+ return _wae_tc_create_app_dek(WAE_DOWNLOADED_NORMAL_APP);
+}
+
+int wae_tc_create_app_dek_for_global_app()
+{
+ return _wae_tc_create_app_dek(WAE_DOWNLOADED_GLOBAL_APP);
+}
+
+int wae_tc_create_app_dek_for_preloaded_app()
+{
+ return _wae_tc_create_app_dek(WAE_PRELOADED_APP);
+}
+
int wae_tc_get_create_preloaded_app_dek()
{
int ret = WAE_ERROR_NONE;
@@ -589,8 +624,8 @@ int wae_tc_load_preloaded_app_deks()
_get_preloaded_app_dek_file_path(pkgId2, path2);
// remove old test data
- remove_app_dek(pkgId1);
- remove_app_dek(pkgId2);
+ remove_app_dek(pkgId1, WAE_PRELOADED_APP);
+ remove_app_dek(pkgId2, WAE_PRELOADED_APP);
unlink(path1);
unlink(path2);
@@ -615,13 +650,13 @@ int wae_tc_load_preloaded_app_deks()
}
// get_app_dek
- ret = get_app_dek(pkgId1, &readDek1, &readDekLen1);
+ ret = get_app_dek(pkgId1, WAE_PRELOADED_APP, &readDek1, &readDekLen1);
if(ret != WAE_ERROR_NONE) {
FPRINTF("...FAIL: get_app_dek. ret=%d\n", ret);
goto error;
}
- ret = get_app_dek(pkgId2, &readDek2, &readDekLen2);
+ ret = get_app_dek(pkgId2, WAE_PRELOADED_APP, &readDek2, &readDekLen2);
if(ret != WAE_ERROR_NONE) {
FPRINTF("...FAIL: get_app_dek. ret=%d\n", ret);
goto error;
@@ -644,8 +679,8 @@ int wae_tc_load_preloaded_app_deks()
}
// remove_app_dek
- remove_app_dek(pkgId1);
- remove_app_dek(pkgId2);
+ remove_app_dek(pkgId1, WAE_PRELOADED_APP);
+ remove_app_dek(pkgId2, WAE_PRELOADED_APP);
ret = WAE_ERROR_NONE;
error:
@@ -665,13 +700,14 @@ error:
return ret;
}
-
-int wae_tc_encrypt_decrypt_web_application()
+int _wae_tc_encrypt_decrypt_web_app(wae_app_type_e appType)
{
int ret = WAE_ERROR_NONE;
- const char* pkgId1 = "testpkg_for_downloaded";
- const char* pkgId2 = "testpkg_for_preloaded";
+ const char* pkgId1 = "testpkg_for_normal";
+ const char* pkgId2 = "testpkg_for_global";
+ const char* pkgId3 = "testpkg_for_preloaded";
+ const char* pkgId = NULL;
const char* plaintext= "adbdfdfdfdfdererfdfdfererfdrerfdrer";
size_t plaintextLen = strlen(plaintext);
unsigned char* encrypted = NULL;
@@ -680,15 +716,26 @@ int wae_tc_encrypt_decrypt_web_application()
size_t decLen = 0;
char decrypted_str[1024] = {0, };
- int isPreloaded = 0; // Downloaded
+ switch(appType) {
+ case WAE_DOWNLOADED_NORMAL_APP:
+ pkgId = pkgId1;
+ break;
+ case WAE_DOWNLOADED_GLOBAL_APP:
+ pkgId = pkgId2;
+ break;
+ case WAE_PRELOADED_APP:
+ pkgId = pkgId3;
+ break;
+ }
// remove old test data
- ret = wae_remove_app_dek(pkgId1);
- ret = wae_remove_app_dek(pkgId2);
- ret = _clear_app_deks_loaded();
+ ret = wae_remove_app_dek(pkgId, appType);
+ if(appType == WAE_PRELOADED_APP) {
+ _clear_app_deks_loaded();
+ }
// test for downloaded web application
- ret = wae_encrypt_web_application(pkgId1, isPreloaded,
+ ret = wae_encrypt_web_application(pkgId, appType,
(const unsigned char*)plaintext, plaintextLen,
&encrypted, &encLen);
if(ret != WAE_ERROR_NONE){
@@ -696,63 +743,27 @@ int wae_tc_encrypt_decrypt_web_application()
goto error;
}
- _remove_app_dek_from_cache(pkgId1);
-
- ret = wae_decrypt_web_application(pkgId1, isPreloaded, encrypted, encLen, &decrypted, &decLen);
- if(ret != WAE_ERROR_NONE){
- FPRINTF("...FAIL: wae_decrypt_web_application. ret=%d\n", ret);
- goto error;
- }
-
- if(plaintextLen != decLen) {
- FPRINTF("...FAIL: plaintextLen(%d) != decLen(%d)\n", (int) plaintextLen, (int) decLen);
- ret = WAE_ERROR_CRYPTO;
- goto error;
- }
-
- memcpy(decrypted_str, decrypted, decLen);
- FPRINTF("...plaintext(downloaded) = %s\n", plaintext);
- FPRINTF("...decrypted(downloaded) = %s\n", decrypted_str);
- if(strcmp(plaintext, decrypted_str) != 0) {
- FPRINTF("...FAIL: plaintext(%s) != decrypted(%s)\n", plaintext, decrypted_str);
- ret = WAE_ERROR_CRYPTO;
- goto error;
- }
-
- ret = wae_remove_app_dek(pkgId1);
- if(ret != WAE_ERROR_NONE){
- FPRINTF("...FAIL: wae_remove_app_dek. ret=%d\n", ret);
- goto error;
- }
-
-
- // test for preloaded web application
- isPreloaded = 1;
-
- ret = wae_encrypt_web_application(pkgId2, isPreloaded,
+ // encrypt test twice
+ ret = wae_encrypt_web_application(pkgId, appType,
(const unsigned char*)plaintext, plaintextLen,
&encrypted, &encLen);
if(ret != WAE_ERROR_NONE){
FPRINTF("...FAIL: wae_encrypt_web_application. ret=%d\n", ret);
goto error;
}
- // encrypt test twice
- ret = wae_encrypt_web_application(pkgId2, isPreloaded,
- (const unsigned char*)plaintext, plaintextLen,
- &encrypted, &encLen);
- if(ret != WAE_ERROR_NONE){
- FPRINTF("...FAIL: wae_encrypt_web_application2. ret=%d\n", ret);
- goto error;
+
+ _remove_app_dek_from_cache(pkgId);
+
+ if(appType == WAE_PRELOADED_APP) {
+ load_preloaded_app_deks(WAE_TRUE);
}
- ret = wae_decrypt_web_application(pkgId2, isPreloaded, encrypted, encLen, &decrypted, &decLen);
+ ret = wae_decrypt_web_application(pkgId, appType, encrypted, encLen, &decrypted, &decLen);
if(ret != WAE_ERROR_NONE){
FPRINTF("...FAIL: wae_decrypt_web_application. ret=%d\n", ret);
goto error;
}
- _remove_app_dek_from_cache(pkgId2);
-
if(plaintextLen != decLen) {
FPRINTF("...FAIL: plaintextLen(%d) != decLen(%d)\n", (int) plaintextLen, (int) decLen);
ret = WAE_ERROR_CRYPTO;
@@ -760,15 +771,15 @@ int wae_tc_encrypt_decrypt_web_application()
}
memcpy(decrypted_str, decrypted, decLen);
- FPRINTF("...plaintext(preloaded) = %s\n", plaintext);
- FPRINTF("...decrypted(preloaded) = %s\n", decrypted_str);
+ FPRINTF("...plaintext(downloaded) = %s\n", plaintext);
+ FPRINTF("...decrypted(downloaded) = %s\n", decrypted_str);
if(strcmp(plaintext, decrypted_str) != 0) {
FPRINTF("...FAIL: plaintext(%s) != decrypted(%s)\n", plaintext, decrypted_str);
ret = WAE_ERROR_CRYPTO;
goto error;
}
- ret = wae_remove_app_dek(pkgId2);
+ ret = wae_remove_app_dek(pkgId, appType);
if(ret != WAE_ERROR_NONE){
FPRINTF("...FAIL: wae_remove_app_dek. ret=%d\n", ret);
goto error;
@@ -783,33 +794,67 @@ error:
return ret;
}
+int wae_tc_encrypt_decrypt_normal_app()
+{
+ return _wae_tc_encrypt_decrypt_web_app(WAE_DOWNLOADED_NORMAL_APP);
+}
+
+int wae_tc_encrypt_decrypt_global_app()
+{
+ return _wae_tc_encrypt_decrypt_web_app(WAE_DOWNLOADED_GLOBAL_APP);
+}
+
+int wae_tc_encrypt_decrypt_preloaded_app()
+{
+ return _wae_tc_encrypt_decrypt_web_app(WAE_PRELOADED_APP);
+}
+
-int run_test_cases()
+int run_test_cases(char* test_mode)
{
- RUNTC(wae_tc_encrypt_decrypt_app_dek, "wae_tc_encrypt_decrypt_app_dek");
- RUNTC(wae_tc_encrypt_decrypt_aes_cbc, "wae_tc_encrypt_decrypt_aes_cbc");
- RUNTC(wae_tc_cache, "wae_tc_cache");
-
- RUNTC(wae_tc_get_random, "wae_tc_get_random");
- RUNTC(wae_tc_get_alias, "wae_tc_get_alias");
- RUNTC(wae_tc_add_get_remove_dek, "wae_tc_add_get_remove_dek");
- RUNTC(wae_tc_get_preloaded_app_dek_file_path, "wae_tc_get_preloaded_app_dek_file_path");
- RUNTC(wae_tc_extract_pkg_id_from_file_name, "wae_tc_extract_pkg_id_from_file_name");
- RUNTC(wae_tc_read_write_encrypted_app_dek, "wae_tc_read_write_encrypted_app_dek");
- RUNTC(wae_tc_create_app_dek, "wae_tc_create_app_dek");
- RUNTC(wae_tc_get_create_preloaded_app_dek, "wae_tc_get_create_preloaded_app_dek");
- RUNTC(wae_tc_load_preloaded_app_deks, "wae_tc_load_preloaded_app_deks");
- RUNTC(wae_tc_encrypt_decrypt_web_application, "wae_tc_encrypt_decrypt_web_application");
+ if(strcmp(test_mode, "system") == 0) {
+ RUNTC(wae_tc_encrypt_decrypt_app_dek, "wae_tc_encrypt_decrypt_app_dek");
+ RUNTC(wae_tc_encrypt_decrypt_aes_cbc, "wae_tc_encrypt_decrypt_aes_cbc");
+ RUNTC(wae_tc_cache, "wae_tc_cache");
+
+ RUNTC(wae_tc_get_random, "wae_tc_get_random");
+ RUNTC(wae_tc_get_alias, "wae_tc_get_alias");
+
+ RUNTC(wae_tc_add_get_remove_dek_for_global_app, "wae_tc_add_get_remove_dek_for_global_app");
+ RUNTC(wae_tc_add_get_remove_dek_for_preloaded_app, "wae_tc_add_get_remove_dek_for_preloaded_app");
+
+ RUNTC(wae_tc_get_preloaded_app_dek_file_path, "wae_tc_get_preloaded_app_dek_file_path");
+ RUNTC(wae_tc_extract_pkg_id_from_file_name, "wae_tc_extract_pkg_id_from_file_name");
+ RUNTC(wae_tc_read_write_encrypted_app_dek, "wae_tc_read_write_encrypted_app_dek");
+
+ RUNTC(wae_tc_create_app_dek_for_global_app, "wae_tc_create_app_dek_for_global_app");
+ RUNTC(wae_tc_create_app_dek_for_preloaded_app, "wae_tc_create_app_dek_for_preloaded_app");
+
+ RUNTC(wae_tc_get_create_preloaded_app_dek, "wae_tc_get_create_preloaded_app_dek");
+ RUNTC(wae_tc_load_preloaded_app_deks, "wae_tc_load_preloaded_app_deks");
+
+ RUNTC(wae_tc_encrypt_decrypt_global_app, "wae_tc_encrypt_decrypt_global_app");
+ RUNTC(wae_tc_encrypt_decrypt_preloaded_app, "wae_tc_encrypt_decrypt_preloaded_app");
+ }else {
+ RUNTC(wae_tc_add_get_remove_dek_for_normal_app, "wae_tc_add_get_remove_dek_for_normal_app");
+ RUNTC(wae_tc_create_app_dek_for_normal_app, "wae_tc_create_app_dek_for_normal_app");
+ RUNTC(wae_tc_encrypt_decrypt_normal_app, "wae_tc_encrypt_decrypt_normal_app");
+ }
PRINT_TC_SUMMARY();
return 0;
}
-int main(void)
+int main(int argc, char* argv[])
{
int ret = 0;
- ret = run_test_cases();
+ if(argc != 2 || (strcmp(argv[1],"system") != 0 && strcmp(argv[1],"user")) ) {
+ FPRINTF("invalid command formant. command format : %s system|user\n", argv[0]);
+ exit(1);
+ }
+
+ ret = run_test_cases(argv[1]);
return ret;
}