forked from MahApps/MahApps.Metro.IconPacks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sign.cake
141 lines (122 loc) · 5.18 KB
/
sign.cake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#module nuget:?package=Cake.DotNetTool.Module
#tool "dotnet:?package=NuGetKeyVaultSignTool&version=2.0.2"
#tool "dotnet:?package=AzureSignTool&version=2.0.17"
void SignFiles(IEnumerable<FilePath> files, string description, string repoUrl)
{
var vurl = EnvironmentVariable("azure-key-vault-url");
if(string.IsNullOrWhiteSpace(vurl)) {
Error("Could not resolve signing url.");
return;
}
var vcid = EnvironmentVariable("azure-key-vault-client-id");
if(string.IsNullOrWhiteSpace(vcid)) {
Error("Could not resolve signing client id.");
return;
}
var vcs = EnvironmentVariable("azure-key-vault-client-secret");
if(string.IsNullOrWhiteSpace(vcs)) {
Error("Could not resolve signing client secret.");
return;
}
var vc = EnvironmentVariable("azure-key-vault-certificate");
if(string.IsNullOrWhiteSpace(vc)) {
Error("Could not resolve signing certificate.");
return;
}
foreach(var file in files)
{
Information($"Sign file: {file}");
var processSettings = new ProcessSettings {
RedirectStandardOutput = true,
RedirectStandardError = true,
Arguments = new ProcessArgumentBuilder()
.Append("sign")
.Append(MakeAbsolute(file).FullPath)
.AppendSwitchQuoted("--file-digest", "sha256")
.AppendSwitchQuoted("--description", description)
.AppendSwitchQuoted("--description-url", repoUrl)
.Append("--no-page-hashing")
.AppendSwitchQuoted("--timestamp-rfc3161", "http://timestamp.digicert.com")
.AppendSwitchQuoted("--timestamp-digest", "sha256")
.AppendSwitchQuoted("--azure-key-vault-url", vurl)
.AppendSwitchQuotedSecret("--azure-key-vault-client-id", vcid)
.AppendSwitchQuotedSecret("--azure-key-vault-client-secret", vcs)
.AppendSwitchQuotedSecret("--azure-key-vault-certificate", vc)
};
using(var process = StartAndReturnProcess("tools/AzureSignTool", processSettings))
{
process.WaitForExit();
if (process.GetStandardOutput().Any())
{
Information($"Output:{Environment.NewLine}{string.Join(Environment.NewLine, process.GetStandardOutput())}");
}
if (process.GetStandardError().Any())
{
Information($"Errors occurred:{Environment.NewLine}{string.Join(Environment.NewLine, process.GetStandardError())}");
}
// This should output 0 as valid arguments supplied
Information("Exit code: {0}", process.GetExitCode());
}
}
}
void SignNuGet(string publishDir)
{
if (!DirectoryExists(Directory(publishDir)))
{
return;
}
var vurl = EnvironmentVariable("azure-key-vault-url");
if(string.IsNullOrWhiteSpace(vurl)) {
Error("Could not resolve signing url.");
return;
}
var vcid = EnvironmentVariable("azure-key-vault-client-id");
if(string.IsNullOrWhiteSpace(vcid)) {
Error("Could not resolve signing client id.");
return;
}
var vcs = EnvironmentVariable("azure-key-vault-client-secret");
if(string.IsNullOrWhiteSpace(vcs)) {
Error("Could not resolve signing client secret.");
return;
}
var vc = EnvironmentVariable("azure-key-vault-certificate");
if(string.IsNullOrWhiteSpace(vc)) {
Error("Could not resolve signing certificate.");
return;
}
var nugetFiles = GetFiles(publishDir + "/*.nupkg");
foreach(var file in nugetFiles)
{
Information($"Sign file: {file}");
var processSettings = new ProcessSettings {
RedirectStandardOutput = true,
RedirectStandardError = true,
Arguments = new ProcessArgumentBuilder()
.Append("sign")
.Append(MakeAbsolute(file).FullPath)
.Append("--force")
.AppendSwitchQuoted("--file-digest", "sha256")
.AppendSwitchQuoted("--timestamp-rfc3161", "http://timestamp.digicert.com")
.AppendSwitchQuoted("--timestamp-digest", "sha256")
.AppendSwitchQuoted("--azure-key-vault-url", vurl)
.AppendSwitchQuotedSecret("--azure-key-vault-client-id", vcid)
.AppendSwitchQuotedSecret("--azure-key-vault-client-secret", vcs)
.AppendSwitchQuotedSecret("--azure-key-vault-certificate", vc)
};
using(var process = StartAndReturnProcess("tools/NuGetKeyVaultSignTool", processSettings))
{
process.WaitForExit();
if (process.GetStandardOutput().Any())
{
Information($"Output:{Environment.NewLine}{string.Join(Environment.NewLine, process.GetStandardOutput())}");
}
if (process.GetStandardError().Any())
{
Information($"Errors occurred:{Environment.NewLine}{string.Join(Environment.NewLine, process.GetStandardError())}");
}
// This should output 0 as valid arguments supplied
Information("Exit code: {0}", process.GetExitCode());
}
}
}