*/
+/**
+ * @brief WAE Errors.
+ * @since_tizen 3.0
+ */
typedef enum
{
WAE_ERROR_NONE = 0x00, /**< Successful */
} 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.
*
* @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.
*
* @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
* @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);
/**
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)
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,};
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;
}
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;
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;
}
}
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;
}
// 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;
}
}
// 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);
}
-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) {
#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"
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);
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
#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)
{
// 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;
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)
{
goto error;
}
- ret = get_app_dek(pPkgId, &pDek, &dekLen);
+ ret = get_app_dek(pPkgId, appType, &pDek, &dekLen);
if(ret != WAE_ERROR_NONE) {
goto 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;
}
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;
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;
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");
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;
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) {
}
-int wae_tc_create_app_dek()
+int _wae_tc_create_app_dek(wae_app_type_e appType)
{
int ret = WAE_ERROR_NONE;
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);
goto error;
}
- remove_app_dek(pkgId);
+ remove_app_dek(pkgId, appType);
ret = WAE_ERROR_NONE;
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;
_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);
}
// 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;
}
// 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:
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;
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){
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;
}
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;
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;
}