首页 > 其他分享 >Android编译 - 证书介绍

Android编译 - 证书介绍

时间:2025-01-10 14:55:38浏览次数:1  
标签:files target 证书 -- system sign 编译 key Android

前言全局说明


一、说明

1.1 环境:

Android

1.2 简介

在Android系统中,每个APK文件必须有一个有效的数字证书来证明其来源和完整性。当需要修改APK后再次发布时,原有的签名将不再有效,因此需要重新签名。

二、证书工具

2.1 路径:

android/build/tools/releasetools/sign_target_files_apks

sign_target_files_apks 是个软链接,实际指向同目录的 sign_target_files_apks.py 文件

2.2 帮助命令

./sign_target_files_apks
或
./sign_target_files_apks --help

2.2 帮助常用内容

更详细内容请查看本页最下面 - 另:帮助详细内容

verify
--print-certs  #打印证书信息
-v, --verbose 显示详情(显示是否使用V1和V2签名)

三、sign_target_files_apks 工具使用

3.1 打印 apk 签名信息

./apksigner verify --print-certs  <apk-name.apk>

3.2 打印 apk 用了哪个版本签名

行结尾为 true 的,是使用的签名

./apksigner verify --verbose  <apk-name.apk>

下图显示用了 V3 版签名
image

如果只使用v1签名方案,那么它就容易受到安卓5.0-8.0上的Janus漏洞(CVE-2017-13156)的攻击。
在安卓5.0-7.0上运行的使用了v1签名方案的应用程序,以及同时使用了v2/v3签名方案的应用程序也同样存在漏洞。


四、

4.1


4.2


另:帮助详细内容

Signs all the APK files in a target-files zipfile, producing a new
target-files zip.

