個人開発者でも出来るコードサイニング証明書によるWindowsアプリの署名

個人開発者でも出来るコードサイニング証明書によるWindowsアプリの署名
Certumの証明書を購入してアプリを署名するまでの手順
先に英語で書いてから日本語に訳しています。元記事は “Code signing certificate for indie developers” をご参照ください。
こんにちは、個人アプリ作家のTAKUYAです。InkdropというSaaSでご飯を食べています。現在のビジネス規模だと個人事業主としてやったほうが生活がシンプルに保てるので、まだ会社化していません。僕のアプリはInkdropというMarkdownノートアプリで、macOS、Windows、Linux、iOSやAndroidで動作します。最近のOperating Systemsは積極的にMaliciousなSoftwareからユーザを守る機能を搭載しています。macOSではApp Store外で配布する際はアプリを自分でNotarizeする必要があります。それは特に難しいことではありません。なぜならAppleが基本的に必要なものを提供してくれるからです。一方Windowsでは、Microsoft Store外で配布する際には、自分でサードパーティのCode Signing Certificateを購入して署名しなければなりません。もし署名しなければ、以下のようなWindows SmartScreenの警告がユーザの画面に表示されます:

これは困ります。警告は十分なボリュームのダウンロードが得られれば、Code Signing無しでも消えます。しかし、新しいバージョンをリリースすると再び表示されます。それはあなたのビジネスにおいて著しくConversion Rateに影響を与えるでしょう。なので、僕は自分のアプリ用にCode Signing Certificateを購入して署名しました:
本記事では、どのようにしてCode Signing Certificateを購入して署名したのか、一連の手順を説明します。英語での情報も少ないし日本語の情報は皆無だったので、きっと役に立つかと思います。ただし、実際の手続きにあたって英語の読解力は必須です。何か問題があれば英語でメールのやりとりは不可避です。ご注意下さい。
個人開発者はEV Code Signing Certificatesを購入できない
ここでの個人開発者とは、主に会社を持たず個人で活動している人とします。EV(Extended Validation) Code Signing Certificateを利用すれば、SmartScreenから即座の評価を得られます。しかしそれは企業のみに許されており、個人開発者は入手できません。しかもとても高価です。一方で、Standard Code Signing Certificateなら個人でも購入できることが分かりました。それは即座の評価は得られませんが、バージョンをまたいで評価を蓄積できます。つまり、一度十分なダウンロード数を稼げば、証明書の更新までSmart Screen Warningは表示されなくなります。
最近、CrystalDiskMarkで有名なhiyohiyoさんのブログ記事を見つけました:
調べてみると、Certumというポーランドの会社が個人向けにも安価なCode Signing Certificatesを提供しているようです。興味深いことに、SimplySignというクラウドサービスを使うと、物理USBトークン無しでモバイル機器を使って認証できるようです。面白い:
コストは €189.00/yr で、Affordableです。これを購入してみました。hiyohiyoさんの記事の通り、オープンソース向けの証明書も更に安価に提供しています。Virtual Machineでも動くかどうか心配だったのですが、人柱になる覚悟で実際に試したところParallels上で無事動きました。ただし公式には対応していないので、やる方は自己責任でお願いします。
証明書の購入

Certum shopで証明書を購入したら、上記のようにOrder Itemが表示されます。“Activate” ボタンでアクティベーションを開始します。
Activation wizard

Click “Next”.

4096-bit key長を選びました。次の画面で、申込者と証明書の情報を入力します。確認画面で、以下のようにVeritication methodを聞かれます:

ここでは “automated identity verification” を選択します。
Submitしたら、ステータスが “Awaiting activation” に変わります:

そしたら、あなたのIdentity Verificationが自動で開始されます。
Identity verification
以下のようなメールが届くはずです:

あと、本人確認にどんな書類が必要か書かれたメールも別途届きます。Verification processについての公式ドキュメントは以下にあります:
要するに本人の存在と、住所の証明が英語で必要です。僕の場合は以下のドキュメントを送信しました:
- パスポート
- 英語表記の残高証明書 (e.g., ゆうちょ銀行は住所表記付きで英語で発行してくれます)
問題なくうまく行きました。数時間で通りました。彼らがチェックしている間のステータスは:

