Esempio n. 1
0
        private void ValidateGeneratedProject(
            string[] itemsToSign,
            Dictionary <string, SignInfo> strongNameSignInfo,
            Dictionary <ExplicitCertificateKey, string> fileSignInfo,
            Dictionary <string, SignInfo> extensionsSignInfo,
            string[] expectedXmlElementsPerSingingRound,
            string[] dualCertificates = null)
        {
            var buildEngine = new FakeBuildEngine();

            var task = new SignToolTask {
                BuildEngine = buildEngine
            };

            // The path to MSBuild will always be null in these tests, this will force
            // the signing logic to call our FakeBuildEngine.BuildProjectFile with a path
            // to the XML that store the content of the would be Microbuild sign request.
            var signToolArgs = new SignToolArgs(_tmpDir, microBuildCorePath: "MicroBuildCorePath", testSign: true, msBuildPath: null, _tmpDir, enclosingDir: "", "");

            var signTool     = new FakeSignTool(signToolArgs, task.Log);
            var signingInput = new Configuration(signToolArgs.TempDir, itemsToSign, strongNameSignInfo, fileSignInfo, extensionsSignInfo, dualCertificates, task.Log).GenerateListOfFiles();
            var util         = new BatchSignUtil(task.BuildEngine, task.Log, signTool, signingInput, new string[] { });

            util.Go(false);

            Assert.Same(ByteSequenceComparer.Instance, signingInput.ZipDataMap.KeyComparer);

            // The list of files that would be signed was captured inside the FakeBuildEngine,
            // here we check if that matches what we expected
            var actualXmlElementsPerSingingRound = buildEngine.FilesToSign.Select(round => string.Join(Environment.NewLine, round));

            AssertEx.Equal(expectedXmlElementsPerSingingRound, actualXmlElementsPerSingingRound, comparer: AssertEx.EqualIgnoringWhitespace, itemInspector: s => s.Replace("\"", "\"\""));

            Assert.False(task.Log.HasLoggedErrors);
        }
Esempio n. 2
0
        public SignToolTests()
        {
            _microbuildPath = string.Empty;
            _publishURL     = null;
            _testSign       = true;

            // As of now we don't have "mscoree.dll" on Linux. This DLL is used when checking
            // if the file is strong name signed: SignTool/ContentUtil.NativeMethods
            // Therefore, test cases won't execute in fully on non-Windows machines.
            _isWindows = System.Environment.OSVersion.VersionString.Contains("Windows");

            var testBasePath = Guid.NewGuid().ToString();
            var tempPath     = $@"{testBasePath}/TestTempDir/";
            var logDir       = $@"{testBasePath}/TestLogDir/";

            // The path to MSBuild will always be null in these tests, this will force
            // the signing logic to call our FakeBuildEngine.BuildProjectFile with a path
            // to the XML that store the content of the would be Microbuild sign request.
            _signToolArgs = new SignToolArgs(tempPath, _microbuildPath, _testSign, null, logDir);

            _signTool = new ValidationOnlySignTool(_signToolArgs);

            _task = new SignToolTask
            {
                BuildEngine = new FakeBuildEngine()
            };
        }
Esempio n. 3
0
        public static async Task RunAsync(BuildContext ctx)
        {
            var ap = ctx.GetArtifactPackage();

            var SignToolExePath = Path.Combine(
                ctx.ToolsDir,
                MagicStrings.Dirs.Cert,
                MagicStrings.Files.SignToolExe);

            bool signed   = false;
            int  tryCount = ctx.Config.TimestampUrls.Count;

            for (int tryNr = 0; tryNr < tryCount; ++tryNr)
            {
                var timestampUrl = ctx.Config.TimestampUrls[tryNr];
                var(certPass, SignToolArgs) = MakeSignToolArgs(ctx, timestampUrl);

                SignToolArgs += Path
                                .Combine(ctx.OutDir, ap.CanonicalTargetName,
                                         Path.GetFileNameWithoutExtension(ap.FileName) + MagicStrings.Ext.DotMsi)
                                .Quote();

                await Console.Out.WriteLineAsync(SignToolExePath + " ");

                await Console.Out.WriteLineAsync(SignToolArgs.Replace(certPass, "[redacted]"));

                try
                {
                    await Command.RunAsync(SignToolExePath, SignToolArgs, noEcho : true);

                    signed = true;
                    break;
                }
                catch (Exception /*ex*/)
                {
                    await Console.Out.WriteLineAsync(
                        $"Error: timestap server {timestampUrl} is unavailable, " +
                        $"{tryCount - tryNr - 1} server(s) left to try.");
                }
            }

            if (!signed)
            {
                throw new Exception("Error: None of the timestamp servers available.");
            }
        }