• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
20 #include <memory>
21 #include <string>
22 #include <vector>
23 #include <ziparchive/zip_archive.h>
24 
25 #include "apex_constants.h"
26 #include "apex_manifest.h"
27 #include "status_or.h"
28 
29 struct AvbHashtreeDescriptor;
30 
31 namespace android {
32 namespace apex {
33 
34 // Data needed to construct a valid VerityTable
35 struct ApexVerityData {
36   std::unique_ptr<AvbHashtreeDescriptor> desc;
37   std::string salt;
38   std::string root_digest;
39 };
40 
41 // Manages the content of an APEX package and provides utilities to navigate
42 // the content.
43 class ApexFile {
44  public:
45   static StatusOr<ApexFile> Open(const std::string& path);
46   ApexFile() = delete;
47   ApexFile(ApexFile&&) = default;
48 
GetPath()49   const std::string& GetPath() const { return apex_path_; }
GetImageOffset()50   int32_t GetImageOffset() const { return image_offset_; }
GetImageSize()51   size_t GetImageSize() const { return image_size_; }
GetManifest()52   const ApexManifest& GetManifest() const { return manifest_; }
IsFlattened()53   bool IsFlattened() const { return flattened_; }
GetBundledPublicKey()54   const std::string& GetBundledPublicKey() const { return apex_pubkey_; }
55 
56   StatusOr<ApexVerityData> VerifyApexVerity() const;
57   Status VerifyManifestMatches(const std::string& mount_path) const;
58 
59  private:
ApexFile(const std::string & apex_path,bool flattened,int32_t image_offset,size_t image_size,ApexManifest & manifest,const std::string & apex_pubkey)60   ApexFile(const std::string& apex_path, bool flattened, int32_t image_offset,
61            size_t image_size, ApexManifest& manifest,
62            const std::string& apex_pubkey)
63       : apex_path_(apex_path),
64         flattened_(flattened),
65         image_offset_(image_offset),
66         image_size_(image_size),
67         manifest_(std::move(manifest)),
68         apex_pubkey_(apex_pubkey) {}
69 
70   std::string apex_path_;
71   bool flattened_;
72   int32_t image_offset_;
73   size_t image_size_;
74   ApexManifest manifest_;
75   std::string apex_pubkey_;
76 };
77 
78 StatusOr<std::vector<std::string>> FindApexes(
79     const std::vector<std::string>& paths);
80 StatusOr<std::vector<std::string>> FindApexFilesByName(const std::string& path,
81                                                        bool include_dirs);
82 
83 bool isPathForBuiltinApexes(const std::string& path);
84 bool isFlattenedApex(const std::string& path);
85 
86 }  // namespace apex
87 }  // namespace android
88 
89 #endif  // ANDROID_APEXD_APEX_FILE_H_
90