Skip to main content

Appleのコマンド、証明書の種類、トラブルシューティング

これらの2つのコマンドで、認識されているあらゆるタイプのAppleのバイナリに署名します。これらのコマンドを実行するには、Apple証明書の識別名 (DN) またはSHA-1フィンガープリントを特定する必要があります。

コマンドのプレースホルダとして [Apple証明書識別子] が使用されている場合、Apple証明書のサブジェクトDNまたはSHA-1フィンガープリントのいずれかを使用することができます。

注記

同じ識別名の証明書が複数ある場合は、識別名の代わりに SHA-1フィンガープリントを使用して、以下のコマンドを実行してください。

サブジェクト識別名の確認方法は? 証明書の識別名は、exportコマンドを実行した後、「プライベートキー」セクションの"labl”フィールドに表示されます。

証明書の識別名は、コードサインコマンドでは"Apple Identity”、プロダクトサインコマンドでは"Apple Developer ID"として参照されます。

証明書の SHA-1フィンガープリントの確認方法は? SHA-1フィンガープリントは、exportコマンドを実行した後、「証明書」セクションの"Sha1"フィールドに表示されます。

codesign

Codesignコマンドは、Apple実行可能形式を示す.app拡張子に署名するために使用されます。

Codesign command

Codesign command codesign [--entitlements entitlements.xml] [--deep] [--force] [--verify] [--verbose] --sign "<Apple certificate identifier>" --options runtime "<Path to .app or .dmg file>"

Codesign using Distinguished Name (DN)

To sign using the Apple certificate's DN:

codesign -v -s "<Apple certificate DN>" --force "<Path to .app or .dmg file>"

Command sample:

codesign -v -s "Apple Development: DigiCert Inc (85W9468PYV)" --force example.app

Sample response using DN:

example.app: signed app bundle with Mach-O universal (x86_64 arm64) [DigiCert]

Codesign using SHA-1 fingerprint

To sign using SHA-1 fingerprint of the Apple certificate:

codesign -v -s "<SHA-1 fingerprint of Apple certificate>" --force "<Path to .app or .dmg file>"

Command sample:

codesign -v -s "88da70819d87865ae21996cb889d9e60abff7c9d" --force example.app

Command output:

example.app: replacing existing signature  
example.app: signed app bundle with Mach-O universal (x86_64 arm64) [DigiCert]

productsign

Use the productsign command to sign .pkg and .dmg file extensions, which indicate Apple application installers and release binary distributables via Apple Mac app store, respectively.

注記

Use your system login password if you receive a private key permission pop-up when attempting to sign for the first time.

productsign command

productsign –sign “<Apple certificate identifier>” <Path to .pkg file> <Path to store signed file>

Productsign using Distinguished Name (DN)

To sign using the Apple certificate's DN:

productsign --sign "<Apple certificate DN>" <Path to .pkg file> <Path to store signed file>

Command sample:

productsign --sign "Developer ID Installer: DigiCert Inc (DHPK4B64QS)" UNSIGNED_PKG.pkg SIGNED_PKG.pkg

Sample response using DN:

productsign: using timestamp authority for signature
productsign: signing product with identity "Developer ID Installer: DigiCert Inc (DHPK4B64QS)" from keychain (null)
productsign: adding certificate "Developer ID Certification Authority"
productsign: adding certificate "Apple Root CA"
productsign: Wrote signed product archive to SIGNED_PKG.pkg

Productsign using SHA-1 fingerprint

To sign using SHA-1 fingerprint of the Apple certificate:

digicert@DC-C02TK34HGTDY Downloads % productsign --sign "<SHA-1 fingerprint of Apple certificate>" <Path to .pkg file> <Path to store signed file>

Command sample:

digicert@DC-C02TK34HGTDY Downloads % productsign --sign "1e50029693922d2f7efcf75488189c49ed3bf0bb" UNSIGNED_PKG.pkg SIGNED_PKG.pkg

Command output:

productsign: using timestamp authority for signature  
productsign: signing product with identity "Developer ID Installer: DigiCert Inc (DHPK4B64QS)" from keychain (null)  
productsign: adding certificate "Developer ID Certification Authority"  
productsign: adding certificate "Apple Root CA"  
productsign: Wrote signed product archive to SIGNED_PKG.pkg

Apple証明書タイプと関連コマンド

署名するファイルのタイプに応じて、Apple証明書タイプを選択します。証明書タイプは、開発者アカウントとアカウント環境設定で証明書を識別するのに役立ちます。

Appleに誤った証明書タイプをオーダーし、証明書タイプと関連付けられていない署名コマンドを使用した場合、署名は失敗となります。

