• 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 #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 const std::string DOMAIN_STR = std::string(HiSysEvent::Domain::USERIAM_FWK);
31 constexpr char STR_USER_ID[] = "USER_ID";
32 constexpr char STR_CALLING_ID[] = "CALLING_ID";
33 constexpr char STR_AUTH_TYPE[] = "AUTH_TYPE";
34 constexpr char STR_OPERATION_TYPE[] = "OPERATION_TYPE";
35 constexpr char STR_OPERATION_RESULT[] = "OPERATION_RESULT";
36 constexpr char STR_AUTH_RESULT[] = "AUTH_RESULT";
37 constexpr char STR_TRIGGER_REASON[] = "TRIGGER_REASON";
38 constexpr char STR_CHANGE_TYPE[] = "CHANGE_TYPE";
39 constexpr char STR_EXECUTOR_TYPE[] = "EXECUTOR_TYPE";
40 constexpr char STR_MODULE_NAME[] = "MODULE_NAME";
41 constexpr char STR_HAPPEN_TIME[] = "HAPPEN_TIME";
42 constexpr char STR_AUTH_TRUST_LEVEL[] = "AUTH_TRUST_LEVEL";
43 constexpr char STR_AUTH_TIME[] = "AUTH_TIME";
44 constexpr char STR_REMAIN_TIME[] = "REMAIN_TIME";
45 constexpr char STR_FREEXING_TIME[] = "FREEXING_TIME";
46 constexpr char STR_AUTH_TIME_SPAN[] = "AUTH_TIME_SPAN";
47 constexpr char STR_SDK_VERSION[] = "SDK_VERSION";
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 = HiSysEvent::Write(DOMAIN_STR, "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 = HiSysEvent::Write(DOMAIN_STR, "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 = HiSysEvent::Write(DOMAIN_STR, "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 = HiSysEvent::Write(DOMAIN_STR, "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 = HiSysEvent::Write(DOMAIN_STR, "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     if (ret != 0) {
115         IAM_LOGE("hisysevent write failed! ret %{public}d, callingUid %{public}"  PRIu64 ", authType %{public}d,"
116             "atl %{public}u, authResult %{public}u, timeSpanString %{public}s, sdkVersion%{public}u.",
117             ret, info.callingUid, info.authType, info.atl, info.authResult,
118             info.timeSpanString.c_str(), info.sdkVersion);
119     }
120 }
121 
ReportPinAuth(const PinAuthInfo & info)122 void ReportPinAuth(const PinAuthInfo &info)
123 {
124     int32_t ret = HiSysEvent::Write(DOMAIN_STR, "USERIAM_PIN_AUTH",
125         HiSysEvent::EventType::SECURITY,
126         STR_USER_ID, info.userId,
127         STR_CALLING_ID, info.callingUid,
128         STR_AUTH_TIME, info.authTimeString,
129         STR_AUTH_RESULT, info.authResult,
130         STR_REMAIN_TIME, info.remainTime,
131         STR_FREEXING_TIME, info.freezingTime);
132     if (ret != 0) {
133         IAM_LOGE("hisysevent write failed! ret %{public}d, userId %{public}d, callingUid %{public}" PRIu64
134             ",authTimeString %{public}s, authResult %{public}u, remainTime %{public}u, freezingTime%{public}u.",
135             ret, info.userId, info.callingUid, info.authTimeString.c_str(), info.authResult,
136             info.remainTime, info.freezingTime);
137     }
138 }
139 } // namespace UserAuth
140 } // namespace UserIam
141 } // namespace OHOS