1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Permission is hereby granted, free of charge, to any person 5 * obtaining a copy of this software and associated documentation 6 * files (the "Software"), to deal in the Software without 7 * restriction, including without limitation the rights to use, copy, 8 * modify, merge, publish, distribute, sublicense, and/or sell copies 9 * of the Software, and to permit persons to whom the Software is 10 * furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be 13 * included in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 */ 24 25 #ifndef __CORE_FS_MGR_PRIV_AVB_OPS_H 26 #define __CORE_FS_MGR_PRIV_AVB_OPS_H 27 28 #include <map> 29 #include <string> 30 31 #include <libavb/libavb.h> 32 33 #include "fs_mgr.h" 34 35 // This class provides C++ bindings to interact with libavb, a small 36 // self-contained piece of code that's intended to be used in bootloaders. 37 // It mainly contains two functions: 38 // - ReadFromPartition(): to read AVB metadata from a given partition. 39 // It provides the implementation of AvbOps.read_from_partition() when 40 // reading metadata through libavb. 41 // - AvbSlotVerify(): the C++ binding of libavb->avb_slot_verify() to 42 // read and verify the metadata and store it into the out_data parameter. 43 // The caller MUST check the integrity of metadata against the 44 // androidboot.vbmeta.{hash_alg, size, digest} values from /proc/cmdline. 45 // e.g., see class FsManagerAvbVerifier for more details. 46 // 47 class FsManagerAvbOps { 48 public: 49 FsManagerAvbOps(const fstab& fstab); 50 FsManagerAvbOps(std::map<std::string, std::string>&& by_name_symlink_map); 51 GetInstanceFromAvbOps(AvbOps * ops)52 static FsManagerAvbOps* GetInstanceFromAvbOps(AvbOps* ops) { 53 return reinterpret_cast<FsManagerAvbOps*>(ops->user_data); 54 } 55 56 AvbIOResult ReadFromPartition(const char* partition, int64_t offset, size_t num_bytes, 57 void* buffer, size_t* out_num_read); 58 59 AvbSlotVerifyResult AvbSlotVerify(const std::string& ab_suffix, bool allow_verification_error, 60 AvbSlotVerifyData** out_data); 61 62 private: 63 void InitializeAvbOps(); 64 65 AvbOps avb_ops_; 66 std::map<std::string, std::string> by_name_symlink_map_; 67 }; 68 #endif /* __CORE_FS_MGR_PRIV_AVB_OPS_H */ 69