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 /**
17  * @file co_auth_client_defines.h
18  *
19  * @brief Type definitions used by user auth client.
20  * @since 3.1
21  * @version 3.2
22  */
23 
24 #ifndef USER_AUTH_CLIENT_DEFINES_H
25 #define USER_AUTH_CLIENT_DEFINES_H
26 
27 #include <vector>
28 
29 #include "attributes.h"
30 #include "iam_common_defines.h"
31 
32 namespace OHOS {
33 namespace UserIam {
34 namespace UserAuth {
35 const uint64_t MAX_ALLOWABLE_REUSE_DURATION = 5 * 60 * 1000;
36 
37 /**
38  * @brief Remote auth parameter.
39  */
40 struct RemoteAuthParam {
41     /** verifier network id */
42     std::optional<std::string> verifierNetworkId;
43     /** collector network id */
44     std::optional<std::string> collectorNetworkId;
45     /** collector token id */
46     std::optional<uint32_t> collectorTokenId;
47 };
48 
49 /**
50  * @brief Auth parameter.
51  */
52 struct AuthParam {
53     /** user id */
54     int32_t userId;
55     /** challenge value */
56     std::vector<uint8_t> challenge;
57     /** Credential type for authentication. */
58     AuthType authType;
59     /** Trust level of authentication result. */
60     AuthTrustLevel authTrustLevel;
61     /** Auth intention. */
62     AuthIntent authIntent;
63     /** Remote auth parameter. */
64     std::optional<RemoteAuthParam> remoteAuthParam;
65 };
66 
67 /**
68  * @brief Window mode type for user authentication widget.
69  */
70 enum WindowModeType : int32_t {
71     /** Window mode type is dialog box. */
72     DIALOG_BOX = 1,
73     /**  Window mode type is full screen. */
74     FULLSCREEN = 2,
75     /**  Window mode type is not set */
76     UNKNOWN_WINDOW_MODE = 3,
77 };
78 
79 /**
80  * @brief The mode for reusing unlock authentication result.
81  */
82 enum ReuseMode : uint32_t {
83     /** Authentication type relevant.The unlock authentication result can be reused only when the result is within
84      * valid duration as well as it comes from one of specified UserAuthTypes of the AuthParam. */
85     AUTH_TYPE_RELEVANT = 1,
86     /** Authentication type irrelevant.The unlock authentication result can be reused as long as the result is within
87      * valid duration. */
88     AUTH_TYPE_IRRELEVANT = 2,
89     /** Caller irrelevant authentication type relevant.The unlock authentication result can be reused only when the
90      * result is within valid duration as well as it comes from one of specified UserAuthTypes of the AuthParam. */
91     CALLER_IRRELEVANT_AUTH_TYPE_RELEVANT = 3,
92     /** Caller irrelevant authentication type irrelevant.The unlock authentication result can be reused as long as the
93      * result is within valid duration. */
94     CALLER_IRRELEVANT_AUTH_TYPE_IRRELEVANT = 4,
95 };
96 
97 /**
98  * @brief Reuse unlock authentication result.
99  */
100 struct ReuseUnlockResult {
101     /** Whether to reuse unlock result, ReuseUnlockResult is valid only when isReuse is true.*/
102     bool isReuse {false};
103     /** The mode for reusing unlock authentication result. */
104     ReuseMode reuseMode {AUTH_TYPE_IRRELEVANT};
105     /** The allowable reuse duration.The value of duration should be between 0 and MAX_ALLOWABLE_REUSE_DURATION. */
106     uint64_t reuseDuration {0};
107 };
108 
109 /**
110  * @brief Auth widget parameter.
111  */
112 struct WidgetParam {
113     /** Title of widget. */
114     std::string title;
115     /** The description text of navigation button. */
116     std::string navigationButtonText;
117     /** Full screen or not. */
118     WindowModeType windowMode;
119 };
120 
121 /**
122  * @brief Auth widget parameter.
123  */
124 struct WidgetAuthParam {
125     /** user id */
126     int32_t userId;
127     /** challenge value */
128     std::vector<uint8_t> challenge;
129     /** Credential type for authentication. */
130     std::vector<AuthType> authTypes;
131     /** Trust level of authentication result. */
132     AuthTrustLevel authTrustLevel;
133     /** Reuse unlock authentication result. */
134     ReuseUnlockResult reuseUnlockResult;
135 };
136 
137 /**
138  * @brief Executor property needed to get.
139  */
140 struct GetPropertyRequest {
141     /** Auth type supported by executor. */
142     AuthType authType {0};
143     /** The keys of attribute needed to get. */
144     std::vector<Attributes::AttributeKey> keys {};
145 };
146 
147 /**
148  * @brief Executor property needed to set.
149  */
150 struct SetPropertyRequest {
151     /** Auth type supported by executor. */
152     AuthType authType {0};
153     /**  The executor's property mode. */
154     PropertyMode mode {0};
155     /** The attributes needed to set. */
156     Attributes attrs {};
157 };
158 
159 /**
160  * @brief Global config type.
161  */
162 enum GlobalConfigType : int32_t {
163     /** Pin expired period */
164     PIN_EXPIRED_PERIOD = 1,
165 };
166 
167 /**
168  * @brief Global config value.
169  */
170 union GlobalConfigValue {
171     /** Global config value of pin expired period.It's value should between 0 and 2^50.
172       * When pinExpiredPeriod <= 0, userAuth won't check pin expired period */
173     int64_t pinExpiredPeriod;
174 };
175 
176 /**
177  * @brief Global config param.
178  */
179 struct GlobalConfigParam {
180     /** Global config type. */
181     GlobalConfigType type;
182     /** Global config value. */
183     GlobalConfigValue value;
184 };
185 } // namespace UserAuth
186 } // namespace UserIam
187 } // namespace OHOS
188 #endif // USER_AUTH_CLIENT_DEFINES_H