1 /*
2 * Copyright (c) 2024 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 "el5_filekey_callback_stub.h"
17 #include "el5_filekey_manager_error.h"
18 #include "el5_filekey_manager_log.h"
19 #include "parcel_utils.h"
20
21 namespace OHOS {
22 namespace Security {
23 namespace AccessToken {
El5FilekeyCallbackStub()24 El5FilekeyCallbackStub::El5FilekeyCallbackStub()
25 {
26 }
27
~El5FilekeyCallbackStub()28 El5FilekeyCallbackStub::~El5FilekeyCallbackStub()
29 {
30 }
31
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)32 int32_t El5FilekeyCallbackStub::OnRemoteRequest(
33 uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
34 {
35 if (data.ReadInterfaceToken() != El5FilekeyCallbackInterface::GetDescriptor()) {
36 LOG_ERROR("get unexpected descriptor");
37 return EFM_ERR_IPC_TOKEN_INVALID;
38 }
39 if (code == static_cast<uint32_t>(El5FilekeyCallbackInterface::Code::ON_REGENERATE_APP_KEY)) {
40 std::vector<AppKeyInfo> infos;
41 uint32_t infosSize = data.ReadUint32();
42 if (infosSize > MAX_RECORD_SIZE) {
43 LOG_ERROR("Parse infos failed, results oversize %{public}d.", infosSize);
44 return EFM_ERR_IPC_READ_DATA;
45 }
46 for (uint32_t i = 0; i < infosSize; ++i) {
47 sptr<AppKeyInfo> info = data.ReadParcelable<AppKeyInfo>();
48 if (info == nullptr) {
49 LOG_ERROR("Parse AppKetInfo failed.");
50 return EFM_ERR_IPC_READ_DATA;
51 }
52 infos.emplace_back(*info);
53 }
54 OnRegenerateAppKey(infos);
55 return NO_ERROR;
56 } else {
57 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
58 }
59 }
60 } // namespace AccessToken
61 } // namespace Security
62 } // namespace OHOS
63