2011-12-16 88 views
10

我試圖打開某個鑰匙串,並關閉另一個鑰匙串。 我需要這個,因爲我們的企業& appstore身份被稱爲相同。CLI:切換鑰匙串以簽署xcodebuild

現在,我做了一個「安全解鎖鑰匙串」,後面跟着一個「安全默認鑰匙串」,以打開正確的鑰匙串並對我不希望使用的鑰匙串執行「安全鎖鑰匙串」。

但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) 

如何防止系統找到我鎖定的鑰匙串中的條目?

回答

3

解決方案: 我已將所有與appstore相關的東西放入登錄鑰匙串中,並將企業內容放入單獨的鑰匙串文件中。

# 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 
+0

但是,在並行構建的情況下,當任務可能同時切換錯誤的鑰匙串時,這可能不是期望的選項。我仍然希望PackageApplication腳本採取選項爲證書查找設置首選鑰匙串。 – lef 2016-01-24 09:06:15

0

爲xcode的版本6和下面的另一個解決方案:通過SHA1,而不是通過(模糊的)名稱指定證書

在buildscript,我那些之間如下進行切換。從「人的協同設計」:

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腳本,它一直deprecated in Xcode 7

+0

聽起來很有希望......但我看不出我如何在xcode中指定SHA1。我可能不得不通過腳本進行簽名。無論如何,謝謝你的提示。我會仔細研究,看看它能否幫助我們。 – P5ycH0 2013-06-02 10:25:34

+1

@ P5ych0對不起,直到現在還沒有看到。是的,我們執行登錄腳本,例如使用「xcrun -sdk iphoneos PackageApplication --sign --embed 」 – 2013-07-29 19:19:13

9

你可以告訴Xcode使用哪個鑰匙串:

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

或者,如果你打電話給codesign直接:

codesign --keychain "$PATH_TO_KEYCHAIN" 

如果使用PackageApplication,則沒有辦法設置它。然而,PackageApplication是一個非常簡單的腳本,如果需要的話可以重新實現(如果要與更大的系統/腳本集成,則非常有用)。