blob: 0476911c8f1ecfaceefca5af16b832eb46b56f8b [file] [log] [blame]
Dario Freni5a259292018-08-14 17:49:00 +01001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_APEXD_APEX_FILE_H_
18#define ANDROID_APEXD_APEX_FILE_H_
19
Andreas Gampe356e40c2018-12-26 10:59:57 -080020#include <memory>
21#include <string>
22#include <vector>
Jooyung Hanf7c8d032019-04-11 15:12:09 +090023
Mohammad Samiul Islam159ea8e2019-06-20 15:55:27 +010024#include <android-base/result.h>
Jooyung Hanf7c8d032019-04-11 15:12:09 +090025#include <libavb/libavb.h>
Andreas Gampe356e40c2018-12-26 10:59:57 -080026#include <ziparchive/zip_archive.h>
27
Jiyong Park5e810232019-04-01 15:24:26 +090028#include "apex_constants.h"
Jiyong Park69c0f112018-11-22 20:38:05 +090029#include "apex_manifest.h"
Jiyong Park69c0f112018-11-22 20:38:05 +090030
Dario Freni5a259292018-08-14 17:49:00 +010031namespace android {
32namespace apex {
33
Andreas Gampe356e40c2018-12-26 10:59:57 -080034// Data needed to construct a valid VerityTable
35struct ApexVerityData {
36 std::unique_ptr<AvbHashtreeDescriptor> desc;
Jooyung Hanf7c8d032019-04-11 15:12:09 +090037 std::string hash_algorithm;
Andreas Gampe356e40c2018-12-26 10:59:57 -080038 std::string salt;
39 std::string root_digest;
40};
41
Dario Freni5a259292018-08-14 17:49:00 +010042// Manages the content of an APEX package and provides utilities to navigate
43// the content.
44class ApexFile {
45 public:
Mohammad Samiul Islam159ea8e2019-06-20 15:55:27 +010046 static android::base::Result<ApexFile> Open(const std::string& path);
Jiyong Park69c0f112018-11-22 20:38:05 +090047 ApexFile() = delete;
48 ApexFile(ApexFile&&) = default;
Andreas Gampe2efadc02018-11-19 16:39:45 -080049
Jiyong Park69c0f112018-11-22 20:38:05 +090050 const std::string& GetPath() const { return apex_path_; }
Dario Freni5a259292018-08-14 17:49:00 +010051 int32_t GetImageOffset() const { return image_offset_; }
52 size_t GetImageSize() const { return image_size_; }
Jiyong Park69c0f112018-11-22 20:38:05 +090053 const ApexManifest& GetManifest() const { return manifest_; }
Jiyong Park9181a2d2018-12-27 15:14:45 +090054 const std::string& GetBundledPublicKey() const { return apex_pubkey_; }
Nikita Ioffef00fc652019-08-30 11:56:52 +010055 bool IsBuiltin() const { return is_builtin_; }
Mohammad Samiul Islam159ea8e2019-06-20 15:55:27 +010056 android::base::Result<ApexVerityData> VerifyApexVerity() const;
57 android::base::Result<void> VerifyManifestMatches(
58 const std::string& mount_path) const;
Andreas Gampe356e40c2018-12-26 10:59:57 -080059
Dario Freni5a259292018-08-14 17:49:00 +010060 private:
Jiyong Park8f55a212019-06-03 20:48:15 +090061 ApexFile(const std::string& apex_path, int32_t image_offset,
Jooyung Hana7983c02020-02-14 07:13:44 +090062 size_t image_size, ApexManifest manifest,
Jooyung Han499de892020-05-12 12:01:05 +090063 const std::string& apex_pubkey, bool is_builtin)
Jiyong Park69c0f112018-11-22 20:38:05 +090064 : apex_path_(apex_path),
Jiyong Park69c0f112018-11-22 20:38:05 +090065 image_offset_(image_offset),
66 image_size_(image_size),
Jiyong Park9181a2d2018-12-27 15:14:45 +090067 manifest_(std::move(manifest)),
Nikita Ioffef00fc652019-08-30 11:56:52 +010068 apex_pubkey_(apex_pubkey),
69 is_builtin_(is_builtin) {}
Dario Freni5a259292018-08-14 17:49:00 +010070
Jiyong Park69c0f112018-11-22 20:38:05 +090071 std::string apex_path_;
Dario Freni5a259292018-08-14 17:49:00 +010072 int32_t image_offset_;
73 size_t image_size_;
Jiyong Park69c0f112018-11-22 20:38:05 +090074 ApexManifest manifest_;
Jiyong Park9181a2d2018-12-27 15:14:45 +090075 std::string apex_pubkey_;
Nikita Ioffef00fc652019-08-30 11:56:52 +010076 bool is_builtin_;
Dario Freni5a259292018-08-14 17:49:00 +010077};
78
Mohammad Samiul Islam159ea8e2019-06-20 15:55:27 +010079android::base::Result<std::vector<std::string>> FindApexes(
Jooyung Han65a25082019-04-05 15:34:13 +090080 const std::vector<std::string>& paths);
Mohammad Samiul Islam159ea8e2019-06-20 15:55:27 +010081android::base::Result<std::vector<std::string>> FindApexFilesByName(
82 const std::string& path);
Jiyong Park5e810232019-04-01 15:24:26 +090083
84bool isPathForBuiltinApexes(const std::string& path);
85
Dario Freni5a259292018-08-14 17:49:00 +010086} // namespace apex
87} // namespace android
88
89#endif // ANDROID_APEXD_APEX_FILE_H_