diff options
author | Kyungwook Tak <k.tak@samsung.com> | 2016-07-18 11:28:53 +0900 |
---|---|---|
committer | Kyungwook Tak <k.tak@samsung.com> | 2016-07-18 13:54:57 +0900 |
commit | f72179753846682e783bbc4dbe1a3a570e7fac23 (patch) | |
tree | 792927dbc3307914f6f45b24a1f3a019e5166c9b /srcs/web_app_enc.c | |
parent | 25dec26957850ba42687ffff35fc226039405654 (diff) | |
download | libwebappenc-f72179753846682e783bbc4dbe1a3a570e7fac23.tar.gz libwebappenc-f72179753846682e783bbc4dbe1a3a570e7fac23.tar.bz2 libwebappenc-f72179753846682e783bbc4dbe1a3a570e7fac23.zip |
Fix C code naming rules & minor fixes
- Remove some goto label which isn't needed
- Change 'num' param of strncmp / strncpy with meaningful value
(static buffer's size)
- Add const to unsigned char array input param
- Change param names (c string array and raw buffer array)
const char *pPkgId -> pkgId
unsigned char *pDek -> dek
unsigned char **ppDek -> pDek
- Change all camel naminges to underbar
- Remove null checking before call free()
free() does nothing if ptr is null pointer.
(refer: http://linux.die.net/man/3/free)
- Add missing closedir() after opendir()
Change-Id: I7e5888ed3dc77e5355cfc441f10dc0d6d916921c
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
Diffstat (limited to 'srcs/web_app_enc.c')
-rw-r--r-- | srcs/web_app_enc.c | 210 |
1 files changed, 64 insertions, 146 deletions
diff --git a/srcs/web_app_enc.c b/srcs/web_app_enc.c index 0e31c30..dd133d9 100644 --- a/srcs/web_app_enc.c +++ b/srcs/web_app_enc.c @@ -22,210 +22,128 @@ #include "web_app_enc.h" #include <stdlib.h> -#include <stdio.h> #include "key_handler.h" #include "crypto_service.h" #include "wae_log.h" -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) +int _wae_encrypt_downloaded_web_application( + const char *pkg_id, wae_app_type_e app_type, + const unsigned char *data, size_t data_len, + unsigned char **pencrypted_data, size_t *pencrypted_data_len) { - int ret = WAE_ERROR_NONE; - unsigned char *pDek = NULL; - size_t dekLen = -1; - - if (pPkgId == NULL) { - WAE_SLOGE("Invalid Parameter. pPkgId is NULL"); - ret = WAE_ERROR_INVALID_PARAMETER; - goto error; - } - - if (pData == NULL || dataLen <= 0) { - WAE_SLOGE("Invalid Parameter. pData is NULL or invalid dataLen(%d)", dataLen); - ret = WAE_ERROR_INVALID_PARAMETER; - goto error; - } - - if (ppEncryptedData == NULL || pEncDataLen == NULL) { - WAE_SLOGE("Invalid Parameter. ppEncryptedData or pEncDataLen is NULL"); - ret = WAE_ERROR_INVALID_PARAMETER; - goto error; - } + if (pkg_id == NULL || data == NULL || data_len == 0 || pencrypted_data == NULL || + pencrypted_data_len == NULL) + return WAE_ERROR_INVALID_PARAMETER; // get APP_DEK. // if not exists, create APP_DEK - ret = get_app_dek(pPkgId, appType, &pDek, &dekLen); + unsigned char *dek = NULL; + size_t dek_len = -1; + int ret = get_app_dek(pkg_id, app_type, &dek, &dek_len); - if (ret == WAE_ERROR_NO_KEY) { - ret = create_app_dek(pPkgId, appType, &pDek, &dekLen); - } + if (ret == WAE_ERROR_NO_KEY) + ret = create_app_dek(pkg_id, app_type, &dek, &dek_len); - if (ret != WAE_ERROR_NONE) { + if (ret != WAE_ERROR_NONE) goto error; - } // encrypt - ret = encrypt_aes_cbc(pDek, dekLen, pData, dataLen, ppEncryptedData, pEncDataLen); - - if (ret != WAE_ERROR_NONE) { - goto error; - } + ret = encrypt_aes_cbc(dek, dek_len, data, data_len, pencrypted_data, pencrypted_data_len); error: - if (pDek != NULL) - free(pDek); + free(dek); return ret; } -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) +int _wae_decrypt_downloaded_web_application(const char *pkg_id, wae_app_type_e app_type, + const unsigned char *data, size_t data_len, + unsigned char **pdecrypted_data, size_t *pdecrypted_data_len) { - int ret = WAE_ERROR_NONE; - unsigned char *pDek = NULL; - size_t dekLen = -1; - if (pPkgId == NULL) { - WAE_SLOGE("Invalid Parameter. pPkgId is NULL"); - ret = WAE_ERROR_INVALID_PARAMETER; - goto error; - } - - if (pData == NULL || dataLen <= 0) { - WAE_SLOGE("Invalid Parameter. pData is NULL or invalid dataLen(%d)", dataLen); - ret = WAE_ERROR_INVALID_PARAMETER; - goto error; - } - - if (ppDecryptedData == NULL || pDecDataLen == NULL) { - WAE_SLOGE("Invalid Parameter. ppDecryptedData or pDecDataLen is NULL"); - ret = WAE_ERROR_INVALID_PARAMETER; - goto error; - } + if (pkg_id == NULL || data == NULL || data_len == 0 || pdecrypted_data == NULL || + pdecrypted_data_len == NULL) + return WAE_ERROR_INVALID_PARAMETER; - ret = get_app_dek(pPkgId, appType, &pDek, &dekLen); + unsigned char *dek = NULL; + size_t dek_len = -1; + int ret = get_app_dek(pkg_id, app_type, &dek, &dek_len); - if (ret != WAE_ERROR_NONE) { + if (ret != WAE_ERROR_NONE) goto error; - } // decrypt - ret = decrypt_aes_cbc(pDek, dekLen, pData, dataLen, ppDecryptedData, pDecDataLen); - - if (ret != WAE_ERROR_NONE) { - goto error; - } + ret = decrypt_aes_cbc(dek, dek_len, data, data_len, pdecrypted_data, pdecrypted_data_len); error: - if (pDek != NULL) - free(pDek); + free(dek); return ret; } -int _wae_encrypt_preloaded_web_application(const char *pPkgId, - const unsigned char *pData, size_t dataLen, - unsigned char **ppEncryptedData, size_t *pEncDataLen) +int _wae_encrypt_preloaded_web_application(const char *pkg_id, + const unsigned char *data, size_t data_len, + unsigned char **pencrypted_data, size_t *pencrypted_data_len) { + if (pkg_id == NULL || data == NULL || data_len == 0 || pencrypted_data == NULL || + pencrypted_data_len == NULL) + return WAE_ERROR_INVALID_PARAMETER; - int ret = WAE_ERROR_NONE; - unsigned char *pDek = NULL; - size_t dekLen = -1; + unsigned char *dek = NULL; + size_t dek_len = -1; + int ret = get_preloaded_app_dek(pkg_id, &dek, &dek_len); - if (pPkgId == NULL) { - WAE_SLOGE("Invalid Parameter. pPkgId is NULL"); - ret = WAE_ERROR_INVALID_PARAMETER; - goto error; - } + if (ret == WAE_ERROR_NO_KEY) + ret = create_preloaded_app_dek(pkg_id, &dek, &dek_len); - if (pData == NULL || dataLen <= 0) { - WAE_SLOGE("Invalid Parameter. pData is NULL or invalid dataLen(%d)", dataLen); - ret = WAE_ERROR_INVALID_PARAMETER; + if (ret != WAE_ERROR_NONE) goto error; - } - - if (ppEncryptedData == NULL || pEncDataLen == NULL) { - WAE_SLOGE("Invalid Parameter. ppEncryptedData or pEncDataLen is NULL"); - ret = WAE_ERROR_INVALID_PARAMETER; - goto error; - } - - ret = get_preloaded_app_dek(pPkgId, &pDek, &dekLen); - - if (ret == WAE_ERROR_NO_KEY) { - ret = create_preloaded_app_dek(pPkgId, &pDek, &dekLen); - } - - if (ret != WAE_ERROR_NONE) { - goto error; - } // encrypt - ret = encrypt_aes_cbc(pDek, dekLen, pData, dataLen, ppEncryptedData, pEncDataLen); - - if (ret != WAE_ERROR_NONE) { - goto error; - } + ret = encrypt_aes_cbc(dek, dek_len, data, data_len, pencrypted_data, pencrypted_data_len); error: - if (pDek != NULL) - free(pDek); + free(dek); return ret; } -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) +int _wae_decrypt_preloaded_web_application(const char *pkg_id, wae_app_type_e app_type, + const unsigned char *data, size_t data_len, + unsigned char **pdecrypted_data, size_t *pdecrypted_data_len) { // same with the decryption of downloaded web application - return _wae_decrypt_downloaded_web_application(pPkgId, appType, - pData, dataLen, ppDecryptedData, pDecDataLen); + return _wae_decrypt_downloaded_web_application(pkg_id, app_type, + data, data_len, pdecrypted_data, pdecrypted_data_len); } -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 wae_encrypt_web_application(const char *pkg_id, wae_app_type_e app_type, + const unsigned char *data, size_t data_len, + unsigned char **pencrypted_data, size_t *pencrypted_data_len) { - int ret = WAE_ERROR_NONE; - - if (appType == WAE_PRELOADED_APP) - ret = _wae_encrypt_preloaded_web_application(pPkgId, - pData, dataLen, ppEncryptedData, pEncDataLen); + if (app_type == WAE_PRELOADED_APP) + return _wae_encrypt_preloaded_web_application(pkg_id, + data, data_len, pencrypted_data, pencrypted_data_len); else - ret = _wae_encrypt_downloaded_web_application(pPkgId, appType, - pData, dataLen, ppEncryptedData, pEncDataLen); - - WAE_SLOGI("Encrypt Web App. pkgId=%s, appType=%d, dataLen=%d, ret=%d", - pPkgId, appType, dataLen, ret); - return ret; + return _wae_encrypt_downloaded_web_application(pkg_id, app_type, + data, data_len, pencrypted_data, pencrypted_data_len); } -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 wae_decrypt_web_application(const char *pkg_id, wae_app_type_e app_type, + const unsigned char *data, size_t data_len, + unsigned char **pdecrypted_data, size_t *pdecrypted_data_len) { - int ret = WAE_ERROR_NONE; - - if (appType == WAE_PRELOADED_APP) - ret = _wae_decrypt_preloaded_web_application(pPkgId, appType, - pData, dataLen, ppDecryptedData, pDecDataLen); + if (app_type == WAE_PRELOADED_APP) + return _wae_decrypt_preloaded_web_application(pkg_id, app_type, + data, data_len, pdecrypted_data, pdecrypted_data_len); else - ret = _wae_decrypt_downloaded_web_application(pPkgId, appType, - pData, dataLen, ppDecryptedData, pDecDataLen); - - WAE_SLOGI("Decrypt Web App. pkgId=%s, appType=%d, dataLen=%d, ret=%d", - pPkgId, appType, dataLen, ret); - return ret; + return _wae_decrypt_downloaded_web_application(pkg_id, app_type, + data, data_len, pdecrypted_data, pdecrypted_data_len); } -int wae_remove_app_dek(const char *pPkgId, wae_app_type_e appType) +int wae_remove_app_dek(const char *pkg_id, wae_app_type_e app_type) { - int ret = remove_app_dek(pPkgId, appType); - WAE_SLOGI("Remove APP DEK. pkgId=%s, appType=%d, ret=%d", pPkgId, appType, ret); - return ret; + return remove_app_dek(pkg_id, app_type); } |