分类 默认分类 下的文章

从已签名 App 恢复被删除的 iOS 开发证书

从已签名 App 恢复被删除的 iOS 开发证书

适用场景:本机钥匙串中的 Apple Development 证书被误删(security delete-certificate),
但私钥仍然存在,且本机/项目里留有用该证书签名过的产物(.app / .ipa)。
本文从这些签名产物中把证书提取回来,与保留的私钥配对,完整恢复签名身份。

原理:为什么能恢复

iOS 代码签名身份(codesign identity)= 证书(public key 载体)+ 私钥,两者缺一不可:

签名身份 = 证书(.cer,含公钥)+ 私钥(本机钥匙串)
  • 已签名的 App 中嵌入了签名时的证书链(叶子证书 + 中间证书 + 根证书),
    codesign --extract-certificates 可将其提取为 DER 格式的证书文件;
  • security delete-certificate 只删除证书,默认不删除私钥(除非加 -t 选项)。
    私钥删除后会保留为"孤儿私钥",只是命令行工具(find-key / dump-keychain)
    受 ACL 保护往往枚举不到,但 Keychain Access 图形界面可见;
  • 因此:补回证书文件 → 导入钥匙串 → 自动与保留的私钥配对 → 签名身份完整复原。
为什么不用开发者中心下载:免费个人团队(Personal Team)账号在
developer.apple.com 没有 "Certificates, IDs & Profiles" 页面(该页面仅付费
开发者计划可访问);Xcode 也不会"打开就自动下载"服务器证书(只在签名构建时按需
创建)。从签名产物提取是免费账号唯一能"原样复原"的途径。

- 阅读剩余部分 -

用 Graphviz 绘制一棵漂亮的二叉树

起因

之前用 Rust 写了一个 AVL 树的实现,就很自然的想把树用可视化的图像画出来,在一波搜索过后,最后都指向了一位叫 Emden Gansner( Graphviz 主要贡献者之一) 的大佬在 2010 年写的一段脚本,原作者是在邮件列表(链接1,链接2)中回复别人的问题时提供的这段脚本,由于这个邮件列表原来的存档网站已经无法访问,现在能搜到的基本上都是别人对这段脚本引用,比如: stackoverflow。

不过这个 gvpr 我实在是看不懂,所以我希望能够直接使用 dot 来绘制二叉树,这样在生成图像的时候就只需要使用 dot 命令行工具而不需要额外的脚本了。

尝试

但是事情看起来并没有那么简单,假如我们现在有一个文件 tree.dot:

digraph G {
    node [shape=circle]
    edge [arrowhead=vee]
    8 -> 4
    4 -> 2
    2 -> 1
    2 -> 3
    4 -> 6
    6 -> 5
    6 -> 7
    8 -> 10
    10 -> 9
    10 -> 12
    12 -> 11
}

- 阅读剩余部分 -

使用 svn 检出 GitHub 项目中的子目录

例如我们想检出 https://github.com/openwrt/packages 项目下的 net/nginx 子目录,但是不想把整个项目克隆下来。

可以利用 svn 来实现, svn 支持 --depth 选项,具体有 empty/files/immediates/infinity 四种参数,含义如下:

      depth-empty ------>  Updates will not pull in any files or
                           subdirectories not already present.
   
      depth-files ------>  Updates will pull in any files not already
                           present, but not subdirectories.
   
      depth-immediates ->  Updates will pull in any files or
                           subdirectories not already present; those
                           subdirectories' this_dir entries will
                           have depth-empty.
   
      depth-infinity --->  Updates will pull in any files or
                           subdirectories not already present; those
                           subdirectories' this_dir entries will
                           have depth-infinity.  Equivalent to
                           today's default update behavior.

1) 检出项目

svn co --depth=empty https://github.com/openwrt/packages/trunk packages

- 阅读剩余部分 -