提交 d52c4079 编写于 作者: O openharmony_ci 提交者: Gitee

!318 hichainL0代码合入

Merge pull request !318 from 胡吉翔/security_lite_20210712
# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
#import("//build/lite/config/component/zlite_component.gni")
#import("//build/lite/ndk/ndk.gni")
import("//test/xts/tools/lite/build/suite_lite.gni")
hctest_suite("ActsSecurityHichainTest0") {
suite_name = "acts"
defines = [ "HILINE_E2E_SECURITY_CONFIG" ]
sources = [
"src/hichain_function_test.c",
# "src/hichain_huks_adapt.c",
]
include_dirs = [
"//base/security/huks/interfaces/innerkits/huks_lite/",
"//third_party/cJSON",
"//base/security/deviceauth/interfaces/innerkits/deviceauth_lite",
"//base/security/deviceauth/frameworks/deviceauth_lite/source/huks_adapter",
"//base/security/deviceauth/frameworks/deviceauth_lite/source/base",
"//base/security/deviceauth/frameworks/deviceauth_lite/source/json",
"//base/security/deviceauth/frameworks/deviceauth_lite/source/key_agreement",
"//base/security/deviceauth/frameworks/deviceauth_lite/source/log",
"//base/security/deviceauth/frameworks/deviceauth_lite/source/schedule",
"//base/security/deviceauth/frameworks/deviceauth_lite/source/struct",
"//base/security/deviceauth/frameworks/deviceauth_lite/source/auth_info",
"//third_party/bounds_checking_function/include",
"//kernel/liteos_a/test/kernel/sample/lwip2.0_linux_CI/dependency/include",
"dbg_code",
"gtest",
"//base/security/huks/interfaces/innerkits/huks_lite/",
]
cflags = [ "-Wno-error" ]
}
{
"description": "Config for hcpptest demo test cases",
"environment": [
{
"type": "device",
"label": "ipcamera"
}
],
"kits": [
{
"type": "MountKit",
"server": "NfsServer",
"mount": [
{
"source": "testcases/security",
"target": "/test_root/security"
}
]
}
],
"driver": {
"type": "CppTestLite",
"execute": "/test_root/security/ActsSecurityHichainTest.bin"
}
}
\ No newline at end of file
{
"description": "Config for $module test cases",
"environment": [
{
"type": "device",
"label": "wifiiot"
}
],
"kits": [
{
"type": "DeployKit",
"timeout": "20000",
"burn_file": "$subsystem/$module.bin"
}
],
"driver": {
"type": "CTestLite"
}
}
\ No newline at end of file
/*
* Copyright (C) 2021 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DEVICE_AUTH_H
#define DEVICE_AUTH_H
#include <stdint.h>
#include <stdbool.h>
#if defined(_LINUX) || defined(_UNIX)
#define DEVICE_AUTH_API_PUBLIC __attribute__ ((visibility("default")))
#else
#define DEVICE_AUTH_API_PUBLIC
#endif
#define FIELD_GROUP_ID "groupId"
#define FIELD_GROUP_TYPE "groupType"
#define FIELD_GROUP_NAME "groupName"
#define FIELD_PEER_DEVICE_ID "peerDeviceId"
#define FIELD_IS_ADMIN "isAdmin"
#define FIELD_CREDENTIAL_TYPE "credentialType"
#define FIELD_IS_FORCE_DELETE "isForceDelete"
#define FIELD_IS_IGNORE_CHANNEL "isIgnoreChannel"
#define FIELD_CONNECT_PARAMS "connectParams"
#define FIELD_ADD_ID "addId"
#define FIELD_DELETE_ID "deleteId"
#define FIELD_APP_ID "appId"
#define FIELD_SERVICE_TYPE "serviceType"
#define FIELD_PEER_AUTH_STATE "peerAuthState"
#define FIELD_IS_DEVICE_LEVEL "isDeviceLevel"
#define FIELD_ALTERNATIVE "alternative"
#define FIELD_PEER_UDID "peerUdid"
#define FIELD_PEER_CONN_DEVICE_ID "peerConnDeviceId"
#define FIELD_KEY_LENGTH "keyLength"
#define FIELD_IS_CLIENT "isClient"
#define FIELD_SESSION_KEY "sessionKey"
#define FIELD_AUTH_FORM "authForm"
#define FIELD_CONFIRMATION "confirmation"
#define FIELD_GROUP_OWNER "groupOwner"
#define FIELD_PEER_AUTH_ID "peerAuthId"
#define FIELD_PEER_USER_TYPE "peerUserType"
#define FIELD_PEER_USER_ID "peerUserId"
#define FIELD_SERVICE_PKG_NAME "servicePkgName"
#define FIELD_USER_TYPE "userType"
#define FIELD_USER_ID "userId"
#define FIELD_DEVICE_ID "deviceId"
#define FIELD_UID_HASH "uidHash"
#define FIELD_PIN_CODE "pinCode"
#define FIELD_AUTH_ID "authId"
#define FIELD_GROUP_VISIBILITY "groupVisibility"
#define FIELD_EXPIRE_TIME "expireTime"
#define FIELD_IS_DELETE_ALL "isDeleteAll"
typedef enum {
GROUP_CREATE = 0,
GROUP_DISBAND = 1,
MEMBER_INVITE = 2,
MEMBER_JOIN = 3,
MEMBER_DELETE = 4,
ACCOUNT_BIND = 5
} GroupOperationCode;
typedef enum {
CREDENTIAL_SAVE = 0,
CREDENTIAL_CLEAR = 1,
CREDENTIAL_UPDATE = 2,
CREDENTIAL_QUERY = 3,
} CredentialCode;
typedef enum {
DEVICE_TYPE_ACCESSORY = 0,
DEVICE_TYPE_CONTROLLER = 1,
DEVICE_TYPE_PROXY = 2
} UserType;
#define REQUEST_REJECTED 0x80000005
#define REQUEST_ACCEPTED 0x80000006
#define REQUEST_WAITING 0x80000007
typedef struct {
void (*onGroupCreated)(const char *groupInfo);
void (*onGroupDeleted)(const char *groupInfo);
void (*onDeviceBound)(const char *peerUdid, const char *groupInfo);
void (*onDeviceUnBound)(const char *peerUdid, const char *groupInfo);
void (*onDeviceNotTrusted)(const char *peerUdid);
void (*onLastGroupDeleted)(const char *peerUdid, int groupType);
void (*onTrustedDeviceNumChanged)(int curTrustedDeviceNum);
} DataChangeListener;
typedef struct {
bool (*onTransmit)(int64_t requestId, const uint8_t *data, uint32_t dataLen);
void (*onSessionKeyReturned)(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen);
void (*onFinish)(int64_t requestId, int operationCode, const char *returnData);
void (*onError)(int64_t requestId, int operationCode, int errorCode, const char *errorReturn);
char *(*onRequest)(int64_t requestId, int operationCode, const char *reqParams);
} DeviceAuthCallback;
typedef struct {
int32_t (*processData)(int64_t authReqId, const uint8_t *data, uint32_t dataLen,
const DeviceAuthCallback *gaCallback);
int32_t (*queryTrustedDeviceNum)(void);
bool (*isTrustedDevice)(const char *udid);
int32_t (*getAuthState)(int64_t authReqId, const char *groupId, const char *peerUdid,
uint8_t *out, uint32_t *outLen);
int32_t (*authDevice)(int64_t authReqId, const char *authParams, const DeviceAuthCallback *gaCallback);
void (*informDeviceDisconnection)(const char *udid);
} GroupAuthManager;
typedef struct {
int32_t (*regCallback)(const char *appId, const DeviceAuthCallback *callback);
int32_t (*unRegCallback)(const char *appId);
int32_t (*regDataChangeListener)(const char *appId, const DataChangeListener *listener);
int32_t (*unRegDataChangeListener)(const char *appId);
int32_t (*createGroup)(int64_t requestId, const char *appId, const char *createParams);
int32_t (*deleteGroup)(int64_t requestId, const char *appId, const char *disbandParams);
int32_t (*addMemberToGroup)(int64_t requestId, const char *appId, const char *addParams);
int32_t (*deleteMemberFromGroup)(int64_t requestId, const char *appId, const char *deleteParams);
int32_t (*processData)(int64_t requestId, const uint8_t *data, uint32_t dataLen);
int32_t (*confirmRequest)(int64_t requestId, const char *appId, const char *confirmParams);
int32_t (*bindPeer)(int64_t requestId, const char *appId, const char *bindParams);
int32_t (*unbindPeer)(int64_t requestId, const char *appId, const char *unBindParams);
int32_t (*processLiteData)(int64_t requestId, const char *appId, const uint8_t *data, uint32_t dataLen);
int32_t (*authKeyAgree)(int64_t requestId, const char *appId, const char *buildParams);
int32_t (*processKeyAgreeData)(int64_t requestId, const char *appId, const uint8_t *data, uint32_t dataLen);
int32_t (*processCredential)(int operationCode, const char *reqJsonStr, char **returnJsonStr);
int32_t (*getRegisterInfo)(char **returnRegisterInfo);
int32_t (*getLocalConnectInfo)(char **returnInfo);
int32_t (*addGroupManager)(const char *appId, const char *groupId, const char *managerAppId);
int32_t (*addGroupFriend)(const char *appId, const char *groupId, const char *friendAppId);
int32_t (*deleteGroupManager)(const char *appId, const char *groupId, const char *managerAppId);
int32_t (*deleteGroupFriend)(const char *appId, const char *groupId, const char *friendAppId);
int32_t (*getGroupManagers)(const char *appId, const char *groupId, char **returnManagers, uint32_t *returnSize);
int32_t (*getGroupFriends)(const char *appId, const char *groupId, char **returnFriends, uint32_t *returnSize);
int32_t (*getGroupInfoById)(const char *appId, const char *groupId, char **returnGroupInfo);
int32_t (*getGroupInfo)(const char *appId, const char *queryParams, char **returnGroupVec, uint32_t *groupNum);
int32_t (*getJoinedGroups)(const char *appId, int groupType, char **returnGroupVec, uint32_t *groupNum);
int32_t (*getRelatedGroups)(const char *appId, const char *peerDeviceId, char **returnGroupVec, uint32_t *groupNum);
int32_t (*getDeviceInfoById)(const char *appId, const char *deviceId, const char *groupId, char **returnDeviceInfo);
int32_t (*getTrustedDevices)(const char *appId, const char *groupId, char **returnDevInfoVec, uint32_t *deviceNum);
bool (*isDeviceInGroup)(const char *appId, const char *groupId, const char *deviceId);
void (*destroyInfo)(char **returnInfo);
} DeviceGroupManager;
#ifdef __cplusplus
extern "C" {
#endif
DEVICE_AUTH_API_PUBLIC int InitDeviceAuthService();
DEVICE_AUTH_API_PUBLIC void DestroyDeviceAuthService();
DEVICE_AUTH_API_PUBLIC const GroupAuthManager *GetGaInstance();
DEVICE_AUTH_API_PUBLIC const DeviceGroupManager *GetGmInstance();
#ifdef __cplusplus
}
#endif
#endif
/*
* Copyright (C) 2021 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DEVICE_AUTH_DEFINES_H
#define DEVICE_AUTH_DEFINES_H
#define HC_GROUP_FRIEND_MAX_NUM 100 /* Visibility is 1, friend list is available, and max is 100 */
#define HC_GROUP_MANAGER_MAX_NUM 10 /* manager max number is 10, it includes owner and other managers */
enum {
/* common error code, 0x00000000 ~ 0x00000FFF */
HC_SUCCESS = 0x00000000,
HC_ERROR = 0x00000001,
HC_ERR_INVALID_PARAMS = 0x00000002,
HC_ERR_INVALID_LEN = 0x00000003,
HC_ERR_NULL_PTR = 0x00000004,
HC_ERR_ALLOC_MEMORY = 0x00000005,
HC_ERR_MEMORY_COPY = 0x00000006,
HC_HEX_CONVERT_FAILED = 0x00000007,
HC_ERR_NOT_SUPPORT = 0x00000008,
HC_ERR_TIME_OUT = 0x00000009,
HC_ERR_CASE = 0x0000000A,
HC_ERR_BAD_TIMING = 0x0000000B,
HC_ERR_PEER_ERROR = 0x0000000C,
/* error code for huks adapter , 0x00001000 ~ 0x00001FFF */
HC_ERR_KEY_NOT_EXIST = 0x00001001,
HC_ERR_GENERATE_KEY_FAILED = 0x000010002,
HC_ERR_INVALID_PUBLIC_KEY = 0x00001003,
HC_ERR_VERIFY_FAILED = 0x00001004,
HC_ERR_HASH_FAIL = 0x00001005,
/* error code for json util , 0x00002000 ~ 0x00002FFF */
HC_ERR_JSON_FAIL = 0x00002001,
HC_ERR_JSON_CREATE = 0x00002002,
HC_ERR_JSON_GET = 0x00002003,
HC_ERR_JSON_ADD = 0x00002004,
HC_ERR_PACKAGE_JSON_TO_STRING_FAIL = 0x00002005,
/* error code for ipc, 0x00003000 ~ 0x00003FFF */
HC_ERR_IPC_INTERNAL_FAILED = 0x00003001,
HC_ERR_IPC_UNKNOW_OPCODE = 0x00003002,
HC_ERR_IPC_CALL_DATA_LENGTH = 0x00003003,
HC_ERR_IPC_METHOD_ID_INVALID = 0x00003004,
HC_ERR_IPC_BAD_MESSAGE_LENGTH = 0x00003005,
HC_ERR_IPC_BAD_VAL_LENGTH = 0x00003006,
HC_ERR_IPC_BAD_PARAM_NUM = 0x00003007,
HC_ERR_IPC_BAD_MSG_TYPE = 0x00003008,
HC_ERR_IPC_GET_SERVICE = 0x00003009,
HC_ERR_IPC_GET_PROXY = 0x0000300A,
HC_ERR_IPC_INIT = 0x0000300B,
HC_ERR_IPC_BUILD_PARAM = 0x0000300C,
HC_ERR_IPC_PROC_FAILED = 0x0000300D,
HC_ERR_IPC_UNKNOW_REPLAY = 0x0000300E,
HC_ERR_IPC_OUT_DATA_NUM = 0x0000300F,
HC_ERR_IPC_OUT_DATA = 0x00003010,
/* error code for module , 0x00004000 ~ 0x00004FFF */
HC_ERR_MODULE_NOT_FOUNT = 0x00004001,
HC_ERR_UNSUPPORTED_METHOD = 0x00004002,
HC_ERR_UNSUPPORTED_VERSION = 0x00004003,
HC_ERR_UNSUPPORTED_CURVE = 0x00004004,
HC_ERR_BAD_MESSAGE = 0x00004005,
HC_ERR_PROOF_NOT_MATCH = 0x00004006,
HC_ERR_INIT_TASK_FAIL = 0x00004007,
HC_ERR_TASK_IS_NULL = 0x00004008,
HC_ERR_TASK_ID_IS_NOT_MATCH = 0x00004009,
HC_ERR_INVALID_ALG = 0x0000400A,
HC_ERR_IGNORE_MSG = 0x0000400B,
HC_ERR_LOCAL_IDENTITY_NOT_EXIST = 0x0000400C,
/* error code for group , 0x00005000 ~ 0x00005FFF */
HC_ERR_ACCESS_DENIED = 0x00005001,
HC_ERR_CALLBACK_NOT_FOUND = 0x00005002,
HC_ERR_SERVICE_NEED_RESTART = 0x00005003,
HC_ERR_NO_CANDIDATE_GROUP = 0x00005004,
HC_ERR_TRANSMIT_FAIL = 0x00005005,
HC_ERR_REQUEST_EXIST = 0x00005006,
HC_ERR_REQUEST_NOT_FOUND = 0x00005007,
HC_ERR_SESSION_NOT_EXIST = 0x00005008,
HC_ERR_SESSION_ID_CONFLICT = 0x00005009,
HC_ERR_REQ_REJECTED = 0x0000500A,
HC_ERR_SERVER_CONFIRM_FAIL = 0x0000500B,
HC_ERR_CREATE_SESSION_FAIL = 0x0000500C,
HC_ERR_SESSION_IS_FULL = 0x0000500D,
/* error code for database , 0x00006000 ~ 0x00006FFF */
HC_ERR_DB = 0x00006001,
HC_ERR_BEYOND_LIMIT = 0x00006002,
HC_ERR_SAVE_DB_FAILED = 0x00006003,
HC_ERR_FRIEND_NOT_EXIST = 0x00006004,
HC_ERR_MANAGER_NOT_EXIST = 0x00006005,
HC_ERR_GROUP_DUPLICATE = 0x00006006,
HC_ERR_GROUP_NOT_EXIST = 0x00006007,
HC_ERR_DEVICE_NOT_EXIST = 0x00006008,
HC_ERR_DEVICE_DUPLICATE = 0x00006009,
HC_ERR_LOST_DATA = 0x0000600A,
/* error code for broadcast , 0x00007000 ~ 0x00007FFF */
HC_ERR_LISTENER_NOT_EXIST = 0x000070012,
/* error code for channel , 0x00008000 ~ 0x00008FFF */
HC_ERR_CHANNEL_NOT_EXIST = 0x000080012,
HC_ERR_SOFT_BUS = 0x00008002,
/* error code used on DAS service */
INVALID_PARAMETERS = 0xF0000001,
EXCEED_AUTHORITY = 0xF0000002,
TIMEOUT = 0xF0000003,
NOT_REGISTERED = 0xF0000004,
NOT_TRUST_PEER = 0xF0000005,
NOT_TRUST_CONTROLLER = 0xF0000006,
NOT_TRUST_ACCESSORY = 0xF0000007,
OVER_MAX_TRUST_NUM = 0xF0000008,
CONNECTION_INTERRUPTED = 0xF0000009,
UNSUPPORTED_VERSION = 0xF000000A,
BAD_PAYLOAD = 0xF000000B,
ALGORITHM_UNSUPPORTED = 0xF000000C,
PROOF_MISMATCH = 0xF000000D,
UNKOWN = 0xF0000000,
};
#endif
此差异已折叠。
/*
* Copyright (C) 2021 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef IPC_SDK_H
#define IPC_SDK_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define IPC_RESULT_NUM_1 1
#define IPC_RESULT_NUM_2 2
#define IPC_CALL_BACK_STUB_AUTH_ID 0
#define IPC_CALL_BACK_STUB_BIND_ID 1
/* params type for ipc call */
#define PARAM_TYPE_APPID 1
#define PARAM_TYPE_DEV_AUTH_CB 2
#define PARAM_TYPE_LISTERNER 3
#define PARAM_TYPE_REQID 4
#define PARAM_TYPE_CREATE_PARAMS 5
#define PARAM_TYPE_GROUPID 6
#define PARAM_TYPE_UDID 7
#define PARAM_TYPE_ADD_PARAMS 8
#define PARAM_TYPE_DEL_PARAMS 9
#define PARAM_TYPE_COMM_DATA 10
#define PARAM_TYPE_REQ_CFM 11
#define PARAM_TYPE_BIND 12
#define PARAM_TYPE_UNBIND 13
#define PARAM_TYPE_GROUP_TYPE 14
#define PARAM_TYPE_CREDENTIAL 15
#define PARAM_TYPE_MGR_APPID 16
#define PARAM_TYPE_FRIEND_APPID 17
#define PARAM_TYPE_QUERY_PARAMS 18
#define PARAM_TYPE_REG_INFO 19
#define PARAM_TYPE_DATA_NUM 20
#define PARAM_TYPE_SESS_KEY 21
#define PARAM_TYPE_OPCODE 22
#define PARAM_TYPE_IPC_RESULT 23
#define PARAM_TYPE_IPC_RESULT_NUM 24
#define PARAM_TYPE_ERRCODE 25
#define PARAM_TYPE_ERR_INFO 26
#define PARAM_TYPE_REQ_INFO 27
#define PARAM_TYPE_GROUP_INFO 28
#define PARAM_TYPE_DEVICE_INFO 29
#define PARAM_TYPE_AUTH_PARAMS 30
#define PARAM_TYPE_CB_OBJECT 31
enum {
IPC_CALL_ID_REG_CB = 1,
IPC_CALL_ID_UNREG_CB,
IPC_CALL_ID_REG_LISTENER,
IPC_CALL_ID_UNREG_LISTENER,
IPC_CALL_ID_CREATE_GROUP,
IPC_CALL_ID_DEL_GROUP,
IPC_CALL_ID_ADD_GROUP_MEMBER,
IPC_CALL_ID_DEL_GROUP_MEMBER,
IPC_CALL_ID_GM_PROC_DATA,
IPC_CALL_ID_CFM_REQUEST,
IPC_CALL_ID_BIND_PEER,
IPC_CALL_ID_UNBIND_PEER,
IPC_CALL_ID_PROC_LIGHT_DATA,
IPC_CALL_ID_SAVE_CREDENTIAL,
IPC_CALL_ID_APPLY_REG_INFO,
IPC_CALL_ID_ADD_GROUP_MGR,
IPC_CALL_ID_ADD_GROUP_FRIEND,
IPC_CALL_ID_DEL_GROUP_MGR,
IPC_CALL_ID_DEL_GROUP_FRIEND,
IPC_CALL_ID_GET_GROUP_MGR,
IPC_CALL_ID_GET_GROUP_FRIEND,
IPC_CALL_ID_GET_GROUP_INFO,
IPC_CALL_ID_SEARCH_GROUPS,
IPC_CALL_ID_GET_JOINED_GROUPS,
IPC_CALL_ID_GET_RELATED_GROUPS,
IPC_CALL_ID_GET_DEV_INFO_BY_ID,
IPC_CALL_ID_GET_TRUST_DEVICES,
IPC_CALL_ID_IS_DEV_IN_GROUP,
IPC_CALL_ID_DESTROY_INFO,
IPC_CALL_ID_GA_PROC_DATA,
IPC_CALL_ID_QUERY_TRUST_DEV_NUM,
IPC_CALL_ID_IS_TRUST_DEVICE,
IPC_CALL_ID_GET_AUTH_STATE,
IPC_CALL_ID_AUTH_DEVICE,
IPC_CALL_ID_INFORM_DEV_DISCONN
};
#ifdef __cplusplus
}
#endif
#endif
此差异已折叠。
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2012-2018. All rights reserved.
* Description: hichain function test
*/
// #include "hichain_function_test.h"
#include "log.h"
#include "distribution.h"
#include "hichain.h"
#include "hctest.h"
#include "hks_client.h"
#include "hks_types.h"
#include <securec.h>
#include <sys/time.h>
#include <sys/time.h>
#define MAX_SEND_MESSAGE_BUFF 1024
#define PRINT(...)
LITE_TEST_SUIT(security, securityData, HichainFunctionTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL HichainFunctionTestSuiteSetUp(void)
{
int32_t status;
status = hks_init();
if (status != 0) {
status = hks_refresh_key_info();
}
TEST_ASSERT_EQUAL_INT(0, status);
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL HichainFunctionTestSuiteTearDown(void)
{
printf("-+++++++++++++++++++++++++++++++++++++++++++++-\n");
return TRUE;
}
static char g_sendMessageBuf[MAX_SEND_MESSAGE_BUFF];
static struct hc_auth_id g_testClientAuthId = { sizeof("authClient") - 1, "authClient" };
static struct hc_auth_id g_testServerAuthId = { sizeof("authServer") - 1, "authServer" };
static struct hc_pin g_testPin = { sizeof("123456789012345") - 1, "123456789012345" };
static uint32_t g_sendLength = 0;
static int32_t g_serviceResult = 0;
static struct session_identity g_clientIdentity = {
0,
{ sizeof("testClient") - 1, "testClient" },
{ sizeof("testClient") - 1, "testClient" },
0
};
static struct session_identity g_serverIdentity = {
0,
{ sizeof("testServer") - 1, "testServer" },
{ sizeof("testServer") - 1, "testServer" },
0
};
void TransmitDoNothing(const struct session_identity *identity, const void *data, uint32_t length)
{
if (memcpy_s(g_sendMessageBuf, MAX_SEND_MESSAGE_BUFF, data, length) != EOK) {
return;
}
g_sendMessageBuf[length] = 0;
PRINT("Send data: %s\n", g_sendMessageBuf);
g_sendLength = length;
identity = identity;
}
void GetProtocolParams(const struct session_identity *identity, int32_t operationCode, struct hc_pin *pin,
struct operation_parameter *para)
{
(void)identity;
(void)operationCode;
*pin = g_testPin;
para->key_length = 32; // 传入128计算hkdf失败, 暂时改成32
para->peer_auth_id = g_testClientAuthId;
para->self_auth_id = g_testServerAuthId;
}
void SetSessionKey(const struct session_identity *identity, const struct hc_session_key *sessionKey)
{
(void)identity;
(void)sessionKey;
}
void SetServiceResult(const struct session_identity *identity, int32_t result)
{
(void)identity;
g_serviceResult = result;
}
int32_t ConfirmReceiveRequestOK(const struct session_identity *identity, int32_t operationCode)
{
(void)identity;
(void)operationCode;
return 0;
}
void GetProtocolParamsClient(const struct session_identity *identity, int32_t operationCode, struct hc_pin *pin,
struct operation_parameter *para)
{
(void)identity;
(void)operationCode;
*pin = g_testPin;
para->key_length = 32; // 传入128计算hkdf失败, 暂时改成32
para->peer_auth_id = g_testServerAuthId;
para->self_auth_id = g_testClientAuthId;
}
static void HcLogd(const char *tag, const char *func, const char *format, ...)
{
printf("%s Debug: %s: ", tag, func);
va_list args;
va_start(args, format);
(void)vprintf(format, args);
va_end(args);
printf("\n");
}
static void HcLogi(const char *tag, const char *func, const char *format, ...)
{
printf("%s Info: %s: ", tag, func);
va_list args;
va_start(args, format);
(void)vprintf(format, args);
va_end(args);
printf("\n");
}
static void HcLogw(const char *tag, const char *func, const char *format, ...)
{
printf("%s Warning: %s: ", tag, func);
va_list args;
va_start(args, format);
(void)vprintf(format, args);
va_end(args);
printf("\n");
}
static void HcLoge(const char *tag, const char *func, const char *format, ...)
{
PrintTime();
printf("%s Error: %s: ", tag, func);
va_list args;
va_start(args, format);
(void)vprintf(format, args);
va_end(args);
printf("\n");
}
/* *
* @tc.name: IntentParseUriToUri001
* @tc.desc: Binding end key exchange
* @tc.type: FUNC
* @tc.require:
* @tc.author: dingjinyan
*/
LITE_TEST_CASE(HichainFunctionTestSuite, HichainBindPeer, Function | MediumTest | Level1)
{
struct log_func_group g = {HcLogd, HcLogi, HcLogw, HcLoge};
registe_log(&g);
/* 设置回调函数 */
struct hc_call_back callBack = { TransmitDoNothing, GetProtocolParams, SetSessionKey, SetServiceResult,
ConfirmReceiveRequestOK };
struct hc_call_back callBackClient = { TransmitDoNothing, GetProtocolParamsClient, SetSessionKey, SetServiceResult,
ConfirmReceiveRequestOK };
/* 构造函数 */
hc_handle server = get_instance(&g_serverIdentity, HC_ACCESSORY, &callBack);
hc_handle client = get_instance(&g_clientIdentity, HC_CENTRE, &callBackClient);
struct operation_parameter params = { g_testClientAuthId, g_testServerAuthId, 32 };
int32_t ret = start_pake(client, &params);
TEST_ASSERT_EQUAL_INT(ret, HC_OK);
TEST_ASSERT_EQUAL_INT(g_serviceResult, KEY_AGREEMENT_PROCESSING);
struct uint8_buff startRequest = { (uint8_t *)g_sendMessageBuf, g_sendLength, g_sendLength };
ret = receive_data(server, &startRequest);
TEST_ASSERT_EQUAL_INT(ret, HC_OK);
TEST_ASSERT_EQUAL_INT(g_serviceResult, KEY_AGREEMENT_PROCESSING);
struct uint8_buff startResponse = { (uint8_t *)g_sendMessageBuf, g_sendLength, g_sendLength };
ret = receive_data(client, &startResponse);
TEST_ASSERT_EQUAL_INT(ret, HC_OK);
TEST_ASSERT_EQUAL_INT(g_serviceResult, KEY_AGREEMENT_PROCESSING);
struct uint8_buff endRequest = { (uint8_t *)g_sendMessageBuf, g_sendLength, g_sendLength };
ret = receive_data(server, &endRequest);
TEST_ASSERT_EQUAL_INT(ret, HC_OK);
TEST_ASSERT_EQUAL_INT(g_serviceResult, KEY_AGREEMENT_END);
struct uint8_buff endResponse = { (uint8_t *)g_sendMessageBuf, g_sendLength, g_sendLength };
ret = receive_data(client, &endResponse);
TEST_ASSERT_EQUAL_INT(ret, HC_OK);
TEST_ASSERT_EQUAL_INT(g_serviceResult, KEY_AGREEMENT_END);
struct uint8_buff exchangeRequest = { (uint8_t *)g_sendMessageBuf, g_sendLength, g_sendLength };
ret = receive_data(server, &exchangeRequest);
TEST_ASSERT_EQUAL_INT(ret, HC_OK);
TEST_ASSERT_EQUAL_INT(g_serviceResult, END_SUCCESS);
struct uint8_buff exchangeResponse = { (uint8_t *)g_sendMessageBuf, g_sendLength, g_sendLength };
ret = receive_data(client, &exchangeResponse);
TEST_ASSERT_EQUAL_INT(ret, HC_OK);
TEST_ASSERT_EQUAL_INT(g_serviceResult, END_SUCCESS);
destroy(&client);
destroy(&server);
}
RUN_TEST_SUITE(HichainFunctionTestSuite);
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册