• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 "hisysevent_adapter.h"
17 
18 #include <cinttypes>
19 
20 #include "hisysevent.h"
21 #include "iam_logger.h"
22 #include "iam_para2str.h"
23 
24 #define LOG_LABEL UserIam::Common::LABEL_USER_AUTH_SA
25 
26 namespace OHOS {
27 namespace UserIam {
28 namespace UserAuth {
29 using HiSysEvent = OHOS::HiviewDFX::HiSysEvent;
30 
31 constexpr char STR_USER_ID[] = "USER_ID";
32 constexpr char STR_AUTH_TYPE[] = "AUTH_TYPE";
33 constexpr char STR_OPERATION_TYPE[] = "OPERATION_TYPE";
34 constexpr char STR_OPERATION_RESULT[] = "OPERATION_RESULT";
35 constexpr char STR_AUTH_RESULT[] = "AUTH_RESULT";
36 constexpr char STR_TRIGGER_REASON[] = "TRIGGER_REASON";
37 constexpr char STR_CHANGE_TYPE[] = "CHANGE_TYPE";
38 constexpr char STR_EXECUTOR_TYPE[] = "EXECUTOR_TYPE";
39 constexpr char STR_MODULE_NAME[] = "MODULE_NAME";
40 constexpr char STR_HAPPEN_TIME[] = "HAPPEN_TIME";
41 constexpr char STR_AUTH_TRUST_LEVEL[] = "AUTH_TRUST_LEVEL";
42 constexpr char STR_SDK_VERSION[] = "SDK_VERSION";
43 constexpr char STR_AUTH_WIDGET_TYPE[] = "AUTH_WIDGET_TYPE";
44 constexpr char STR_CALLER_NAME[] = "CALLER_NAME";
45 constexpr char STR_REQUEST_CONTEXTID[] = "REQUEST_CONTEXTID";
46 constexpr char STR_TIME_SPAN[] = "TIME_SPAN";
47 constexpr char STR_AUTH_CONTEXTID[] = "AUTH_CONTEXTID";
48 constexpr char STR_SCHEDULE_ID[] = "SCHEDULE_ID";
49 
ReportSystemFault(const std::string & timeString,const std::string & moudleName)50 void ReportSystemFault(const std::string &timeString, const std::string &moudleName)
51 {
52     int32_t ret = HiSysEventWrite(HiSysEvent::Domain::USERIAM_FWK, "USERIAM_SYSTEM_FAULT",
53         HiSysEvent::EventType::FAULT,
54         STR_HAPPEN_TIME, timeString,
55         STR_MODULE_NAME, moudleName);
56     if (ret != 0) {
57         IAM_LOGE("hisysevent write failed! ret %{public}d, timeString %{public}s, moudleName %{public}s.",
58             ret, timeString.c_str(), moudleName.c_str());
59     }
60 }
61 
ReportSecurityTemplateChange(const TemplateChangeTrace & info)62 void ReportSecurityTemplateChange(const TemplateChangeTrace &info)
63 {
64     int32_t ret = HiSysEventWrite(HiSysEvent::Domain::USERIAM_FWK, "USERIAM_TEMPLATE_CHANGE",
65         HiSysEvent::EventType::SECURITY,
66         STR_SCHEDULE_ID, info.scheduleId,
67         STR_EXECUTOR_TYPE, info.executorType,
68         STR_CHANGE_TYPE, info.changeType,
69         STR_TRIGGER_REASON, info.reason);
70     if (ret != 0) {
71         IAM_LOGE("hisysevent write failed! ret %{public}d, executorType %{public}d, changeType %{public}u,"
72             "scheduleId %{public}s, trigger reason %{public}s.", ret, info.executorType, info.changeType,
73             GET_MASKED_STRING(info.scheduleId).c_str(), info.reason.c_str());
74     }
75 }
76 
ReportBehaviorCredManager(const UserCredManagerTrace & info)77 void ReportBehaviorCredManager(const UserCredManagerTrace &info)
78 {
79     int32_t ret = HiSysEventWrite(HiSysEvent::Domain::USERIAM_FWK, "USERIAM_USER_CREDENTIAL_MANAGER",
80         HiSysEvent::EventType::BEHAVIOR,
81         STR_CALLER_NAME, info.callerName,
82         STR_USER_ID, info.userId,
83         STR_AUTH_TYPE, info.authType,
84         STR_OPERATION_TYPE, info.operationType,
85         STR_OPERATION_RESULT, info.operationResult);
86     if (ret != 0) {
87         IAM_LOGE("hisysevent write failed! ret %{public}d, userId %{public}d, authType %{public}d,"
88             "operationType %{public}u, operationResult %{public}d, callerName %{public}s.", ret, info.userId,
89             info.authType, info.operationType, info.operationResult, info.callerName.c_str());
90     }
91 }
92 
ReportSecurityCredChange(const UserCredChangeTrace & info)93 void ReportSecurityCredChange(const UserCredChangeTrace &info)
94 {
95     int32_t ret = HiSysEventWrite(HiSysEvent::Domain::USERIAM_FWK, "USERIAM_CREDENTIAL_CHANGE",
96         HiSysEvent::EventType::SECURITY,
97         STR_CALLER_NAME, info.callerName,
98         STR_REQUEST_CONTEXTID, info.requestContextId,
99         STR_USER_ID, info.userId,
100         STR_AUTH_TYPE, info.authType,
101         STR_OPERATION_TYPE, info.operationType,
102         STR_OPERATION_RESULT, info.operationResult,
103         STR_TIME_SPAN, info.timeSpan);
104     if (ret != 0) {
105         IAM_LOGE("hisysevent write failed! ret %{public}d, userId %{public}d, authType %{public}d,"
106             "operationType %{public}u, timeSpan %{public}" PRIu64 ", operationResult %{public}d, callerName %{public}s"
107             ", requestContextId %{public}s.", ret, info.userId, info.authType, info.operationType, info.timeSpan,
108             info.operationResult, info.callerName.c_str(),  GET_MASKED_STRING(info.requestContextId).c_str());
109     }
110 }
111 
ReportUserAuth(const UserAuthTrace & info)112 void ReportUserAuth(const UserAuthTrace &info)
113 {
114     int32_t ret = HiSysEventWrite(HiSysEvent::Domain::USERIAM_FWK, "USERIAM_USER_AUTH",
115         HiSysEvent::EventType::BEHAVIOR,
116         STR_CALLER_NAME, info.callerName,
117         STR_SDK_VERSION, info.sdkVersion,
118         STR_AUTH_TRUST_LEVEL, info.atl,
119         STR_AUTH_TYPE, info.authType,
120         STR_AUTH_RESULT, info.authResult,
121         STR_TIME_SPAN, info.timeSpan,
122         STR_AUTH_WIDGET_TYPE, info.authWidgetType);
123     if (ret != 0) {
124         IAM_LOGE("hisysevent write failed! ret %{public}d, authType %{public}d, atl %{public}u, authResult %{public}d"
125             ", timeSpan %{public}" PRIu64 ", sdkVersion %{public}u, authwidgetType %{public}u, callerName %{public}s.",
126             ret, info.authType, info.atl, info.authResult, info.timeSpan, info.sdkVersion, info.authWidgetType,
127             info.callerName.c_str());
128     }
129 }
130 
ReportSecurityUserAuthFwk(const UserAuthFwkTrace & info)131 void ReportSecurityUserAuthFwk(const UserAuthFwkTrace &info)
132 {
133     int32_t ret = HiSysEventWrite(HiSysEvent::Domain::USERIAM_FWK, "USERIAM_USER_AUTH_FWK",
134         HiSysEvent::EventType::SECURITY,
135         STR_CALLER_NAME, info.callerName,
136         STR_REQUEST_CONTEXTID, info.requestContextId,
137         STR_AUTH_CONTEXTID, info.authContextId,
138         STR_AUTH_TRUST_LEVEL, info.atl,
139         STR_AUTH_TYPE, info.authType,
140         STR_AUTH_RESULT, info.authResult,
141         STR_TIME_SPAN, info.timeSpan);
142     if (ret != 0) {
143         IAM_LOGE("hisysevent write failed! ret %{public}d, authType %{public}d, atl %{public}u, authResult %{public}d,"
144             "timeSpan %{public}" PRIu64 ", callerName %{public}s, requestContextId %{public}s, "
145             "authContextId %{public}s.", ret, info.authType, info.atl, info.authResult, info.timeSpan,
146             info.callerName.c_str(), GET_MASKED_STRING(info.requestContextId).c_str(),
147             GET_MASKED_STRING(info.authContextId).c_str());
148     }
149 }
150 } // namespace UserAuth
151 } // namespace UserIam
152 } // namespace OHOS