android antirollback verno 获取方法

背景

项目中经常碰到下载版本时遇到错误ERROR:STATUS_SEC_VIOLATE_ANTI_ROLLBACK(0xC002002D),无法下载的情况,此时如果有一个工具可以直接查询到版本的antirollback值多好,那就可以明确看到问题点了,这就是这个exe小工具的原动力 ^_^

错误提示:

exe 工具可以去这里直接下载:https://download.csdn.net/download/jimbo_lee/89393012?spm=1001.2014.3001.5501

ReadRollbackIndex.exe 获取

调查avbVBMeta结构体

typedef struct AvbVBMetaImageHeader {
  /*   0: Four bytes equal to "AVB0" (AVB_MAGIC). */
  uint8_t magic[AVB_MAGIC_LEN];

  /*   4: The major version of libavb required for this header. */
  uint32_t required_libavb_version_major;
  /*   8: The minor version of libavb required for this header. */
  uint32_t required_libavb_version_minor;

  /*  12: The size of the signature block. */
  uint64_t authentication_data_block_size;
  /*  20: The size of the auxiliary data block. */
  uint64_t auxiliary_data_block_size;

  /*  28: The verification algorithm used, see |AvbAlgorithmType| enum. */
  uint32_t algorithm_type;

  /*  32: Offset into the "Authentication data" block of hash data. */
  uint64_t hash_offset;
  /*  40: Length of the hash data. */
  uint64_t hash_size;

  /*  48: Offset into the "Authentication data" block of signature data. */
  uint64_t signature_offset;
  /*  56: Length of the signature data. */
  uint64_t signature_size;

  /*  64: Offset into the "Auxiliary data" block of public key data. */
  uint64_t public_key_offset;
  /*  72: Length of the public key data. */
  uint64_t public_key_size;

  /*  80: Offset into the "Auxiliary data" block of public key metadata. */
  uint64_t public_key_metadata_offset;
  /*  88: Length of the public key metadata. Must be set to zero if there
   *  is no public key metadata.
   */
  uint64_t public_key_metadata_size;

  /*  96: Offset into the "Auxiliary data" block of descriptor data. */
  uint64_t descriptors_offset;
  /* 104: Length of descriptor data. */
  uint64_t descriptors_size;

  /* 112: The rollback index which can be used to prevent rollback to
   *  older versions.
   */
  uint64_t rollback_index;

  /* 120: Flags from the AvbVBMetaImageFlags enumeration. This must be
   * set to zero if the vbmeta image is not a top-level image.
   */
  uint32_t flags;

  /* 124: The location of the rollback index defined in this header.
   * Only valid for the main vbmeta. For chained partitions, the rollback
   * index location must be specified in the AvbChainPartitionDescriptor
   * and this value must be set to 0.
   */
  uint32_t rollback_index_location;

  /* 128: The release string from avbtool, e.g. "avbtool 1.0.0" or
   * "avbtool 1.0.0 xyz_board Git-234abde89". Is guaranteed to be NUL
   * terminated. Applications must not make assumptions about how this
   * string is formatted.
   */
  uint8_t release_string[AVB_RELEASE_STRING_SIZE];

  /* 176: Padding to ensure struct is size AVB_VBMETA_IMAGE_HEADER_SIZE
   * bytes. This must be set to zeroes.
   */
  uint8_t reserved[80];
} AVB_ATTR_PACKED AvbVBMetaImageHeader;

发现antirollback 值保存位置在vbmeata.img offset 是112~119

故可以做一个exe文件读取vbmeta.img文件rollback index值,代码如下:

// ReadRollbackIndex.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"

#include "stdio.h"
#include "stdlib.h"
#include <direct.h>
#include "Windows.h"

#define MAX_PATH_LEN 1024

//0x77 <==> 119
#define ROLLBAK_INDEX_OFFSET 0x77

void TcharToChar(const TCHAR * tchar, char * _char)
{
    int iLength;
    //获取字节长度   
    iLength = WideCharToMultiByte(CP_ACP, 0, tchar, -1, NULL, 0, NULL, NULL);

    //将tchar值赋给_char    
    WideCharToMultiByte(CP_ACP, 0, tchar, -1, _char, iLength, NULL, NULL);
}

