Version: 2022.1
言語: 日本語
Building your macOS application
Digital distribution services for macOS applications

Notarizing your macOS application

Notarization is a process where Apple verifies your application to make sure it has a Developer ID code signature and doesn’t contain malicious content. For more information about noratization, see Apple’s documentation on Notarizing macOS Software Before Distribution.

If you develop on an Apple device, you can use Xcode, Xcode command-line tools, or Unity Cloud Build to notarize your application. If you don’t have an Apple device, use Unity Cloud Build.

This page contains information on the following notarization methods:

Notarization using Xcode

Unity can create an Xcode project that represents your Unity project during the build process. You can use this Xcode project to notarize your application. To create an Xcode project from your Unity project, follow the macOS application build steps. For information on how to notarize the Xcode project, see Apple’s documentation on Notarizing macOS Software Before Distribution.

Notarization using Xcode command-line tools

If you are unable to notarize your application in the Xcode environment, or if you want to manually control notarization, you can use Xcode’s command-line tools. To do this, you need:

Code signing your application

To notarize your application with the Xcode command-line tools, you first need to code sign the application. This section explains how to code sign your application using Xcode’s command-line tools. For information about what code signing is and why Apple requires it, see Code signing.

署名 ID

Unity adds a code signature to every macOS build it produces. This is a simple code signature and doesn’t identify you as the developer. To notarize an application, Apple requires the code signature to include a cryptographic signature that identifies the developer. This is called a signing identity. Usually, you use a Developer ID certificate.

新しい Developer ID 証明書を作成するには、Create a New Certificate にアクセスし、以下を行ってください。

  1. プロンプトに従って秘密鍵を作成し、Certificate Signing Request をアップロードします。
  2. Developer ID 証明書をダウンロードします。この証明書のファイル形式は .cer です。
  3. 証明書をクリックしてキーチェーンに追加します。キーチェーン内に Developer ID Application : XXX (YYY) といった形式で名前が表示されます。

アプリケーション識別子

Apple は、アプリケーションを公証するにあたって、アプリケーションを識別する必要があります。アプリケーションの識別子の取得は、2 つの方法 (Unity で取得する方法と、ビルドされたアプリケーションの 情報プロパティリストファイル 内で取得する方法) で行えます。

  • Unity で取得する方法
    1. Edit > Project Settings > Player を開きます。
    2. Other Settings セクションを展開し、Mac App Store Options を開きます。
    3. Bundle Identifier の値を確認してください。
  • 情報プロパティリストファイル内で取得する方法
    1. Finder で、ビルドしたアプリケーションに移動します。
    2. アプリケーションを右クリックし、Show Package Contents を選択します。
    3. Contents へ移動し、Info.plist を開きます。
    4. アプリケーション識別子を表すキーは CFBundleIdentifier です。

アプリケーション識別子が取得できたら、それを Apple に登録できます。これは以下の手順で行えます。

  1. Apple Developer にアクセスし、ログインしてください。
  2. Certificates, IDs & Profiles を選択します。
  3. Select Identifiers, and add your bundle ID.

エンタイトルメント

Entitlements are permissions or restrictions that your code signature includes that allow or prevent your application from taking specific actions. For more information, see Entitlements.

アプリケーションのエンタイトルメントの設定は、以下の手順で行えます。

  1. ビルドしたアプリケーションと同じディレクトリに、アプリケーションと同じ名前にファイル拡張子 .entitlements を付加したファイルを作成します。例えば、アプリケーションの名前が Sample であれば、Sample.entitlements という名前のファイルを作成します。
  2. このファイルをテキストエディターで開き、以下の内容をファイル内にコピーしてください。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
       <key>com.apple.security.cs.disable-library-validation</key>
       <true/>
       <key>com.apple.security.cs.disable-executable-page-protection</key>
       <true/>
    </dict>
</plist>

これらのエンタイトルメントは、macOS アプリケーションが Hardened Runtime を使用するための必要最低限のエンタイトルメントです。アプリケーションにこれ以上のエンタイトルメントが必要な場合は、このリストに追加してください。

Code signing

コード署名の処理にはコマンドラインが使用されます。開始するには、ターミナルを開き、アプリケーションのあるディレクトリに移動します。コード署名の処理に必要な読み取り権限があることを確認するために、以下のコマンドを実行してください。"application_name.app" はアプリケーションの名前です。

chmod -R a+xr "application_name.app"

A code signature uses a particular signing identity. Usually, this is your Developer ID Application signing identity. However, some digital distribution services, such as the Mac App Store require a different signing identity. For information about which signing identity a particular digital distribution service requires, see the documentation for that digital distribution service.

アプリケーションにコード署名するには、以下のコマンドを実行してください。

  • "application_name.app" は、ビルドしたアプリケーションです。
  • "application_name.entitlements" は、エンタイトルメントファイル の名前です。
  • "Developer ID Application : XXX (YYY)" は、署名 ID です。
codesign --deep --force --verify --verbose --timestamp --options runtime --entitlements "application_name.entitlements" --sign "Developer ID Application : XXX (YYY)" "application_name.app"