1. Appleの証明書タイプとコマンド

タイプ

目的

関連付けられているコマンド

Mac Installer 配布

署名したアプリケーションを含む Mac Installer Packageに署名して、Mac App Storeに提出します。

Productsignコマンドと互換性があります。

デベロッパーID申請

Mac App Store 外で配布する前に、macOS アプリケーションに署名します。

codesignコマンドと互換性があります。

デベロッパーIDインストーラ

署名したアプリケーションを含むMac Installer Packageに署名して、Mac App Store 外に配布します。

Productsignコマンドと互換性があります。

APN 認承鍵

通知依頼の証明書の代わりに、サーバサイドトークンを生成します。

適用不可

ApplEプッシュサービス

通知サービスと APN 間の接続を確立し、アプリにリモート通知を配信します。

適用不可

Apple 開発

iOS、tvOS、または watchOS アプリの場合、デバイス上でアプリを実行し、開発中にアプリサービスを使用します。macOS アプリの場合、開発およびテスト時にアプリサービスを使用します。メモ:Xcode 11.0 以降で利用可能です。以前の Xcode バージョンには、iOS 開発または Mac 開発証明書を使用します。

適用不可

Apple 配布

iOS、tvOS、または watchOS アプリの場合、テストに指定されたデバイスでアプリを実行するか、App Storeに提出します。macOS アプリの場合、Mac App Storeを通して配布する前にアプリに署名します。メモ:Xcode 11.0 以降で利用可能です。以前の Xcode バージョンには、iOS 開発または Mac App 配布証明書を使用します。

適用不可

Apple Pay

Apple から販売店/デベロッパーに送信されるアプリのトランザクションデータを復号化します。

適用不可

マーチャントアイデンティティ

貴組織を Apple Pay サーバへの加盟店認証します。

適用不可

パスタイプ ID

Wallet 内のパスに署名し、更新を送信します。

適用不可

VoIPサービス

通知サーバとAPN間の接続を確立し、バックグラウンドの VoIP アプリに着信アクティビティを通知します。

適用不可

WatchKit サービス

通知サーバとAPN間の接続を確立し、ClockKitのコンプリケーションデータを更新します。

適用不可

ウェブサイトプッシュ ID

ウェブサイトの更新を署名して送信します。メモ:キーチェーンでは証明書名にタイプのヒントが含まれ、チーム名とチームIDが含まれます。開発用証明書名には、ユーザーの名前とメンバーIDが含まれます。

適用不可


Apple signing errors and solutions

The following errors may occur during Apple signing.

トラブルシューティング

Error message:

88 da 70 81 9d 87 86 5a e2 19 96 cb 88 9d 9e 60 ab ff 7c 9d: no identity found

エラーの原因:署名コマンドで SHA-1フィンガープリントを使用する際に、スペースが削除されませんでした。

This error is caused if the spaces were not removed when using the SHA-1 fingerprint in the signing command.

エラーの解決方法:スペースを削除した正しい署名コマンド形式を使用してください。

Remove the spaces in the SHA-1 fingerprint in the signing command.

Could not find appropriate signing identity

Error message:

Could not find appropriate signing identity for "Developer ID Installer: Example Inc (DHPK4B64QS)

Description:

This error occurs when you use the productsign command and reference an incompatible certificate.

Solution:

Use a compatible certificate (Mac Installer Distribution or Developer ID Installer) in the productsign command.

This identity cannot be used for signing code

Error message:

Developer ID Installer: Example Inc (DHPK4B64QS): this identity cannot be used for signing code

Description:

This error occurs when you use the codesign command and reference an incompatible certificate.

Solution:

Use a compatible certificate (Developer ID Application) in the codesign command.

トラブルシューティング

The pluginkit command should show the Secure Software Manager TokenExtension driver after starting the Digicert SSM Signing Clients.app. If it does not:

  1. Digicert SSM Signing Clients.appを起動後ろに、pluginkitコマンドに“DigiCert​​®​​ Software Trust Manager” TokenExtension ドライバが表示されるはずです。表示されない場合は、Digicert SSM Signing Clients.appを削除してください。MacOS を再起動し、アプリを再インストールしてからもう一度やり直してください。

    1. Reinstall Digicert SSM Signing Clients.app.

    2. Restart your MacOS and retry the pluginkit command .

  2. TokenExtension ドライバを手動で削除します。

    pluginkit -r “/Applications/Digicert SSM Signing Clients.app/Contents/PlugIns/TokenExtension.appx”
  3. ログは、Appleのロギンググレームワークで書かれています。以下を使ってこれらを確認します。

    1. To check the logs for DigiCert SSM Signing Clients:

      log stream | grep Digicert SSM Signing Clients
    2. To check the logs of the token:

      log stream | grep TokenExtension
  4. Codesign や productign コマンドの詳細については、man コマンドを実行します

    1. To see more details about codesign, run:

      man codesign
    2. To see more details about productsign, run:

      man productsign
  5. ホスト、APIキー、クライアント証明書パスワード、プロキシ設定が正しいことを確認します。サーバから受け取ったエラーメッセージを確認するためにログを探します。

