mirror of
https://gitee.com/openharmony/security_huks
synced 2024-11-27 00:40:54 +00:00
add code for fix huks log
Signed-off-by: wuxintao <wuxintao5@huawei.com>
This commit is contained in:
parent
1b96b00f6a
commit
526a863017
@ -101,12 +101,12 @@ do { \
|
||||
} while (0)
|
||||
|
||||
#define HKS_LOG_ERRNO(msg, ret) ({ int currentErrno = errno; \
|
||||
HKS_LOG_E(msg " %" LOG_PUBLIC "d, errno %" LOG_PUBLIC "d, strerror %" LOG_PUBLIC "s", \
|
||||
HKS_LOG_E(msg " %" LOG_PUBLIC "d, errno: %" LOG_PUBLIC "d, strerror: %" LOG_PUBLIC "s", \
|
||||
(ret), currentErrno, strerror(currentErrno)); })
|
||||
|
||||
#define HKS_IF_NOT_SUCC_LOG_ERRNO_RETURN(msg, ret) ({ int currentErrno = errno; \
|
||||
if ((ret) != 0) { \
|
||||
HKS_LOG_E(msg " %" LOG_PUBLIC "d, errno %" LOG_PUBLIC "d, strerror %" LOG_PUBLIC "s", \
|
||||
HKS_LOG_E(msg " %" LOG_PUBLIC "d, errno: %" LOG_PUBLIC "d, strerror: %" LOG_PUBLIC "s", \
|
||||
(ret), currentErrno, strerror(currentErrno)); \
|
||||
return HKS_FAILURE; \
|
||||
}})
|
||||
|
@ -2021,7 +2021,7 @@ static int32_t CheckOptionalParams(bool needCheck, bool isAbsent, uint32_t input
|
||||
if (needCheck) {
|
||||
if (!isAbsent) {
|
||||
if (HksCheckValue(inputValue, expectValue, expectCnt) != HKS_SUCCESS) {
|
||||
HKS_LOG_E("CheckOptionalParams invalid argument, %d", inputValue);
|
||||
HKS_LOG_E("CheckOptionalParams invalid argument, %" LOG_PUBLIC "u", inputValue);
|
||||
return HKS_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
}
|
||||
@ -2051,7 +2051,7 @@ int32_t HksCheckOptionalParam(uint32_t tag, uint32_t alg, uint32_t purpose, bool
|
||||
if (((purpose & HKS_KEY_PURPOSE_DERIVE) != 0) || ((purpose & HKS_KEY_PURPOSE_MAC) != 0)) {
|
||||
if ((alg != HKS_ALG_AES) && (alg != HKS_ALG_DES) && (alg != HKS_ALG_3DES) &&
|
||||
(alg != HKS_ALG_HMAC) && (alg != HKS_ALG_CMAC) && (alg != HKS_ALG_SM3)) {
|
||||
HKS_LOG_E("check mac or derive, not aes alg, alg: %u", alg);
|
||||
HKS_LOG_E("check mac or derive, not aes alg, alg: %" LOG_PUBLIC "u", alg);
|
||||
return HKS_ERROR_INVALID_PURPOSE;
|
||||
}
|
||||
if (purpose == HKS_KEY_PURPOSE_DERIVE) {
|
||||
@ -2083,7 +2083,7 @@ int32_t HksCheckOptionalParam(uint32_t tag, uint32_t alg, uint32_t purpose, bool
|
||||
"check param fail:0x%" LOG_PUBLIC "x failed", HKS_TAG_PADDING);
|
||||
break;
|
||||
default:
|
||||
HKS_LOG_E("invalid tag: %d", tag);
|
||||
HKS_LOG_E("invalid tag: %" LOG_PUBLIC "u", tag);
|
||||
ret = HKS_FAILURE;
|
||||
}
|
||||
return ret;
|
||||
|
@ -381,7 +381,7 @@ int32_t ConvertPrivX25519FromED25519(const struct HksBlob *keyIn, struct HksBlob
|
||||
uint32_t tmpSize = sizeof(struct KeyMaterial25519) + CURVE25519_KEY_LEN;
|
||||
uint32_t totalSize = sizeof(struct KeyMaterial25519) + CURVE25519_KEY_LEN * 2; // 2: private key and public key
|
||||
if (keyIn->size < totalSize || keyOut->size < tmpSize) {
|
||||
HKS_LOG_E("Invalid keyInSize=%u or keyOutSize=%u", keyIn->size, keyOut->size);
|
||||
HKS_LOG_E("Invalid keyInSize=%" LOG_PUBLIC "u or keyOutSize=%" LOG_PUBLIC "u", keyIn->size, keyOut->size);
|
||||
return HKS_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
struct KeyMaterial25519 *keyMaterialOut = (struct KeyMaterial25519 *)keyOut->data;
|
||||
|
@ -546,7 +546,7 @@ int32_t GetBnBinpadFromPkey(const EVP_PKEY *pkey, const char *keyName, struct Hk
|
||||
}
|
||||
out->data = HksMalloc(len);
|
||||
if (!out->data) {
|
||||
HKS_LOG_E("HksMalloc %d failed", len);
|
||||
HKS_LOG_E("HksMalloc %" LOG_PUBLIC "d failed", len);
|
||||
break;
|
||||
}
|
||||
osRet = BN_bn2binpad(bn, out->data, len);
|
||||
|
@ -120,7 +120,7 @@ int32_t HksOpensslSm2GenerateKey(const struct HksKeySpec *spec, struct HksBlob *
|
||||
|
||||
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_SM2, NULL);
|
||||
if (!ctx) {
|
||||
HKS_LOG_E("ctx NULL %s", ERR_reason_error_string(ERR_get_error()));
|
||||
HKS_LOG_E("ctx NULL %" LOG_PUBLIC "s", ERR_reason_error_string(ERR_get_error()));
|
||||
return HKS_ERROR_CRYPTO_ENGINE_ERROR;
|
||||
}
|
||||
int ret = HKS_ERROR_CRYPTO_ENGINE_ERROR;
|
||||
@ -128,12 +128,14 @@ int32_t HksOpensslSm2GenerateKey(const struct HksKeySpec *spec, struct HksBlob *
|
||||
do {
|
||||
int osRet = EVP_PKEY_keygen_init(ctx);
|
||||
if (osRet != HKS_OPENSSL_SUCCESS) {
|
||||
HKS_LOG_E("EVP_PKEY_keygen_init ret = %d %s", osRet, ERR_reason_error_string(ERR_get_error()));
|
||||
HKS_LOG_E("EVP_PKEY_keygen_init ret = %" LOG_PUBLIC "d %" LOG_PUBLIC "s",
|
||||
osRet, ERR_reason_error_string(ERR_get_error()));
|
||||
break;
|
||||
}
|
||||
osRet = EVP_PKEY_keygen(ctx, &pkey);
|
||||
if (osRet != HKS_OPENSSL_SUCCESS) {
|
||||
HKS_LOG_E("EVP_PKEY_keygen ret = %d %s", osRet, ERR_reason_error_string(ERR_get_error()));
|
||||
HKS_LOG_E("EVP_PKEY_keygen ret = %" LOG_PUBLIC "d %" LOG_PUBLIC "s",
|
||||
osRet, ERR_reason_error_string(ERR_get_error()));
|
||||
break;
|
||||
}
|
||||
ret = EvpPkeyToKeyMaterialEc(spec, pkey, key);
|
||||
|
@ -99,7 +99,7 @@ HKS_API_EXPORT int32_t HksRefreshKeyInfo(void)
|
||||
#ifndef _CUT_AUTHENTICATE_
|
||||
HKS_LOG_D("enter refresh key info");
|
||||
int32_t ret = HksClientRefreshKeyInfo();
|
||||
HKS_LOG_D("leave refresh key info, result = %" LOG_PUBLIC "d", ret);
|
||||
HKS_LOG_I("leave refresh key info, result = %" LOG_PUBLIC "d", ret);
|
||||
return ret;
|
||||
#else
|
||||
return HKS_ERROR_API_NOT_SUPPORTED;
|
||||
@ -118,7 +118,7 @@ HKS_API_EXPORT int32_t HksGenerateKey(const struct HksBlob *keyAlias,
|
||||
return HKS_ERROR_NULL_POINTER;
|
||||
}
|
||||
ret = HksLocalGenerateKey(paramSetIn, paramSetOut);
|
||||
HKS_LOG_D("leave generate temp key, result = %" LOG_PUBLIC "d", ret);
|
||||
HKS_LOG_I("leave generate temp key, result = %" LOG_PUBLIC "d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ HKS_API_EXPORT int32_t HksGenerateKey(const struct HksBlob *keyAlias,
|
||||
return HKS_ERROR_NULL_POINTER;
|
||||
}
|
||||
ret = HksClientGenerateKey(keyAlias, paramSetIn, paramSetOut);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
#else
|
||||
(void)keyAlias;
|
||||
@ -146,7 +146,7 @@ HKS_API_EXPORT int32_t HksImportKey(const struct HksBlob *keyAlias,
|
||||
return HKS_ERROR_NULL_POINTER;
|
||||
}
|
||||
int32_t ret = HksImportKeyAdapter(keyAlias, paramSet, key);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
#else
|
||||
(void)keyAlias;
|
||||
@ -165,7 +165,7 @@ HKS_API_EXPORT int32_t HksImportWrappedKey(const struct HksBlob *keyAlias, const
|
||||
return HKS_ERROR_NULL_POINTER;
|
||||
}
|
||||
int32_t ret = HksClientImportWrappedKey(keyAlias, wrappingKeyAlias, paramSet, wrappedKeyData);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
#else
|
||||
(void)keyAlias;
|
||||
@ -185,7 +185,7 @@ HKS_API_EXPORT int32_t HksExportPublicKey(const struct HksBlob *keyAlias,
|
||||
return HKS_ERROR_NULL_POINTER;
|
||||
}
|
||||
int32_t ret = HksExportPublicKeyAdapter(keyAlias, paramSet, key);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
#else
|
||||
(void)keyAlias;
|
||||
@ -201,7 +201,7 @@ HKS_API_EXPORT int32_t HksDeleteKey(const struct HksBlob *keyAlias, const struct
|
||||
HKS_LOG_D("enter %" LOG_PUBLIC "s", __func__);
|
||||
HKS_IF_NULL_RETURN(keyAlias, HKS_ERROR_NULL_POINTER)
|
||||
int32_t ret = HksClientDeleteKey(keyAlias, paramSet);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
#else
|
||||
(void)keyAlias;
|
||||
@ -219,7 +219,7 @@ HKS_API_EXPORT int32_t HksGetKeyParamSet(const struct HksBlob *keyAlias,
|
||||
return HKS_ERROR_NULL_POINTER;
|
||||
}
|
||||
int32_t ret = HksClientGetKeyParamSet(keyAlias, paramSetIn, paramSetOut);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
#else
|
||||
(void)keyAlias;
|
||||
@ -235,7 +235,7 @@ HKS_API_EXPORT int32_t HksKeyExist(const struct HksBlob *keyAlias, const struct
|
||||
HKS_LOG_D("enter %" LOG_PUBLIC "s", __func__);
|
||||
HKS_IF_NULL_RETURN(keyAlias, HKS_ERROR_NULL_POINTER)
|
||||
int32_t ret = HksClientKeyExist(keyAlias, paramSet);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
#else
|
||||
(void)keyAlias;
|
||||
@ -250,7 +250,7 @@ HKS_API_EXPORT int32_t HksGenerateRandom(const struct HksParamSet *paramSet, str
|
||||
HKS_LOG_D("enter %" LOG_PUBLIC "s", __func__);
|
||||
HKS_IF_NULL_RETURN(random, HKS_ERROR_NULL_POINTER)
|
||||
int32_t ret = HksClientGenerateRandom(random, paramSet);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
#else
|
||||
(void)paramSet;
|
||||
@ -275,7 +275,7 @@ HKS_API_EXPORT int32_t HksSign(const struct HksBlob *key, const struct HksParamS
|
||||
}
|
||||
|
||||
ret = HksClientSign(key, paramSet, srcData, signature);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
#else
|
||||
(void)key;
|
||||
@ -299,11 +299,11 @@ HKS_API_EXPORT int32_t HksVerify(const struct HksBlob *key, const struct HksPara
|
||||
int32_t ret = HksGetParam(paramSet, HKS_TAG_IS_KEY_ALIAS, &isKeyAlias);
|
||||
if ((ret == HKS_SUCCESS) && (!isKeyAlias->boolParam)) {
|
||||
ret = HksLocalVerify(key, paramSet, srcData, signature);
|
||||
HKS_LOG_D("leave verify with plain key, result = %" LOG_PUBLIC "d", ret);
|
||||
HKS_LOG_I("leave verify with plain key, result = %" LOG_PUBLIC "d", ret);
|
||||
return ret;
|
||||
}
|
||||
ret = HksClientVerify(key, paramSet, srcData, signature);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
#else
|
||||
(void)key;
|
||||
@ -327,12 +327,12 @@ HKS_API_EXPORT int32_t HksEncrypt(const struct HksBlob *key, const struct HksPar
|
||||
int32_t ret = HksGetParam(paramSet, HKS_TAG_IS_KEY_ALIAS, &isKeyAlias);
|
||||
if ((ret == HKS_SUCCESS) && (!isKeyAlias->boolParam)) {
|
||||
ret = HksLocalEncrypt(key, paramSet, plainText, cipherText);
|
||||
HKS_LOG_D("leave encrypt with plain key, result = %" LOG_PUBLIC "d", ret);
|
||||
HKS_LOG_I("leave encrypt with plain key, result = %" LOG_PUBLIC "d", ret);
|
||||
return ret;
|
||||
}
|
||||
#ifndef _CUT_AUTHENTICATE_
|
||||
ret = HksClientEncrypt(key, paramSet, plainText, cipherText);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
#else
|
||||
return HKS_ERROR_NOT_SUPPORTED;
|
||||
@ -359,12 +359,12 @@ HKS_API_EXPORT int32_t HksDecrypt(const struct HksBlob *key, const struct HksPar
|
||||
int32_t ret = HksGetParam(paramSet, HKS_TAG_IS_KEY_ALIAS, &isKeyAlias);
|
||||
if ((ret == HKS_SUCCESS) && (!isKeyAlias->boolParam)) {
|
||||
ret = HksLocalDecrypt(key, paramSet, cipherText, plainText);
|
||||
HKS_LOG_D("leave decrypt with plain key, result = %" LOG_PUBLIC "d", ret);
|
||||
HKS_LOG_I("leave decrypt with plain key, result = %" LOG_PUBLIC "d", ret);
|
||||
return ret;
|
||||
}
|
||||
#ifndef _CUT_AUTHENTICATE_
|
||||
ret = HksClientDecrypt(key, paramSet, cipherText, plainText);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
#else
|
||||
return HKS_ERROR_NOT_SUPPORTED;
|
||||
@ -391,12 +391,12 @@ HKS_API_EXPORT int32_t HksAgreeKey(const struct HksParamSet *paramSet, const str
|
||||
int32_t ret = HksGetParam(paramSet, HKS_TAG_IS_KEY_ALIAS, &isKeyAlias);
|
||||
if ((ret == HKS_SUCCESS) && (!isKeyAlias->boolParam)) {
|
||||
ret = HksLocalAgreeKey(paramSet, privateKey, peerPublicKey, agreedKey);
|
||||
HKS_LOG_D("leave agree key with plain key, result = %" LOG_PUBLIC "d", ret);
|
||||
HKS_LOG_I("leave agree key with plain key, result = %" LOG_PUBLIC "d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = HksAgreeKeyAdapter(paramSet, privateKey, peerPublicKey, agreedKey);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
#else
|
||||
(void)paramSet;
|
||||
@ -420,12 +420,12 @@ HKS_API_EXPORT int32_t HksDeriveKey(const struct HksParamSet *paramSet, const st
|
||||
int32_t ret = HksGetParam(paramSet, HKS_TAG_IS_KEY_ALIAS, &isKeyAlias);
|
||||
if ((ret == HKS_SUCCESS) && (!isKeyAlias->boolParam)) {
|
||||
ret = HksLocalDeriveKey(paramSet, mainKey, derivedKey);
|
||||
HKS_LOG_D("leave derive key with plain key, result = %" LOG_PUBLIC "d", ret);
|
||||
HKS_LOG_I("leave derive key with plain key, result = %" LOG_PUBLIC "d", ret);
|
||||
return ret;
|
||||
}
|
||||
#ifndef _CUT_AUTHENTICATE_
|
||||
ret = HksClientDeriveKey(paramSet, mainKey, derivedKey);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
#else
|
||||
return HKS_ERROR_NOT_SUPPORTED;
|
||||
@ -451,12 +451,12 @@ HKS_API_EXPORT int32_t HksMac(const struct HksBlob *key, const struct HksParamSe
|
||||
int32_t ret = HksGetParam(paramSet, HKS_TAG_IS_KEY_ALIAS, &isKeyAlias);
|
||||
if ((ret == HKS_SUCCESS) && (!isKeyAlias->boolParam)) {
|
||||
ret = HksLocalMac(key, paramSet, srcData, mac);
|
||||
HKS_LOG_D("leave mac with plain key, result = %" LOG_PUBLIC "d", ret);
|
||||
HKS_LOG_I("leave mac with plain key, result = %" LOG_PUBLIC "d", ret);
|
||||
return ret;
|
||||
}
|
||||
#ifndef _CUT_AUTHENTICATE_
|
||||
ret = HksClientMac(key, paramSet, srcData, mac);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
#else
|
||||
return HKS_ERROR_NOT_SUPPORTED;
|
||||
@ -479,7 +479,7 @@ HKS_API_EXPORT int32_t HksHash(const struct HksParamSet *paramSet,
|
||||
return HKS_ERROR_NULL_POINTER;
|
||||
}
|
||||
int32_t ret = HksLocalHash(paramSet, srcData, hash);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
#else
|
||||
(void)paramSet;
|
||||
@ -498,7 +498,7 @@ HKS_API_EXPORT int32_t HksGetKeyInfoList(const struct HksParamSet *paramSet,
|
||||
return HKS_ERROR_NULL_POINTER;
|
||||
}
|
||||
int32_t ret = HksClientGetKeyInfoList(paramSet, keyInfoList, listCount);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
#else
|
||||
(void)paramSet;
|
||||
@ -566,7 +566,7 @@ HKS_API_EXPORT int32_t HksAttestKey(const struct HksBlob *keyAlias, const struct
|
||||
|
||||
ret = HksClientAttestKey(keyAlias, newParamSet, certChain, false);
|
||||
HksFreeParamSet(&newParamSet);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
#else
|
||||
(void)keyAlias;
|
||||
@ -593,7 +593,7 @@ HKS_API_EXPORT int32_t HksAnonAttestKey(const struct HksBlob *keyAlias, const st
|
||||
|
||||
ret = HksClientAttestKey(keyAlias, newParamSet, certChain, true);
|
||||
HksFreeParamSet(&newParamSet);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
#else
|
||||
(void)keyAlias;
|
||||
@ -642,7 +642,7 @@ HKS_API_EXPORT int32_t HksBnExpMod(struct HksBlob *x, const struct HksBlob *a,
|
||||
}
|
||||
|
||||
int32_t ret = HksLocalBnExpMod(x, a, e, n);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
#else
|
||||
(void)x;
|
||||
@ -671,7 +671,7 @@ HKS_API_EXPORT int32_t HksValidateCertChain(const struct HksCertChain *certChain
|
||||
return HKS_ERROR_NULL_POINTER;
|
||||
}
|
||||
int32_t ret = HksClientValidateCertChain(certChain, paramSetOut);
|
||||
HKS_LOG_D("leave validate cert chain, result = %" LOG_PUBLIC "d", ret);
|
||||
HKS_LOG_I("leave validate cert chain, result = %" LOG_PUBLIC "d", ret);
|
||||
return ret;
|
||||
#else
|
||||
(void)certChain;
|
||||
@ -690,7 +690,7 @@ HKS_API_EXPORT int32_t HksInit(const struct HksBlob *keyAlias, const struct HksP
|
||||
}
|
||||
|
||||
int32_t ret = HksClientInit(keyAlias, paramSet, handle, token);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -704,7 +704,7 @@ HKS_API_EXPORT int32_t HksUpdate(const struct HksBlob *handle, const struct HksP
|
||||
}
|
||||
|
||||
int32_t ret = HksClientUpdate(handle, paramSet, inData, outData);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -718,7 +718,7 @@ HKS_API_EXPORT int32_t HksFinish(const struct HksBlob *handle, const struct HksP
|
||||
}
|
||||
|
||||
int32_t ret = HksClientFinish(handle, paramSet, inData, outData);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -731,7 +731,7 @@ HKS_API_EXPORT int32_t HksAbort(const struct HksBlob *handle, const struct HksPa
|
||||
}
|
||||
|
||||
int32_t ret = HksClientAbort(handle, paramSet);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -742,7 +742,7 @@ HKS_API_EXPORT int32_t HksListAliases(const struct HksParamSet *paramSet, struct
|
||||
return HKS_ERROR_NULL_POINTER;
|
||||
}
|
||||
int32_t ret = HksClientListAliases(paramSet, outData);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -754,7 +754,7 @@ HKS_API_EXPORT int32_t HksRenameKeyAlias(const struct HksBlob *oldKeyAlias, cons
|
||||
return HKS_ERROR_NULL_POINTER;
|
||||
}
|
||||
int32_t ret = HksClientRenameKeyAlias(oldKeyAlias, paramSet, newKeyAlias);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -767,6 +767,6 @@ HKS_API_EXPORT int32_t HksChangeStorageLevel(const struct HksBlob *keyAlias, con
|
||||
return HKS_ERROR_NULL_POINTER;
|
||||
}
|
||||
int32_t ret = HksClientChangeStorageLevel(keyAlias, srcParamSet, destParamSet);
|
||||
HKS_LOG_D("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
HKS_LOG_I("leave %" LOG_PUBLIC "s, result = %" LOG_PUBLIC "d", __func__, ret);
|
||||
return ret;
|
||||
}
|
@ -199,7 +199,7 @@ static int32_t HksCoreInitProcess(const struct HuksKeyNode *keyNode, const struc
|
||||
}
|
||||
|
||||
if (ret != HKS_SUCCESS || i == size) {
|
||||
HKS_LOG_E("CoreInit failed, pur : %u, ret : %d", pur, ret);
|
||||
HKS_LOG_E("CoreInit failed, pur : %" LOG_PUBLIC "u, ret : %" LOG_PUBLIC "d", pur, ret);
|
||||
ret = ((i == size) ? HKS_ERROR_INVALID_ARGUMENT : ret);
|
||||
}
|
||||
return ret;
|
||||
|
@ -1193,7 +1193,9 @@ int32_t HksServiceDeleteKey(const struct HksProcessInfo *processInfo, const stru
|
||||
#endif
|
||||
|
||||
#ifdef L2_STANDARD
|
||||
HksReport(__func__, processInfo, NULL, ret);
|
||||
if (ret != HKS_ERROR_NOT_EXIST) {
|
||||
HksReport(__func__, processInfo, NULL, ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
@ -1229,7 +1231,9 @@ int32_t HksServiceKeyExist(const struct HksProcessInfo *processInfo, const struc
|
||||
#endif
|
||||
|
||||
#ifdef L2_STANDARD
|
||||
HksReport(__func__, processInfo, NULL, ret);
|
||||
if (ret != HKS_ERROR_NOT_EXIST) {
|
||||
HksReport(__func__, processInfo, NULL, ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
|
@ -52,7 +52,8 @@ int32_t HksStoreIsKeyBlobExist(const struct HksStoreFileInfo *fileInfo);
|
||||
int32_t HksStoreGetKeyBlob(const struct HksStoreInfo *fileInfoPath, const struct HksStoreMaterial *material,
|
||||
struct HksBlob *keyBlob);
|
||||
|
||||
int32_t HksStoreGetKeyBlobSize(const struct HksStoreInfo *fileInfoPath, uint32_t *keyBlobSize);
|
||||
int32_t HksStoreGetKeyBlobSize(const struct HksStoreInfo *fileInfoPath, const struct HksStoreMaterial *material,
|
||||
uint32_t *keyBlobSize);
|
||||
|
||||
int32_t HksGetKeyCountByProcessName(const struct HksStoreFileInfo *fileInfo, uint32_t *fileCount);
|
||||
|
||||
|
@ -87,6 +87,7 @@ enum KeyOperation {
|
||||
KEY_OPERATION_SAVE = 0,
|
||||
KEY_OPERATION_GET = 1,
|
||||
KEY_OPERATION_DELETE = 2,
|
||||
KEY_OPERATION_CHECK = 3,
|
||||
};
|
||||
|
||||
int32_t ConstructPlainName(const struct HksBlob *blob, char *targetName, uint32_t nameLen);
|
||||
|
@ -337,12 +337,16 @@ int32_t HksStoreGetKeyBlob(const struct HksStoreInfo *fileInfoPath, const struct
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t HksStoreGetKeyBlobSize(const struct HksStoreInfo *fileInfoPath, uint32_t *keyBlobSize)
|
||||
int32_t HksStoreGetKeyBlobSize(const struct HksStoreInfo *fileInfoPath, const struct HksStoreMaterial *material,
|
||||
uint32_t *keyBlobSize)
|
||||
{
|
||||
int32_t ret;
|
||||
do {
|
||||
ret = GetKeyBlobSize(fileInfoPath, keyBlobSize);
|
||||
HKS_IF_NOT_SUCC_LOGE(ret, "hks get keyblob size failed, ret = %" LOG_PUBLIC "d.", ret)
|
||||
if (ret != HKS_SUCCESS) {
|
||||
RecordKeyOperation(KEY_OPERATION_CHECK, material, fileInfoPath->fileName);
|
||||
HKS_LOG_E("hks get keyblob size failed, ret = %" LOG_PUBLIC "d.", ret);
|
||||
}
|
||||
} while (0);
|
||||
|
||||
return ret;
|
||||
|
@ -449,11 +449,11 @@ int32_t HksManageStoreGetKeyBlobSize(const struct HksProcessInfo *processInfo, c
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "hks construct store file info failed, ret = %" LOG_PUBLIC "d.", ret)
|
||||
|
||||
if (storageType != HKS_STORAGE_TYPE_BAK_KEY) {
|
||||
ret = HksStoreGetKeyBlobSize(&fileInfo.mainPath, keyBlobSize);
|
||||
ret = HksStoreGetKeyBlobSize(&fileInfo.mainPath, &material, keyBlobSize);
|
||||
}
|
||||
#ifdef SUPPORT_STORAGE_BACKUP
|
||||
else {
|
||||
ret = HksStoreGetKeyBlobSize(&fileInfo.bakPath, keyBlobSize);
|
||||
ret = HksStoreGetKeyBlobSize(&fileInfo.bakPath, &material, keyBlobSize);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
@ -329,6 +329,11 @@ int32_t RecordKeyOperation(uint32_t operation, const struct HksStoreMaterial *ma
|
||||
"storage level: %" LOG_PUBLIC "u, key alias: %" LOG_PUBLIC "s",
|
||||
material->userIdPath, material->uidPath, material->pathType, anonymousKeyAlias);
|
||||
break;
|
||||
case KEY_OPERATION_CHECK:
|
||||
HKS_LOG_I("check key, storage userid: %" LOG_PUBLIC "s, uid: %" LOG_PUBLIC "s, "
|
||||
"storage level: %" LOG_PUBLIC "u, key alias: %" LOG_PUBLIC "s",
|
||||
material->userIdPath, material->uidPath, material->pathType, anonymousKeyAlias);
|
||||
break;
|
||||
default:
|
||||
ret = HKS_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ void HksIpcServiceDeleteKey(const struct HksBlob *srcData, const uint8_t *contex
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "HksCheckAcrossAccountsPermission fail, ret = %" LOG_PUBLIC "d", ret)
|
||||
|
||||
ret = HksServiceDeleteKey(&processInfo, &keyAlias, paramSet);
|
||||
HKS_IF_NOT_SUCC_LOGE(ret, "HksIpcServiceDeleteKey fail")
|
||||
HKS_IF_NOT_SUCC_LOGE(ret, "HksIpcServiceDeleteKey fail, ret = %" LOG_PUBLIC "d", ret)
|
||||
} while (0);
|
||||
|
||||
HksSendResponse(context, ret, NULL);
|
||||
@ -358,7 +358,7 @@ void HksIpcServiceSign(const struct HksBlob *srcData, const uint8_t *context)
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "HksCheckAcrossAccountsPermission fail, ret = %" LOG_PUBLIC "d", ret)
|
||||
|
||||
ret = HksServiceSign(&processInfo, &keyAlias, inParamSet, &unsignedData, &signature);
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "HksServiceSign fail")
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "HksServiceSign fail, ret = %" LOG_PUBLIC "d", ret)
|
||||
|
||||
HksSendResponse(context, ret, &signature);
|
||||
} while (0);
|
||||
@ -392,7 +392,7 @@ void HksIpcServiceVerify(const struct HksBlob *srcData, const uint8_t *context)
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "HksCheckAcrossAccountsPermission fail, ret = %" LOG_PUBLIC "d", ret)
|
||||
|
||||
ret = HksServiceVerify(&processInfo, &keyAlias, inParamSet, &unsignedData, &signature);
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "HksServiceVerify fail")
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "HksServiceVerify fail ret = %" LOG_PUBLIC "d", ret)
|
||||
} while (0);
|
||||
|
||||
HksSendResponse(context, ret, NULL);
|
||||
@ -421,7 +421,7 @@ void HksIpcServiceEncrypt(const struct HksBlob *srcData, const uint8_t *context)
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "HksCheckAcrossAccountsPermission fail, ret = %" LOG_PUBLIC "d", ret)
|
||||
|
||||
ret = HksServiceEncrypt(&processInfo, &keyAlias, inParamSet, &plainText, &cipherText);
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "HksServiceEncrypt fail")
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "HksServiceEncrypt fail, ret = %" LOG_PUBLIC "d", ret)
|
||||
|
||||
HksSendResponse(context, ret, &cipherText);
|
||||
} while (0);
|
||||
@ -455,7 +455,7 @@ void HksIpcServiceDecrypt(const struct HksBlob *srcData, const uint8_t *context)
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "HksCheckAcrossAccountsPermission fail, ret = %" LOG_PUBLIC "d", ret)
|
||||
|
||||
ret = HksServiceDecrypt(&processInfo, &keyAlias, inParamSet, &cipherText, &plainText);
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "HksServiceDecrypt fail")
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "HksServiceDecrypt fail, ret = %" LOG_PUBLIC "d", ret)
|
||||
|
||||
HksSendResponse(context, ret, &plainText);
|
||||
} while (0);
|
||||
@ -928,7 +928,7 @@ void HksIpcServiceListAliases(const struct HksBlob *srcData, const uint8_t *cont
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "HksServiceListAliases fail, ret = %" LOG_PUBLIC "d", ret)
|
||||
|
||||
ret = HksListAliasesPackFromService(keyAliasSet, &outBlob);
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "HksListAliasesPackFromService fail")
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "HksListAliasesPackFromService fail, ret = %" LOG_PUBLIC "d", ret)
|
||||
} while (0);
|
||||
|
||||
// query success and key size is not 0
|
||||
@ -962,7 +962,7 @@ void HksIpcServiceRenameKeyAlias(const struct HksBlob *srcData, const uint8_t *c
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "HksCheckAcrossAccountsPermission fail, ret = %" LOG_PUBLIC "d", ret)
|
||||
|
||||
ret = HksServiceRenameKeyAlias(&processInfo, &oldKeyAlias, paramSet, &newKeyAlias);
|
||||
HKS_IF_NOT_SUCC_LOGE(ret, "HksServiceRenameKeyAliasy fail")
|
||||
HKS_IF_NOT_SUCC_LOGE(ret, "HksServiceRenameKeyAliasy fail, ret = %" LOG_PUBLIC "d", ret)
|
||||
} while (0);
|
||||
|
||||
HksSendResponse(context, ret, NULL);
|
||||
|
@ -51,7 +51,7 @@ int32_t SensitivePermissionCheck(const char *permission)
|
||||
HKS_LOG_I("Check Permission success!");
|
||||
return HKS_SUCCESS;
|
||||
} else {
|
||||
HKS_LOG_E("Check Permission failed!%" LOG_PUBLIC "s", permission);
|
||||
HKS_LOG_E("Check Permission failed!%" LOG_PUBLIC "s, ret = %" LOG_PUBLIC "d", permission, result);
|
||||
return HKS_ERROR_NO_PERMISSION;
|
||||
}
|
||||
}
|
||||
|
@ -50,14 +50,19 @@
|
||||
#endif // HAS_OS_ACCOUNT_PART
|
||||
|
||||
using namespace OHOS;
|
||||
|
||||
#ifndef HAS_OS_ACCOUNT_PART
|
||||
constexpr static int UID_TRANSFORM_DIVISOR = 200000;
|
||||
static void GetOsAccountIdFromUid(int uid, int &osAccountId)
|
||||
{
|
||||
osAccountId = uid / UID_TRANSFORM_DIVISOR;
|
||||
}
|
||||
#endif // HAS_OS_ACCOUNT_PART
|
||||
int HksGetOsAccountIdFromUid(int uid)
|
||||
{
|
||||
#ifdef HAS_OS_ACCOUNT_PART
|
||||
int accountId = 0;
|
||||
OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, accountId);
|
||||
return accountId;
|
||||
#else // HAS_OS_ACCOUNT_PART
|
||||
return uid / UID_TRANSFORM_DIVISOR;
|
||||
#endif // HAS_OS_ACCOUNT_PART
|
||||
}
|
||||
|
||||
void HksSendResponse(const uint8_t *context, int32_t result, const struct HksBlob *response)
|
||||
{
|
||||
@ -92,16 +97,8 @@ int32_t HksGetProcessInfoForIPC(const uint8_t *context, struct HksProcessInfo *p
|
||||
processInfo->processName.size = sizeof(callingUid);
|
||||
processInfo->processName.data = name;
|
||||
processInfo->uidInt = callingUid;
|
||||
int userId = 0;
|
||||
#ifdef HAS_OS_ACCOUNT_PART
|
||||
OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, userId);
|
||||
#else // HAS_OS_ACCOUNT_PART
|
||||
GetOsAccountIdFromUid(callingUid, userId);
|
||||
#endif // HAS_OS_ACCOUNT_PART
|
||||
|
||||
HKS_LOG_I("Get callingUid = %" LOG_PUBLIC "d, userId = %" LOG_PUBLIC "d, sessionId = %" LOG_PUBLIC "u",
|
||||
callingUid, userId, g_sessionId);
|
||||
|
||||
int userId = HksGetOsAccountIdFromUid(callingUid);
|
||||
uint32_t size;
|
||||
if (userId == 0) {
|
||||
size = strlen("0");
|
||||
|
@ -28,6 +28,8 @@ int32_t HksGetProcessInfoForIPC(const uint8_t *context, struct HksProcessInfo *p
|
||||
|
||||
int32_t HksGetFrontUserId(int32_t *outId);
|
||||
|
||||
int HksGetOsAccountIdFromUid(int uid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -271,7 +271,11 @@ int HksService::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParce
|
||||
uint64_t enterTime = 0;
|
||||
(void)HksElapsedRealTime(&enterTime);
|
||||
g_sessionId++;
|
||||
HKS_LOG_I("OnRemoteRequest code:%" LOG_PUBLIC "d, sessionId = %" LOG_PUBLIC "u", code, g_sessionId);
|
||||
auto callingUid = IPCSkeleton::GetCallingUid();
|
||||
int userId = HksGetOsAccountIdFromUid(callingUid);
|
||||
|
||||
HKS_LOG_I("OnRemoteRequest code:%" LOG_PUBLIC "u, callingUid = %" LOG_PUBLIC "d, userId = %" LOG_PUBLIC
|
||||
"d, sessionId = %" LOG_PUBLIC "u", code, callingUid, userId, g_sessionId);
|
||||
|
||||
// judge whether is upgrading, wait for upgrade finished
|
||||
if (HksWaitIfPowerOnUpgrading() != HKS_SUCCESS) {
|
||||
|
@ -270,7 +270,7 @@ static int32_t CopyDeToTmpPathIfNeed(void)
|
||||
}
|
||||
int32_t ret = rename(HKS_KEY_STORE_PATH, HKS_KEY_STORE_TMP_PATH);
|
||||
if (ret != 0) {
|
||||
HKS_LOG_E("move de file path to old file path failed, error code is %" LOG_PUBLIC "d.", errno);
|
||||
HKS_LOG_ERRNO("move de file path to old file path failed, ret =", HKS_ERROR_MAKE_DIR_FAIL);
|
||||
return HKS_ERROR_MAKE_DIR_FAIL;
|
||||
}
|
||||
ret = HksMakeDir(HKS_KEY_STORE_PATH);
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "hks_log.h"
|
||||
@ -93,6 +94,9 @@ static int32_t IsValidPath(const char *path)
|
||||
static int32_t IsFileExist(const char *fileName)
|
||||
{
|
||||
if (access(fileName, F_OK) != 0) {
|
||||
if (errno != ENOENT) {
|
||||
HKS_LOG_ERRNO("Check IsFileExist fail!", HKS_ERROR_OPEN_FILE_FAIL);
|
||||
}
|
||||
return HKS_ERROR_NOT_EXIST;
|
||||
}
|
||||
|
||||
@ -121,10 +125,20 @@ static int32_t FileRead(const char *fileName, uint32_t offset, struct HksBlob *b
|
||||
HKS_LOG_E("Check Permission failed!");
|
||||
return HKS_ERROR_NO_PERMISSION;
|
||||
}
|
||||
HKS_LOG_E("open file fail, errno = 0x%" LOG_PUBLIC "x", errno);
|
||||
HKS_LOG_ERRNO("open file fail,", HKS_ERROR_OPEN_FILE_FAIL);
|
||||
return HKS_ERROR_OPEN_FILE_FAIL;
|
||||
}
|
||||
|
||||
// Print file time info
|
||||
struct stat fileStat;
|
||||
(void)memset_s(&fileStat, sizeof(fileStat), 0, sizeof(fileStat));
|
||||
if (stat(fileName, &fileStat) != 0) {
|
||||
HKS_LOG_ERRNO("file stat fail,", HKS_ERROR_OPEN_FILE_FAIL);
|
||||
return HKS_ERROR_OPEN_FILE_FAIL;
|
||||
}
|
||||
HKS_LOG_I("File ctime: %" LOG_PUBLIC "s, mtime: %" LOG_PUBLIC "s",
|
||||
ctime(&fileStat.st_ctime), ctime(&fileStat.st_mtime));
|
||||
|
||||
uint32_t len = fread(blob->data, 1, blob->size, fp);
|
||||
if (fclose(fp) < 0) {
|
||||
HKS_LOG_E("failed to close file, errno = 0x%" LOG_PUBLIC "x", errno);
|
||||
@ -141,7 +155,7 @@ static uint32_t FileSize(const char *fileName)
|
||||
struct stat fileStat;
|
||||
(void)memset_s(&fileStat, sizeof(fileStat), 0, sizeof(fileStat));
|
||||
if (stat(fileName, &fileStat) != 0) {
|
||||
HKS_LOG_E("file stat fail, errno = 0x%" LOG_PUBLIC "x", errno);
|
||||
HKS_LOG_ERRNO("file stat fail,", HKS_ERROR_OPEN_FILE_FAIL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -228,6 +242,7 @@ static int32_t FileRemove(const char *fileName)
|
||||
|
||||
struct stat tmp;
|
||||
if (stat(fileName, &tmp) != 0) {
|
||||
HKS_LOG_ERRNO("file stat fail,", HKS_ERROR_OPEN_FILE_FAIL);
|
||||
return HKS_ERROR_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
@ -236,7 +251,7 @@ static int32_t FileRemove(const char *fileName)
|
||||
}
|
||||
|
||||
if ((unlink(fileName) != 0) && (errno != ENOENT)) {
|
||||
HKS_LOG_E("failed to remove file: errno = 0x%" LOG_PUBLIC "x", errno);
|
||||
HKS_LOG_ERRNO("unlink fail,", HKS_ERROR_REMOVE_FILE_FAIL);
|
||||
return HKS_ERROR_REMOVE_FILE_FAIL;
|
||||
}
|
||||
|
||||
@ -299,6 +314,7 @@ int32_t HksMakeDir(const char *path)
|
||||
case EEXIST:
|
||||
return HKS_ERROR_ALREADY_EXISTS;
|
||||
default:
|
||||
HKS_LOG_ERRNO("mkdir fail, ret = ", HKS_ERROR_MAKE_DIR_FAIL);
|
||||
return HKS_ERROR_MAKE_DIR_FAIL;
|
||||
}
|
||||
}
|
||||
@ -347,7 +363,7 @@ int32_t HksRemoveDir(const char *dirPath)
|
||||
struct stat fileStat;
|
||||
int32_t ret = stat(dirPath, &fileStat);
|
||||
if (ret != 0) {
|
||||
HKS_LOG_E("file stat failed");
|
||||
HKS_LOG_ERRNO("file stat failed", HKS_ERROR_OPEN_FILE_FAIL);
|
||||
return HKS_FAILURE;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user