このコマンドは、アプリケーションバンドルフォルダー内を再帰的に移動し、全てのファイルに署名し、安全なタイムスタンプを追加し、署名内に設定されたエンタイトルメントを埋め込みます。

Warning: Using the --deep option might cause issues with your code signature. This is because:

  • このオプションは、署名対象の全てのコードに、同じコード署名オプションとエンタイトルメントを適用するため。

  • このオプションは、その見つけたコードファイルにのみ署名するため。システムがデータを見つけることを想定している場所にコードファイルがある場合、--deep は、そうしたコードファイルには署名しません。

For more information about the --deep option and how to resolve issues with it, see Sign your code.

Uploading to Apple for notarization

After you code sign your application, you need to upload it to Apple for notarization. To do this, Apple requires:

Compressing the application

Apple は、公証のためにアプリケーションをアップロードする前にアプリケーションを圧縮することを要件として設けています。これは以下の手順で行ってください。

  1. ターミナルを開き、アプリケーションのあるディレクトリに移動します。

  2. 以下のコマンドを実行します。
    • "application_name.app" は、ビルドしたアプリケーションです。
    • "application_name.zip" は、生成する圧縮ファイルの名前です。
ditto -c -k --sequesterRsrc --keepParent "application_name.app" "application_name.zip"

これにより、アプリケーションが圧縮され、アプリケーションと同じディレクトリに圧縮ファイルが出力されます。

Generating an application Password

Apple は、アプリケーションを公証するにあたって、特定の形式の固有のパスワードを必要とします。App 用パスワードを生成するには Apple ID が必要です。Apple ID を持っていない場合は、Apple ID 管理ページ にアクセスして作成してください。

For information on how to generate an application password, see How to generate an app-specific password. The password you generate uses the following format: xxxx-xxxx-xxxx-xxxx.

Getting your provider short name

プロバイダーのショートネームは、個人または企業を識別するための一語のラベルです。Apple は、Apple ID が複数の組織に関連付けられている場合に、どの組織に対して公証を行うか特定するためにプロバイダーのショートネームを使用します。プロバイダーのショートネームは以下の方法で取得できます。

  1. ターミナルを開きます。
  2. 以下の Xcode コマンドを実行します。
xcrun iTMSTransporter -m provider -u apple_id -p xxxx-xxxx-xxxx-xxxx

Starting the upload process

Apple からアプリケーションの公証を受けるには、アプリケーションを公証サーバーにアップロードする必要があります。これは、以下の手順で行います。

  1. ターミナルを開き、圧縮されたアプリケーション があるディレクトリに移動します。
  2. 以下のコマンドを実行します。
xcrun altool --notarize-app --username apple_id --password xxxx-xxxx-xxxx-xxxx --asc-provider provider_short_name --primary-bundle-id application_bundle_id --file application_name.zip

アップロードが成功すると、Apple が、リクエスト ID を含む応答をターミナルに表示します。このリクエスト ID を使用して、リクエストの状況を確認できます。サービスへのトラフィック状況によっては、公証プロセスに何時間かかかる場合があるため、これは役に立ちます。方法は以下の通りです。

  1. ターミナルを開き、圧縮されたアプリケーション があるディレクトリに移動します。
  2. 以下のコマンドを実行します。
xcrun altool --notarization-info request_id --username apple_id --password xxxx-xxxx-xxxx-xxxx --asc-provider provider_short_name

公証プロセスが完了すると、Apple から、Apple ID に関連付けられたアドレスに、確認メールが送られます。その後で、公証が成功したかどうか確認することができます。これは以下のように行います。

  1. ターミナルを開き、アプリケーションのあるディレクトリに移動します。
  2. 以下のコマンドを実行します。
    • application_name.app は、アプリケーションの名前です。
spctl -a -v application_name.app

公証が成功した場合は、これにより、Apple がアプリケーションを受理したことを示す、Developer ID を含むメッセージが返されます。

Stapling the application

After notarizing your application, any device that runs it can verify that it has a code signature and contains no malicious content. However, the device can only perform this verification if it has an internet connection. To make a device able to verify your application without an internet connection, you must staple the application. For information about stapling, see Staple the Ticket to Your Distribution. To staple your application,

  1. ターミナルを開き、アプリケーションのあるディレクトリに移動します。
  2. Run the following command "ApplicationName.app" is the name of your application: xcrun stapler staple "ApplicationName.app".

Unity Cloud Build を使用した公証

Unity Cloud Build can notarize and staple your macOS application during the build process. To do this, Unity requires:

Depending on the platform you are developing on, the process for some of these requirements differ. If you develop on an Apple device, you can use Xcode command-line tools to get the information and create the relevant files. However, If you develop on Windows or Linux, you don’t have access to Apple-specific Xcode command-line tools.

どのプラットフォームを使用する場合も、Apple ID、パスワード、エンタイトルメントファイルの取得方法は同じです。

  1. Apple ID を持っていない場合は、Apple ID 管理ページ にアクセスして作成してください。
  2. Create an application password. For information on how to do this, see Generating an application Password.
  3. Apple Developer のメンバーシップを持っていない場合は、Apple Developer でサインアップしてください。
  4. Create an entitlements file for your application. For information on how to do this, see Entitlements.