Regaining access to the SimplySign service
SimplySignサービスの利用を開始するために認証します。彼らが公式のビデオを提供しています。割とわかりやすい:
6-digit secret tokenとQRコードがメールで送られてきます。僕はiOS版SimplySignをインストールし、スキャンしました:

するとアカウントがアクティベートされます:

Order Statusが以下のように変わりました:

Looks nice.
How to use the certificate
まずデスクトップ版のSimplySignをインストールします:
モバイルアプリで発行されたトークンを使ってログインします:


するとSimplySignの通知が出ます:

自分の証明書を確認するには、タスクバートレイのアイコンをクリックしてメニューを選びます:


ほんまにWindowsにインストールされているのか確認するには、certmgr.msc
を起動して Certificates -> Personal -> Certificates を選択。

Sign your app
公式マニュアルはこちら。ここではsigntool.exe
を使います。Windows SDKにバンドルされています。コマンドは C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64
にあるはずです。もし“signtool is not recognized”というエラーが出たら、%PATH%
環境変数に通してあげましょう。以下のように signtool を実行します:
❯ signtool sign /debug /n "<YOUR CERT NAME>" /t http://time.certum.pl/ /fd sha256 /v <FILENAME>
例えば、僕のElectronアプリのインストーラーの署名は:
❯ signtool sign /debug /n "Takuya Matsuyama" /t http://time.certum.pl/ /fd sha256 /v .\Setup.exeThe following certificates were considered:
Issued to: Takuya Matsuyama
Issued by: Certum Code Signing 2021 CA
Expires: Fri Aug 23 09:00:00 2024
SHA1 hash: ****************************************After EKU filter, 1 certs were left.
After expiry filter, 1 certs were left.
After Subject Name filter, 1 certs were left.
After Private Key filter, 1 certs were left.
The following certificate was selected:
Issued to: Takuya Matsuyama
Issued by: Certum Code Signing 2021 CA
Expires: Fri Aug 23 09:00:00 2024
SHA1 hash: ****************************************Done Adding Additional Store
Successfully signed: .\Setup.exeNumber of files successfully Signed: 1
Number of warnings: 0
Number of errors: 0
もし /n
パラメータがおかしいと、以下のようなエラーが出るでしょう:
SignTool Error: No certificates were found that met all the given criteria.
これでアプリが署名できました。やったね!おめでとう。確認するには:
❯ signtool verify /pa .\Setup.exe
File: .\Setup.exe
Index Algorithm Timestamp
========================================
0 sha256 AuthenticodeSuccessfully verified: .\Setup.exe
これでSmartScreen警告が出る時、Publisherには以下のように表示されます:

“Publisher: Unknown”と表示されるより1万倍良いですね。これで十分なダウンロード数が得られれば、最終的には警告が消えるでしょう。
When got a new iPhone, how to migrate
もしiPhoneを機種変更した時はどうするのという疑問があったので調べました。このドキュメントに書かれていました:
Resetting the access to the service
Resetting the access to the service consists in contacting the Certum Help line in order to submit a request for service access reset. The employee of the Certum Help line performs the access resetting process by verification of personal details of the User requesting the reset of the access to the service. The User’s data contained in their Application for qualified certificate submitted in the Certum system are verified. After correct verification, the User receives a 6-digit code, the so-called secret, from the Certum Operator. Certum sends a one time link for resetting the service access to the e-mail address, which is the User’s ID in the SimplySign System — the link is valid for 24 hours from the moment of its generation in the SimplySign system. The User receives the e-mail message, clicks on the activation link and is directed to Certum website, where they are asked to enter the 6-digit secret. Depending on the reset method, when a secret is entered and the Send button is pressed, the User obtains either the so-called QR Code called a photocode or the so-called 16-character resetting code. After receiving this data, do not close the browser but proceed to the next step of resetting the access to the service.
要するに、Certumに問い合わせてアクセスをリセットしてねとの事。
参考になれば幸いです。