int _tmain(int argc, _TCHAR* argv[])
{
    char currPath[MAX_PATH_LEN] = "\0";

    char fileName[MAX_PATH_LEN] = "\0";
    if(argc > 1)
    {
        TcharToChar(argv[1], fileName);
        printf("transfer filename: %s \n", fileName);
    }


    // get current path
    if (getcwd(currPath, sizeof(currPath)) == NULL){
        printf("getcwd() error");
    };
    //printf(" currPath = %s \n", currPath);

    char vbmetaFileName[MAX_PATH_LEN] = "\0";

    //if(strlen(fileName) > 0){
    if(argc > 1)
        sprintf(vbmetaFileName, "%s\\%s", currPath, fileName);
    }else{
        sprintf(vbmetaFileName, "%s\\vbmeta.img", currPath);
    }
    printf("vbmeta.img file path: %s \n", vbmetaFileName);
    

    // open and read file
    FILE* pVbmetaFile = fopen(vbmetaFileName, "rb");
    if (pVbmetaFile == NULL)
    {
        printf("open %s failed.", vbmetaFileName);
        return -1;
    }

    //文件指针偏移  SEEK_SET初始位置开始偏移
    if(!fseek(pVbmetaFile, ROLLBAK_INDEX_OFFSET, SEEK_SET)){
        int rollbackIndex = fgetc(pVbmetaFile);  
        printf("Rollback Index:    %d\n", rollbackIndex);
    }
    
    // release file handle
    fclose(pVbmetaFile);

    return 0;
}

此段代码经 vs2010  编译验证ok,程序运行结果:

代码中获取

antirollback 获取:

pl阶段获取 pl/lk的version。 需要在校验完LK img后可以呼叫获取:
获取pl ver api:seclib_get_pl_ver
获取LK ver api:get_img_ver

LK阶段获取modem 的img ver:
api: get_img_ver


MTK:
/vendor/mediatek/proprietary/bootable/bootloader/lk/platform/common/avb/libavb/avb_slot_verify.c
io_ret = ops->read_rollback_index(ops, rollback_index_location, &stored_rollback_index);
这里会根据rollback_index_location来读anti-rollback值

/vendor/mediatek/proprietary/bootable/bootloader/lk/platform/common/boot/avb20/load_vfy_boot.c
int load_vfy_boot(uint32_t bootimg_type, uint32_t addr)函数
        ret = record_avb_version(slot_data);
这里会在验证AVB结束后更新anti-rollback ver。

set_avb_otp_ver(AVB_GROUP, (uint32_t)min_ver);

#define AVB_MAX_NUMBER_OF_ROLLBACK_INDEX_LOCATIONS 32


qcom:
LINUX/android/external/u-boot/common/avb_verify.c
 virtual AvbIOResult read_rollback_index(AvbOps* ops,
                                           size_t rollback_index_slot,
                                           uint64_t* out_rollback_index) = 0;
 
 virtual AvbIOResult write_rollback_index(AvbOps* ops,
                                           size_t rollback_index_slot,
                                           uint64_t rollback_index) = 0;
    memset(param, 0, sizeof(param));
      param[0].attr = TEE_PARAM_ATTR_TYPE_VALUE_INPUT;
      param[0].u.value.a = rollback_index_slot;
      param[1].attr = TEE_PARAM_ATTR_TYPE_VALUE_INPUT;
      param[1].u.value.a = (u32)(rollback_index >> 32);
      param[1].u.value.b = (u32)rollback_index;
  
      return invoke_func(ops->user_data, TA_AVB_CMD_WRITE_ROLLBACK_INDEX,
                 ARRAY_SIZE(param), param);

