Authentication Status Query (C/C++)
From API version 22, huksExternalCrypto provides the API for querying the PIN authentication status. This API can be used by applications to query whether the PIN passes authentication. For details about the scenarios and specifications, see Ukey PIN Authentication Management Overview and Specifications.
Linking the Dynamic Library in the CMake Script
target_link_libraries(entry PUBLIC libhuks_ndk.z.so libhuks_external_crypto.z.so)
How to Develop
-
Obtain keyUri as resourceId by calling the certificate selection API provided by the certificate management system.
-
Call OH_Huks_InitExternalCryptoParamSet to set specified parameters.
-
Call OH_Huks_GetUkeyPinAuthState to obtain the PIN authentication status.
Development Cases
#include "huks/native_huks_external_crypto_api.h"
#include "huks/native_huks_param.h"
#include "napi/native_api.h"
#include <string.h>
OH_Huks_Result InitParamSet(
struct OH_Huks_ExternalCryptoParamSet **paramSet,
const struct OH_Huks_ExternalCryptoParam *params,
uint32_t paramCount)
{
OH_Huks_Result ret = OH_Huks_InitExternalCryptoParamSet(paramSet);
if (ret.errorCode != OH_HUKS_SUCCESS) {
return ret;
}
ret = OH_Huks_AddExternalCryptoParams(*paramSet, params, paramCount);
if (ret.errorCode != OH_HUKS_SUCCESS) {
OH_Huks_FreeExternalCryptoParamSet(paramSet);
return ret;
}
ret = OH_Huks_BuildExternalCryptoParamSet(paramSet);
if (ret.errorCode != OH_HUKS_SUCCESS) {
OH_Huks_FreeExternalCryptoParamSet(paramSet);
return ret;
}
return ret;
}
static const char *resourceId = "{\"providerName\":\"testProviderName\",\"abilityName\":\"CryptoExtension\",\"bundleName\":\"com.example.cryptoapplication\",\"index\":{\"key\":\"testKey\"}}";
static struct OH_Huks_ExternalCryptoParam g_getPinStateParamsTest[] = {};
static napi_value GetUkeyPinAuthState(napi_env env, napi_callback_info info)
{
struct OH_Huks_Blob g_resourceId = {
(uint32_t)strlen(resourceId),
(uint8_t *)resourceId
};
struct OH_Huks_ExternalCryptoParamSet *pinStateParamSet = nullptr;
OH_Huks_ExternalPinAuthState authState = OH_HUKS_EXT_CRYPTO_PIN_NO_AUTH;
OH_Huks_Result ohResult;
do {
ohResult = InitParamSet(&pinStateParamSet, g_getPinStateParamsTest,
sizeof(g_getPinStateParamsTest) / sizeof(OH_Huks_ExternalCryptoParam));
if (ohResult.errorCode != OH_HUKS_SUCCESS) {
break;
}
ohResult = OH_Huks_GetUkeyPinAuthState(&g_resourceId, pinStateParamSet, &authState);
if (ohResult.errorCode != OH_HUKS_SUCCESS) {
break;
}
} while (0);
OH_Huks_FreeExternalCryptoParamSet(&pinStateParamSet);
napi_value ret;
napi_create_int32(env, ohResult.errorCode, &ret);
return ret;
}
你可能感兴趣的鸿蒙文章
openharmony 鸿蒙 huks-key-import-overview
openharmony 鸿蒙 huks-signing-signature-verification-arkts
openharmony 鸿蒙 huks-hmac-arkts
openharmony 鸿蒙 huks-key-agreement-overview
openharmony 鸿蒙 huks-as-user-sys
openharmony 鸿蒙 huks-delete-key-ndk