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 "app_account_authenticator_stub.h"
17
18 #include "account_error_no.h"
19 #include "account_log_wrapper.h"
20
21 namespace OHOS {
22 namespace AccountSA {
23
AppAccountAuthenticatorStub()24 AppAccountAuthenticatorStub::AppAccountAuthenticatorStub()
25 {}
26
~AppAccountAuthenticatorStub()27 AppAccountAuthenticatorStub::~AppAccountAuthenticatorStub()
28 {}
29
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)30 int AppAccountAuthenticatorStub::OnRemoteRequest(
31 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
32 {
33 if (data.ReadInterfaceToken() != GetDescriptor()) {
34 ACCOUNT_LOGE("failed to check descriptor! code %{public}u.", code);
35 return ERR_ACCOUNT_COMMON_CHECK_DESCRIPTOR_ERROR;
36 }
37
38 switch (code) {
39 case static_cast<uint32_t>(AppAccountAuthenticatorInterfaceCode::ADD_ACCOUNT_IMPLICITLY):
40 return ProcAddAccountImplicitly(data, reply);
41 case static_cast<uint32_t>(AppAccountAuthenticatorInterfaceCode::AUTHENTICATE):
42 return ProcAuthenticate(data, reply);
43 case static_cast<uint32_t>(AppAccountAuthenticatorInterfaceCode::VERIFY_CREDENTIAL):
44 return ProcVerifyCredential(data, reply);
45 case static_cast<uint32_t>(AppAccountAuthenticatorInterfaceCode::CHECK_ACCOUNT_LABELS):
46 return ProcCheckAccountLabels(data, reply);
47 case static_cast<uint32_t>(AppAccountAuthenticatorInterfaceCode::SET_PROPERTIES):
48 return ProcSetProperties(data, reply);
49 case static_cast<uint32_t>(AppAccountAuthenticatorInterfaceCode::IS_ACCOUNT_REMOVABLE):
50 return ProcIsAccountRemovable(data, reply);
51 case static_cast<uint32_t>(AppAccountAuthenticatorInterfaceCode::CREATE_ACCOUNT_IMPLICITLY):
52 return ProcCreateAccountImplicitly(data, reply);
53 case static_cast<uint32_t>(AppAccountAuthenticatorInterfaceCode::AUTH):
54 return ProcAuth(data, reply);
55 default:
56 break;
57 }
58
59 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
60 }
61
ProcAddAccountImplicitly(MessageParcel & data,MessageParcel & reply)62 ErrCode AppAccountAuthenticatorStub::ProcAddAccountImplicitly(MessageParcel &data, MessageParcel &reply)
63 {
64 std::string authType = data.ReadString();
65 std::string callerBundleName = data.ReadString();
66 std::shared_ptr<AAFwk::WantParams> options(data.ReadParcelable<AAFwk::WantParams>());
67 sptr<IRemoteObject> callback = data.ReadRemoteObject();
68 ErrCode result = ERR_OK;
69 if ((options == nullptr) || (callback == nullptr)) {
70 ACCOUNT_LOGE("invalid request parameters");
71 result = ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
72 } else {
73 result = AddAccountImplicitly(authType, callerBundleName, *options, callback);
74 }
75 if (!reply.WriteInt32(result)) {
76 ACCOUNT_LOGE("failed to write reply");
77 return IPC_STUB_WRITE_PARCEL_ERR;
78 }
79 return ERR_NONE;
80 }
81
ProcAuthenticate(MessageParcel & data,MessageParcel & reply)82 ErrCode AppAccountAuthenticatorStub::ProcAuthenticate(MessageParcel &data, MessageParcel &reply)
83 {
84 std::string name = data.ReadString();
85 std::string authType = data.ReadString();
86 std::string callerBundleName = data.ReadString();
87 std::shared_ptr<AAFwk::WantParams> options(data.ReadParcelable<AAFwk::WantParams>());
88 sptr<IRemoteObject> callback = data.ReadRemoteObject();
89 ErrCode result = ERR_OK;
90 if ((options == nullptr) || (callback == nullptr)) {
91 ACCOUNT_LOGE("invalid request parameters");
92 result = ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
93 } else {
94 result = Authenticate(name, authType, callerBundleName, *options, callback);
95 }
96 if (!reply.WriteInt32(result)) {
97 ACCOUNT_LOGE("failed to write reply");
98 return IPC_STUB_WRITE_PARCEL_ERR;
99 }
100 return ERR_NONE;
101 }
102
ProcCreateAccountImplicitly(MessageParcel & data,MessageParcel & reply)103 ErrCode AppAccountAuthenticatorStub::ProcCreateAccountImplicitly(MessageParcel &data, MessageParcel &reply)
104 {
105 sptr<CreateAccountImplicitlyOptions> options = data.ReadParcelable<CreateAccountImplicitlyOptions>();
106 sptr<IRemoteObject> callback = data.ReadRemoteObject();
107 ErrCode result = ERR_OK;
108 if ((options == nullptr) || (callback == nullptr)) {
109 ACCOUNT_LOGE("invalid request parameters");
110 result = ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
111 } else {
112 result = CreateAccountImplicitly(*options, callback);
113 }
114 if (!reply.WriteInt32(result)) {
115 ACCOUNT_LOGE("failed to write reply");
116 return IPC_STUB_WRITE_PARCEL_ERR;
117 }
118 return ERR_NONE;
119 }
120
ProcAuth(MessageParcel & data,MessageParcel & reply)121 ErrCode AppAccountAuthenticatorStub::ProcAuth(MessageParcel &data, MessageParcel &reply)
122 {
123 std::string name = data.ReadString();
124 std::string authType = data.ReadString();
125 std::shared_ptr<AAFwk::WantParams> options(data.ReadParcelable<AAFwk::WantParams>());
126 sptr<IRemoteObject> callback = data.ReadRemoteObject();
127 ErrCode result = ERR_OK;
128 if ((options == nullptr) || (callback == nullptr)) {
129 ACCOUNT_LOGE("invalid request parameters");
130 result = ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
131 } else {
132 result = Auth(name, authType, *options, callback);
133 }
134 if (!reply.WriteInt32(result)) {
135 ACCOUNT_LOGE("failed to write reply");
136 return IPC_STUB_WRITE_PARCEL_ERR;
137 }
138 return ERR_NONE;
139 }
140
ProcVerifyCredential(MessageParcel & data,MessageParcel & reply)141 ErrCode AppAccountAuthenticatorStub::ProcVerifyCredential(MessageParcel &data, MessageParcel &reply)
142 {
143 std::string name = data.ReadString();
144 sptr<VerifyCredentialOptions> options = data.ReadParcelable<VerifyCredentialOptions>();
145 sptr<IRemoteObject> callback = data.ReadRemoteObject();
146 ErrCode result = ERR_OK;
147 if ((options == nullptr) || (callback == nullptr)) {
148 ACCOUNT_LOGE("invalid request parameters");
149 result = ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
150 } else {
151 result = VerifyCredential(name, *options, callback);
152 }
153 if (!reply.WriteInt32(result)) {
154 ACCOUNT_LOGE("failed to write reply");
155 return IPC_STUB_WRITE_PARCEL_ERR;
156 }
157 return ERR_NONE;
158 }
159
ProcCheckAccountLabels(MessageParcel & data,MessageParcel & reply)160 ErrCode AppAccountAuthenticatorStub::ProcCheckAccountLabels(MessageParcel &data, MessageParcel &reply)
161 {
162 std::string name = data.ReadString();
163 std::vector<std::string> labels;
164 data.ReadStringVector(&labels);
165 sptr<IRemoteObject> callback = data.ReadRemoteObject();
166 ErrCode result = ERR_OK;
167 if (callback == nullptr) {
168 ACCOUNT_LOGE("invalid request parameters");
169 result = ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
170 } else {
171 result = CheckAccountLabels(name, labels, callback);
172 }
173 if (!reply.WriteInt32(result)) {
174 ACCOUNT_LOGE("failed to write reply");
175 return IPC_STUB_WRITE_PARCEL_ERR;
176 }
177 return ERR_NONE;
178 }
179
ProcSetProperties(MessageParcel & data,MessageParcel & reply)180 ErrCode AppAccountAuthenticatorStub::ProcSetProperties(MessageParcel &data, MessageParcel &reply)
181 {
182 sptr<SetPropertiesOptions> options = data.ReadParcelable<SetPropertiesOptions>();
183 sptr<IRemoteObject> callback = data.ReadRemoteObject();
184 ErrCode result = ERR_OK;
185 if ((options == nullptr) || (callback == nullptr)) {
186 ACCOUNT_LOGE("invalid request parameters");
187 result = ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
188 } else {
189 result = SetProperties(*options, callback);
190 }
191 if (!reply.WriteInt32(result)) {
192 ACCOUNT_LOGE("failed to write reply");
193 return IPC_STUB_WRITE_PARCEL_ERR;
194 }
195 return ERR_NONE;
196 }
197
ProcIsAccountRemovable(MessageParcel & data,MessageParcel & reply)198 ErrCode AppAccountAuthenticatorStub::ProcIsAccountRemovable(MessageParcel &data, MessageParcel &reply)
199 {
200 std::string name = data.ReadString();
201 sptr<IRemoteObject> callback = data.ReadRemoteObject();
202 ErrCode result = ERR_OK;
203 if (callback == nullptr) {
204 ACCOUNT_LOGE("invalid request parameters");
205 result = ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
206 } else {
207 result = IsAccountRemovable(name, callback);
208 }
209 if (!reply.WriteInt32(result)) {
210 ACCOUNT_LOGE("failed to write reply");
211 return IPC_STUB_WRITE_PARCEL_ERR;
212 }
213 return ERR_NONE;
214 }
215 } // namespace AccountSA
216 } // namespace OHOS
217