1 /* 2 * Copyright (C) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef COMMON_DEFS_H 17 #define COMMON_DEFS_H 18 19 #include "device_auth.h" 20 #include "device_auth_defines.h" 21 #include "hc_string.h" 22 #include "hc_vector.h" 23 #include "json_utils.h" 24 25 #define FIELD_DEVICE_PK "devicePk" 26 #define FIELD_UDID "udid" 27 #define FIELD_PK_INFO_SIGNATURE "pkInfoSignature" 28 #define FIELD_CREDENTIAL "credential" 29 #define FIELD_SERVER_PK "serverPk" 30 31 #define FIELD_ADD_TYPE "addType" 32 #define FIELD_ADD_ID "addId" 33 #define FIELD_ADD_KEY "addKey" 34 #define FIELD_AUTH_DATA "authData" 35 #define FIELD_AUTH_RETURN "authReturn" 36 #define FIELD_AUTH_ID "authId" 37 #define FIELD_AUTH_PK "authPk" 38 #define FIELD_ADD_AUTH_INFO "addAuthInfo" 39 #define FIELD_ADD_RETURN "addReturn" 40 #define FIELD_APP_ID "appId" 41 #define FIELD_BIND_SESSION_TYPE "bindSessionType" 42 #define FIELD_CHALLENGE "challenge" 43 #define FIELD_CHANNEL_ID "channelId" 44 #define FIELD_CHANNEL_TYPE "channelType" 45 #define FIELD_CONN_DEVICE_ID "connDeviceId" 46 #define FIELD_CONNECT_PARAMS "connectParams" 47 #define FIELD_CROSS_USER_ID_LIST "crossUserIdList" 48 #define FIELD_CURRENT_VERSION "currentVersion" 49 #define FIELD_DELETE_ID "deleteId" 50 #define FIELD_DELETED_RESULT "deletedResult" 51 #define FIELD_DEVICE_CLOUD_CREDENTIAL "devCloudCred" 52 #define FIELD_DEV_ID "devId" 53 #define FIELD_DEVICES_CREDENTIAL "devicesCredential" 54 #define FIELD_ENC_AUTH_TOKEN "encAuthToken" 55 #define FIELD_ENC_RESULT "encResult" 56 #define FIELD_ENC_DATA "encData" 57 #define FIELD_EPK "epk" 58 #define FIELD_EPK_LEN "epkLen" 59 #define FIELD_EX_AUTH_INFO "exAuthInfo" 60 #define FIELD_EXPIRE_TIME "expireTime" 61 #define FIELD_ERROR_CODE "errorCode" 62 #define FIELD_GROUP_INFO "groupInfo" 63 #define FIELD_GROUP_MANAGERS "groupManagers" 64 #define FIELD_GROUP_NAME "groupName" 65 #define FIELD_GROUP_OP "groupOp" 66 #define FIELD_GROUP_TYPE "groupType" 67 #define FIELD_GROUP_VISIBILITY "groupVisibility" 68 #define FIELD_IS_ADMIN "isAdmin" 69 #define FIELD_IS_ACCOUNT_BIND "isAccountBind" 70 #define FIELD_IS_BIND "isBind" 71 #define FIELD_IS_FORCE_DELETE "isForceDelete" 72 #define FIELD_IS_CREDENTIAL_EXISTS "isCredentialExists" 73 #define FIELD_IS_DIRECT_AUTH "isDirectAuth" 74 #define FIELD_KCF_DATA "kcfData" 75 #define FIELD_KEY_TYPE "keyType" 76 #define FIELD_TRUST_TYPE "trustType" 77 #define FIELD_MESSAGE "message" 78 #define FIELD_GROUP_ERROR_MSG "groupErrorMsg" 79 #define FIELD_MIN_VERSION "minVersion" 80 #define FIELD_GROUP_AND_MODULE_VERSION "groupAndModuleVersion" 81 #define FIELD_NONCE "nonce" 82 #define FIELD_OP_CODE "opCode" 83 #define FIELD_OPERATION_CODE "operationCode" 84 #define FIELD_OPERATION_PARAMS "operationParams" 85 #define FIELD_OWNER_ID "ownerId" 86 #define FIELD_OWNER_NAME "ownerName" 87 #define FIELD_PERMISSION "Permission" 88 #define FIELD_PAYLOAD "payload" 89 #define FIELD_PIN_CODE "pinCode" 90 #define FIELD_PUBLIC_KEY "publicKey" 91 #define FIELD_SIGN_ALG "signAlg" 92 #define FIELD_PK_INFO "pkInfo" 93 #define FIELD_REAL_INFO "realInfo" 94 #define FIELD_PSEUDONYM_ID "pseudonymId" 95 #define FIELD_INDEX_KEY "indexKey" 96 #define FIELD_PKG_NAME "pkgName" 97 #define FIELD_SELF_AUTH_ID "selfAuthId" 98 #define FIELD_SELF_DEVICE_ID "selfDeviceId" 99 #define FIELD_SELF_DEV_ID "selfDevId" 100 #define FIELD_SELF_USER_ID "selfUserId" 101 #define FIELD_REQUEST_ID "requestId" 102 #define FIELD_RECEIVED_DATA "receivedData" 103 #define FIELD_RETURN_CODE "returnCode" 104 #define FIELD_RETURN_DATA "returnData" 105 #define FIELD_RETURN_CODE_MAC "returnCodeMac" 106 #define FIELD_RMV_TYPE "rmvType" 107 #define FIELD_RMV_ID "rmvId" 108 #define FIELD_RMV_AUTH_INFO "rmvAuthInfo" 109 #define FIELD_RMV_RETURN "rmvReturn" 110 #define FIELD_SALT "salt" 111 #define FIELD_ISO_SALT "isoSalt" 112 #define FIELD_SEED "seed" 113 #define FIELD_SELF_TYPE "selfType" 114 #define FIELD_SEND_TO_PEER "sendToPeer" 115 #define FIELD_SEND_TO_SELF "sendToSelf" 116 #define FIELD_SHARED_USER_ID_LIST "sharedUserIdList" 117 #define FIELD_SUPPORT_256_MOD "support256mod" 118 #define FIELD_TOKEN "token" 119 #define FIELD_IS_UUID "uuIdAsDeviceId" 120 #define FIELD_VERSION "version" 121 #define FIELD_MK_AGREE_MSG "mkaMsg" 122 #define FIELD_PEER_ID_FROM_REQUEST "peerIdFromRequest" 123 #define FIELD_STEP "step" 124 #define FIELD_DATA "data" 125 #define FIELD_AUTH_KEY_ALG_ENCODE "authKeyAlgEncode" 126 #define FIELD_AUTH_PK_INFO "authPkInfo" 127 #define FIELD_AUTH_PK_INFO_SIGN "authPkInfoSign" 128 #define FIELD_AUTH_RESULT_MAC "authResultMac" 129 #define FIELD_LOCAL_DEVICE_TYPE "localDeviceType" 130 #define FIELD_PLUGIN_EXT_DATA "originPeerData" 131 #define FIELD_META_NODE_TYPE "metaNodeType" 132 #define FIELD_UPGRADE_FLAG "upgradeFlag" 133 #define FIELD_COMMON_EVENT_NAME "commonEventName" 134 #define FIELD_COMMON_EVENT_CODE "commonEventCode" 135 #define FIELD_IS_SINGLE_CRED "isSingleCred" 136 #define FIELD_ACCOUNT_PEER_PK_WITH_SIG "peerPkWithSig" 137 #define FIELD_ACCOUNT_SERVICE_ID "serviceId" 138 #define FIELD_ACCOUNT_SHARED_KEY_LEN "sharedKeyLen" 139 #define FIELD_ACCOUNT_SHARED_KEY_VAL "sharedKeyVal" 140 #define FIELD_ACCOUNT_RANDOM_LEN "randomLen" 141 #define FIELD_ACCOUNT_RANDOM_VAL "randomVal" 142 #define FIELD_LIGHT_ACCOUNT_MSG "lightAccountMsg" 143 #define FIELD_PEER_ACCOUNT_RANDOM_LEN "peerRandomLen" 144 #define FIELD_PEER_ACCOUNT_RANDOM_VAL "peerRandomVal" 145 146 #define INVALID_MODULE_TYPE (-1) 147 #define GROUP_ERR_MSG 0x8080 148 149 #define CLIENT 1 150 #define SERVER 0 151 152 #define CREATE_KEY_PAIR 1 153 #define DELETE_KEY_PAIR 2 154 155 /* DefaultValue */ 156 #define DEFAULT_MEMORY_SIZE 64 157 #define DEFAULT_USER_ID_HASH "" 158 #define DEFAULT_REQUEST_ID 0 159 #define DEFAULT_CHANNEL_ID (-1) 160 #define DEFAULT_EXPIRE_TIME 90 161 #define DEFAULT_SERVICE_TYPE "service.type.default" 162 #define SERVICE_TYPE_IMPORT "service.type.import" 163 #define DEFAULT_PACKAGE_NAME "deviceauth_service" 164 #define GROUP_MANAGER_PACKAGE_NAME "com.huawei.devicegroupmanage" 165 #define DM_APP_ID "ohos.distributedhardware.devicemanager" 166 #define SOFTBUS_APP_ID "softbus_auth" 167 #define DEFAULT_RETURN_KEY_LENGTH 32 168 #define MAX_BUFFER_LEN 1024 169 #define MAX_DATA_BUFFER_SIZE 4096 170 #define MAX_AUTH_ID_LEN 256 171 #define MAX_REQUEST_ID_LEN 128 172 173 #define IS_UPGRADE 1 174 #define IS_NOT_UPGRADE 0 175 176 #define COMPATIBLE_GROUP 512 177 #define GROUP_TYPE_INVALID (-1) 178 #define INVALID_OS_ACCOUNT (-1) 179 #define ALL_GROUP_VISIBILITY (-2) 180 #define INVALID_CRED 0 181 #define PUBLIC_KEY_MAX_LENGTH 128 182 #define PIN_CODE_LEN_SHORT 6 183 #define PIN_CODE_LEN_LONG 128 184 #define INVALID_PROTOCOL_EXPAND_VALUE (-1) 185 186 typedef enum { 187 NO_CHANNEL = 1, 188 SERVICE_CHANNEL = 2, 189 SOFT_BUS = 3, 190 } ChannelType; 191 192 typedef enum { 193 SELF_CREATED = 0, 194 IMPORTED_FROM_CLOUD = 1, 195 } RelationShipSource; 196 197 #define MAX_IN_PARAM_LEN 4096 198 199 #define CHECK_PTR_RETURN_NULL(ptr, paramTag) \ 200 do { \ 201 if ((ptr) == NULL) { \ 202 LOGE(paramTag " is null ptr"); \ 203 return NULL; \ 204 } \ 205 } while (0) 206 207 #define CHECK_PTR_RETURN_ERROR_CODE(ptr, paramTag) \ 208 do { \ 209 if ((ptr) == NULL) { \ 210 LOGE(paramTag " is null ptr"); \ 211 return HC_ERR_NULL_PTR; \ 212 } \ 213 } while (0) 214 215 #define CHECK_PTR_RETURN_NONE(ptr, paramTag) \ 216 do { \ 217 if ((ptr) == NULL) { \ 218 LOGE(paramTag " is null ptr"); \ 219 return; \ 220 } \ 221 } while (0) 222 223 #define GOTO_IF_ERR(x) do { \ 224 int32_t res = x; \ 225 if ((res) != HC_SUCCESS) { \ 226 goto ERR; \ 227 } \ 228 } while (0) 229 230 #define GOTO_IF_CHECK_NULL(ptr, paramTag) \ 231 do { \ 232 if ((ptr) == NULL) { \ 233 LOGE(paramTag " is null ptr"); \ 234 goto ERR; \ 235 } \ 236 } while (0) 237 238 #define GOTO_ERR_AND_SET_RET(x, res) do { \ 239 res = x; \ 240 if ((res) != HC_SUCCESS) { \ 241 goto ERR; \ 242 } \ 243 } while (0) 244 245 #define RETURN_IF_ERR(x) do { \ 246 int32_t res = x; \ 247 if ((res) != HC_SUCCESS) { \ 248 return res; \ 249 } \ 250 } while (0) 251 252 typedef enum { 253 ACCOUNT_RELATED_PLUGIN = 0x0010, 254 } EnumCredPluginType; 255 256 typedef enum { 257 DAS_MODULE = 0x0001, 258 ACCOUNT_MODULE = 0x0010, 259 } EnumModuleType; 260 261 typedef enum { 262 CONTINUE = 0, 263 IGNORE_MSG = 1, 264 FINISH, 265 } TaskStatus; 266 267 typedef enum { 268 CODE_NULL = 0, 269 OP_BIND = 1, 270 AUTHENTICATE = 2, 271 ADD_AUTH_INFO = 3, 272 REMOVE_AUTH_INFO = 4, 273 OP_UNBIND = 5, 274 AUTH_KEY_AGREEMENT = 6, 275 REGISTER = 7, 276 SECURE_CLONE = 8, 277 } OperationCode; 278 279 typedef enum { 280 IMPORT_SELF_CREDENTIAL = 0, 281 DELETE_SELF_CREDENTIAL = 1, 282 QUERY_SELF_CREDENTIAL_INFO = 2, 283 IMPORT_TRUSTED_CREDENTIALS = 3, 284 DELETE_TRUSTED_CREDENTIALS = 4, 285 QUERY_TRUSTED_CREDENTIALS = 5, 286 REQUEST_SIGNATURE = 6, 287 GET_SHARED_SECRET_BY_PEER_CERT = 8, 288 UPGRADE_DATA = 10, 289 CHECK_UPGRADE_IDENTITY = 11, 290 CHECK_UPGRADE_DATA = 12, 291 HANDLE_COMMON_EVENT = 13, 292 RELOAD_CRED_MGR = 14, 293 ACCOUNT_GET_CLIENT_SHARED_KEY = 15, 294 ACCOUNT_GET_SERVER_SHARED_KEY = 16, 295 QUERY_ACCOUNT_STATE_BY_USER_ID = 17, 296 LIGHT_ACCOUNT_AUTH_START = 18, 297 LIGHT_ACCOUNT_AUTH_PROCESS_CLIENT = 19, 298 LIGHT_ACCOUNT_AUTH_PROCESS_SERVER = 20, 299 LIGHT_ACCOUNT_AUTH_VERIFY_SIGN = 21, 300 } CredentialCode; 301 302 #endif 303