1 /* 2 * Copyright (C) 2021-2022 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 DEVICE_AUTH_H 17 #define DEVICE_AUTH_H 18 19 #include <stdint.h> 20 #include <stdbool.h> 21 22 #if defined(__LINUX__) || defined(_UNIX) 23 #define DEVICE_AUTH_API_PUBLIC __attribute__ ((visibility("default"))) 24 #else 25 #define DEVICE_AUTH_API_PUBLIC 26 #endif 27 28 #define FIELD_GROUP_ID "groupId" 29 #define FIELD_GROUP_TYPE "groupType" 30 #define FIELD_GROUP_NAME "groupName" 31 #define FIELD_PEER_DEVICE_ID "peerDeviceId" 32 #define FIELD_IS_ADMIN "isAdmin" 33 #define FIELD_CREDENTIAL_TYPE "credentialType" 34 #define FIELD_IS_FORCE_DELETE "isForceDelete" 35 #define FIELD_IS_IGNORE_CHANNEL "isIgnoreChannel" 36 #define FIELD_CONNECT_PARAMS "connectParams" 37 #define FIELD_ADD_ID "addId" 38 #define FIELD_DELETE_ID "deleteId" 39 #define FIELD_APP_ID "appId" 40 #define FIELD_SERVICE_TYPE "serviceType" 41 #define FIELD_IS_DEVICE_LEVEL "isDeviceLevel" 42 #define FIELD_ALTERNATIVE "alternative" 43 #define FIELD_PEER_UDID "peerUdid" 44 #define FIELD_PEER_CONN_DEVICE_ID "peerConnDeviceId" 45 #define FIELD_KEY_LENGTH "keyLength" 46 #define FIELD_IS_CLIENT "isClient" 47 #define FIELD_SESSION_KEY "sessionKey" 48 #define FIELD_AUTH_FORM "authForm" 49 #define FIELD_CONFIRMATION "confirmation" 50 #define FIELD_GROUP_OWNER "groupOwner" 51 #define FIELD_PEER_AUTH_ID "peerAuthId" 52 #define FIELD_PEER_USER_TYPE "peerUserType" 53 #define FIELD_PEER_USER_ID "peerUserId" 54 #define FIELD_SERVICE_PKG_NAME "servicePkgName" 55 #define FIELD_USER_TYPE "userType" 56 #define FIELD_USER_ID "userId" 57 #define FIELD_SHARED_USER_ID "sharedUserId" 58 #define FIELD_OWNER_USER_ID "ownerUserId" 59 #define FIELD_DEVICE_ID "deviceId" 60 #define FIELD_PIN_CODE "pinCode" 61 #define FIELD_AUTH_ID "authId" 62 #define FIELD_UDID "udid" 63 #define FIELD_IS_SELF_PK "isSelfPk" 64 #define FIELD_GROUP_VISIBILITY "groupVisibility" 65 #define FIELD_EXPIRE_TIME "expireTime" 66 #define FIELD_IS_DELETE_ALL "isDeleteAll" 67 #define FIELD_OS_ACCOUNT_ID "osAccountId" 68 #define FIELD_AUTH_CODE "authCode" 69 #define FIELD_DEVICE_LIST "deviceList" 70 71 typedef enum { 72 DEFAULT_OS_ACCOUNT = 0, 73 INVALID_OS_ACCOUNT = -1, 74 ANY_OS_ACCOUNT = -2, 75 } OsAccountEnum; 76 77 typedef enum { 78 GROUP_TYPE_INVALID = -1, 79 ALL_GROUP = 0, 80 IDENTICAL_ACCOUNT_GROUP = 1, 81 PEER_TO_PEER_GROUP = 256, 82 COMPATIBLE_GROUP = 512, 83 ACROSS_ACCOUNT_AUTHORIZE_GROUP = 1282 84 } GroupType; 85 86 typedef enum { 87 ALL_GROUP_VISIBILITY = -2, 88 GROUP_VISIBILITY_PRIVATE = 0, 89 GROUP_VISIBILITY_ALLOW_LIST = 1, 90 GROUP_VISIBILITY_SIGNATURE = 2, 91 GROUP_VISIBILITY_SYSTEM = 4, 92 GROUP_VISIBILITY_PRIVILEGE = 8, 93 GROUP_VISIBILITY_PUBLIC = -1 94 } GroupVisibility; 95 96 typedef enum { 97 GROUP_CREATE = 0, 98 GROUP_DISBAND = 1, 99 MEMBER_INVITE = 2, 100 MEMBER_JOIN = 3, 101 MEMBER_DELETE = 4, 102 ACCOUNT_BIND = 5 103 } GroupOperationCode; 104 105 typedef enum { 106 AUTH_FORM_INVALID_TYPE = -1, 107 AUTH_FORM_ACCOUNT_UNRELATED = 0, 108 AUTH_FORM_IDENTICAL_ACCOUNT = 1, 109 AUTH_FORM_ACROSS_ACCOUNT = 2, 110 } GroupAuthForm; 111 112 typedef enum { 113 INVALID_CRED = 0, 114 SYMMETRIC_CRED = 1, 115 ASYMMETRIC_CRED = 2, 116 } CredType; 117 118 typedef enum { 119 DEVICE_TYPE_ACCESSORY = 0, 120 DEVICE_TYPE_CONTROLLER = 1, 121 DEVICE_TYPE_PROXY = 2 122 } UserType; 123 124 typedef enum { 125 EXPIRE_TIME_INDEFINITE = -1, 126 EXPIRE_TIME_MIN = 1, 127 EXPIRE_TIME_MAX = 90, 128 } ExpireTime; 129 130 typedef enum { 131 REQUEST_REJECTED = 0x80000005, 132 REQUEST_ACCEPTED = 0x80000006, 133 } RequestResponse; 134 135 typedef struct { 136 void (*onGroupCreated)(const char *groupInfo); 137 void (*onGroupDeleted)(const char *groupInfo); 138 void (*onDeviceBound)(const char *peerUdid, const char *groupInfo); 139 void (*onDeviceUnBound)(const char *peerUdid, const char *groupInfo); 140 void (*onDeviceNotTrusted)(const char *peerUdid); 141 void (*onLastGroupDeleted)(const char *peerUdid, int groupType); 142 void (*onTrustedDeviceNumChanged)(int curTrustedDeviceNum); 143 } DataChangeListener; 144 145 typedef struct { 146 bool (*onTransmit)(int64_t requestId, const uint8_t *data, uint32_t dataLen); 147 void (*onSessionKeyReturned)(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen); 148 void (*onFinish)(int64_t requestId, int operationCode, const char *returnData); 149 void (*onError)(int64_t requestId, int operationCode, int errorCode, const char *errorReturn); 150 char *(*onRequest)(int64_t requestId, int operationCode, const char *reqParams); 151 } DeviceAuthCallback; 152 153 typedef struct { 154 int32_t (*processData)(int64_t authReqId, const uint8_t *data, uint32_t dataLen, 155 const DeviceAuthCallback *gaCallback); 156 int32_t (*authDevice)(int32_t osAccountId, int64_t authReqId, const char *authParams, 157 const DeviceAuthCallback *gaCallback); 158 void (*cancelRequest)(int64_t requestId, const char *appId); 159 } GroupAuthManager; 160 161 typedef struct { 162 int32_t (*regCallback)(const char *appId, const DeviceAuthCallback *callback); 163 int32_t (*unRegCallback)(const char *appId); 164 int32_t (*regDataChangeListener)(const char *appId, const DataChangeListener *listener); 165 int32_t (*unRegDataChangeListener)(const char *appId); 166 int32_t (*createGroup)(int32_t osAccountId, int64_t requestId, const char *appId, const char *createParams); 167 int32_t (*deleteGroup)(int32_t osAccountId, int64_t requestId, const char *appId, const char *disbandParams); 168 int32_t (*addMemberToGroup)(int32_t osAccountId, int64_t requestId, const char *appId, const char *addParams); 169 int32_t (*deleteMemberFromGroup)(int32_t osAccountId, int64_t requestId, const char *appId, 170 const char *deleteParams); 171 int32_t (*processData)(int64_t requestId, const uint8_t *data, uint32_t dataLen); 172 int32_t (*addMultiMembersToGroup)(int32_t osAccountId, const char *appId, const char *addParams); 173 int32_t (*delMultiMembersFromGroup)(int32_t osAccountId, const char *appId, const char *deleteParams); 174 int32_t (*getRegisterInfo)(const char *reqJsonStr, char **returnRegisterInfo); 175 int32_t (*checkAccessToGroup)(int32_t osAccountId, const char *appId, const char *groupId); 176 int32_t (*getPkInfoList)(int32_t osAccountId, const char *appId, const char *queryParams, char **returnInfoList, 177 uint32_t *returnInfoNum); 178 int32_t (*getGroupInfoById)(int32_t osAccountId, const char *appId, const char *groupId, char **returnGroupInfo); 179 int32_t (*getGroupInfo)(int32_t osAccountId, const char *appId, const char *queryParams, 180 char **returnGroupVec, uint32_t *groupNum); 181 int32_t (*getJoinedGroups)(int32_t osAccountId, const char *appId, int groupType, 182 char **returnGroupVec, uint32_t *groupNum); 183 int32_t (*getRelatedGroups)(int32_t osAccountId, const char *appId, const char *peerDeviceId, 184 char **returnGroupVec, uint32_t *groupNum); 185 int32_t (*getDeviceInfoById)(int32_t osAccountId, const char *appId, const char *deviceId, const char *groupId, 186 char **returnDeviceInfo); 187 int32_t (*getTrustedDevices)(int32_t osAccountId, const char *appId, const char *groupId, 188 char **returnDevInfoVec, uint32_t *deviceNum); 189 bool (*isDeviceInGroup)(int32_t osAccountId, const char *appId, const char *groupId, const char *deviceId); 190 void (*cancelRequest)(int64_t requestId, const char *appId); 191 void (*destroyInfo)(char **returnInfo); 192 } DeviceGroupManager; 193 194 #ifdef __cplusplus 195 extern "C" { 196 #endif 197 DEVICE_AUTH_API_PUBLIC int InitDeviceAuthService(void); 198 DEVICE_AUTH_API_PUBLIC void DestroyDeviceAuthService(void); 199 DEVICE_AUTH_API_PUBLIC const GroupAuthManager *GetGaInstance(void); 200 DEVICE_AUTH_API_PUBLIC const DeviceGroupManager *GetGmInstance(void); 201 #ifdef __cplusplus 202 } 203 #endif 204 #endif 205