1b51722b4e2c31355971100c21628a9e881756c3abowgotsai/* 2b51722b4e2c31355971100c21628a9e881756c3abowgotsai * Copyright (C) 2016 The Android Open Source Project 3b51722b4e2c31355971100c21628a9e881756c3abowgotsai * 4b51722b4e2c31355971100c21628a9e881756c3abowgotsai * Permission is hereby granted, free of charge, to any person 5b51722b4e2c31355971100c21628a9e881756c3abowgotsai * obtaining a copy of this software and associated documentation 6b51722b4e2c31355971100c21628a9e881756c3abowgotsai * files (the "Software"), to deal in the Software without 7b51722b4e2c31355971100c21628a9e881756c3abowgotsai * restriction, including without limitation the rights to use, copy, 8b51722b4e2c31355971100c21628a9e881756c3abowgotsai * modify, merge, publish, distribute, sublicense, and/or sell copies 9b51722b4e2c31355971100c21628a9e881756c3abowgotsai * of the Software, and to permit persons to whom the Software is 10b51722b4e2c31355971100c21628a9e881756c3abowgotsai * furnished to do so, subject to the following conditions: 11b51722b4e2c31355971100c21628a9e881756c3abowgotsai * 12b51722b4e2c31355971100c21628a9e881756c3abowgotsai * The above copyright notice and this permission notice shall be 13b51722b4e2c31355971100c21628a9e881756c3abowgotsai * included in all copies or substantial portions of the Software. 14b51722b4e2c31355971100c21628a9e881756c3abowgotsai * 15b51722b4e2c31355971100c21628a9e881756c3abowgotsai * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16b51722b4e2c31355971100c21628a9e881756c3abowgotsai * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17b51722b4e2c31355971100c21628a9e881756c3abowgotsai * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18b51722b4e2c31355971100c21628a9e881756c3abowgotsai * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19b51722b4e2c31355971100c21628a9e881756c3abowgotsai * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20b51722b4e2c31355971100c21628a9e881756c3abowgotsai * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21b51722b4e2c31355971100c21628a9e881756c3abowgotsai * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22b51722b4e2c31355971100c21628a9e881756c3abowgotsai * SOFTWARE. 23b51722b4e2c31355971100c21628a9e881756c3abowgotsai */ 24b51722b4e2c31355971100c21628a9e881756c3abowgotsai 2520651f62d081c88596e70b3b589863a75e2a9c35Bowgo Tsai#ifndef __CORE_FS_MGR_PRIV_AVB_OPS_H 2620651f62d081c88596e70b3b589863a75e2a9c35Bowgo Tsai#define __CORE_FS_MGR_PRIV_AVB_OPS_H 2720651f62d081c88596e70b3b589863a75e2a9c35Bowgo Tsai 2820651f62d081c88596e70b3b589863a75e2a9c35Bowgo Tsai#include <map> 2920651f62d081c88596e70b3b589863a75e2a9c35Bowgo Tsai#include <string> 30b51722b4e2c31355971100c21628a9e881756c3abowgotsai 31b51722b4e2c31355971100c21628a9e881756c3abowgotsai#include <libavb/libavb.h> 32b51722b4e2c31355971100c21628a9e881756c3abowgotsai 33b51722b4e2c31355971100c21628a9e881756c3abowgotsai#include "fs_mgr.h" 34b51722b4e2c31355971100c21628a9e881756c3abowgotsai 3595c966a8599a069c40707c933c31155d625bd355Bowgo Tsai// This class provides C++ bindings to interact with libavb, a small 3695c966a8599a069c40707c933c31155d625bd355Bowgo Tsai// self-contained piece of code that's intended to be used in bootloaders. 3795c966a8599a069c40707c933c31155d625bd355Bowgo Tsai// It mainly contains two functions: 3895c966a8599a069c40707c933c31155d625bd355Bowgo Tsai// - ReadFromPartition(): to read AVB metadata from a given partition. 3995c966a8599a069c40707c933c31155d625bd355Bowgo Tsai// It provides the implementation of AvbOps.read_from_partition() when 4095c966a8599a069c40707c933c31155d625bd355Bowgo Tsai// reading metadata through libavb. 4195c966a8599a069c40707c933c31155d625bd355Bowgo Tsai// - AvbSlotVerify(): the C++ binding of libavb->avb_slot_verify() to 4295c966a8599a069c40707c933c31155d625bd355Bowgo Tsai// read and verify the metadata and store it into the out_data parameter. 4395c966a8599a069c40707c933c31155d625bd355Bowgo Tsai// The caller MUST check the integrity of metadata against the 4495c966a8599a069c40707c933c31155d625bd355Bowgo Tsai// androidboot.vbmeta.{hash_alg, size, digest} values from /proc/cmdline. 4595c966a8599a069c40707c933c31155d625bd355Bowgo Tsai// e.g., see class FsManagerAvbVerifier for more details. 4695c966a8599a069c40707c933c31155d625bd355Bowgo Tsai// 4795c966a8599a069c40707c933c31155d625bd355Bowgo Tsaiclass FsManagerAvbOps { 4895c966a8599a069c40707c933c31155d625bd355Bowgo Tsai public: 4920651f62d081c88596e70b3b589863a75e2a9c35Bowgo Tsai FsManagerAvbOps(const fstab& fstab); 5020651f62d081c88596e70b3b589863a75e2a9c35Bowgo Tsai FsManagerAvbOps(std::map<std::string, std::string>&& by_name_symlink_map); 5195c966a8599a069c40707c933c31155d625bd355Bowgo Tsai 5295c966a8599a069c40707c933c31155d625bd355Bowgo Tsai static FsManagerAvbOps* GetInstanceFromAvbOps(AvbOps* ops) { 5395c966a8599a069c40707c933c31155d625bd355Bowgo Tsai return reinterpret_cast<FsManagerAvbOps*>(ops->user_data); 5495c966a8599a069c40707c933c31155d625bd355Bowgo Tsai } 5595c966a8599a069c40707c933c31155d625bd355Bowgo Tsai 5695c966a8599a069c40707c933c31155d625bd355Bowgo Tsai AvbIOResult ReadFromPartition(const char* partition, int64_t offset, size_t num_bytes, 5795c966a8599a069c40707c933c31155d625bd355Bowgo Tsai void* buffer, size_t* out_num_read); 5895c966a8599a069c40707c933c31155d625bd355Bowgo Tsai 59e2e1b67c8863758243965a7aa6f6764eaec5bb6eDavid Zeuthen AvbSlotVerifyResult AvbSlotVerify(const std::string& ab_suffix, AvbSlotVerifyFlags flags, 6095c966a8599a069c40707c933c31155d625bd355Bowgo Tsai AvbSlotVerifyData** out_data); 6195c966a8599a069c40707c933c31155d625bd355Bowgo Tsai 6295c966a8599a069c40707c933c31155d625bd355Bowgo Tsai private: 6320651f62d081c88596e70b3b589863a75e2a9c35Bowgo Tsai void InitializeAvbOps(); 6420651f62d081c88596e70b3b589863a75e2a9c35Bowgo Tsai 6595c966a8599a069c40707c933c31155d625bd355Bowgo Tsai AvbOps avb_ops_; 6620651f62d081c88596e70b3b589863a75e2a9c35Bowgo Tsai std::map<std::string, std::string> by_name_symlink_map_; 6795c966a8599a069c40707c933c31155d625bd355Bowgo Tsai}; 6820651f62d081c88596e70b3b589863a75e2a9c35Bowgo Tsai#endif /* __CORE_FS_MGR_PRIV_AVB_OPS_H */ 69