bool RunSignTool(string args, string inputFile, HashMode hashMode, RSA rsaPrivateKey, X509Certificate2 publicCertificate, string timestampUrl) { // Append a sha256 signature using (var signtool = new Process { StartInfo = { FileName = magetoolPath, UseShellExecute = false, RedirectStandardError = false, RedirectStandardOutput = false, Arguments = args } }) { logger.LogInformation("Signing {fileName}", signtool.StartInfo.FileName); signtool.Start(); if (!signtool.WaitForExit(30 * 1000)) { logger.LogError("Error: Mage took too long to respond {exitCode}", signtool.ExitCode); try { signtool.Kill(); } catch (Exception ex) { throw new Exception("Mage timed out and could not be killed", ex); } logger.LogError("Error: Mage took too long to respond {exitCode}", signtool.ExitCode); throw new Exception($"Mage took too long to respond"); } if (signtool.ExitCode == 0) { // Now add the signature ManifestSigner.SignFile(inputFile, hashMode, rsaPrivateKey, publicCertificate, timestampUrl); return(true); } logger.LogError("Error: Signtool returned {exitCode}", signtool.ExitCode); return(false); } }
bool RunSignTool(string args, string inputFile, HashMode hashMode, RSA rsaPrivateKey, X509Certificate2 publicCertificate, string timestampUrl) { // Append a sha256 signature using (var signtool = new Process { StartInfo = { FileName = magetoolPath, UseShellExecute = false, CreateNoWindow = true, RedirectStandardError = true, RedirectStandardOutput = true, Arguments = args } }) { var startTime = DateTimeOffset.UtcNow; var stopwatch = Stopwatch.StartNew(); logger.LogInformation("Signing {fileName}", signtool.StartInfo.FileName); signtool.Start(); var output = signtool.StandardOutput.ReadToEnd(); var error = signtool.StandardError.ReadToEnd(); logger.LogInformation("Mage Out {MageOutput}", output); if (!string.IsNullOrWhiteSpace(error)) { logger.LogInformation("Mage Err {MageError}", error); } if (!signtool.WaitForExit(30 * 1000)) { logger.LogError("Error: Mage took too long to respond {exitCode}", signtool.ExitCode); try { signtool.Kill(); } catch (Exception ex) { throw new Exception("Mage timed out and could not be killed", ex); } logger.LogError("Error: Mage took too long to respond {exitCode}", signtool.ExitCode); throw new Exception($"Mage took too long to respond"); } if (signtool.ExitCode == 0) { // Now add the signature ManifestSigner.SignFile(inputFile, hashMode, rsaPrivateKey, publicCertificate, timestampUrl); telemetryLogger.TrackSignToolDependency(signToolName, inputFile, startTime, stopwatch.Elapsed, null, signtool.ExitCode); return(true); } telemetryLogger.TrackSignToolDependency(signToolName, inputFile, startTime, stopwatch.Elapsed, null, signtool.ExitCode); logger.LogError("Error: Signtool returned {exitCode}", signtool.ExitCode); return(false); } }