Skip to content

Commit

Permalink
Merge pull request #1319 from andrei-aliashkevich/wix-v3-master
Browse files Browse the repository at this point in the history
Support StoreType.sha1Hash in DigitalSignatureBootstrapper
  • Loading branch information
oleg-shilo authored Jul 19, 2023
2 parents a4ffd6c + e9ecd81 commit e2d541f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
18 changes: 8 additions & 10 deletions Source/src/WixSharp/CommonTasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,13 @@ static public int DigitalySign(string fileToSign, string certificateId, string t
/// <param name="optionalArguments">Extra arguments to pass to the <c>SignTool.exe</c> utility.</param>
/// <param name="wellKnownLocations">The optional ';' separated list of directories where SignTool.exe can be located.
/// If this parameter is not specified WixSharp will try to locate the SignTool in the built-in well-known locations (system PATH)</param>
/// <param name="useCertificateStore">A flag indicating if the value of <c>pfxFile</c> is a name of the subject of the signing certificate
/// from the certificate store (as opposite to the certificate file). This value can be a substring of the entire subject name.</param>
/// <param name="certificateStore">Type of the certificate store to load it from.</param>
/// <param name="outputLevel">A flag indicating the output level</param>
/// <param name="hashAlgorithm">the hash algorithm to use. SHA1, SHA256, or both. NOTE: MSIs only allow
/// a single signature. If SHA1 | SHA256 is requested, the MSI will be signed with SHA1 only.
/// </param>
/// <returns>Exit code of the <c>SignTool.exe</c> process.</returns>
///
///
/// <example>The following is an example of signing <c>SetupBootstrapper.exe</c> file.
/// <code>
/// WixSharp.CommonTasks.Tasks.DigitalySignBootstrapper(
Expand All @@ -318,13 +317,13 @@ static public int DigitalySign(string fileToSign, string certificateId, string t
/// </code>
/// </example>
static public int DigitalySignBootstrapper(string bootstrapperFileToSign, string pfxFile, string timeURL, string password,
string optionalArguments = null, string wellKnownLocations = null, bool useCertificateStore = false, SignOutputLevel outputLevel = SignOutputLevel.Verbose, HashAlgorithmType hashAlgorithm = HashAlgorithmType.sha1)
string optionalArguments = null, string wellKnownLocations = null, StoreType certificateStore = StoreType.file, SignOutputLevel outputLevel = SignOutputLevel.Verbose, HashAlgorithmType hashAlgorithm = HashAlgorithmType.sha1)
{
var retval = DigitalySignBootstrapperEngine(bootstrapperFileToSign, pfxFile, timeURL, password, optionalArguments, wellKnownLocations, useCertificateStore, outputLevel, hashAlgorithm);
var retval = DigitalySignBootstrapperEngine(bootstrapperFileToSign, pfxFile, timeURL, password, optionalArguments, wellKnownLocations, certificateStore, outputLevel, hashAlgorithm);
if (retval != 0)
return retval;

return DigitalySign(bootstrapperFileToSign, pfxFile, timeURL, password, optionalArguments, wellKnownLocations, useCertificateStore ? StoreType.commonName : StoreType.file, outputLevel, hashAlgorithm);
return DigitalySign(bootstrapperFileToSign, pfxFile, timeURL, password, optionalArguments, wellKnownLocations, certificateStore, outputLevel, hashAlgorithm);
}

/// <summary>
Expand All @@ -342,8 +341,7 @@ static public int DigitalySignBootstrapper(string bootstrapperFileToSign, string
/// <param name="optionalArguments">Extra arguments to pass to the <c>SignTool.exe</c> utility.</param>
/// <param name="wellKnownLocations">The optional ';' separated list of directories where SignTool.exe can be located.
/// If this parameter is not specified WixSharp will try to locate the SignTool in the built-in well-known locations (system PATH)</param>
/// <param name="useCertificateStore">A flag indicating if the value of <c>pfxFile</c> is a name of the subject of the signing certificate
/// from the certificate store (as opposite to the certificate file). This value can be a substring of the entire subject name.</param>
/// <param name="certificateStore">Type of the certificate store to load it from.</param>
/// <param name="outputLevel">A flag indicating the output level</param>
/// <param name="hashAlgorithm">the hash algorithm to use. SHA1, SHA256, or both. NOTE: MSIs only allow
/// a single signature. If SHA1 | SHA256 is requested, the MSI will be signed with SHA1 only.
Expand All @@ -361,7 +359,7 @@ static public int DigitalySignBootstrapper(string bootstrapperFileToSign, string
/// </code>
/// </example>
static public int DigitalySignBootstrapperEngine(string bootstrapperFileToSign, string pfxFile, string timeURL, string password,
string optionalArguments = null, string wellKnownLocations = null, bool useCertificateStore = false, SignOutputLevel outputLevel = SignOutputLevel.Verbose, HashAlgorithmType hashAlgorithm = HashAlgorithmType.sha1)
string optionalArguments = null, string wellKnownLocations = null, StoreType certificateStore = StoreType.file, SignOutputLevel outputLevel = SignOutputLevel.Verbose, HashAlgorithmType hashAlgorithm = HashAlgorithmType.sha1)
{
var insigniaPath = IO.Path.Combine(Compiler.WixLocation, "insignia.exe");
string enginePath = IO.Path.GetTempFileName();
Expand All @@ -378,7 +376,7 @@ static public int DigitalySignBootstrapperEngine(string bootstrapperFileToSign,
if (retval != 0)
return retval;

retval = DigitalySign(enginePath, pfxFile, timeURL, password, optionalArguments, wellKnownLocations, useCertificateStore ? StoreType.commonName : StoreType.file, outputLevel, hashAlgorithm);
retval = DigitalySign(enginePath, pfxFile, timeURL, password, optionalArguments, wellKnownLocations, certificateStore, outputLevel, hashAlgorithm);
if (retval != 0)
return retval;

Expand Down
2 changes: 1 addition & 1 deletion Source/src/WixSharp/DigitalSignatureBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DigitalSignatureBootstrapper : DigitalSignature
public override int Apply(string bootstrapperFileToSign)
{
var retValue = CommonTasks.Tasks.DigitalySignBootstrapper(bootstrapperFileToSign, PfxFilePath, TimeUrl?.AbsoluteUri, Password,
PrepareOptionalArguments(), WellKnownLocations, UseCertificateStore, OutputLevel, HashAlgorithm);
PrepareOptionalArguments(), WellKnownLocations, CertificateStore, OutputLevel, HashAlgorithm);
Console.WriteLine(retValue != 0
? $"Could not sign the {bootstrapperFileToSign} Bootstrapper file."
: $"The Bootstrapper file {bootstrapperFileToSign} was signed successfully.");
Expand Down

0 comments on commit e2d541f

Please sign in to comment.