fs_mgr_priv_avb_ops.h revision 95c966a8599a069c40707c933c31155d625bd355
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
25b51722b4e2c31355971100c21628a9e881756c3abowgotsai#ifndef __CORE_FS_MGR_AVB_OPS_H
26b51722b4e2c31355971100c21628a9e881756c3abowgotsai#define __CORE_FS_MGR_AVB_OPS_H
27b51722b4e2c31355971100c21628a9e881756c3abowgotsai
28b51722b4e2c31355971100c21628a9e881756c3abowgotsai#include <libavb/libavb.h>
29b51722b4e2c31355971100c21628a9e881756c3abowgotsai
30b51722b4e2c31355971100c21628a9e881756c3abowgotsai#include "fs_mgr.h"
31b51722b4e2c31355971100c21628a9e881756c3abowgotsai
3295c966a8599a069c40707c933c31155d625bd355Bowgo Tsai// This class provides C++ bindings to interact with libavb, a small
3395c966a8599a069c40707c933c31155d625bd355Bowgo Tsai// self-contained piece of code that's intended to be used in bootloaders.
3495c966a8599a069c40707c933c31155d625bd355Bowgo Tsai// It mainly contains two functions:
3595c966a8599a069c40707c933c31155d625bd355Bowgo Tsai//   - ReadFromPartition(): to read AVB metadata from a given partition.
3695c966a8599a069c40707c933c31155d625bd355Bowgo Tsai//     It provides the implementation of AvbOps.read_from_partition() when
3795c966a8599a069c40707c933c31155d625bd355Bowgo Tsai//     reading metadata through libavb.
3895c966a8599a069c40707c933c31155d625bd355Bowgo Tsai//   - AvbSlotVerify(): the C++ binding of libavb->avb_slot_verify() to
3995c966a8599a069c40707c933c31155d625bd355Bowgo Tsai//     read and verify the metadata and store it into the out_data parameter.
4095c966a8599a069c40707c933c31155d625bd355Bowgo Tsai//     The caller MUST check the integrity of metadata against the
4195c966a8599a069c40707c933c31155d625bd355Bowgo Tsai//     androidboot.vbmeta.{hash_alg, size, digest} values from /proc/cmdline.
4295c966a8599a069c40707c933c31155d625bd355Bowgo Tsai//     e.g., see class FsManagerAvbVerifier for more details.
4395c966a8599a069c40707c933c31155d625bd355Bowgo Tsai//
4495c966a8599a069c40707c933c31155d625bd355Bowgo Tsaiclass FsManagerAvbOps {
4595c966a8599a069c40707c933c31155d625bd355Bowgo Tsai  public:
4695c966a8599a069c40707c933c31155d625bd355Bowgo Tsai    FsManagerAvbOps(const std::string& device_file_by_name_prefix);
4795c966a8599a069c40707c933c31155d625bd355Bowgo Tsai
4895c966a8599a069c40707c933c31155d625bd355Bowgo Tsai    static FsManagerAvbOps* GetInstanceFromAvbOps(AvbOps* ops) {
4995c966a8599a069c40707c933c31155d625bd355Bowgo Tsai        return reinterpret_cast<FsManagerAvbOps*>(ops->user_data);
5095c966a8599a069c40707c933c31155d625bd355Bowgo Tsai    }
5195c966a8599a069c40707c933c31155d625bd355Bowgo Tsai
5295c966a8599a069c40707c933c31155d625bd355Bowgo Tsai    AvbIOResult ReadFromPartition(const char* partition, int64_t offset, size_t num_bytes,
5395c966a8599a069c40707c933c31155d625bd355Bowgo Tsai                                  void* buffer, size_t* out_num_read);
5495c966a8599a069c40707c933c31155d625bd355Bowgo Tsai
5595c966a8599a069c40707c933c31155d625bd355Bowgo Tsai    AvbSlotVerifyResult AvbSlotVerify(const std::string& ab_suffix, bool allow_verification_error,
5695c966a8599a069c40707c933c31155d625bd355Bowgo Tsai                                      AvbSlotVerifyData** out_data);
5795c966a8599a069c40707c933c31155d625bd355Bowgo Tsai
5895c966a8599a069c40707c933c31155d625bd355Bowgo Tsai  private:
5995c966a8599a069c40707c933c31155d625bd355Bowgo Tsai    AvbOps avb_ops_;
6095c966a8599a069c40707c933c31155d625bd355Bowgo Tsai    std::string device_file_by_name_prefix_;
6195c966a8599a069c40707c933c31155d625bd355Bowgo Tsai};
62b51722b4e2c31355971100c21628a9e881756c3abowgotsai#endif /* __CORE_FS_MGR_AVB_OPS_H */
63