Dario Freni | 5a25929 | 2018-08-14 17:49:00 +0100 | [diff] [blame] | 1 | /* |
| 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 Gampe | 356e40c | 2018-12-26 10:59:57 -0800 | [diff] [blame] | 20 | #include <memory> |
| 21 | #include <string> |
| 22 | #include <vector> |
Jooyung Han | f7c8d03 | 2019-04-11 15:12:09 +0900 | [diff] [blame] | 23 | |
Mohammad Samiul Islam | 159ea8e | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 24 | #include <android-base/result.h> |
Jooyung Han | f7c8d03 | 2019-04-11 15:12:09 +0900 | [diff] [blame] | 25 | #include <libavb/libavb.h> |
Andreas Gampe | 356e40c | 2018-12-26 10:59:57 -0800 | [diff] [blame] | 26 | #include <ziparchive/zip_archive.h> |
| 27 | |
Jiyong Park | 5e81023 | 2019-04-01 15:24:26 +0900 | [diff] [blame] | 28 | #include "apex_constants.h" |
Jiyong Park | 69c0f11 | 2018-11-22 20:38:05 +0900 | [diff] [blame] | 29 | #include "apex_manifest.h" |
Jiyong Park | 69c0f11 | 2018-11-22 20:38:05 +0900 | [diff] [blame] | 30 | |
Dario Freni | 5a25929 | 2018-08-14 17:49:00 +0100 | [diff] [blame] | 31 | namespace android { |
| 32 | namespace apex { |
| 33 | |
Andreas Gampe | 356e40c | 2018-12-26 10:59:57 -0800 | [diff] [blame] | 34 | // Data needed to construct a valid VerityTable |
| 35 | struct ApexVerityData { |
| 36 | std::unique_ptr<AvbHashtreeDescriptor> desc; |
Jooyung Han | f7c8d03 | 2019-04-11 15:12:09 +0900 | [diff] [blame] | 37 | std::string hash_algorithm; |
Andreas Gampe | 356e40c | 2018-12-26 10:59:57 -0800 | [diff] [blame] | 38 | std::string salt; |
| 39 | std::string root_digest; |
| 40 | }; |
| 41 | |
Dario Freni | 5a25929 | 2018-08-14 17:49:00 +0100 | [diff] [blame] | 42 | // Manages the content of an APEX package and provides utilities to navigate |
| 43 | // the content. |
| 44 | class ApexFile { |
| 45 | public: |
Mohammad Samiul Islam | 159ea8e | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 46 | static android::base::Result<ApexFile> Open(const std::string& path); |
Jiyong Park | 69c0f11 | 2018-11-22 20:38:05 +0900 | [diff] [blame] | 47 | ApexFile() = delete; |
| 48 | ApexFile(ApexFile&&) = default; |
Andreas Gampe | 2efadc0 | 2018-11-19 16:39:45 -0800 | [diff] [blame] | 49 | |
Jiyong Park | 69c0f11 | 2018-11-22 20:38:05 +0900 | [diff] [blame] | 50 | const std::string& GetPath() const { return apex_path_; } |
Dario Freni | 5a25929 | 2018-08-14 17:49:00 +0100 | [diff] [blame] | 51 | int32_t GetImageOffset() const { return image_offset_; } |
| 52 | size_t GetImageSize() const { return image_size_; } |
Jiyong Park | 69c0f11 | 2018-11-22 20:38:05 +0900 | [diff] [blame] | 53 | const ApexManifest& GetManifest() const { return manifest_; } |
Jiyong Park | 9181a2d | 2018-12-27 15:14:45 +0900 | [diff] [blame] | 54 | const std::string& GetBundledPublicKey() const { return apex_pubkey_; } |
Nikita Ioffe | f00fc65 | 2019-08-30 11:56:52 +0100 | [diff] [blame] | 55 | bool IsBuiltin() const { return is_builtin_; } |
Mohammad Samiul Islam | 159ea8e | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 56 | android::base::Result<ApexVerityData> VerifyApexVerity() const; |
| 57 | android::base::Result<void> VerifyManifestMatches( |
| 58 | const std::string& mount_path) const; |
Andreas Gampe | 356e40c | 2018-12-26 10:59:57 -0800 | [diff] [blame] | 59 | |
Dario Freni | 5a25929 | 2018-08-14 17:49:00 +0100 | [diff] [blame] | 60 | private: |
Jiyong Park | 8f55a21 | 2019-06-03 20:48:15 +0900 | [diff] [blame] | 61 | ApexFile(const std::string& apex_path, int32_t image_offset, |
Jooyung Han | a7983c0 | 2020-02-14 07:13:44 +0900 | [diff] [blame] | 62 | size_t image_size, ApexManifest manifest, |
Jooyung Han | 499de89 | 2020-05-12 12:01:05 +0900 | [diff] [blame] | 63 | const std::string& apex_pubkey, bool is_builtin) |
Jiyong Park | 69c0f11 | 2018-11-22 20:38:05 +0900 | [diff] [blame] | 64 | : apex_path_(apex_path), |
Jiyong Park | 69c0f11 | 2018-11-22 20:38:05 +0900 | [diff] [blame] | 65 | image_offset_(image_offset), |
| 66 | image_size_(image_size), |
Jiyong Park | 9181a2d | 2018-12-27 15:14:45 +0900 | [diff] [blame] | 67 | manifest_(std::move(manifest)), |
Nikita Ioffe | f00fc65 | 2019-08-30 11:56:52 +0100 | [diff] [blame] | 68 | apex_pubkey_(apex_pubkey), |
| 69 | is_builtin_(is_builtin) {} |
Dario Freni | 5a25929 | 2018-08-14 17:49:00 +0100 | [diff] [blame] | 70 | |
Jiyong Park | 69c0f11 | 2018-11-22 20:38:05 +0900 | [diff] [blame] | 71 | std::string apex_path_; |
Dario Freni | 5a25929 | 2018-08-14 17:49:00 +0100 | [diff] [blame] | 72 | int32_t image_offset_; |
| 73 | size_t image_size_; |
Jiyong Park | 69c0f11 | 2018-11-22 20:38:05 +0900 | [diff] [blame] | 74 | ApexManifest manifest_; |
Jiyong Park | 9181a2d | 2018-12-27 15:14:45 +0900 | [diff] [blame] | 75 | std::string apex_pubkey_; |
Nikita Ioffe | f00fc65 | 2019-08-30 11:56:52 +0100 | [diff] [blame] | 76 | bool is_builtin_; |
Dario Freni | 5a25929 | 2018-08-14 17:49:00 +0100 | [diff] [blame] | 77 | }; |
| 78 | |
Mohammad Samiul Islam | 159ea8e | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 79 | android::base::Result<std::vector<std::string>> FindApexes( |
Jooyung Han | 65a2508 | 2019-04-05 15:34:13 +0900 | [diff] [blame] | 80 | const std::vector<std::string>& paths); |
Mohammad Samiul Islam | 159ea8e | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 81 | android::base::Result<std::vector<std::string>> FindApexFilesByName( |
| 82 | const std::string& path); |
Jiyong Park | 5e81023 | 2019-04-01 15:24:26 +0900 | [diff] [blame] | 83 | |
| 84 | bool isPathForBuiltinApexes(const std::string& path); |
| 85 | |
Dario Freni | 5a25929 | 2018-08-14 17:49:00 +0100 | [diff] [blame] | 86 | } // namespace apex |
| 87 | } // namespace android |
| 88 | |
| 89 | #endif // ANDROID_APEXD_APEX_FILE_H_ |