• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 AUTH_SESSION_H
17 #define AUTH_SESSION_H
18 
19 #include "auth_common.h"
20 #include "auth_device_common_key.h"
21 #include "lnn_p2p_info.h"
22 #include "lnn_state_machine.h"
23 #include "legacy/softbus_hisysevt_bus_center.h"
24 
25 #ifdef __cplusplus
26 #if __cplusplus
27 extern "C" {
28 #endif
29 #endif
30 
31 #define AUTH_FSM_NAME_LEN 32
32 
33 typedef enum {
34     STATE_SYNC_NEGOTIATION,
35     STATE_SYNC_DEVICE_ID,
36     STATE_DEVICE_AUTH,
37     STATE_SYNC_DEVICE_INFO,
38     STATE_NUM_MAX
39 } AuthFsmStateIndex;
40 
41 typedef enum {
42     EXCHANGE_UDID = 0,
43     EXCHANGE_NETWORKID,
44     EXCHANGE_FAIL,
45     EXCHANGE_TYPE_MAX
46 } ExchangeDataType;
47 
48 typedef enum {
49     NORMALIZED_NOT_SUPPORT,
50     NORMALIZED_KEY_ERROR,
51     NORMALIZED_SUPPORT,
52 } NormalizedType;
53 
54 typedef enum {
55     AUTH_STATE_WAIT = 1,
56     AUTH_STATE_START,
57     AUTH_STATE_UNKNOW,
58     AUTH_STATE_ACK,
59     AUTH_STATE_COMPATIBLE,
60 } AuthStartState;
61 
62 typedef struct {
63     uint32_t requestId;
64     bool isServer;
65     bool isConnectServer;
66     uint64_t connId;
67     AuthConnInfo connInfo;
68     uint8_t *deviceInfoData;
69     uint32_t deviceInfoDataLen;
70     NodeInfo nodeInfo;
71     bool isNodeInfoReceived;
72     bool isCloseAckReceived;
73     bool isAuthFinished;
74     char udid[UDID_BUF_LEN];
75     char uuid[UUID_BUF_LEN];
76     char udidHash[SHA_256_HEX_HASH_LEN];
77     SoftBusVersion version;
78     bool isSupportCompress;
79     bool isSupportFastAuth;
80     bool isNeedFastAuth;
81     bool isSupportDmDeviceKey;
82     int64_t oldIndex;
83     int32_t idType;
84     int32_t userId;
85     bool isNeedPackCert;
86     uint64_t sessionKeyRandomNum;
87     AuthVerifyModule module;
88     NormalizedType normalizedType;
89     SessionKey *normalizedKey;
90     int64_t normalizedIndex;
91     bool isOldKey;
92     bool isSavedSessionKey;
93     AuthStartState localState;
94     AuthStartState peerState;
95 } AuthSessionInfo;
96 
97 typedef struct {
98     ListNode node;
99     uint32_t id;
100     int64_t authSeq;
101     char fsmName[AUTH_FSM_NAME_LEN];
102     FsmStateMachine fsm;
103     AuthSessionInfo info;
104     AuthFsmStateIndex curState;
105     AuthStatisticData statisticData;
106     bool isDead;
107 } AuthFsm;
108 
109 typedef struct {
110     int64_t authSeq;
111     uint32_t requestId;
112     uint64_t connId;
113     bool isServer;
114     bool isFastAuth;
115 } AuthParam;
116 
117 void AuthSessionSetReSyncDeviceName(void);
118 int32_t AuthSessionStartAuth(const AuthParam *authParam, const AuthConnInfo *connInfo);
119 int32_t AuthSessionProcessDevIdData(int64_t authSeq, const uint8_t *data, uint32_t len);
120 int32_t AuthSessionPostAuthData(int64_t authSeq, const uint8_t *data, uint32_t len);
121 int32_t AuthSessionProcessAuthData(int64_t authSeq, const uint8_t *data, uint32_t len);
122 int32_t AuthSessionGetUdid(int64_t authSeq, char *udid, uint32_t size);
123 int32_t AuthSessionSaveSessionKey(int64_t authSeq, const uint8_t *key, uint32_t len);
124 int32_t AuthSessionHandleAuthFinish(int64_t authSeq);
125 int32_t AuthSessionHandleAuthError(int64_t authSeq, int32_t reason);
126 int32_t AuthSessionProcessDevInfoData(int64_t authSeq, const uint8_t *data, uint32_t len);
127 int32_t AuthSessionProcessCloseAck(int64_t authSeq, const uint8_t *data, uint32_t len);
128 int32_t AuthSessionProcessDevInfoDataByConnId(uint64_t connId, bool isServer, const uint8_t *data, uint32_t len);
129 int32_t AuthSessionProcessCloseAckByConnId(uint64_t connId, bool isServer, const uint8_t *data, uint32_t len);
130 int32_t AuthSessionProcessCancelAuthByConnId(uint64_t connId, bool isConnectServer, const uint8_t *data, uint32_t len);
131 int32_t AuthSessionProcessAuthTestData(int64_t authSeq, const uint8_t *data, uint32_t len);
132 int32_t AuthSessionHandleDeviceNotTrusted(const char *udid);
133 int32_t AuthSessionHandleDeviceDisconnected(uint64_t connId, bool isNeedDisconnect);
134 int32_t AuthNotifyRequestVerify(int64_t authSeq);
135 AuthFsm *GetAuthFsmByConnId(uint64_t connId, bool isServer, bool isConnectSide);
136 void AuthSessionFsmExit(void);
137 AuthFsm *GetAuthFsmByAuthSeq(int64_t authSeq);
138 
139 #ifdef __cplusplus
140 #if __cplusplus
141 }
142 #endif
143 #endif
144 #endif /* AUTH_SESSION_H */
145