blob: 67ebdd9f40316f4afdae6428ee99698e38f810d0 [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>
Andreas Gampe356e40c2018-12-26 10:59:57 -080023#include <ziparchive/zip_archive.h>
24
Jiyong Park5e810232019-04-01 15:24:26 +090025#include "apex_constants.h"
Jiyong Park69c0f112018-11-22 20:38:05 +090026#include "apex_manifest.h"
27#include "status_or.h"
28
Andreas Gampe356e40c2018-12-26 10:59:57 -080029struct AvbHashtreeDescriptor;
Dario Freni5a259292018-08-14 17:49:00 +010030
31namespace 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;
37 std::string salt;
38 std::string root_digest;
39};
40
Dario Freni5a259292018-08-14 17:49:00 +010041// Manages the content of an APEX package and provides utilities to navigate
42// the content.
43class ApexFile {
44 public:
Jiyong Park69c0f112018-11-22 20:38:05 +090045 static StatusOr<ApexFile> Open(const std::string& path);
46 ApexFile() = delete;
47 ApexFile(ApexFile&&) = default;
Andreas Gampe2efadc02018-11-19 16:39:45 -080048
Jiyong Park69c0f112018-11-22 20:38:05 +090049 const std::string& GetPath() const { return apex_path_; }
Dario Freni5a259292018-08-14 17:49:00 +010050 int32_t GetImageOffset() const { return image_offset_; }
51 size_t GetImageSize() const { return image_size_; }
Jiyong Park69c0f112018-11-22 20:38:05 +090052 const ApexManifest& GetManifest() const { return manifest_; }
Jiyong Parkd02c88c2018-11-13 19:23:32 +090053 bool IsFlattened() const { return flattened_; }
Jiyong Park9181a2d2018-12-27 15:14:45 +090054 const std::string& GetBundledPublicKey() const { return apex_pubkey_; }
Dario Freniaeb233c2018-08-28 12:48:42 +010055
Jiyong Park5e810232019-04-01 15:24:26 +090056 StatusOr<ApexVerityData> VerifyApexVerity() const;
Martijn Coenen329f1122019-02-28 16:10:08 +010057 Status VerifyManifestMatches(const std::string& mount_path) const;
Andreas Gampe356e40c2018-12-26 10:59:57 -080058
Dario Freni5a259292018-08-14 17:49:00 +010059 private:
Jiyong Park69c0f112018-11-22 20:38:05 +090060 ApexFile(const std::string& apex_path, bool flattened, int32_t image_offset,
Jiyong Park9181a2d2018-12-27 15:14:45 +090061 size_t image_size, ApexManifest& manifest,
62 const std::string& apex_pubkey)
Jiyong Park69c0f112018-11-22 20:38:05 +090063 : apex_path_(apex_path),
64 flattened_(flattened),
65 image_offset_(image_offset),
66 image_size_(image_size),
Jiyong Park9181a2d2018-12-27 15:14:45 +090067 manifest_(std::move(manifest)),
68 apex_pubkey_(apex_pubkey) {}
Dario Freni5a259292018-08-14 17:49:00 +010069
Jiyong Park69c0f112018-11-22 20:38:05 +090070 std::string apex_path_;
Jiyong Parkd02c88c2018-11-13 19:23:32 +090071 bool flattened_;
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_;
Dario Freni5a259292018-08-14 17:49:00 +010076};
77
Jooyung Han40531a82019-04-05 15:34:13 +090078StatusOr<std::vector<std::string>> FindApexes(
79 const std::vector<std::string>& paths);
Jiyong Park5e810232019-04-01 15:24:26 +090080StatusOr<std::vector<std::string>> FindApexFilesByName(const std::string& path,
81 bool include_dirs);
82
83bool isPathForBuiltinApexes(const std::string& path);
Jooyung Han451cc342019-04-12 04:52:42 +090084bool isFlattenedApex(const std::string& path);
Jiyong Park5e810232019-04-01 15:24:26 +090085
Dario Freni5a259292018-08-14 17:49:00 +010086} // namespace apex
87} // namespace android
88
89#endif // ANDROID_APEXD_APEX_FILE_H_