Skip to content

[sigh] fix: prevent empty string as input to codesign on KEYCHAIN_FLAG#30018

Merged
iBotPeaches merged 2 commits into
fastlane:masterfrom
zengchunshan:patch-2
May 8, 2026
Merged

[sigh] fix: prevent empty string as input to codesign on KEYCHAIN_FLAG#30018
iBotPeaches merged 2 commits into
fastlane:masterfrom
zengchunshan:patch-2

Conversation

@zengchunshan

@zengchunshan zengchunshan commented May 6, 2026

Copy link
Copy Markdown
Contributor

使用 fastlane sigh resign 对一个包含 OnDemandResources 目录(其中带有 .assetpack 资源包)的 .ipa 进行重签名时,签名过程会中止并报错:

No such file or directory
Encountered an error, aborting!
[!] Failed to re-sign .ipa

该问题只在未传 --keychain-path 参数(即 KEYCHAIN_FLAG 为空)时出现。

根因分析

在 sigh/lib/assets/resign.sh 中,用于签名 .assetpack 的 codesign 调用对 ${KEYCHAIN_FLAG} 加了双引号:

https://github.com/fastlane/fastlane/blob/master/sigh/lib/assets/resign.sh#L565

/usr/bin/codesign ${VERBOSE} "${PAGESIZE_ARGS[@]}" --generate-entitlement-der "${KEYCHAIN_FLAG}" -f -s "$CERTIFICATE" "$assetpack"

当用户没有传 --keychain-path 时,KEYCHAIN_FLAG 是空字符串。由于被双引号包裹,bash 会把它展开成一个字面量空参数 '' 传给 codesign,于是 codesign
把这个空字符串当作要签的文件路径来处理,从而抛出 No such file or directory 错误。

同一脚本里另外两处 codesign 调用(约第 587 行的 frameworks 签名、约第 900 行的主 app 签名)做法是正确的——${KEYCHAIN_FLAG} 不加引号,并附有明确注释:

Must not quote KEYCHAIN_FLAG because it needs to be unwrapped and passed to codesign with spaces

shellcheck disable=SC2086

/usr/bin/codesign ${VERBOSE} "${PAGESIZE_ARGS[@]}" --generate-entitlement-der ${KEYCHAIN_FLAG} -f -s "$CERTIFICATE" "$framework"

所以第 565 行看起来是一处回归 / 与文件其余部分不一致的写法。

Checklist

  • I've run bundle exec rspec from the root directory to see all new and existing tests pass
  • I've followed the fastlane code style and run bundle exec rubocop -a to ensure the code style is valid
  • I see several green ci/circleci builds in the "All checks have passed" section of my PR (connect CircleCI to GitHub if not)
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary.
  • I've added or updated relevant unit tests.

Motivation and Context

Description

Testing Steps

 "${KEYCHAIN_FLAG}" 被加了引号,当 KEYCHAIN_FLAG 为空时,会传一个空字符串参数给 codesign,导致 "No such file or directory"
   错误。第 587 行和第 900 行的同名变量都没有加引号,是正确的。
@zengchunshan zengchunshan changed the title KEYCHAIN_FLAG 的引号问题 sigh resign:当 .ipa 包含 OnDemandResources assetpack 时 codesign 报 "No such file or directory"(KEYCHAIN_FLAG 引号使用错误) May 6, 2026

@iBotPeaches iBotPeaches left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! We aren't going to add the ignore back, so lets fix this the right way like we did for the other properties - f6017ed

I imagine we can treat it like any of the other ones there. So we can unquote it later. Make sure shelllint passes :)

  - KEYCHAIN_FLAG (string) → KEYCHAIN_ARGS (array), initialized as (), populated as (--keychain "$KEYCHAIN_PATH") — same shape as PAGESIZE_ARGS.
  - The 3 codesign call sites all use "${KEYCHAIN_ARGS[@]}" (quoted, like "${PAGESIZE_ARGS[@]}").
  - Both # shellcheck disable=SC2086 comments and their "Must not quote KEYCHAIN_FLAG…" notes can be removed — they no longer apply.
  - The log-presence check switches from [[ -n "${KEYCHAIN_FLAG}" ]] to [[ ${#KEYCHAIN_ARGS[@]} -gt 0 ]] (the array equivalent).
  - shellcheck on resign.sh should now pass without that suppression on these lines.

@zengchunshan zengchunshan left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pointer to f6017ed — makes total sense. I've updated the patch to follow the same approach: convert KEYCHAIN_FLAG into a KEYCHAIN_ARGS=() array (mirror of PAGESIZE_ARGS), use "${KEYCHAIN_ARGS[@]}" at all three codesign call sites, and drop both # shellcheck disable=SC2086 suppressions plus the "Must not quote KEYCHAIN_FLAG…" comments. The presence check at the top becomes [[ ${#KEYCHAIN_ARGS[@]} -gt 0]]. shellcheck passes cleanly on resign.sh now, and the original OnDemandResources/*.assetpack failure is fixed as a side-effect (empty array → zero args, so no stray '' reaches codesign).

@iBotPeaches iBotPeaches left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acts like PAGESIZE_ARGS now and makes sense and bonus without the shell lint ignore.

@iBotPeaches iBotPeaches changed the title sigh resign:当 .ipa 包含 OnDemandResources assetpack 时 codesign 报 "No such file or directory"(KEYCHAIN_FLAG 引号使用错误) [sigh] fix: prevent empty string as input to codesign on KEYCHAIN_FLAG May 7, 2026
@iBotPeaches iBotPeaches merged commit 02f45ea into fastlane:master May 8, 2026
9 checks passed

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @zengchunshan 👋

Thank you for your contribution to fastlane and congrats on getting this pull request merged 🎉
The code change now lives in the master branch, however it wasn't released to RubyGems yet.
We usually ship about once a month, and your PR will be included in the next one.

Please let us know if this change requires an immediate release by adding a comment here 👍
We'll notify you once we shipped a new release with your changes 🚀"

PratikPatil131 pushed a commit to PratikPatil131/fastlane that referenced this pull request May 9, 2026
fastlane#30018)

* KEYCHAIN_FLAG 的引号问题

 "${KEYCHAIN_FLAG}" 被加了引号,当 KEYCHAIN_FLAG 为空时,会传一个空字符串参数给 codesign,导致 "No such file or directory"
   错误。第 587 行和第 900 行的同名变量都没有加引号,是正确的。

* Refactor keychain handling in resign.sh

  - KEYCHAIN_FLAG (string) → KEYCHAIN_ARGS (array), initialized as (), populated as (--keychain "$KEYCHAIN_PATH") — same shape as PAGESIZE_ARGS.
  - The 3 codesign call sites all use "${KEYCHAIN_ARGS[@]}" (quoted, like "${PAGESIZE_ARGS[@]}").
  - Both # shellcheck disable=SC2086 comments and their "Must not quote KEYCHAIN_FLAG…" notes can be removed — they no longer apply.
  - The log-presence check switches from [[ -n "${KEYCHAIN_FLAG}" ]] to [[ ${#KEYCHAIN_ARGS[@]} -gt 0 ]] (the array equivalent).
  - shellcheck on resign.sh should now pass without that suppression on these lines.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congratulations! 🎉 This was released as part of fastlane 2.234.0 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants