CLI:切换密钥链以签署xcodebuild

kmbjn2e3  于 2023-02-09  发布在  其他
关注(0)|答案(3)|浏览(88)

我正试图打开某个钥匙链,并关闭另一个。我需要这个,因为我们的企业和应用商店的身份被称为相同的。
现在,我先执行“安全解锁-keychain”,然后执行“安全默认-keychain”以打开正确的keychain,并对我不希望使用的keychain执行“安全锁定-keychain”。
但是xcodebuild仍然看到两个键链中的条目并放弃。

iPhone Distribution: Company name.: ambiguous (matches "iPhone Distribution: Company name." in /Users/user/Library/Keychains/login.keychain and "iPhone Distribution: Company name" in /Users/user/Library/Keychains/enterprise.keychain)

如何防止系统找到我锁定的钥匙串中的条目?

aiqt4smr

aiqt4smr1#

您可以告诉Xcode要使用哪个钥匙串:

xcodebuild "OTHER_CODE_SIGN_FLAGS=--keychain '$PATH_TO_KEYCHAIN'"

或者,如果直接调用codesign

codesign --keychain "$PATH_TO_KEYCHAIN"

如果你使用PackageApplication,就没有办法设置它。然而,PackageApplication是一个非常简单的脚本,可以在必要时重新实现(如果你要集成一个更大的系统/脚本,这非常有用)。

hiz5n14c

hiz5n14c2#

解决方案:我已经把所有与appstore相关的东西放在了登录keychain中,而企业的东西放在了一个单独的keychain文件中。
在buildscript中,我按如下所示在它们之间切换:

# 1. Only activate the System and either the Appstore(=login) or Enterprise keychain.
security list-keychains -s $KEYCHAIN_NAME $SYSTEM_KEYCHAIN

# 2. Loop through App Schema's
for APP_SCHEME in ${APP_SCHEMES[@]}; do
    echo "--=  Processing $APP_SCHEME  =--"
    xcodebuild -scheme "${APP_SCHEME}" archive
done ### Looping through App Schema's

# 3. Restore login & system keychains
security list-keychains -s $APPSTORE_KEYCHAIN $ENTERPRISE_KEYCHAIN $SYSTEM_KEYCHAIN
rjjhvcjd

rjjhvcjd3#

xcode版本6及以下版本的另一种解决方案:用SHA1而不是(不明确)名称指定证书。来自“man codesign”:

If identity consists of exactly forty hexadecimal digits, it is instead
 interpreted as the SHA-1 hash of the certificate part of the desired iden-
 tity.  In this case, the identity's subject name is not considered.

从“安全帮助查找-证书”

-Z  Print SHA-1 hash of the certificate

遗憾的是,此方法需要使用PackageSign脚本,而Xcode 7中已弃用该脚本

相关问题