!166 修改Js侧返回证书部分字段长度错误

Merge pull request !166 from hhhFun/hhhfun
This commit is contained in:
openharmony_ci 2024-05-23 15:17:59 +00:00 committed by Gitee
commit 72a5b2838a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 27 additions and 18 deletions

View File

@ -719,7 +719,7 @@ static CfResult GetNotBeforeX509Openssl(HcfX509CertificateSpi *self, CfBlob *out
LOGE("Failed to get notBeforeDate data!");
return CF_ERR_CRYPTO_OPERATION;
}
uint32_t length = strlen(date);
uint32_t length = strlen(date) + 1;
return DeepCopyDataToOut(date, length, outDate);
}
@ -751,7 +751,7 @@ static CfResult GetNotAfterX509Openssl(HcfX509CertificateSpi *self, CfBlob *outD
LOGE("Failed to get notAfterDate data!");
return CF_ERR_CRYPTO_OPERATION;
}
uint32_t length = strlen(date);
uint32_t length = strlen(date) + 1;
return DeepCopyDataToOut(date, length, outDate);
}
@ -811,7 +811,7 @@ static CfResult GetSigAlgNameX509Openssl(HcfX509CertificateSpi *self, CfBlob *ou
if (algName == NULL) {
return CF_ERR_CRYPTO_OPERATION;
}
uint32_t len = strlen(algName);
uint32_t len = strlen(algName) + 1;
return DeepCopyDataToOut(algName, len, outName);
}
@ -838,7 +838,7 @@ static CfResult GetSigAlgOidX509Openssl(HcfX509CertificateSpi *self, CfBlob *out
CfPrintOpensslError();
return CF_ERR_CRYPTO_OPERATION;
}
uint32_t len = strlen(algOid);
uint32_t len = strlen(algOid) + 1;
return DeepCopyDataToOut(algOid, len, out);
}

View File

