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 #include "trans_channel_limit.h"
17
18 #include <securec.h>
19
20 #include "softbus_def.h"
21 #include "softbus_log.h"
22
23
24 #define AUTH_SESSION_WHITE_LIST_NUM (8)
25 static char g_sessionWhiteList[AUTH_SESSION_WHITE_LIST_NUM][SESSION_NAME_SIZE_MAX] = {
26 "ohos.distributedhardware.devicemanager.resident",
27 "com.huawei.devicegroupmanage",
28 "IShareAuthSession",
29 "com.huawei.devicemanager.resident",
30 "com.huawei.plrdtest.dsoftbus",
31 "com.huawei.android.airsharing+CastPlusDiscoveryModule",
32 "com.huawei.dmsdp+dmsdp",
33 "com.huawei.devicemanager.dynamic",
34 };
35
36 #define NO_PKG_NAME_SESSION_WHITE_LIST_NUM (1)
37 static char g_noPkgNameSessionWhiteList[NO_PKG_NAME_SESSION_WHITE_LIST_NUM][SESSION_NAME_SIZE_MAX] = {
38 "com.huawei.devicemanager.resident",
39 };
40
CheckSessionNameValidOnAuthChannel(const char * sessionName)41 NO_SANITIZE("cfi") bool CheckSessionNameValidOnAuthChannel(const char *sessionName)
42 {
43 if (sessionName == NULL) {
44 return false;
45 }
46
47 uint16_t index = 0;
48 size_t len = 0;
49 for (; index < AUTH_SESSION_WHITE_LIST_NUM; ++index) {
50 len = strnlen(g_sessionWhiteList[index], SESSION_NAME_SIZE_MAX);
51 if (strncmp(sessionName, g_sessionWhiteList[index], len) == 0) {
52 return true;
53 }
54 }
55 SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_INFO,
56 "auth channel sessionname[%s] invalid.", sessionName);
57 return false;
58 }
59
IsNoPkgNameSession(const char * sessionName)60 bool IsNoPkgNameSession(const char *sessionName)
61 {
62 if (sessionName == NULL) {
63 return false;
64 }
65
66 uint16_t index = 0;
67 size_t len = 0;
68 for (; index < NO_PKG_NAME_SESSION_WHITE_LIST_NUM; ++index) {
69 len = strnlen(g_noPkgNameSessionWhiteList[index], SESSION_NAME_SIZE_MAX);
70 if (strncmp(sessionName, g_noPkgNameSessionWhiteList[index], len) == 0) {
71 return true;
72 }
73 }
74
75 return false;
76 }
77