• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 AUTH_MANAGER_H
17 #define AUTH_MANAGER_H
18 
19 #include <pthread.h>
20 #include <stdint.h>
21 #include <string.h>
22 
23 #include "auth_interface.h"
24 #include "bus_center_info_key.h"
25 #include "common_list.h"
26 #include "device_auth.h"
27 #include "softbus_common.h"
28 #include "softbus_conn_manager.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #define AUTH_APPID "softbus_auth"
35 
36 /* auth timeout delay */
37 #define AUTH_DELAY_MS (10 * 1000)
38 
39 /* auth data max length */
40 #define AUTH_MAX_DATA_LEN (64 * 1024)
41 
42 /* the length of the groupID */
43 #define GROUPID_BUF_LEN 65
44 
45 /* group type */
46 #define IDENTICAL_ACCOUNT_GROUP 1
47 
48 /* auth status */
49 #define INIT_STATE 0
50 #define WAIT_CONNECTION_ESTABLISHED 1
51 #define IN_AUTH_PROGRESS 2
52 #define IN_SYNC_PROGRESS 3
53 #define SYNC_FINISH 4
54 #define WAIT_PEER_DEV_INFO 5
55 #define WAIT_CLOSE_ACK 6
56 #define AUTH_PASSED 7
57 
58 
59 typedef struct {
60     uint32_t type;
61     int32_t module;
62     int64_t seq;
63     int32_t flag;
64     uint32_t dataLen;
65 } AuthDataInfo;
66 
67 typedef struct {
68     uint32_t requestId;
69     uint32_t connectionId;
70 
71     int64_t authId;
72     AuthSideFlag side;
73     uint8_t status;
74     uint16_t id;
75     int32_t fd;
76     ConnectOption option;
77     int32_t encryptInfoStatus;
78 
79     const GroupAuthManager *hichain;
80     VerifyCallback *cb;
81 
82     AuthConnCallback connCb;
83     bool isAuthP2p;
84 
85     char peerP2pMac[MAC_LEN];
86     char peerUdid[UDID_BUF_LEN];
87     char peerUuid[UUID_BUF_LEN];
88     char peerUid[MAX_ACCOUNT_HASH_LEN];
89     int32_t softbusVersion;
90     SoftBusVersion peerVersion;
91 
92     uint8_t *encryptDevData;
93     uint32_t encryptLen;
94     bool isValid;
95     uint64_t timeStamp;
96 
97     ListNode node;
98 } AuthManager;
99 
100 AuthManager *AuthGetManagerByRequestId(uint32_t requestId);
101 AuthManager *AuthGetManagerByAuthId(int64_t authId);
102 AuthManager *AuthGetManagerByConnId(uint16_t id);
103 AuthManager *AuthGetManagerByFd(int32_t fd);
104 AuthManager *AuthGetManagerByConnectionId(uint32_t connectionId);
105 int32_t CreateServerIpAuth(int32_t cfd, const char *ip, int32_t port);
106 void AuthHandlePeerSyncDeviceInfo(AuthManager *auth, uint8_t *data, uint32_t len);
107 void HandleReceiveDeviceId(AuthManager *auth, uint8_t *data);
108 void HandleReceiveAuthData(AuthManager *auth, int32_t module, uint8_t *data, uint32_t dataLen);
109 void AuthNotifyLnnDisconn(const AuthManager *auth);
110 void AuthNotifyTransDisconn(int64_t authId);
111 void AuthHandleTransInfo(const AuthManager *auth, const ConnPktHead *head, char *data);
112 void AuthHandleFail(AuthManager *auth, int32_t reason);
113 int32_t GetActiveAuthConnInfo(const char *uuid, ConnectType type, AuthConnInfo *connInfo);
114 
115 #ifdef __cplusplus
116 }
117 #endif
118 #endif /* AUTH_MANAGER_H */
119