@ -169,7 +169,7 @@ static CfResult GetRevocationDate(HcfX509CrlEntry *self, CfBlob *out)
LOGE("Get revocation date from ASN1_TIME fail!");
return CF_ERR_CRYPTO_OPERATION;
}
uint32_t length = strlen(revTime);
uint32_t length = strlen(revTime) + 1;
out->data = (uint8_t *)CfMalloc(length, 0);
if (out->data == NULL) {
LOGE("Failed to malloc for revTime!");

View File

@ -296,7 +296,7 @@ static CfResult GetLastUpdate(HcfX509CrlSpi *self, CfBlob *out)
LOGE("ThisUpdate convert String fail, or thisUpdate is too long!");
return CF_ERR_CRYPTO_OPERATION;
}
uint32_t length = strlen(thisUpdate);
uint32_t length = strlen(thisUpdate) + 1;
out->data = (uint8_t *)CfMalloc(length, 0);
if (out->data == NULL) {
LOGE("Failed to malloc for thisUpdate!");
@ -329,7 +329,7 @@ static CfResult GetNextUpdate(HcfX509CrlSpi *self, CfBlob *out)
LOGE("Get next update time is null, or nextUpdate is too long!");
return CF_ERR_CRYPTO_OPERATION;
}
uint32_t length = strlen(nextUpdate);
uint32_t length = strlen(nextUpdate) + 1;
out->data = (uint8_t *)CfMalloc(length, 0);
if (out->data == NULL) {
LOGE("Failed to malloc for nextUpdate!");
@ -596,7 +596,7 @@ static CfResult GetSignatureAlgOidInner(X509_CRL *crl, CfBlob *oidOut)
CfFree(output);
return CF_ERR_CRYPTO_OPERATION;
}
uint32_t length = strlen(output);
uint32_t length = strlen(output) + 1;
oidOut->data = (uint8_t *)CfMalloc(length, 0);
if (oidOut->data == NULL) {
LOGE("Failed to malloc for oidOut!");
@ -647,7 +647,7 @@ static CfResult GetSignatureAlgName(HcfX509CrlSpi *self, CfBlob *algNameOut)
LOGE("Can not find algorithmName!");
return CF_ERR_CRYPTO_OPERATION;
}
uint32_t length = strlen(algName);
uint32_t length = strlen(algName) + 1;
algNameOut->data = (uint8_t *)CfMalloc(length, 0);
if (algNameOut->data == NULL) {
LOGE("Failed to malloc for algName!");

View File

@ -463,7 +463,8 @@ napi_value NapiX509Certificate::GetNotBeforeTime(napi_env env, napi_callback_inf
return nullptr;
}
napi_value result = nullptr;
napi_create_string_utf8(env, reinterpret_cast<char *>(blob->data), blob->size, &result);
uint32_t size = blob->data[blob->size - 1] == '\0' ? blob->size - 1 : blob->size;
napi_create_string_utf8(env, reinterpret_cast<char *>(blob->data), size, &result);
CfBlobDataFree(blob);
CfFree(blob);
blob = nullptr;
@ -487,7 +488,8 @@ napi_value NapiX509Certificate::GetNotAfterTime(napi_env env, napi_callback_info
return nullptr;
}
napi_value result = nullptr;
napi_create_string_utf8(env, reinterpret_cast<char *>(blob->data), blob->size, &result);
uint32_t size = blob->data[blob->size - 1] == '\0' ? blob->size - 1 : blob->size;
napi_create_string_utf8(env, reinterpret_cast<char *>(blob->data), size, &result);
CfBlobDataFree(blob);
CfFree(blob);
blob = nullptr;
@ -534,7 +536,8 @@ napi_value NapiX509Certificate::GetSigAlgName(napi_env env, napi_callback_info i
return nullptr;
}
napi_value result = nullptr;
napi_create_string_utf8(env, reinterpret_cast<char *>(blob->data), blob->size, &result);
uint32_t size = blob->data[blob->size - 1] == '\0' ? blob->size - 1 : blob->size;
napi_create_string_utf8(env, reinterpret_cast<char *>(blob->data), size, &result);
CfBlobDataFree(blob);
CfFree(blob);
blob = nullptr;
@ -558,7 +561,8 @@ napi_value NapiX509Certificate::GetSigAlgOID(napi_env env, napi_callback_info in
return nullptr;
}
napi_value result = nullptr;
napi_create_string_utf8(env, reinterpret_cast<char *>(blob->data), blob->size, &result);
uint32_t size = blob->data[blob->size - 1] == '\0' ? blob->size - 1 : blob->size;
napi_create_string_utf8(env, reinterpret_cast<char *>(blob->data), size, &result);
CfBlobDataFree(blob);
CfFree(blob);
blob = nullptr;

View File

@ -468,7 +468,8 @@ napi_value NapiX509Crl::GetThisUpdate(napi_env env, napi_callback_info info)
return nullptr;
}
napi_value result = nullptr;
napi_create_string_utf8(env, reinterpret_cast<char *>(blob->data), blob->size, &result);
uint32_t size = blob->data[blob->size - 1] == '\0' ? blob->size - 1 : blob->size;
napi_create_string_utf8(env, reinterpret_cast<char *>(blob->data), size, &result);
CfBlobDataFree(blob);
CfFree(blob);
blob = nullptr;
@ -492,7 +493,8 @@ napi_value NapiX509Crl::GetNextUpdate(napi_env env, napi_callback_info info)
return nullptr;
}
napi_value result = nullptr;
napi_create_string_utf8(env, reinterpret_cast<char *>(blob->data), blob->size, &result);
uint32_t size = blob->data[blob->size - 1] == '\0' ? blob->size - 1 : blob->size;
napi_create_string_utf8(env, reinterpret_cast<char *>(blob->data), size, &result);
CfBlobDataFree(blob);
CfFree(blob);
blob = nullptr;
@ -889,7 +891,8 @@ napi_value NapiX509Crl::GetSigAlgName(napi_env env, napi_callback_info info)
return nullptr;
}
napi_value result = nullptr;
napi_create_string_utf8(env, reinterpret_cast<char *>(blob->data), blob->size, &result);
uint32_t size = blob->data[blob->size - 1] == '\0' ? blob->size - 1 : blob->size;
napi_create_string_utf8(env, reinterpret_cast<char *>(blob->data), size, &result);
CfBlobDataFree(blob);
CfFree(blob);
blob = nullptr;
@ -913,7 +916,8 @@ napi_value NapiX509Crl::GetSigAlgOID(napi_env env, napi_callback_info info)
return nullptr;
}
napi_value result = nullptr;
napi_create_string_utf8(env, reinterpret_cast<char *>(blob->data), blob->size, &result);
uint32_t size = blob->data[blob->size - 1] == '\0' ? blob->size - 1 : blob->size;
napi_create_string_utf8(env, reinterpret_cast<char *>(blob->data), size, &result);
CfBlobDataFree(blob);
CfFree(blob);
blob = nullptr;

View File

@ -284,7 +284,8 @@ napi_value NapiX509CrlEntry::GetRevocationDate(napi_env env, napi_callback_info
return nullptr;
}
napi_value returnDate = nullptr;
napi_create_string_utf8(env, reinterpret_cast<char *>(blob->data), blob->size, &returnDate);
uint32_t size = blob->data[blob->size - 1] == '\0' ? blob->size - 1 : blob->size;
napi_create_string_utf8(env, reinterpret_cast<char *>(blob->data), size, &returnDate);
CfBlobDataFree(blob);
CfFree(blob);
blob = nullptr;