1 /*
2 * Copyright (c) 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 "ipc/code_signature_param.h"
17
18 #include "bundle_constants.h"
19 #include "nlohmann/json.hpp"
20 #include "parcel_macro.h"
21 #include "string_ex.h"
22
23 namespace OHOS {
24 namespace AppExecFwk {
25 namespace {
26 constexpr const char* CODE_SIGNATURE_MODULE_PATH = "modulePath";
27 constexpr const char* CODE_SIGNATURE_CPU_ABI = "cpuAbi";
28 constexpr const char* CODE_SIGNATURE_TARGET_SO_PATH = "targetSoPath";
29 constexpr const char* CODE_SIGNATURE_SIGNATURE_FILE_PATH = "signatureFileDir";
30 constexpr const char* CODE_SIGNATURE_IS_ENTERPRISE_BUNDLE = "isEnterpriseBundle";
31 constexpr const char* CODE_SIGNATURE_APP_IDENTIFIER = "appIdentifier";
32 constexpr const char* CODE_SIGNATURE_IS_PREINSTALLED_BUNDLE = "isPreInstalledBundle";
33 constexpr const char* CODE_SIGNATURE_IS_COMPILE_SDK_OPENHARMONY = "isCompileSdkOpenHarmony";
34 constexpr const char* CODE_SIGNATURE_IS_COMPRESS_NATIVE_LIBRARY = "isCompressNativeLibrary";
35 constexpr const char* CODE_SIGNATURE_IS_PLUGIN = "isPlugin";
36 constexpr const char* CODE_SIGNATURE_PLUGIN_ID = "pluginId";
37 } // namespace
38
ReadFromParcel(Parcel & parcel)39 bool CodeSignatureParam::ReadFromParcel(Parcel &parcel)
40 {
41 modulePath = Str16ToStr8(parcel.ReadString16());
42 cpuAbi = Str16ToStr8(parcel.ReadString16());
43 targetSoPath = Str16ToStr8(parcel.ReadString16());
44 signatureFileDir = Str16ToStr8(parcel.ReadString16());
45 isEnterpriseBundle = parcel.ReadBool();
46 appIdentifier = Str16ToStr8(parcel.ReadString16());
47 isPreInstalledBundle = parcel.ReadBool();
48 isCompileSdkOpenHarmony = parcel.ReadBool();
49 isCompressNativeLibrary = parcel.ReadBool();
50 isPlugin = parcel.ReadBool();
51 pluginId = Str16ToStr8(parcel.ReadString16());
52 return true;
53 }
54
Marshalling(Parcel & parcel) const55 bool CodeSignatureParam::Marshalling(Parcel &parcel) const
56 {
57 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(modulePath));
58 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(cpuAbi));
59 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(targetSoPath));
60 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(signatureFileDir));
61 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isEnterpriseBundle);
62 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(appIdentifier));
63 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isPreInstalledBundle);
64 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isCompileSdkOpenHarmony);
65 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isCompressNativeLibrary);
66 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isPlugin);
67 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(pluginId));
68 return true;
69 }
70
Unmarshalling(Parcel & parcel)71 CodeSignatureParam *CodeSignatureParam::Unmarshalling(Parcel &parcel)
72 {
73 CodeSignatureParam *info = new (std::nothrow) CodeSignatureParam();
74 if ((info != nullptr) && (!info->ReadFromParcel(parcel))) {
75 APP_LOGE("read from parcel failed");
76 delete info;
77 info = nullptr;
78 }
79 return info;
80 }
81
ToString() const82 std::string CodeSignatureParam::ToString() const
83 {
84 nlohmann::json codeSignatureParamJson = nlohmann::json {
85 { CODE_SIGNATURE_MODULE_PATH, modulePath },
86 { CODE_SIGNATURE_CPU_ABI, cpuAbi },
87 { CODE_SIGNATURE_TARGET_SO_PATH, targetSoPath },
88 { CODE_SIGNATURE_SIGNATURE_FILE_PATH, signatureFileDir },
89 { CODE_SIGNATURE_IS_ENTERPRISE_BUNDLE, isEnterpriseBundle },
90 { CODE_SIGNATURE_APP_IDENTIFIER, appIdentifier },
91 { CODE_SIGNATURE_IS_PREINSTALLED_BUNDLE, isPreInstalledBundle },
92 { CODE_SIGNATURE_IS_COMPILE_SDK_OPENHARMONY, isCompileSdkOpenHarmony },
93 { CODE_SIGNATURE_IS_COMPRESS_NATIVE_LIBRARY, isCompressNativeLibrary },
94 { CODE_SIGNATURE_IS_PLUGIN, isPlugin },
95 { CODE_SIGNATURE_PLUGIN_ID, pluginId },
96 };
97 return codeSignatureParamJson.dump(Constants::DUMP_INDENT);
98 }
99 } // AppExecFwk
100 } // OHOS
101