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
23 #define LOG_LABEL UserIam::Common::LABEL_USER_AUTH_SA
24
25 namespace OHOS {
26 namespace UserIam {
27 namespace UserAuth {
28 using HiSysEvent = OHOS::HiviewDFX::HiSysEvent;
29
30 constexpr char STR_USER_ID[] = "USER_ID";
31 constexpr char STR_CALLING_ID[] = "CALLING_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_AUTH_TIME[] = "AUTH_TIME";
43 constexpr char STR_REMAIN_TIME[] = "REMAIN_TIME";
44 constexpr char STR_FREEXING_TIME[] = "FREEXING_TIME";
45 constexpr char STR_AUTH_TIME_SPAN[] = "AUTH_TIME_SPAN";
46 constexpr char STR_SDK_VERSION[] = "SDK_VERSION";
47 constexpr char STR_AUTH_WIDGET_TYPE[] = "AUTH_WIDGET_TYPE";
48
ReportSystemFault(const std::string & timeString,const std::string & moudleName)49 void ReportSystemFault(const std::string &timeString, const std::string &moudleName)
50 {
51 int32_t ret = HiSysEventWrite(HiSysEvent::Domain::USERIAM_FWK, "USERIAM_SYSTEM_FAULT",
52 HiSysEvent::EventType::FAULT,
53 STR_HAPPEN_TIME, timeString,
54 STR_MODULE_NAME, moudleName);
55 if (ret != 0) {
56 IAM_LOGE("hisysevent write failed! ret %{public}d, timeString %{public}s, moudleName %{public}s.",
57 ret, timeString.c_str(), moudleName.c_str());
58 }
59 }
60
ReportTemplateChange(int32_t executorType,uint32_t changeType,const std::string & reason)61 void ReportTemplateChange(int32_t executorType, uint32_t changeType, const std::string &reason)
62 {
63 int32_t ret = HiSysEventWrite(HiSysEvent::Domain::USERIAM_FWK, "USERIAM_TEMPLATE_CHANGE",
64 HiSysEvent::EventType::SECURITY,
65 STR_EXECUTOR_TYPE, executorType,
66 STR_CHANGE_TYPE, changeType,
67 STR_TRIGGER_REASON, reason);
68 if (ret != 0) {
69 IAM_LOGE("hisysevent write failed! ret %{public}d, executorType %{public}d,"
70 "changeType %{public}u, trigger reason %{public}s.",
71 ret, executorType, changeType, reason.c_str());
72 }
73 }
ReportBehaviorCredChange(int32_t userId,int32_t authType,uint32_t operationType,uint32_t optResult)74 void ReportBehaviorCredChange(int32_t userId, int32_t authType, uint32_t operationType, uint32_t optResult)
75 {
76 int32_t ret = HiSysEventWrite(HiSysEvent::Domain::USERIAM_FWK, "USERIAM_USER_CREDENTIAL_MANAGER",
77 HiSysEvent::EventType::BEHAVIOR,
78 STR_USER_ID, userId,
79 STR_AUTH_TYPE, authType,
80 STR_OPERATION_TYPE, operationType,
81 STR_OPERATION_RESULT, optResult);
82 if (ret != 0) {
83 IAM_LOGE("hisysevent write failed! ret %{public}d, userId %{public}d, authType %{public}d,"
84 "operationType %{public}u, optResult %{public}u.",
85 ret, userId, authType, operationType, optResult);
86 }
87 }
88
ReportSecurityCredChange(int32_t userId,int32_t authType,uint32_t operationType,uint32_t optResult)89 void ReportSecurityCredChange(int32_t userId, int32_t authType, uint32_t operationType, uint32_t optResult)
90 {
91 int32_t ret = HiSysEventWrite(HiSysEvent::Domain::USERIAM_FWK, "USERIAM_CREDENTIAL_CHANGE",
92 HiSysEvent::EventType::SECURITY,
93 STR_USER_ID, userId,
94 STR_AUTH_TYPE, authType,
95 STR_OPERATION_TYPE, operationType,
96 STR_OPERATION_RESULT, optResult);
97 if (ret != 0) {
98 IAM_LOGE("hisysevent write failed! ret %{public}d, userId %{public}d, authType %{public}d,"
99 "operationType %{public}u, optResult %{public}u.",
100 ret, userId, authType, operationType, optResult);
101 }
102 }
103
ReportUserAuth(const UserAuthInfo & info)104 void ReportUserAuth(const UserAuthInfo &info)
105 {
106 int32_t ret = HiSysEventWrite(HiSysEvent::Domain::USERIAM_FWK, "USERIAM_USER_AUTH",
107 HiSysEvent::EventType::BEHAVIOR,
108 STR_CALLING_ID, info.callingUid,
109 STR_AUTH_TYPE, info.authType,
110 STR_AUTH_TRUST_LEVEL, info.atl,
111 STR_AUTH_RESULT, info.authResult,
112 STR_AUTH_TIME_SPAN, info.timeSpanString,
113 STR_SDK_VERSION, info.sdkVersion,
114 STR_AUTH_WIDGET_TYPE, info.authWidgetType);
115 if (ret != 0) {
116 IAM_LOGE("hisysevent write failed! ret %{public}d, callingUid %{public}" PRIu64 ", authType %{public}d,"
117 "atl %{public}u, authResult %{public}u, timeSpanString %{public}s,"
118 "sdkVersion%{public}u, authwidgetType%{public}u",
119 ret, info.callingUid, info.authType, info.atl, info.authResult,
120 info.timeSpanString.c_str(), info.sdkVersion, info.authWidgetType);
121 }
122 }
123
ReportPinAuth(const PinAuthInfo & info)124 void ReportPinAuth(const PinAuthInfo &info)
125 {
126 int32_t ret = HiSysEventWrite(HiSysEvent::Domain::USERIAM_FWK, "USERIAM_PIN_AUTH",
127 HiSysEvent::EventType::SECURITY,
128 STR_USER_ID, info.userId,
129 STR_CALLING_ID, info.callingUid,
130 STR_AUTH_TIME, info.authTimeString,
131 STR_AUTH_RESULT, info.authResult,
132 STR_REMAIN_TIME, info.remainTime,
133 STR_FREEXING_TIME, info.freezingTime);
134 if (ret != 0) {
135 IAM_LOGE("hisysevent write failed! ret %{public}d, userId %{public}d, callingUid %{public}" PRIu64
136 ",authTimeString %{public}s, authResult %{public}u, remainTime %{public}u, freezingTime%{public}u.",
137 ret, info.userId, info.callingUid, info.authTimeString.c_str(), info.authResult,
138 info.remainTime, info.freezingTime);
139 }
140 }
141 } // namespace UserAuth
142 } // namespace UserIam
143 } // namespace OHOS