open north interfaces

Signed-off-by: huyiqi <huyiqi3@huawei.com>
This commit is contained in:
huyiqi 2024-03-27 09:55:48 +08:00
parent 73b7c9374d
commit 7c48011e56
26 changed files with 142 additions and 124 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -39,9 +39,9 @@ extern "C" {
#define MAX_SUFFIX_LEN 16
#define MAX_COUNT_CERTIFICATE 256
#define MAX_LEN_URI 64
#define MAX_LEN_URI 256
#define MAX_AUTH_LEN_URI 256
#define MAX_LEN_CERT_ALIAS 64
#define MAX_LEN_CERT_ALIAS 65 /* include 1 byte: the terminator('\0') */
#define MAX_LEN_SUBJECT_NAME 256
#define MAX_LEN_PACKGE_NAME 64
#define MAX_UINT32_LEN 16
@ -121,7 +121,7 @@ enum CmErrorCode {
CMR_ERROR_REMOVE_FILE_FAIL = -13,
CMR_ERROR_CLOSE_FILE_FAIL = -14,
CMR_ERROR_MALLOC_FAIL = -15,
CMR_ERROR_NOT_EXIST = -16,
CMR_ERROR_NOT_EXIST = -16,
CMR_ERROR_ALREADY_EXISTS = -17,
CMR_ERROR_INSUFFICIENT_DATA = -18,
CMR_ERROR_BUFFER_TOO_SMALL = -19,
@ -132,6 +132,8 @@ enum CmErrorCode {
CMR_ERROR_AUTH_CHECK_FAILED = -24,
CMR_ERROR_KEY_OPERATION_FAILED = -25,
CMR_ERROR_NOT_SYSTEMP_APP = -26,
CMR_ERROR_CERT_NUM_REACHED_LIMIT = -27,
CMR_ERROR_ALIAS_LENGTH_REACHED_LIMIT = -28,
};
enum CMErrorCode { /* temp use */

View File

@ -95,8 +95,8 @@ declare namespace CertificateManager {
* @syscap SystemCapability.Security.CertificateManager
* @permission ohos.permission.ACCESS_CERT_MANAGER
*/
function getUserTrustedCertificateList(callback: AsyncCallback<CMResult>) : void;
function getUserTrustedCertificateList() : Promise<CMResult>;
function getAllUserTrustedCertificates(callback: AsyncCallback<CMResult>) : void;
function getAllUserTrustedCertificates() : Promise<CMResult>;
/**
* Get the detail of user root certificate.
@ -118,8 +118,8 @@ declare namespace CertificateManager {
* @permission ohos.permission.ACCESS_CERT_MANAGER_INTERNAL
* @systemapi Hide this for inner system use
*/
function installAppCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string, callback: AsyncCallback<CMResult>) : void;
function installAppCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string) : Promise<CMResult>;
function installPublicCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string, callback: AsyncCallback<CMResult>) : void;
function installPublicCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string) : Promise<CMResult>;
/**
* Install private application certificate.
@ -174,8 +174,8 @@ declare namespace CertificateManager {
* @permission ohos.permission.ACCESS_CERT_MANAGER_INTERNAL
* @systemapi Hide this for inner system use
*/
function uninstallAppCertificate(keyUri: string, callback: AsyncCallback<boolean>) : void;
function uninstallAppCertificate(keyUri: string) : Promise<boolean>;
function uninstallPublicCertificate(keyUri: string, callback: AsyncCallback<boolean>) : void;
function uninstallPublicCertificate(keyUri: string) : Promise<boolean>;
/**
* Uninstall the specified normal application certificate.
@ -194,8 +194,8 @@ declare namespace CertificateManager {
* @permission ohos.permission.ACCESS_CERT_MANAGER_INTERNAL
* @systemapi Hide this for inner system use
*/
function getAppCertificateList(callback: AsyncCallback<CMResult>) : void;
function getAppCertificateList() : Promise<CMResult>;
function getAllPublicCertificates(callback: AsyncCallback<CMResult>) : void;
function getAllPublicCertificates() : Promise<CMResult>;
/**
* Get a list of private application certificates.
@ -214,8 +214,8 @@ declare namespace CertificateManager {
* @param keyUri Indicates key's name.
* @permission ohos.permission.ACCESS_CERT_MANAGER
*/
function getAppCertificate(keyUri: string, callback: AsyncCallback<CMResult>) : void;
function getAppCertificate(keyUri: string, ) : Promise<CMResult>;
function getPublicCertificate(keyUri: string, callback: AsyncCallback<CMResult>) : void;
function getPublicCertificate(keyUri: string, ) : Promise<CMResult>;
/**
* Get the detail of private application certificate.
@ -236,8 +236,8 @@ declare namespace CertificateManager {
* @permission ohos.permission.ACCESS_CERT_MANAGER_INTERNAL
* @systemapi Hide this for inner system use
*/
function grantAppCertificate(keyUri: string, clientAppUid: string, callback: AsyncCallback<CMResult>) : void;
function grantAppCertificate(keyUri: string, clientAppUid: string) : Promise<CMResult>;
function grantPublicCertificate(keyUri: string, clientAppUid: string, callback: AsyncCallback<CMResult>) : void;
function grantPublicCertificate(keyUri: string, clientAppUid: string) : Promise<CMResult>;
/**
* Whether the current application is authorized by the specified application certificate.
@ -269,8 +269,8 @@ declare namespace CertificateManager {
* @permission ohos.permission.ACCESS_CERT_MANAGER_INTERNAL
* @systemapi Hide this for inner system use
*/
function removeGrantedAppCertificate(keyUri: string, clientAppUid: string, callback: AsyncCallback<boolean>) : void;
function removeGrantedAppCertificate(keyUri: string, clientAppUid: string) : Promise<boolean>;
function removeGrantedPublicCertificate(keyUri: string, clientAppUid: string, callback: AsyncCallback<boolean>) : void;
function removeGrantedPublicCertificate(keyUri: string, clientAppUid: string) : Promise<boolean>;
/**
* Init operation for signing and verifying etc.
@ -394,11 +394,15 @@ declare namespace CertificateManager {
}
export enum CMErrorCode {
CM_SUCCESS = 0,
CM_ERROR_INNER_ERROR = 17500001,
CM_ERROR_NO_PERMISSION = 17500002,
CM_ERROR_NO_FOUND = 17500003,
CM_ERROR_X509_FORMATE = 17500004,
CM_ERROR_NO_PERMISSION = 201,
CM_ERROR_NOT_SYSTEM_APP = 202,
CM_ERROR_INVALID_PARAMS = 401,
CM_ERROR_GENERIC = 17500001,
CM_ERROR_NO_FOUND = 17500002,
CM_ERROR_INCORRECT_FORMAT = 17500003,
CM_ERROR_CERT_NUM_REACHED_LIMIT = 17500004,
CM_ERROR_NO_AUTHORIZATION = 17500005,
CM_ERROR_ALIAS_LENGTH_REACHED_LIMIT = 17500006
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -155,6 +155,9 @@ enum ErrorCode {
INNER_FAILURE = 17500001,
NOT_FOUND = 17500002,
INVALID_CERT_FORMAT = 17500003,
CERT_NUM_REACHED_LIMIT = 17500004,
NO_AUTHORIZATION = 17500005,
ALIAS_LENGTH_REACHED_LIMIT = 17500006,
};
enum CmJSKeyDigest {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -20,7 +20,7 @@
#include "napi/native_node_api.h"
namespace CMNapi {
napi_value CMNapiGetAppCertInfo(napi_env env, napi_callback_info info);
napi_value CMNapiGetPublicCertInfo(napi_env env, napi_callback_info info);
napi_value CMNapiGetPrivateAppCertInfo(napi_env env, napi_callback_info info);
} // namespace CertManagerNapi

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -20,7 +20,7 @@
#include "napi/native_node_api.h"
namespace CMNapi {
napi_value CMNapiGetAppCertList(napi_env env, napi_callback_info info);
napi_value CMNapiGetAllPublicCertList(napi_env env, napi_callback_info info);
napi_value CMNapiGetPrivateAppCertList(napi_env env, napi_callback_info info);
} // namespace CertManagerNapi

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -22,7 +22,7 @@
namespace CMNapi {
napi_value CMNapiGetSystemCertList(napi_env env, napi_callback_info info);
napi_value CMNapiGetUserTrustedCertList(napi_env env, napi_callback_info info);
napi_value CMNapiGetAllUserTrustedCertList(napi_env env, napi_callback_info info);
} // namespace CertManagerNapi
#endif // CM_NAPI_GET_CERTIFICATE_LIST_H

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -20,10 +20,10 @@
#include "napi/native_node_api.h"
namespace CMNapi {
napi_value CMNapiGrantAppCertificate(napi_env env, napi_callback_info info);
napi_value CMNapiGrantPublicCertificate(napi_env env, napi_callback_info info);
napi_value CMNapiIsAuthorizedApp(napi_env env, napi_callback_info info);
napi_value CMNapiGetAuthorizedAppList(napi_env env, napi_callback_info info);
napi_value CMNapiRemoveGrantedApp(napi_env env, napi_callback_info info);
napi_value CMNapiRemoveGrantedPublic(napi_env env, napi_callback_info info);
} // namespace CMNapi
#endif /* CM_NAPI_GRANT_H */

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -20,7 +20,7 @@
#include "napi/native_node_api.h"
namespace CMNapi {
napi_value CMNapiInstallAppCert(napi_env env, napi_callback_info info);
napi_value CMNapiInstallPublicCert(napi_env env, napi_callback_info info);
napi_value CMNapiInstallPrivateAppCert(napi_env env, napi_callback_info info);
} // namespace CertManagerNapi

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -20,7 +20,7 @@
#include "napi/native_node_api.h"
namespace CMNapi {
napi_value CMNapiUninstallAppCert(napi_env env, napi_callback_info info);
napi_value CMNapiUninstallPublicCert(napi_env env, napi_callback_info info);
napi_value CMNapiUninstallPrivateAppCert(napi_env env, napi_callback_info info);
} // namespace CertManagerNapi

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -46,6 +46,9 @@ namespace CMNapi {
AddInt32Property(env, errorCode, "CM_ERROR_GENERIC", INNER_FAILURE);
AddInt32Property(env, errorCode, "CM_ERROR_NO_FOUND", NOT_FOUND);
AddInt32Property(env, errorCode, "CM_ERROR_INCORRECT_FORMAT", INVALID_CERT_FORMAT);
AddInt32Property(env, errorCode, "CM_ERROR_CERT_NUM_REACHED_LIMIT", CERT_NUM_REACHED_LIMIT);
AddInt32Property(env, errorCode, "CM_ERROR_NO_AUTHORIZATION", NO_AUTHORIZATION);
AddInt32Property(env, errorCode, "CM_ERROR_ALIAS_LENGTH_REACHED_LIMIT", ALIAS_LENGTH_REACHED_LIMIT);
}
static napi_value CreateCMErrorCode(napi_env env)
@ -110,26 +113,33 @@ extern "C" {
DECLARE_NAPI_FUNCTION("getSystemTrustedCertificateList", CMNapiGetSystemCertList),
DECLARE_NAPI_FUNCTION("getSystemTrustedCertificate", CMNapiGetSystemCertInfo),
DECLARE_NAPI_FUNCTION("setCertificateStatus", CMNapiSetCertStatus),
DECLARE_NAPI_FUNCTION("installAppCertificate", CMNapiInstallAppCert),
DECLARE_NAPI_FUNCTION("installAppCertificate", CMNapiInstallPublicCert),
DECLARE_NAPI_FUNCTION("installPublicCertificate", CMNapiInstallPublicCert),
DECLARE_NAPI_FUNCTION("uninstallAllAppCertificate", CMNapiUninstallAllAppCert),
DECLARE_NAPI_FUNCTION("uninstallAppCertificate", CMNapiUninstallAppCert),
DECLARE_NAPI_FUNCTION("getAppCertificateList", CMNapiGetAppCertList),
DECLARE_NAPI_FUNCTION("getAppCertificate", CMNapiGetAppCertInfo),
DECLARE_NAPI_FUNCTION("uninstallAppCertificate", CMNapiUninstallPublicCert),
DECLARE_NAPI_FUNCTION("getAppCertificateList", CMNapiGetAllPublicCertList),
DECLARE_NAPI_FUNCTION("getAppCertificate", CMNapiGetPublicCertInfo),
DECLARE_NAPI_FUNCTION("uninstallPublicCertificate", CMNapiUninstallPublicCert),
DECLARE_NAPI_FUNCTION("getAllPublicCertificates", CMNapiGetAllPublicCertList),
DECLARE_NAPI_FUNCTION("getPublicCertificate", CMNapiGetPublicCertInfo),
DECLARE_NAPI_FUNCTION("installUserTrustedCertificate", CMNapiInstallUserTrustedCert),
DECLARE_NAPI_FUNCTION("uninstallAllUserTrustedCertificate", CMNapiUninstallAllUserTrustedCert),
DECLARE_NAPI_FUNCTION("uninstallUserTrustedCertificate", CMNapiUninstallUserTrustedCert),
DECLARE_NAPI_FUNCTION("getUserTrustedCertificateList", CMNapiGetUserTrustedCertList),
DECLARE_NAPI_FUNCTION("getUserTrustedCertificateList", CMNapiGetAllUserTrustedCertList),
DECLARE_NAPI_FUNCTION("getAllUserTrustedCertificates", CMNapiGetAllUserTrustedCertList),
DECLARE_NAPI_FUNCTION("getUserTrustedCertificate", CMNapiGetUserTrustedCertInfo),
DECLARE_NAPI_FUNCTION("installPrivateCertificate", CMNapiInstallPrivateAppCert),
DECLARE_NAPI_FUNCTION("uninstallPrivateCertificate", CMNapiUninstallPrivateAppCert),
DECLARE_NAPI_FUNCTION("getPrivateCertificateList", CMNapiGetPrivateAppCertList),
DECLARE_NAPI_FUNCTION("getAllAppPrivateCertificates", CMNapiGetPrivateAppCertList),
DECLARE_NAPI_FUNCTION("getPrivateCertificate", CMNapiGetPrivateAppCertInfo),
DECLARE_NAPI_FUNCTION("grantAppCertificate", CMNapiGrantAppCertificate),
DECLARE_NAPI_FUNCTION("grantAppCertificate", CMNapiGrantPublicCertificate),
DECLARE_NAPI_FUNCTION("grantPublicCertificate", CMNapiGrantPublicCertificate),
DECLARE_NAPI_FUNCTION("isAuthorizedApp", CMNapiIsAuthorizedApp),
DECLARE_NAPI_FUNCTION("getAuthorizedAppList", CMNapiGetAuthorizedAppList),
DECLARE_NAPI_FUNCTION("removeGrantedAppCertificate", CMNapiRemoveGrantedApp),
DECLARE_NAPI_FUNCTION("removeGrantedAppCertificate", CMNapiRemoveGrantedPublic),
DECLARE_NAPI_FUNCTION("removeGrantedPublicCertificate", CMNapiRemoveGrantedPublic),
DECLARE_NAPI_FUNCTION("init", CMNapiInit),
DECLARE_NAPI_FUNCTION("update", CMNapiUpdate),
DECLARE_NAPI_FUNCTION("finish", CMNapiFinish),

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -15,6 +15,7 @@
#include "cm_napi_common.h"
#include <unordered_map>
#include "securec.h"
#include "cm_log.h"
@ -23,6 +24,23 @@
namespace CMNapi {
namespace {
constexpr int CM_MAX_DATA_LEN = 0x6400000; // The maximum length is 100M
static const std::unordered_map<int32_t, int32_t> NATIVE_CODE_TO_JS_CODE_MAP = {
// invalid params
{ CMR_ERROR_INVALID_ARGUMENT, PARAM_ERROR },
// no permission
{ CMR_ERROR_PERMISSION_DENIED, HAS_NO_PERMISSION },
{ CMR_ERROR_NOT_SYSTEMP_APP, NOT_SYSTEM_APP },
{ CMR_ERROR_INVALID_CERT_FORMAT, INVALID_CERT_FORMAT },
{ CMR_ERROR_INSUFFICIENT_DATA, INVALID_CERT_FORMAT },
{ CMR_ERROR_NOT_FOUND, NOT_FOUND },
{ CMR_ERROR_NOT_EXIST, NOT_FOUND },
{ CMR_ERROR_CERT_NUM_REACHED_LIMIT, CERT_NUM_REACHED_LIMIT },
{ CMR_ERROR_AUTH_CHECK_FAILED, NO_AUTHORIZATION },
{ CMR_ERROR_ALIAS_LENGTH_REACHED_LIMIT, ALIAS_LENGTH_REACHED_LIMIT },
};
} // namespace
napi_value ParseUint32(napi_env env, napi_value object, uint32_t &store)
@ -334,20 +352,9 @@ napi_value GenerateCertInfo(napi_env env, const struct CertInfo *certInfo)
int32_t TranformErrorCode(int32_t errorCode)
{
if (errorCode == CMR_ERROR_INVALID_CERT_FORMAT || errorCode == CMR_ERROR_INSUFFICIENT_DATA) {
return INVALID_CERT_FORMAT;
}
if (errorCode == CMR_ERROR_NOT_FOUND || errorCode == CMR_ERROR_NOT_EXIST) {
return NOT_FOUND;
}
if (errorCode == CMR_ERROR_PERMISSION_DENIED) {
return HAS_NO_PERMISSION;
}
if (errorCode == CMR_ERROR_NOT_SYSTEMP_APP) {
return NOT_SYSTEM_APP;
}
if (errorCode == CMR_ERROR_INVALID_ARGUMENT) {
return PARAM_ERROR;
auto iter = NATIVE_CODE_TO_JS_CODE_MAP.find(errorCode);
if (iter != NATIVE_CODE_TO_JS_CODE_MAP.end()) {
return iter->second;
}
return INNER_FAILURE;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -19,7 +19,7 @@
#include "cm_log.h"
namespace CMNapi {
napi_value CMNapiGetAppCertInfo(napi_env env, napi_callback_info info)
napi_value CMNapiGetPublicCertInfo(napi_env env, napi_callback_info info)
{
return CMNapiGetAppCertInfoCommon(env, info, APPLICATION_CERTIFICATE_STORE);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -19,7 +19,7 @@
#include "cm_log.h"
namespace CMNapi {
napi_value CMNapiGetAppCertList(napi_env env, napi_callback_info info)
napi_value CMNapiGetAllPublicCertList(napi_env env, napi_callback_info info)
{
return CMNapiGetAppCertListCommon(env, info, APPLICATION_CERTIFICATE_STORE);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -208,7 +208,7 @@ napi_value CMNapiGetSystemCertList(napi_env env, napi_callback_info info)
return result;
}
napi_value CMNapiGetUserTrustedCertList(napi_env env, napi_callback_info info)
napi_value CMNapiGetAllUserTrustedCertList(napi_env env, napi_callback_info info)
{
GetCertListAsyncContext context = CreateGetCertListAsyncContext();
if (context == nullptr) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -245,6 +245,10 @@ static void RemoveOrIsAuthedComplete(napi_env env, napi_status status, void *dat
if (context->errCode == CM_SUCCESS) {
napi_create_uint32(env, 0, &result[0]);
napi_get_boolean(env, true, &result[1]);
} else if (context->errCode == CMR_ERROR_AUTH_CHECK_FAILED) {
napi_create_uint32(env, 0, &result[0]);
napi_get_boolean(env, false, &result[1]);
context->errCode = CM_SUCCESS;
} else {
result[0] = GenerateBusinessError(env, context->errCode, "remove or check is authed process failed");
napi_get_undefined(env, &result[1]);
@ -428,7 +432,7 @@ static napi_value GetUidListAsyncWork(napi_env env, GrantAsyncContext context)
return promise;
}
napi_value CMNapiGrantAppCertificate(napi_env env, napi_callback_info info)
napi_value CMNapiGrantPublicCertificate(napi_env env, napi_callback_info info)
{
GrantAsyncContext context = InitGrantAsyncContext();
if (context == nullptr) {
@ -503,7 +507,7 @@ napi_value CMNapiGetAuthorizedAppList(napi_env env, napi_callback_info info)
return result;
}
napi_value CMNapiRemoveGrantedApp(napi_env env, napi_callback_info info)
napi_value CMNapiRemoveGrantedPublic(napi_env env, napi_callback_info info)
{
GrantAsyncContext context = InitGrantAsyncContext();
if (context == nullptr) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -19,7 +19,7 @@
#include "cm_log.h"
namespace CMNapi {
napi_value CMNapiInstallAppCert(napi_env env, napi_callback_info info)
napi_value CMNapiInstallPublicCert(napi_env env, napi_callback_info info)
{
return CMNapiInstallAppCertCommon(env, info, APPLICATION_CERTIFICATE_STORE);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -19,7 +19,7 @@
#include "cm_log.h"
namespace CMNapi {
napi_value CMNapiUninstallAppCert(napi_env env, napi_callback_info info)
napi_value CMNapiUninstallPublicCert(napi_env env, napi_callback_info info)
{
return CMNapiUninstallAppCertCommon(env, info, APPLICATION_CERTIFICATE_STORE);
}

View File

@ -25,11 +25,6 @@ extern "C" {
#define DEC_LEN 10
// maximum length of object names for cert manager
#define CM_NAME_MAX_LEN 32
// maximum length of URI
#define CM_URI_MAX_LEN 256
#define CM_URI_TYPE_CERTIFICATE ((uint32_t)0)
#define CM_URI_TYPE_MAC_KEY ((uint32_t)1)
#define CM_URI_TYPE_APP_KEY ((uint32_t)2)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -468,7 +468,7 @@ int32_t CmWriteUserCert(const struct CmContext *context, struct CmMutableBlob *p
{
if (certAlias->size > MAX_LEN_CERT_ALIAS) {
CM_LOG_E("alias size is too large");
return CMR_ERROR_INVALID_ARGUMENT;
return CMR_ERROR_ALIAS_LENGTH_REACHED_LIMIT;
}
int32_t ret;
@ -488,7 +488,7 @@ int32_t CmWriteUserCert(const struct CmContext *context, struct CmMutableBlob *p
ret = CherkCertCountBeyondMax((char*)pathBlob->data, (char *)certUri->data);
if (ret != CM_SUCCESS) {
CM_LOG_E("cert count beyond maxcount, can't install");
ret = CMR_ERROR_INVALID_ARGUMENT;
ret = CMR_ERROR_CERT_NUM_REACHED_LIMIT;
break;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -470,7 +470,7 @@ static int32_t CheckIsAuthorizedApp(const struct CMUri *uriObj)
if (ret != CM_SUCCESS) {
CM_LOG_E("calc uri mac failed, ret = %d", ret);
CM_FREE_PTR(macByte.data);
return ret;
return CMR_ERROR_AUTH_CHECK_FAILED;
}
if ((macByte.size != mac.size) || (memcmp(macByte.data, mac.data, macByte.size) != 0)) {

View File

@ -106,24 +106,6 @@ int32_t CmServiceSetCertStatusCheck(const uint32_t store, const struct CmBlob *c
return CM_SUCCESS;
}
static bool AppCertCheckBlobValid(const struct CmBlob *data)
{
for (uint32_t i = 0; i < data->size; i++) {
if ((i > 0) && (data->data[i] == '\0')) { /* from index 1 has '\0' */
CM_LOG_D("data has string end character");
return true;
}
if ((!isalnum(data->data[i])) && (data->data[i] != '_')) { /* has invalid character */
CM_LOG_E("data include invalid character");
return false;
}
}
CM_LOG_E("data has no string end character");
return false;
}
static bool CmCheckMaxInstalledCertCount(const uint32_t store, const struct CmContext *cmContext)
{
bool isValid = true;
@ -163,21 +145,24 @@ int32_t CmServiceInstallAppCertCheck(const struct CmBlob *appCert, const struct
return CMR_ERROR_INVALID_ARGUMENT;
}
if (appCert->size > MAX_LEN_APP_CERT || appCertPwd->size > MAX_LEN_APP_CERT_PASSWD ||
certAlias->size > MAX_LEN_CERT_ALIAS) {
CM_LOG_E("CmInstallAppCertCheck max check fail, appCert:%u, appCertPwd:%u, certAlias:%u",
appCert->size, appCertPwd->size, certAlias->size);
if (certAlias->size > MAX_LEN_CERT_ALIAS) {
CM_LOG_E("alias size is too large");
return CMR_ERROR_ALIAS_LENGTH_REACHED_LIMIT;
}
if (appCert->size > MAX_LEN_APP_CERT || appCertPwd->size > MAX_LEN_APP_CERT_PASSWD) {
CM_LOG_E("CmInstallAppCertCheck max check fail, appCert:%u, appCertPwd:%u", appCert->size, appCertPwd->size);
return CMR_ERROR_INVALID_ARGUMENT;
}
if ((CheckUri(appCertPwd) != CM_SUCCESS) || (!AppCertCheckBlobValid(certAlias))) {
if ((CheckUri(appCertPwd) != CM_SUCCESS) || (CheckUri(certAlias) != CM_SUCCESS)) {
CM_LOG_E("CmInstallAppCertCheck blob data check fail");
return CMR_ERROR_INVALID_ARGUMENT;
}
if (CmCheckMaxInstalledCertCount(store, cmContext) == false) {
CM_LOG_E("CmCheckMaxInstalledCertCount check fail");
return CM_FAILURE;
return CMR_ERROR_CERT_NUM_REACHED_LIMIT;
}
if (!CmPermissionCheck(store)) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -533,7 +533,6 @@ int32_t CmInstallUserCert(const struct CmContext *context, const struct CmBlob *
ret = CmWriteUserCert(context, &pathBlob, userCert, certAlias, certUri);
if (ret != CM_SUCCESS) {
CM_LOG_E("CertManagerWriteUserCert fail");
ret = CM_FAILURE;
break;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -127,11 +127,16 @@ int32_t ConstructAuthListPath(const struct CmContext *context, uint32_t store,
int32_t CmStorageGetBuf(const char *path, const char *fileName, struct CmBlob *storageBuf)
{
uint32_t fileSize = CmFileSize(path, fileName);
if (fileSize == 0 || fileSize > MAX_OUT_BLOB_SIZE) {
if (fileSize > MAX_OUT_BLOB_SIZE) {
CM_LOG_E("file size[%u] invalid", fileSize);
return CMR_ERROR_INVALID_OPERATION;
}
if (fileSize == 0) {
CM_LOG_E("file is not exist");
return CMR_ERROR_NOT_EXIST;
}
uint8_t *data = (uint8_t *)CMMalloc(fileSize);
if (data == NULL) {
CM_LOG_E("malloc file buffer failed");
@ -142,7 +147,7 @@ int32_t CmStorageGetBuf(const char *path, const char *fileName, struct CmBlob *s
if (readSize == 0) {
CM_LOG_E("read file size 0 invalid");
CMFree(data);
return CMR_ERROR_INVALID_OPERATION;
return CMR_ERROR_NOT_EXIST;
}
storageBuf->data = data;

View File

@ -359,7 +359,7 @@ HWTEST_F(CmInnerPermissionTest, CmInnerPermissionTest018, TestSize.Level0)
"oh:t=ak;o=inner018;u=0;a=0?ca=0&m=BA632421B76F1059BC28184FB9E50D5795232B6D5C535E0DCAC0114A7AD8FAFE";
struct CmBlob authUri = { sizeof(uriData), uriData };
int32_t ret = CmIsAuthorizedApp(&authUri);
EXPECT_EQ(ret, CMR_ERROR_KEY_OPERATION_FAILED);
EXPECT_EQ(ret, CMR_ERROR_AUTH_CHECK_FAILED);
}
/**

View File

@ -324,7 +324,7 @@ HWTEST_F(CmIsAuthedTest, CmIsAuthedTest016, TestSize.Level0)
"oh:t=ak;o=keyA;u=0;a=0?ca=0&m=BA632421B76F1059BC28184FB9E50D5795232B6D5C535E0DCAC0114A7AD8FAFE";
struct CmBlob authUriFail = { sizeof(uriDataFail), uriDataFail };
int32_t ret = CmIsAuthorizedApp(&authUriFail);
EXPECT_EQ(ret, CMR_ERROR_KEY_OPERATION_FAILED);
EXPECT_EQ(ret, CMR_ERROR_AUTH_CHECK_FAILED);
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -683,7 +683,7 @@ HWTEST_F(CmUserCertTest, InstallUserCertTest007, TestSize.Level0)
struct CmBlob certUri257 = { sizeof(certUriBuf257), certUriBuf257 };
ret = CmInstallUserTrustedCert(&userCertTest, &certAlias257, &certUri257);
EXPECT_EQ(ret, CM_FAILURE) << "Normal user cert Install test failed, recode:" << ret;
EXPECT_EQ(ret, CMR_ERROR_CERT_NUM_REACHED_LIMIT) << "Normal user cert Install test failed, recode:" << ret;
uint8_t certAliasBuf000[] = "alias0"; /* update 001th user cert */
uint8_t certUriBuf000[MAX_URI_LEN] = {0};
@ -727,7 +727,8 @@ HWTEST_F(CmUserCertTest, InstallUserCertTest008, TestSize.Level0)
HWTEST_F(CmUserCertTest, InstallUserCertTest009, TestSize.Level0)
{
int32_t ret;
uint8_t largeAliasBuf[] = "large-size-input-cert-alias-000000000000000000000000000000000000";
/* size is 66, include 1 byte: the terminator('\0') */
uint8_t largeAliasBuf[] = "large-size-input-cert-alias-0000000000000000000000000000000000000";
uint8_t certUriBuf[MAX_URI_LEN] = {0};
struct CmBlob userCertTemp = { sizeof(g_certData02), const_cast<uint8_t *>(g_certData02) };
@ -735,7 +736,7 @@ HWTEST_F(CmUserCertTest, InstallUserCertTest009, TestSize.Level0)
struct CmBlob certUriTemp = { sizeof(certUriBuf), certUriBuf };
ret = CmInstallUserTrustedCert(&userCertTemp, &largeAlias, &certUriTemp);
EXPECT_EQ(ret, CM_FAILURE) << "Normal user cert Install test failed, recode:" << ret;
EXPECT_EQ(ret, CMR_ERROR_ALIAS_LENGTH_REACHED_LIMIT) << "Normal user cert Install test failed, recode:" << ret;
}
/**
@ -760,22 +761,25 @@ HWTEST_F(CmUserCertTest, InstallUserCertTest010, TestSize.Level0)
/**
* @tc.name: InstallUserCertTest011
* @tc.desc: Test CertManager Install user cert interface Abnormal function
* @tc.desc: Test CertManager Install user cert interface normal function
* @tc.type: FUNC
* @tc.require: AR000H0MJ8 /SR000H09N7
*/
HWTEST_F(CmUserCertTest, InstallUserCertTest011, TestSize.Level0)
{
int32_t ret;
char edgeAliasBuf[] = "aliaslengthis4800000000000000000000000000000000"; /* size is 48 */
uint8_t largeUriBuf[MAX_URI_LEN] = {0}; /* oh:t=c;o=;u=0;a=0 + alias size is 65 */
char edgeAliasBuf[] = "alias-length-is-48-000000000000000000000000000000000000000000000"; /* size is 64 */
uint8_t uriBuf[MAX_URI_LEN] = {0};
struct CmBlob userCertTemp = { sizeof(g_certData01), const_cast<uint8_t *>(g_certData01) };
struct CmBlob edgeAlias = { strlen(edgeAliasBuf) + 1, reinterpret_cast<uint8_t *>(edgeAliasBuf) };
struct CmBlob largeUri = { sizeof(largeUriBuf), largeUriBuf };
struct CmBlob uri = { sizeof(uriBuf), uriBuf };
ret = CmInstallUserTrustedCert(&userCertTemp, &edgeAlias, &largeUri);
EXPECT_EQ(ret, CM_FAILURE) << "Normal user cert Install test failed, recode:" << ret;
ret = CmInstallUserTrustedCert(&userCertTemp, &edgeAlias, &uri);
EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Install test failed, recode:" << ret;
ret = CmUninstallUserTrustedCert(&uri);
EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Uninstall test failed, recode:" << ret;
}
/**