Failed to sign hash

Error message:

Logs:

2023-11-16 08:39:08.441813+0000 0x1149     Default     0x4d03               557    0    TokenExtension: (Security) [com.apple.securityd:security_exception] CSSM Exception: -25264 MAC verification failed during PKCS12 import (wrong password?)
2023-11-16 08:39:08.441908+0000 0x1149     Default     0x4d03               557    0    TokenExtension: (SSMAPIClient) Info: SecPKCS12Import status -25264

SMCTL:

User is not multi-factor authenticated. Missing Client Authentication Certificate. As per compliance rules, user needs to be authenticated using multi-factor for performing sign operation.

Description:

OpenSSL 3.x changed their default algorithm. This new algorithm is not compatible with macOS SSL libraries starting from Ventura OS. This issue affects Apple Keychain's ability to read DigiCert ONE client authentication certificates (cert.12) because it relies on LibreSSL.

Solution:

Use the OpenSSL -legacy flag available on OpenSSL version 3.x to convert your DigiCert ONE client authentication certificate to cert.pem and then convert it into a PKCS#12 certificate which is readable with LibreSSL and therefore compatible with Apple Keychain.

  1. Confirm which OpenSSL version you're using:

    OpenSSL version

    注記

    If the output is LibreSSL, continue with the steps below on the machine with OpenSSL 3.x installed.

  2. Convert the certificate from .p12 to .pem:

    openssl pkcs12 -in cert.p12 -out cert.pem
  3. Create a new .cert file:

    1. Copy the contents of the .pem file from -----BEGIN CERTIFICATE----- to -----END CERTIFICATE-----.

    2. Paste the contents into a plain text editor or IDE.

    3. Save the file as certname.crt.

  4. Create a new .key:

    1. Copy the contents of the .pem file from -----BEGIN ENCRYPTED PRIVATE KEY----- to -----END ENCRYPTED PRIVATE KEY-----.

    2. Paste the contents into a plain text editor or IDE.

    3. Save the file as encrypted.key.

  5. Decrypt the encrypted .key file:

    openssl rsa -in encrypted.key -out decryptedKey.key
  6. Run the following command to create a certificate file compatible with Ventura and Sonoma OS:

    1. Link the decrypted private key (decryptedKey.key) and its associated X.509 certificate (certname.crt), and export them as a PKCS#12 file (newcert.pfx):

      openssl pkcs12 -inkey decryptedKey.key -in certname.crt -export -legacy -out  newcert.pfx
    2. Save newcert.pfx in the environment variables of the CTK.

    3. Save newcert.pfx password in the environment variables of the CTK.

For these changes to apply and start signing, you must:

  1. Remove the existing token:

    /Applications/DigiCert SSM Signing Clients.app/Contents/MacOS/DigiCert\ SSM\ Signing\ Clients smctl token remove-token
  2. Add a new token:

    /Applications/DigiCert SSM Signing Clients.app/Contents/MacOS/DigiCert\ SSM\ Signing\ Clients smctl token add-token
  3. Move the required keys to the new token:

    /Applications/DigiCert SSM Signing Clients.app/Contents/MacOS/DigiCert\ SSM\ Signing\ Clients smctl keypair add-keys <keypair ID>

注記

For more information about how to complete these steps, refer to CryptoTokenKit (CTK).

Failed to save configuration to keychain: -25308\

Error message:

Failed to save configuration into Keychain. configurationError(message: "Failed to save configuration to keychain: -25308")
Failed to set environment Veraibles. configurationError(message: "Failed to save configuration into Keychain. configurationError(message: \"Failed to save configuration to keychain: -25308\")")

Description:

This error is occurs when your environment variables cannot be saved to Keychain because one or more variables are incorrect.

Solution:

Use the following macOS "security" command to unlock Keychain and provide the correct variables:

% security unlock-keychain -p <password> ~/Library/Keychains/login.keychain

注意

This macOS command stores your password in plaintext in your history file (.zsh_history), it is therefore important that you manually erase this line from your history file so that your plaintext password cannot be accessed by others.

Unlocking the Keychain increases your system's vulnerability until it is locked again. Any command typed in the terminal window will be saved in a history file.