Windows SDK のツールを使用してコード署名用の自己署名証明書を作成するにはどうすればよいですか?
6 に答える
更新された回答
次の Windows バージョン以降を使用している場合: Windows Server 2012、Windows Server 2012 R2、または Windows 8.1 の場合、MakeCert は非推奨になり、Microsoftは PowerShell コマンドレットNew-SelfSignedCertificateを使用することをお勧めします。
Windows 7 などの古いバージョンを使用している場合は、MakeCert または別のソリューションを使用する必要があります。Public Key Infrastructure Powershell (PSPKI) Moduleを提案する人もいます。
元の回答
自己署名コード署名証明書 (SPC - Software Publisher Certificate ) を一度に作成することもできますが、私は次の方法をお勧めします。
自己署名認証局 (CA) の作成
makecert -r -pe -n "CN=My CA" -ss CA -sr CurrentUser ^
-a sha256 -cy authority -sky signature -sv MyCA.pvk MyCA.cer
(^ = バッチ コマンド ラインで行を折り返すことができます)
これにより、エクスポート可能な秘密鍵 (-pe) を使用して、自己署名 (-r) 証明書が作成されます。これは「My CA」という名前で、現在のユーザーの CA ストアに配置する必要があります。SHA-256アルゴリズムを使用しています。キーは署名用です (-sky)。
秘密鍵は MyCA.pvk ファイルに保存し、証明書は MyCA.cer ファイルに保存する必要があります。
CA 証明書のインポート
信頼できない CA 証明書を持っていても意味がないため、Windows 証明書ストアにインポートする必要があります。証明書 MMC スナップインを使用できますが、コマンド ラインから:
certutil -user -addstore Root MyCA.cer
コード署名証明書 (SPC) の作成
makecert -pe -n "CN=My SPC" -a sha256 -cy end ^
-sky signature ^
-ic MyCA.cer -iv MyCA.pvk ^
-sv MySPC.pvk MySPC.cer
上記とほとんど同じですが、発行者キーと証明書 (-ic および -iv スイッチ) を提供しています。
また、証明書とキーを PFX ファイルに変換します。
pvk2pfx -pvk MySPC.pvk -spc MySPC.cer -pfx MySPC.pfx
パスワードをご利用の方は下記をご利用ください
pvk2pfx -pvk MySPC.pvk -spc MySPC.cer -pfx MySPC.pfx -po fess
PFX ファイルを保護する場合は、-po スイッチを追加します。そうしないと、PVK2PFX はパスフレーズのない PFX ファイルを作成します。
コードに署名するための証明書の使用
signtool sign /v /f MySPC.pfx ^
/t http://timestamp.url MyExecutable.exe
PFX ファイルを証明書ストアにインポートすると (PVKIMPRT または MMC スナップインを使用できます)、次のようにコードに署名できます。
signtool sign /v /n "Me" /s SPC ^
/t http://timestamp.url MyExecutable.exe
可能なタイムスタンプ URL は次のsigntool /tとおりです。
http://timestamp.verisign.com/scripts/timstamp.dllhttp://timestamp.globalsign.com/scripts/timstamp.dllhttp://timestamp.comodoca.com/authenticodehttp://timestamp.digicert.com
完全な Microsoft ドキュメント
ダウンロード
.NET 開発者でない場合は、Windows SDK と .NET フレームワークのコピーが必要です。現在のリンクはここにあります: [SDK & .NET][5] (`C:\Program Files\Microsoft SDKs\Windows\v7.1` に makecert をインストールします)。あなたのマイレージは異なる場合があります。MakeCert は、Visual Studio コマンド プロンプトから利用できます。Visual Studio 2015にはそれがあり、「VS 2015の開発者コマンドプロンプト」または「VS2015 x64ネイティブツールコマンドプロンプト」の下のWindows 7のスタートメニューから起動できます(おそらくすべて同じフォルダーにあります)。
ロジャーの答えはとても役に立ちました。
ただし、使用に少し問題があり、「Windowsはこのドライバーソフトウェアの発行元を確認できません」という赤いエラーダイアログが表示され続けました。鍵は、テストルート証明書をインストールすることでした
certutil -addstore Root Demo_CA.cer
ロジャーの答えは完全にはカバーしていませんでした。
これは私のために働いたバッチファイルです(私の.infファイルは含まれていません)。GUI ツールをまったく使用せずに (いくつかのパスワード プロンプトを除いて)、最初から最後まですべてを実行する方法を示します。
REM Demo of signing a printer driver with a self-signed test certificate.
REM Run as administrator (else devcon won't be able to try installing the driver)
REM Use a single 'x' as the password for all certificates for simplicity.
PATH %PATH%;"c:\Program Files\Microsoft SDKs\Windows\v7.1\Bin";"c:\Program Files\Microsoft SDKs\Windows\v7.0\Bin";c:\WinDDK\7600.16385.1\bin\selfsign;c:\WinDDK\7600.16385.1\Tools\devcon\amd64
makecert -r -pe -n "CN=Demo_CA" -ss CA -sr CurrentUser ^
-a sha256 -cy authority -sky signature ^
-sv Demo_CA.pvk Demo_CA.cer
makecert -pe -n "CN=Demo_SPC" -a sha256 -cy end ^
-sky signature ^
-ic Demo_CA.cer -iv Demo_CA.pvk ^
-sv Demo_SPC.pvk Demo_SPC.cer
pvk2pfx -pvk Demo_SPC.pvk -spc Demo_SPC.cer ^
-pfx Demo_SPC.pfx ^
-po x
inf2cat /drv:driver /os:XP_X86,Vista_X64,Vista_X86,7_X64,7_X86 /v
signtool sign /d "description" /du "www.yoyodyne.com" ^
/f Demo_SPC.pfx ^
/p x ^
/v driver\demoprinter.cat
certutil -addstore Root Demo_CA.cer
rem Needs administrator. If this command works, the driver is properly signed.
devcon install driver\demoprinter.inf LPTENUM\Yoyodyne_IndustriesDemoPrinter_F84F
rem Now uninstall the test driver and certificate.
devcon remove driver\demoprinter.inf LPTENUM\Yoyodyne_IndustriesDemoPrinter_F84F
certutil -delstore Root Demo_CA
PowerShell 4.0 (Windows 8.1/ Server 2012 R2) 以降、makecert.exeを使用せずに Windows で証明書を作成できます。
必要なコマンドはNew-SelfSignedCertificateとExport-PfxCertificateです。
手順は、PowerShell を使用した自己署名証明書の作成にあります。