Usage:  sign_target_files_apks [flags] input_target_files output_target_files

  -e  (--extra_apks)  <name,name,...=key>
      Add extra APK/APEX name/key pairs as though they appeared in apkcerts.txt
      or apexkeys.txt (so mappings specified by -k and -d are applied). Keys
      specified in -e override any value for that app contained in the
      apkcerts.txt file, or the container key for an APEX. Option may be
      repeated to give multiple extra packages.

  --extra_apex_payload_key <name=key>
      Add a mapping for APEX package name to payload signing key, which will
      override the default payload signing key in apexkeys.txt. Note that the
      container key should be overridden via the `--extra_apks` flag above.
      Option may be repeated for multiple APEXes.

  --skip_apks_with_path_prefix  <prefix>
      Skip signing an APK if it has the matching prefix in its path. The prefix
      should be matching the entry name, which has partition names in upper
      case, e.g. "VENDOR/app/", or "SYSTEM_OTHER/preloads/". Option may be
      repeated to give multiple prefixes.

  -k  (--key_mapping)  <src_key=dest_key>
      Add a mapping from the key name as specified in apkcerts.txt (the
      src_key) to the real key you wish to sign the package with
      (dest_key).  Option may be repeated to give multiple key
      mappings.

  -d  (--default_key_mappings)  <dir>
      Set up the following key mappings:

        $devkey/devkey    ==>  $dir/releasekey
        $devkey/testkey   ==>  $dir/releasekey
        $devkey/media     ==>  $dir/media
        $devkey/shared    ==>  $dir/shared
        $devkey/platform  ==>  $dir/platform

      where $devkey is the directory part of the value of
      default_system_dev_certificate from the input target-files's
      META/misc_info.txt.  (Defaulting to "build/make/target/product/security"
      if the value is not present in misc_info.

      -d and -k options are added to the set of mappings in the order
      in which they appear on the command line.

  -o  (--replace_ota_keys)
      Replace the certificate (public key) used by OTA package verification
      with the ones specified in the input target_files zip (in the
      META/otakeys.txt file). Key remapping (-k and -d) is performed on the
      keys. For A/B devices, the payload verification key will be replaced
      as well. If there're multiple OTA keys, only the first one will be used
      for payload verification.

  -t  (--tag_changes)  <+tag>,<-tag>,...
      Comma-separated list of changes to make to the set of tags (in
      the last component of the build fingerprint).  Prefix each with
      '+' or '-' to indicate whether that tag should be added or
      removed.  Changes are processed in the order they appear.
      Default value is "-test-keys,-dev-keys,+release-keys".

  --replace_verity_private_key <key>
      Replace the private key used for verity signing. It expects a filename
      WITHOUT the extension (e.g. verity_key).

  --replace_verity_public_key <key>
      Replace the certificate (public key) used for verity verification. The
      key file replaces the one at BOOT/RAMDISK/verity_key (or ROOT/verity_key
      for devices using system_root_image). It expects the key filename WITH
      the extension (e.g. verity_key.pub).

  --replace_verity_keyid <path_to_X509_PEM_cert_file>
      Replace the veritykeyid in BOOT/cmdline of input_target_file_zip
      with keyid of the cert pointed by <path_to_X509_PEM_cert_file>.

  --remove_avb_public_keys <key1>,<key2>,...
      Remove AVB public keys from the first-stage ramdisk. The key file to
      remove is located at either of the following dirs:
        - BOOT/RAMDISK/avb/ or
        - BOOT/RAMDISK/first_stage_ramdisk/avb/
      The second dir will be used for lookup if BOARD_USES_RECOVERY_AS_BOOT is
      set to true.

  --avb_{boot,init_boot,recovery,system,system_other,vendor,dtbo,vbmeta,
         vbmeta_system,vbmeta_vendor}_algorithm <algorithm>
  --avb_{boot,init_boot,recovery,system,system_other,vendor,dtbo,vbmeta,
         vbmeta_system,vbmeta_vendor}_key <key>
      Use the specified algorithm (e.g. SHA256_RSA4096) and the key to AVB-sign
      the specified image. Otherwise it uses the existing values in info dict.

  --avb_{apex,init_boot,boot,recovery,system,system_other,vendor,dtbo,vbmeta,
         vbmeta_system,vbmeta_vendor}_extra_args <args>
      Specify any additional args that are needed to AVB-sign the image
      (e.g. "--signing_helper /path/to/helper"). The args will be appended to
      the existing ones in info dict.

  --avb_extra_custom_image_key <partition=key>
  --avb_extra_custom_image_algorithm <partition=algorithm>
      Use the specified algorithm (e.g. SHA256_RSA4096) and the key to AVB-sign
      the specified custom images mounted on the partition. Otherwise it uses
      the existing values in info dict.

  --avb_extra_custom_image_extra_args <partition=extra_args>
      Specify any additional args that are needed to AVB-sign the custom images
      mounted on the partition (e.g. "--signing_helper /path/to/helper"). The
      args will be appended to the existing ones in info dict.

  --gki_signing_algorithm <algorithm>
  --gki_signing_key <key>
      Use the specified algorithm (e.g. SHA256_RSA4096) and the key to generate
      'boot signature' in a v4 boot.img. Otherwise it uses the existing values
      in info dict.

  --gki_signing_extra_args <args>
      Specify any additional args that are needed to generate 'boot signature'
      (e.g. --prop foo:bar). The args will be appended to the existing ones
      in info dict.

  --android_jar_path <path>
      Path to the android.jar to repack the apex file.

  --allow_gsi_debug_sepolicy
      Allow the existence of the file 'userdebug_plat_sepolicy.cil' under
      (/system/system_ext|/system_ext)/etc/selinux.
      If not set, error out when the file exists.
Global options

  -p  (--path) <dir>
      Prepend <dir>/bin to the list of places to search for binaries run by this
      script, and expect to find jars in <dir>/framework.

  -s  (--device_specific) <file>
      Path to the Python module containing device-specific releasetools code.

  -x  (--extra) <key=value>
      Add a key/value pair to the 'extras' dict, which device-specific extension
      code may look at.

  -v  (--verbose)
      Show command lines being executed.

  -h  (--help)
      Display this usage message and exit.

  --logfile <file>
      Put verbose logs to specified file (regardless of --verbose option.)



免责声明:本号所涉及内容仅供安全研究与教学使用,如出现其他风险,后果自负。




参考、来源:
https://www.jianshu.com/p/bb5325760506 (AOSP系统签名的生成以及替换、自签名、创建证书)
https://blog.csdn.net/gitblog_00079/article/details/137450852
https://www.cnblogs.com/3clove/p/16949939.html
https://blog.csdn.net/qq_53003652/article/details/134186457 (证书攻击)
https://blog.csdn.net/mozushixin_1/article/details/144430804 (参数详细说明)
https://blog.csdn.net/yzyeilin/article/details/139968840 (问题分析)
https://source.android.google.cn/docs/core/ota/sign_builds?hl=zh-cn (对要发布的 build 进行签名)
https://magesfc.github.io/mage/6b05d90d3608239b75a55f283f5a45cc588cb157/ (sign_target_files_apks脚本执行过程分析)



标签:files,target,证书,--,system,sign,编译,key,Android
From: https://www.cnblogs.com/wutou/p/18661880

相关文章

  • 移植Android百度OCR:百度超轻量级中文OCR Android模型整合到自有工程中的问题与解决
    文章目录移植百度超轻量级中文OCR模型到Android项目的踩坑经历步骤一:下载并准备模型工程目录简介TestInferOcrTask步骤二:问题总结软件闪退识别结果为空log日志一直提示权限未赋予步骤三解决方案总结参考资料移植百度超轻量级中文OCR模型到Android项目的踩坑经历......
  • android逆向—头条新闻app的token算法
    某刷新闻赚钱token算法逆向分析1.前言因为学校被当作高考考点,所以有了几天假期,正好可以用来逆逆前几天找到的一个刷新闻赚钱app。2.工具:Xposed、Charles、反射大师、VMOSPro3.抓包:通过抓包,发现手机验证码提交时有一个token。4.逆向token算法在jadx-gui里直接搜索t......
  • 百度Android最新150道面试题及参考答案 (中)
    Android中一个View的显示渲染过程,自定义View的时候需要避免什么操作?一、View的显示渲染过程测量(Measure)阶段这个阶段是View渲染的第一步。父容器会调用子View的measure()方法来确定子View的大小。measure()方法会传入两个参数,即MeasureSpec(测量规格),它包含......
  • 还不会 Cert Manager 自动签发证书?一文掌握
    相信很多小伙伴对于CertManager不陌生,CertManager是Kubernetes上的证书管理工具,基于ACME协议与Let'sEncrypt签发免费证书并为证书自动续期,实现永久免费使用证书。本文将介绍如何使用CertManager实现自动签发证书并与Rainbond结合使用。CertManager概述工作......
  • 在数据分析师圈中很火的,PowerBI数据分析认证证书!
    在数据分析师圈中,有一个很火是证书,PowerBI数据分析认证(微软PL300认证)。当然现在市面上也有很多BI的软件,其实方法原理是想通的。所以这个认证在数据分析师招聘当中还是很火的。那么来详细介绍一下这个证书!一、PowerBI数据分析是认证-PL300简介PL-300认证是微软提供的一项专业......
  • 1.搭建命令行编译环境
    1.搭建命令行编译环境1.1下载JDK1.进入官网(Java下载|神谕)。2.根据自己的电脑系统选择对应的版本进行下载。3.下载完成后,双击打开,一直点击Next,直到安装完成,此时的JDK是安装在默认目录(C:\ProgramFiles\Java)下的。1.2JDK的简单介绍作为初学者,目前对于JDK官方的介绍肯定是......
  • Android运行第一个hello world项目
    AndroidStudio安装公众号:木木与代码本文作者:@MuMu编写日期:2024年01月25日本文字数:1861个字符关注可了解更多的教程。问题或建议,请公众号留言;/开始/ 01环境系统:Windows10专业版软件:AndroidStudio2022.3.1Patch102创建项目打开AndroidStudio......
  • 2025年百科荣创Android -- AI视觉检测模型集成--
    文章目录文章目录前言AndroidOCR文字识别简介PyddleOCR实现方法Android智能交通灯检测简介智能交通灯检测实现方法Android手势识别简介手势识别实现方法Android车牌矫正识别简介车牌矫正与识别方法Android口罩识别简介口罩识别实现方法结语文章目录......
  • 根据相关算法对FIRSTVT或LASTVT进行求解(编译原理与技术)
    实验名称FIRSTVT与LASTVT的求解。实验内容根据相关算法对FIRSTVT或LASTVT进行求解。实验目的根据实验内容编写程序,上机调试、得出正确的运行程序,掌握FIRSTVT和LASTVT的求解方法,了解其求解过程。上机环境设计思想(流程)FIRSTVT找FIRSTVT的三条规则:如果要找A的FIRSTVT,A的......
  • Android权限初认识
    一、Android中对权限的定义根据Android官方文档,Android中的权限用于保护对受限数据和受限操作的访问/执行权限,目的是为用户隐私提供支持。二、使用权限的工作流Android官网向我们给出了在Android中使用权限的概要工作流,如图:1.判断能否在不声明权限的情况下提供......