| 1614 | } |
| 1615 | |
| 1616 | static int cbfs_print(void) |
| 1617 | { |
| 1618 | struct cbfs_image image; |
| 1619 | if (cbfs_image_from_buffer(&image, param.image_region, |
| 1620 | param.headeroffset)) |
| 1621 | return 1; |
| 1622 | if (param.machine_parseable) { |
| 1623 | if (verbose) |
| 1624 | printf("[FMAP REGION]\t%s\n", param.region_name); |
| 1625 | cbfs_print_parseable_directory(&image); |
| 1626 | } else { |
| 1627 | printf("FMAP REGION: %s\n", param.region_name); |
| 1628 | cbfs_print_directory(&image); |
| 1629 | } |
| 1630 | |
| 1631 | if (verbose) { |
| 1632 | const char *verification_state = "fully valid"; |
| 1633 | struct mh_cache *mhc = get_mh_cache(); |
| 1634 | if (mhc->cbfs_hash.algo == VB2_HASH_INVALID) |
| 1635 | return 0; |
| 1636 | |
| 1637 | struct vb2_hash real_hash = { .algo = mhc->cbfs_hash.algo }; |
| 1638 | enum cb_err err = cbfs_walk(&image, verify_walker, buffer_get(&image.buffer), |
| 1639 | &real_hash, CBFS_WALK_WRITEBACK_HASH); |
| 1640 | if (err == CB_CBFS_HASH_MISMATCH) |
| 1641 | verification_state = "invalid file hashes"; |
| 1642 | else if (err != CB_CBFS_NOT_FOUND) |
| 1643 | verification_state = "missing file hashes"; |
| 1644 | char *hash_str = bintohex(real_hash.raw, |
| 1645 | vb2_digest_size(real_hash.algo)); |
| 1646 | printf("[METADATA HASH]\t%s:%s", |
| 1647 | vb2_get_hash_algorithm_name(real_hash.algo), hash_str); |
| 1648 | if (is_main_cbfs_region(param.region_name)) { |
| 1649 | if (!memcmp(mhc->cbfs_hash.raw, real_hash.raw, |
| 1650 | vb2_digest_size(real_hash.algo))) { |
| 1651 | printf(":valid"); |
| 1652 | } else { |
| 1653 | printf(":invalid"); |
| 1654 | verification_state = "invalid metadata hash"; |
| 1655 | } |
| 1656 | } |
| 1657 | printf("\n"); |
| 1658 | printf("[CBFS VERIFICATION (%s)]\t%s\n", param.region_name, verification_state); |
| 1659 | free(hash_str); |
| 1660 | } |
| 1661 | |
| 1662 | return 0; |
| 1663 | } |
| 1664 | |
| 1665 | static int cbfs_extract(void) |
| 1666 | { |
nothing calls this directly
no test coverage detected