• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PEER_AUTH_STATE "peerAuthState"
42 #define FIELD_IS_DEVICE_LEVEL "isDeviceLevel"
43 #define FIELD_ALTERNATIVE "alternative"
44 #define FIELD_PEER_UDID "peerUdid"
45 #define FIELD_PEER_CONN_DEVICE_ID "peerConnDeviceId"
46 #define FIELD_KEY_LENGTH "keyLength"
47 #define FIELD_IS_CLIENT "isClient"
48 #define FIELD_SESSION_KEY "sessionKey"
49 #define FIELD_AUTH_FORM "authForm"
50 #define FIELD_CONFIRMATION "confirmation"
51 #define FIELD_GROUP_OWNER "groupOwner"
52 #define FIELD_PEER_AUTH_ID "peerAuthId"
53 #define FIELD_PEER_USER_TYPE "peerUserType"
54 #define FIELD_PEER_USER_ID "peerUserId"
55 #define FIELD_SERVICE_PKG_NAME "servicePkgName"
56 #define FIELD_USER_TYPE "userType"
57 #define FIELD_USER_ID "userId"
58 #define FIELD_SHARED_USER_ID "sharedUserId"
59 #define FIELD_OWNER_USER_ID "ownerUserId"
60 #define FIELD_DEVICE_ID "deviceId"
61 #define FIELD_UID_HASH "uidHash"
62 #define FIELD_PIN_CODE "pinCode"
63 #define FIELD_AUTH_ID "authId"
64 #define FIELD_UDID "udid"
65 #define FIELD_IS_SELF_PK "isSelfPk"
66 #define FIELD_GROUP_VISIBILITY "groupVisibility"
67 #define FIELD_EXPIRE_TIME "expireTime"
68 #define FIELD_IS_DELETE_ALL "isDeleteAll"
69 #define FIELD_BLE_CHALLENGE "bleChallenge"
70 #define FIELD_OS_ACCOUNT_ID "osAccountId"
71 
72 typedef enum {
73     DEFAULT_OS_ACCOUNT = 0,
74     INVALID_OS_ACCOUNT = -1,
75     ANY_OS_ACCOUNT = -2,
76 } OsAccountEnum;
77 
78 typedef enum {
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     IMPORT_SELF_CREDENTIAL = 0,
114     DELETE_SELF_CREDENTIAL = 1,
115     QUERY_SELF_CREDENTIAL_INFO = 2,
116     IMPORT_TRUSTED_CREDENTIALS = 3,
117     DELETE_TRUSTED_CREDENTIALS = 4,
118     QUERY_TRUSTED_CREDENTIALS = 5,
119     REQUEST_SIGNATURE = 6,
120 } CredentialCode;
121 
122 typedef enum {
123     DEVICE_TYPE_ACCESSORY = 0,
124     DEVICE_TYPE_CONTROLLER = 1,
125     DEVICE_TYPE_PROXY = 2
126 } UserType;
127 
128 typedef enum {
129     EXPIRE_TIME_INDEFINITE = -1,
130     EXPIRE_TIME_MIN = 1,
131     EXPIRE_TIME_MAX = 90,
132 } ExpireTime;
133 
134 typedef enum {
135     REQUEST_REJECTED = 0x80000005,
136     REQUEST_ACCEPTED = 0x80000006,
137     REQUEST_WAITING = 0x80000007
138 } RequestResponse;
139 
140 typedef struct {
141     void (*onGroupCreated)(const char *groupInfo);
142     void (*onGroupDeleted)(const char *groupInfo);
143     void (*onDeviceBound)(const char *peerUdid, const char *groupInfo);
144     void (*onDeviceUnBound)(const char *peerUdid, const char *groupInfo);
145     void (*onDeviceNotTrusted)(const char *peerUdid);
146     void (*onLastGroupDeleted)(const char *peerUdid, int groupType);
147     void (*onTrustedDeviceNumChanged)(int curTrustedDeviceNum);
148 } DataChangeListener;
149 
150 typedef struct {
151     bool (*onTransmit)(int64_t requestId, const uint8_t *data, uint32_t dataLen);
152     void (*onSessionKeyReturned)(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen);
153     void (*onFinish)(int64_t requestId, int operationCode, const char *returnData);
154     void (*onError)(int64_t requestId, int operationCode, int errorCode, const char *errorReturn);
155     char *(*onRequest)(int64_t requestId, int operationCode, const char *reqParams);
156 } DeviceAuthCallback;
157 
158 typedef struct {
159     int32_t (*processData)(int64_t authReqId, const uint8_t *data, uint32_t dataLen,
160         const DeviceAuthCallback *gaCallback);
161     int32_t (*authDevice)(int32_t osAccountId, int64_t authReqId, const char *authParams,
162         const DeviceAuthCallback *gaCallback);
163 } GroupAuthManager;
164 
165 typedef struct {
166     int32_t (*regCallback)(const char *appId, const DeviceAuthCallback *callback);
167     int32_t (*unRegCallback)(const char *appId);
168     int32_t (*regDataChangeListener)(const char *appId, const DataChangeListener *listener);
169     int32_t (*unRegDataChangeListener)(const char *appId);
170     int32_t (*createGroup)(int32_t osAccountId, int64_t requestId, const char *appId, const char *createParams);
171     int32_t (*deleteGroup)(int32_t osAccountId, int64_t requestId, const char *appId, const char *disbandParams);
172     int32_t (*addMemberToGroup)(int32_t osAccountId, int64_t requestId, const char *appId, const char *addParams);
173     int32_t (*deleteMemberFromGroup)(int32_t osAccountId, int64_t requestId, const char *appId,
174         const char *deleteParams);
175     int32_t (*processData)(int64_t requestId, const uint8_t *data, uint32_t dataLen);
176     int32_t (*processCredential)(int operationCode, const char *reqJsonStr, char **returnJsonStr);
177     int32_t (*getRegisterInfo)(char **returnRegisterInfo);
178     int32_t (*checkAccessToGroup)(int32_t osAccountId, const char *appId, const char *groupId);
179     int32_t (*getPkInfoList)(int32_t osAccountId, const char *appId, const char *queryParams, char **returnInfoList,
180         uint32_t *returnInfoNum);
181     int32_t (*getGroupInfoById)(int32_t osAccountId, const char *appId, const char *groupId, char **returnGroupInfo);
182     int32_t (*getGroupInfo)(int32_t osAccountId, const char *appId, const char *queryParams,
183         char **returnGroupVec, uint32_t *groupNum);
184     int32_t (*getJoinedGroups)(int32_t osAccountId, const char *appId, int groupType,
185         char **returnGroupVec, uint32_t *groupNum);
186     int32_t (*getRelatedGroups)(int32_t osAccountId, const char *appId, const char *peerDeviceId,
187         char **returnGroupVec, uint32_t *groupNum);
188     int32_t (*getDeviceInfoById)(int32_t osAccountId, const char *appId, const char *deviceId, const char *groupId,
189         char **returnDeviceInfo);
190     int32_t (*getTrustedDevices)(int32_t osAccountId, const char *appId, const char *groupId,
191         char **returnDevInfoVec, uint32_t *deviceNum);
192     bool (*isDeviceInGroup)(int32_t osAccountId, const char *appId, const char *groupId, const char *deviceId);
193     void (*destroyInfo)(char **returnInfo);
194 } DeviceGroupManager;
195 
196 #ifdef __cplusplus
197 extern "C" {
198 #endif
199 DEVICE_AUTH_API_PUBLIC int InitDeviceAuthService(void);
200 DEVICE_AUTH_API_PUBLIC void DestroyDeviceAuthService(void);
201 DEVICE_AUTH_API_PUBLIC const GroupAuthManager *GetGaInstance(void);
202 DEVICE_AUTH_API_PUBLIC const DeviceGroupManager *GetGmInstance(void);
203 #ifdef __cplusplus
204 }
205 #endif
206 #endif
207