# 课程背景2021年ARM又推出了ARMv9架构,系统软件架构也在悄无声息地发生变化。在这种架构中,强调的是隔离技术,包括资源的隔离、运行时隔离,特权操作系统的权限也变得越来越小…不管您是什么领域,ARM服务器、汽车电子、手机或者是其它设备终端,安全都是其中的一个重要环节。我们常说的安全一般是只网络安全/业务安全/App安全,这些安全依赖的正是操作系统安全,操作系统安全所依赖的就是安全架构技术,在该安全架构中,首当要学习的就是Trustzone/TEE技术。只有设备安全/操作系统安全/APP安全/网络安全/服务器安全整个一条链都安全了,那么你的业务才算得上的安全.不管您是做什么的,您做不做安全或虚拟化,掌握整个系统软件架构也是一件必要的事情。您只有掌握了安全架构,你才具有全局的视野,才能进行全局的软件设计,才称得上架构师。安全不仅仅是架构安全,安全还是一种生态,安全还产生一类标准。安全出现在产品声明周期的任何一个角落,它可能零碎地出现在硬件中、零碎地出现在软件代码中。如果你不了解安全,你可能无法进行优秀的产品设计,你甚至无法去正确的阅读代码。# 课程介绍(1) 讲解ARM最新硬件架构(ARM Core、ARM Architecture)、SOC架构(2) 讲解最新的Trustzone安全架构、TEE架构、Secureboot等(3) 讲解软件组件:TF-A(ATF)、optee_os、Linux Kernel、CA/TA应用程序等,及其交互模型、设计模型(4) 多系统交互代码导读、安全论证实践、CA/TA示例实践、安全业务设计实践(5) 我们学习的是全部硬件、全部系统,软硬结合,或者是大系统的软硬件融合# 课程收益1、安全不再神秘,能cover住全局2、熟悉ARM Architecture架构知识3、熟悉SOC架构知识4、熟悉主流的系统软件框架5、知道多系统之间是如何交互的,也能够进行系统级的设计6、深入了解当前的系统安全架构以及未来安全架构趋势7、熟悉基础的安全业务设计方法8、熟悉系统的启动流程、Secureboot等9、知道Linux Kernel在大系统中的位置,以及与其它系统交互的方法10、熟悉各类标准和规范11、学习资料的获取方法 # 课程大纲《Trustzone/TEE/系统安全开发速成班》 --当前48节课/19小时说明: 本视频会持续更新,购买时请以课程目录为主。本EXCEL一个月更新一次。章节编号课程时常第一章基础和简介1课程介绍 8:332ARM和SOC的架构简介60:13第二章软硬件基础3armv8/armv9基础概念26:204ARMv8/ARMv9的Trustzone技术77:565ARMv7的Trustzone技术8:376安全架构及其未来趋势(FF-A/SPM/CCA)6:417ARMv9 CCA机密计算框架底层核心原理简介20:448ARMv9 RME安全扩展详解61:299ATF Quick Start0161:2710Optee Quick Start49:3411系统软件Quick Start21:0412Secureboot原理深度讲解60:2813Android AVB的介绍26:0914TZC400详解17:5615TZC400代码导读之ATF13:4416RPMB详解30:0617RPMB代码导读之optee14:0318efuse详解12:1919Anti-Rollback的介绍11:33第三章软件架构20TEE的组件介绍67:5921TEE的RPC反向调用31:1422TEE的调度模型21:3223各类标准和规范22:17第四章软件架构(高级)24多系统之间的管理模型(ABI/标准)10:3025多系统之间的调度12:2126多系统之间的中断(不含虚拟化)61:4727多系统之间的中断(虚拟化)6:5728再谈多系统之间的调度(多核多线程)10:3129其它(内存管理/PSCI...)10:12第五章安全应用开发基础30安全应用开发基础5:3731TEE环境:qemu_V8环境的使用4:2032TEE环境:编写一个CA和TA程序11:0433TEE环境:编写漂亮的文档4:1434TEE环境:搭建阅读代码神器opengrok3:2635TEE环境(必看):使用集成好的qemu_v8镜像程序20:2936[CA/TA开发]CA到TA的通信9:1837[CA/TA开发]CA到TA的传参27:1638[CA/TA开发]TEE中的存储系统20:5739[CA/TA开发]TEE中的密码学系统简介12:3740[CA/TA开发]TEE中的密码学系统简介-数字摘要Hash等33:2141[CA/TA开发]TEE中的密码学系统简介-对称密码学算法AES等12:2042[CA/TA开发]TEE中的密码学系统简介-消息摘要算法HMAC等15:4843[CA/TA开发]TEE中的密码学系统简介-非对称密码学算法RSA等7:33第六章安全业务设计高级44Gatekeeper的介绍29:3245keymaster/keymint/keystore/keystore213:2746生物认证(指纹/人脸)13:5747DRM的介绍21:3748TUI的介绍17:03总计时统计(分钟)1128:12 说明:本课程会持续更新…
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值