如何避免 Authenticode 在自動構建中對 .NET 項目中的第三方庫進行簽名? (How can I avoid Authenticode signing third-party libraries in a .NET project in an automated build?)


問題描述

如何避免 Authenticode 在自動構建中對 .NET 項目中的第三方庫進行簽名? (How can I avoid Authenticode signing third-party libraries in a .NET project in an automated build?)

We recently purchased a code-signing certificate and I've been incorporating the code signing step into our automated builds.

Our build script has to build both VB6 and .NET projects, so we currently have a batch file that builds everything. For the .NET projects, our build script calls MSBUILD, passing in a solution file to build. The projects in these solutions have some third-party dependencies, and these files all have the Copy Local option turned on in References, since they are needed to run the application. In addition, some projects use COM Interop, and so they have automatically-generated Interop assemblies (such as Interop.MSXML2.dll) that are also copied to the to the output folder during a build.

I'm trying to figure out an easy to only code sign the files that are compiled during the build (i.e. our assemblies), and ignore third-party libraries and Interop assemblies, without resorting to having to call signtool.exe on each assembly separately.

Currently, I worked around this by doing the following in the build script:

  • Make sure the build cleans all previously-built files
  • Compile the .NET solution with MSBUILD, specifying an output folder for the build
  • Recursively sign all of the binaries (EXE's, DLL's, OCX's) in the output folder with signtool.exe. This signs everything, including the third-party libraries and auto-generated Interop assemblies
  • My third-party dependencies are in a separate lib folder, so I copy all of the files from lib back into the build output folder, overwriting the copies that the build copied there. This way these files are no longer signed, but our assemblies still are

My question is, is there a better way to do this? The only other alternative I can think of is to call signtool.exe individually on each assembly that needs signing, but this could be a pain because of the number of projects and the amount of change occurring in them (assemblies get renamed, move, get deleted as the projects evolve). Plus, I don't want to have to guess whether a particular assembly got signed or not, so looping through the files and signing them in bulk makes the most sense to me.

At the same time, however, it doesn't seem right (morally, legally, or otherwise) to arbitrarily sign files that we didn't create with our code-signing certificate.

Or maybe I'm going about this the wrong way altogether?


參考解法

方法 1:

If you have license to distribute all of the libraries you're including then I don't think adding your digital signature to them is going to be a problem. I'd just sign everything before creating your installer. 

That said, there are some benefits to having everything signed on the user's machine but the most important thing to sign is your installer - that's where most users see the scary messages that a digital signature helps mitigate. 

As far as building goes - I use Visual Build Professional to manage all of my build processes and it has an integrated code signing step that I use to sign everything as it is copied. My longest deployment project is over 300 steps in total and does everything from signing to uploading. I'm not associated with Kinook but I try to promote the software - I can't imagine how much time it saves me in a given work week. 

(by Mike SprossMitchell V)

參考文件

  1. How can I avoid Authenticode signing third-party libraries in a .NET project in an automated build? (CC BY-SA 3.0/4.0)

#authenticode #code-signing #.net #msbuild






相關問題

關於唯一下載的未知發布者警告 (unknown publisher warning on unique downloads)

如何避免 Authenticode 在自動構建中對 .NET 項目中的第三方庫進行簽名? (How can I avoid Authenticode signing third-party libraries in a .NET project in an automated build?)

CAPICOM - 驗證 SignedCode 來自沒有 UI 的受信任的發布者 (CAPICOM - Verify SignedCode is from a Trusted Publisher without UI)

SignTool 錯誤:訪問被拒絕 (SignTool error: Access is denied)

代碼簽名證書過期問題 (Code Signing Certificate Expiration Issue)

在沒有 app.config 的情況下在 .NET exe 中禁用驗證碼簽名驗證 (Disabling authenticode signature verification in .NET exe without app.config)

驗證 EXE 上的 Authenticode 簽名 - 沒有 CAPICOM 的 C++ (Validate Authenticode signature on EXE - C++ without CAPICOM)

EV 代碼簽名證書或 Microsoft Authenticode 的代碼簽名證書 (EV Code Signing certificate or Code Signing Certificates for Microsoft Authenticode)







留言討論