Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 33f344cb authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "libfs_avb: support key rotation for standalone partitions"

parents c620f4a1 f3e28e16
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1089,7 +1089,7 @@ int fs_mgr_mount_all(Fstab* fstab, int mount_mode) {
                // Skips mounting the device.
                continue;
            }
        } else if (!current_entry.avb_key.empty()) {
        } else if (!current_entry.avb_keys.empty()) {
            if (AvbHandle::SetUpStandaloneAvbHashtree(&current_entry) == AvbHashtreeResult::kFail) {
                LERROR << "Failed to set up AVB on standalone partition: "
                       << current_entry.mount_point << ", skipping!";
@@ -1320,7 +1320,7 @@ static int fs_mgr_do_mount_helper(Fstab* fstab, const std::string& n_name,
                // Skips mounting the device.
                continue;
            }
        } else if (!fstab_entry.avb_key.empty()) {
        } else if (!fstab_entry.avb_keys.empty()) {
            if (AvbHandle::SetUpStandaloneAvbHashtree(&fstab_entry) == AvbHashtreeResult::kFail) {
                LERROR << "Failed to set up AVB on standalone partition: "
                       << fstab_entry.mount_point << ", skipping!";
+4 −3
Original line number Diff line number Diff line
@@ -325,8 +325,8 @@ void ParseFsMgrFlags(const std::string& flags, FstabEntry* entry) {
            }
        } else if (StartsWith(flag, "zram_backing_dev_path=")) {
            entry->zram_backing_dev_path = arg;
        } else if (StartsWith(flag, "avb_key=")) {
            entry->avb_key = arg;
        } else if (StartsWith(flag, "avb_keys=")) {
            entry->avb_keys = arg;
        } else {
            LWARNING << "Warning: unknown flag: " << flag;
        }
@@ -759,7 +759,8 @@ FstabEntry BuildGsiSystemFstabEntry() {
                         .fs_type = "ext4",
                         .flags = MS_RDONLY,
                         .fs_options = "barrier=1",
                         .avb_key = "/gsi.avbpubkey",
                         // could add more keys separated by ':'.
                         .avb_keys = "/avb/gsi.avbpubkey:",
                         .logical_partition_name = "system"};
    system.fs_mgr_flags.wait = true;
    system.fs_mgr_flags.logical = true;
+1 −1
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ struct FstabEntry {
    std::string zram_loopback_path;
    uint64_t zram_loopback_size = 512 * 1024 * 1024;  // 512MB by default;
    std::string zram_backing_dev_path;
    std::string avb_key;
    std::string avb_keys;

    struct FsMgrFlags {
        bool wait : 1;
+19 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include "util.h"

using android::base::Basename;
using android::base::ReadFileToString;
using android::base::StartsWith;
using android::base::unique_fd;

@@ -311,7 +312,8 @@ std::unique_ptr<AvbFooter> GetAvbFooter(int fd) {
    return footer;
}

bool VerifyPublicKeyBlob(const uint8_t* key, size_t length, const std::string& expected_key_blob) {
bool ValidatePublicKeyBlob(const uint8_t* key, size_t length,
                           const std::string& expected_key_blob) {
    if (expected_key_blob.empty()) {  // no expectation of the key, return true.
        return true;
    }
@@ -324,6 +326,21 @@ bool VerifyPublicKeyBlob(const uint8_t* key, size_t length, const std::string& e
    return false;
}

bool ValidatePublicKeyBlob(const std::string key_blob_to_validate,
                           const std::vector<std::string>& allowed_key_paths) {
    std::string allowed_key_blob;
    if (key_blob_to_validate.empty()) {
        LWARNING << "Failed to validate an empty key";
        return false;
    }
    for (const auto& path : allowed_key_paths) {
        if (ReadFileToString(path, &allowed_key_blob)) {
            if (key_blob_to_validate == allowed_key_blob) return true;
        }
    }
    return false;
}

VBMetaVerifyResult VerifyVBMetaSignature(const VBMetaData& vbmeta,
                                         const std::string& expected_public_key_blob,
                                         std::string* out_public_key_data) {
@@ -347,7 +364,7 @@ VBMetaVerifyResult VerifyVBMetaSignature(const VBMetaData& vbmeta,
                       << ": Error verifying vbmeta image: failed to get public key";
                return VBMetaVerifyResult::kError;
            }
            if (!VerifyPublicKeyBlob(pk_data, pk_len, expected_public_key_blob)) {
            if (!ValidatePublicKeyBlob(pk_data, pk_len, expected_public_key_blob)) {
                LERROR << vbmeta.partition() << ": Error verifying vbmeta image: public key used to"
                       << " sign data does not match key in chain descriptor";
                return VBMetaVerifyResult::kErrorVerification;
+4 −1
Original line number Diff line number Diff line
@@ -78,7 +78,10 @@ VBMetaVerifyResult VerifyVBMetaSignature(const VBMetaData& vbmeta,
                                         const std::string& expected_public_key_blob,
                                         std::string* out_public_key_data);

bool VerifyPublicKeyBlob(const uint8_t* key, size_t length, const std::string& expected_key_blob);
bool ValidatePublicKeyBlob(const uint8_t* key, size_t length, const std::string& expected_key_blob);

bool ValidatePublicKeyBlob(const std::string key_blob_to_validate,
                           const std::vector<std::string>& expected_key_paths);

// Detects if whether a partition contains a rollback image.
bool RollbackDetected(const std::string& partition_name, uint64_t rollback_index);
Loading