Skip to content

Commit e877f5c

Browse files
Fix/tweak CI Files (#9)
* Re-add missing CI files * Tweak AzureAuth build options
1 parent 6bd0c50 commit e877f5c

File tree

10 files changed

+622
-3
lines changed

10 files changed

+622
-3
lines changed

bin/azureauth.cmd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
:: Copyright (c) Microsoft Corporation.
2+
:: Licensed under the MIT License.
3+
4+
@ECHO OFF
5+
CALL dotnet run --project src\AzureAuth -- %* --debug
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
import json
5+
import os
6+
import glob
7+
import pprint
8+
import subprocess
9+
import sys
10+
from pathlib import Path
11+
12+
AAD_ID = os.environ['AZURE_AAD_ID']
13+
WORKSPACE = Path(os.environ["WORKSPACE"])
14+
TENANT_ID = os.environ['TENANT_ID']
15+
KEY_CODE = os.environ['KEY_CODE']
16+
17+
esrp_tool = os.path.join("esrp", "tools", "EsrpClient.exe")
18+
SOURCE = WORKSPACE / "osx-x64"
19+
DESTINATION = WORKSPACE
20+
21+
files = []
22+
extensions = [".dll"]
23+
for path in Path(SOURCE).iterdir():
24+
if path.suffix in extensions and path.is_file():
25+
files.append(path)
26+
27+
#empty list check
28+
if not files:
29+
sys.exit("Error: cannot find files to sign")
30+
31+
print(f"Found {len(files)} files:")
32+
pprint.pp(files)
33+
34+
files_to_sign = [os.path.basename(f) for f in files]
35+
36+
auth_json = {
37+
"Version": "1.0.0",
38+
"AuthenticationType": "AAD_CERT",
39+
"TenantId": TENANT_ID,
40+
"ClientId": AAD_ID,
41+
"AuthCert": {
42+
"SubjectName": f"CN={AAD_ID}.microsoft.com",
43+
"StoreLocation": "CurrentUser",
44+
"StoreName": "My",
45+
},
46+
"RequestSigningCert": {
47+
"SubjectName": f"CN={AAD_ID}",
48+
"StoreLocation": "CurrentUser",
49+
"StoreName": "My",
50+
}
51+
}
52+
53+
input_json = {
54+
"Version": "1.0.0",
55+
"SignBatches": [
56+
{
57+
"SourceLocationType": "UNC",
58+
"SourceRootDirectory": SOURCE,
59+
"DestinationLocationType": "UNC",
60+
"DestinationRootDirectory": DESTINATION,
61+
"SignRequestFiles": [
62+
{
63+
"CustomerCorrelationId": "01A7F55F-6CDD-4123-B255-77E6F212CDAD",
64+
"SourceLocation": f,
65+
"DestinationLocation": os.path.join("Mac_signed", f),
66+
}
67+
for f in files_to_sign
68+
],
69+
"SigningInfo": {
70+
"Operations": [
71+
{
72+
"KeyCode": KEY_CODE,
73+
"OperationCode": "SigntoolSign",
74+
"Parameters" : {
75+
"OpusName" : "Microsoft",
76+
"OpusInfo" : "http://www.microsoft.com",
77+
"FileDigest" : "/fd \"SHA256\"",
78+
"PageHash" : "/NPH",
79+
"TimeStamp" : "/tr \"http://rfc3161.gtm.corp.microsoft.com/TSS/HttpTspServer\" /td sha256"
80+
},
81+
"ToolName": "sign",
82+
"ToolVersion": "1.0",
83+
},
84+
{
85+
"KeyCode" : KEY_CODE,
86+
"OperationCode" : "SigntoolVerify",
87+
"Parameters" : {},
88+
"ToolName" : "sign",
89+
"ToolVersion" : "1.0"
90+
}
91+
]
92+
}
93+
}
94+
]
95+
}
96+
97+
policy_json = {
98+
"Version": "1.0.0",
99+
"Intent": "production release",
100+
"ContentType": "Signed Binaries",
101+
}
102+
103+
configs = [
104+
("auth.json", auth_json),
105+
("input.json", input_json),
106+
("policy.json", policy_json),
107+
]
108+
109+
for filename, data in configs:
110+
with open(filename, 'w') as fp:
111+
json.dump(data, fp)
112+
113+
# Run ESRP Client
114+
esrp_out = "esrp_out.json"
115+
result = subprocess.run(
116+
[esrp_tool, "sign",
117+
"-a", "auth.json",
118+
"-i", "input.json",
119+
"-p", "policy.json",
120+
"-o", esrp_out,
121+
"-l", "Verbose"],
122+
cwd=WORKSPACE)
123+
124+
if result.returncode != 0:
125+
sys.exit("Failed to run ESRPClient.exe")
126+
127+
if os.path.isfile(esrp_out):
128+
print("ESRP output json:")
129+
with open(esrp_out, 'r') as fp:
130+
pprint.pp(json.load(fp))
131+
132+
signed_files_location = os.path.join(DESTINATION, "Mac_signed")
133+
134+
signed_files = glob.glob(signed_files_location + '**/*')
135+
signed_files = [f for f in signed_files if os.path.isfile(f)]
136+
137+
if not signed_files:
138+
sys.exit("Error: no signed files found")
139+
140+
print(f"Signed {len(signed_files)} files:")
141+
pprint.pp(signed_files)
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
import json
5+
import os
6+
import glob
7+
import pprint
8+
import subprocess
9+
import sys
10+
from pathlib import Path
11+
import zipfile
12+
13+
AAD_ID = os.environ['AZURE_AAD_ID']
14+
WORKSPACE = Path(os.environ["WORKSPACE"])
15+
TENANT_ID = os.environ['TENANT_ID']
16+
KEY_CODE = os.environ['KEY_CODE']
17+
18+
esrp_tool = os.path.join("esrp", "tools", "EsrpClient.exe")
19+
SOURCE = WORKSPACE / "osx-x64"
20+
DESTINATION = WORKSPACE / "Mac_signed"
21+
22+
zip_file = SOURCE / "mac_dylibs.zip"
23+
extensions = [".dylib",".a",".Cli"]
24+
25+
# zipping the files
26+
with zipfile.ZipFile(zip_file, 'w', zipfile.ZIP_DEFLATED) as zip_obj:
27+
for path in Path(SOURCE).iterdir():
28+
if path.suffix in extensions and path.is_file():
29+
zip_obj.write(path, path.relative_to(SOURCE))
30+
31+
if not zip_file.exists():
32+
sys.exit("Error: cannot find file to sign")
33+
else:
34+
print(f"Found file: {zip_file}")
35+
36+
37+
auth_json = {
38+
"Version": "1.0.0",
39+
"AuthenticationType": "AAD_CERT",
40+
"TenantId": TENANT_ID,
41+
"ClientId": AAD_ID,
42+
"AuthCert": {
43+
"SubjectName": f"CN={AAD_ID}.microsoft.com",
44+
"StoreLocation": "CurrentUser",
45+
"StoreName": "My",
46+
},
47+
"RequestSigningCert": {
48+
"SubjectName": f"CN={AAD_ID}",
49+
"StoreLocation": "CurrentUser",
50+
"StoreName": "My",
51+
}
52+
}
53+
54+
input_json = {
55+
"Version": "1.0.0",
56+
"SignBatches": [
57+
{
58+
"SourceLocationType": "UNC",
59+
"SourceRootDirectory": SOURCE,
60+
"DestinationLocationType": "UNC",
61+
"DestinationRootDirectory": DESTINATION,
62+
"SignRequestFiles": [
63+
{
64+
"CustomerCorrelationId": "01A7F55F-6CDD-4123-B255-77E6F212CDAD",
65+
"SourceLocation": str(zip_file),
66+
"DestinationLocation": str(DESTINATION / "mac_dylibs.zip"),
67+
}
68+
],
69+
"SigningInfo": {
70+
"Operations": [
71+
{
72+
"KeyCode": KEY_CODE,
73+
"OperationCode": "MacAppDeveloperSign",
74+
"Parameters" : {
75+
"OpusName" : "Microsoft",
76+
"OpusInfo" : "http://www.microsoft.com",
77+
"FileDigest" : "/fd \"SHA256\"",
78+
"PageHash" : "/NPH",
79+
"TimeStamp" : "/tr \"http://rfc3161.gtm.corp.microsoft.com/TSS/HttpTspServer\" /td sha256"
80+
},
81+
"ToolName": "sign",
82+
"ToolVersion": "1.0",
83+
}
84+
]
85+
86+
}
87+
}
88+
]
89+
}
90+
91+
policy_json = {
92+
"Version": "1.0.0",
93+
"Intent": "production release",
94+
"ContentType": "Signed Binaries",
95+
}
96+
97+
configs = [
98+
("auth.json", auth_json),
99+
("input.json", input_json),
100+
("policy.json", policy_json),
101+
]
102+
103+
for filename, data in configs:
104+
with open(filename, 'w') as fp:
105+
json.dump(data, fp)
106+
107+
# Run ESRP Client
108+
esrp_out = "esrp_out.json"
109+
result = subprocess.run(
110+
[esrp_tool, "sign",
111+
"-a", "auth.json",
112+
"-i", "input.json",
113+
"-p", "policy.json",
114+
"-o", esrp_out,
115+
"-l", "Verbose"],
116+
cwd=WORKSPACE)
117+
118+
if result.returncode != 0:
119+
sys.exit("Failed to run ESRPClient.exe")
120+
121+
if os.path.isfile(esrp_out):
122+
print("ESRP output json:")
123+
with open(esrp_out, 'r') as fp:
124+
pprint.pp(json.load(fp))
125+
126+
signed_zip_file = os.path.join(DESTINATION, "mac_dylibs.zip")
127+
128+
if not signed_zip_file:
129+
sys.exit("Error: no signed file found")
130+
else:
131+
print(f"The Zipped file with signed binaries: {signed_zip_file}")
132+
133+
#Extracting all the signed file and removing the zip file to cleanup temporary files
134+
with zipfile.ZipFile(signed_zip_file, 'r') as zipObj:
135+
zipObj.extractall(DESTINATION)
136+
137+
signed_zip_file.unlink()
138+
139+
#list of signed files
140+
signed_binaries = [f for f in DESTINATION if os.path.isfile(f)]
141+
142+
if not signed_binaries:
143+
sys.exit("Error: no signed files found")
144+
145+
print(f"Signed {len(signed_binaries)} files:")
146+
pprint.pp(signed_binaries)

bin/package.cmd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
:: Copyright (c) Microsoft Corporation.
2+
:: Licensed under the MIT License.
3+
4+
@ECHO OFF
5+
python ci\package.py AzureAuth Microsoft.Authentication.AzureAuth win10-x64

bin/package.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
import sys
5+
import os
6+
import shutil
7+
from subprocess import run
8+
from versioning import get_version, print_header
9+
10+
WIN_RID = "win10-x64"
11+
OSX_RID = "osx-x64"
12+
13+
14+
def generate_nuspec(nuspec: str, gen_nuspec: str, id: str, rid: str) -> None:
15+
with open(nuspec, 'r', encoding='utf-8') as in_f:
16+
nuspec_content = in_f.read()
17+
18+
nuspec_content = nuspec_content \
19+
.replace('<id></id>', f"<id>{id}</id>") \
20+
.replace('<!--insert-dist-->', f'<file src="dist\\{rid}\\" target="dist\\{rid}\\" />')
21+
22+
print(f"Generating nuspec to use at '{gen_nuspec}'", flush=True)
23+
with open(gen_nuspec, 'w', encoding='utf-8') as out_f:
24+
out_f.write(nuspec_content)
25+
26+
27+
def package_up(project: str, nuspec: str, package_name: str, rid: str) -> int:
28+
id = f"{package_name}.{rid}"
29+
version = get_version()
30+
print_header(f"\nPackaging {id} @ {version}")
31+
32+
gen_nuspec = os.path.join(project, f"{project}.gen.{rid}.nuspec")
33+
generate_nuspec(nuspec, gen_nuspec, id, rid)
34+
result = run(["nuget", "pack", gen_nuspec, "-NoPackageAnalysis", "-Version", version],
35+
stdout=sys.stdout, stderr=sys.stderr)
36+
37+
os.remove(gen_nuspec)
38+
39+
return result.returncode == 0
40+
41+
42+
def main():
43+
if len(sys.argv) < 4:
44+
print(
45+
f"Error: Usage: {sys.argv[0]} CSPROJ_FOLDER PACKAGE_NAME_BASE RUNTIME")
46+
sys.exit(1)
47+
48+
project = sys.argv[1].strip()
49+
package_name = sys.argv[2].strip()
50+
runtime = sys.argv[3].strip()
51+
52+
nuspec = os.path.join(project, f"{project}.template.nuspec")
53+
54+
if package_up(project, nuspec, package_name, runtime):
55+
return 0
56+
else:
57+
return 1
58+
59+
60+
if __name__ == "__main__":
61+
exit(main())

bin/publish.cmd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
:: Copyright (c) Microsoft Corporation.
2+
:: Licensed under the MIT License.
3+
4+
@ECHO OFF
5+
python ci\publish.py AzureAuth win10-x64

0 commit comments

Comments
 (0)