上記の手順が完了したら、以下を確認してください。

Apple デバイスでの Unity Cloud Build による公証

Apple デバイスで開発する場合、Xcode コマンドラインツールを使用して、Unity Cloud Build を使用した公証 に記載の要件を満たすことができます。その後、Unity Cloud Build を設定し、ビルドプロセスの一環として、アプリケーションの公証を受け、ステープルすることができます。要件を満たすには、以下を行ってください。

  1. Unity Cloud Build を使用した公証 に記載されている、プラットフォームに依存しない手順に従ってください。
  2. Create a Developer ID certificate and add it to your Keychain. For information on how to do this, see Signing identity.
  3. From the Keychain, export the Developer ID certificate as a file in Personal Information Exchange (.p12) format. For information on how to do this, see Import and export keychain items using Keychain Access on Mac.
  4. Get your provider short name. For information on how to do this, see Getting your provider short name.

要件を満たした後で、Unity Cloud Build の公証フォーム に必要事項を記入し、提出します。

Windows および Linux デバイスでの Unity Cloud Build による公証

If you develop on Windows or Linux but want to build, notarize, and staple your application for macOS, you can’t use Xcode command-line tools. To meet the requirements listed in Notarization using Unity Cloud Build so you can set up Unity Cloud Build to notarize and staple your application as part of the build process:

  1. Unity Cloud Build を使用した公証 に記載されている、プラットフォームに依存しない手順に従ってください。
  2. Create a Developer ID certificate and download it. For information on how to do this, see Signing identity. Note: The last step in Signing identity is only relevant for macOS users.
  3. Convert the Developer ID certificate to the PKCS #12 Personal Information Exchange (.p12) file format. For information on how to do this, see Converting a Developer ID certificate to a .p12 file on Windows and Linux.
  4. Apple Developer アカウントからプロバイダーのショートネームを取得します。これを行うには、メンバーシップの詳細 にアクセスし、 チーム ID を見つけてください。チーム ID をプロバイダーのショートネームとして使用できます。

要件を満たした後で、Unity Cloud Build の公証フォーム に必要事項を記入し、提出します。

Converting a Developer ID certificate to a .p12 file on Windows and Linux

.p12 ファイルは、Developer ID 証明書と秘密鍵の両方をバンドルします。以下の手順で、このファイルを Developer ID 証明書から作成できます、

  1. Open a command-line interface and go to the directory that contains your Developer ID certificate file. If you didn’t download your Developer ID certificate, see Signing identity.

  2. Developer ID 証明書には .cer ファイル形式が使用されています。このファイルを .pem ファイル形式に変換してください。これを行うには、以下のコマンドを実行します。
    • developer_identity.cer は、変換する Developer ID 証明書ファイルです。
    • developer_identity.pem は、出力するファイルの名前とファイルタイプです。

    openssl x509 -in developer_identity.cer -inform DER -out developer_identity.pem -outform PEM

  3. 新しい秘密鍵を生成します。これを行うには、以下のコマンドを実行します。
    • mykey.key is the file name and file type of the private key to output.

    openssl genrsa -out mykey.key 2048

  4. .p12 ファイルを生成します。これを行うには、以下のコマンドを実行します。
    • mykey.key は、手順 3 で生成した秘密鍵のファイルです。
    • developer_identity.pem は、手順 2 で生成した .pem ファイルです。

    openssl pkcs12 -export -inkey mykey.key -in developer_identity.pem -out iphone_dev.p12

Submitting the Unity Cloud Build notarization form

Unity Cloud Build を使用した公証 に記載されている要件を満たした後で、以下の手順に従って Unity Cloud Build 公証を設定してください。

  1. Set up your project to use Unity Cloud Build. For information on how to do this, see Unity Cloud Build.
  2. Cloud Build で新しい Mac Desktop ビルドターゲットを作成します。
  3. Config ページに戻ります。このページに、Notarization (公証) のセクションが含まれるようになりました。このセクションを開き、EDIT NOTARIZATION をクリックしてください。
    Config ページに提供されるセクション
  4. Enable the Notarization flag. If you have previously supplied a set of notarization credentials to Unity Cloud Build, for the same Organization, you can select those from Credentials. Otherwise, select Add new provisioning credentials.
    The credentials drop-down.
  5. 以下を提供してください。
  6. 認証情報を保存します。
  7. Build History ページに戻り、Mac ターゲット用のビルドを開始します。
  8. ビルドが成功すると、Unity Cloud Build は結果の公証とステープルを試みます。
    • Cloud Build が、--deep --force --verify --verbose --timestamp --options runtime フラグで codesign コマンドを実行します。カスタムフラグの指定は現時点では不可能です。
    • If you want to see additional log output from notarization, set the environment variable FASTLANE_NOTARIZE_VERBOSE=true in your build target Environment Variables.
  9. Unity Cloud Build によるプロジェクトのビルド、公証、ステープルの処理が完了したら、ビルドの含まれた圧縮ファイルがダウンロード可能になります。
Building your macOS application
Digital distribution services for macOS applications