1+ import argparse
12import json
23import os
34import glob
67import sys
78import re
89
10+ parser = argparse .ArgumentParser (description = 'Sign binaries for Windows, macOS, and Linux' )
11+ parser .add_argument ('path' , help = 'Path to file for signing' )
12+ parser .add_argument ('keycode' , help = 'Platform-specific key code for signing' )
13+ parser .add_argument ('opcode' , help = 'Platform-specific operation code for signing' )
14+ # Setting nargs=argparse.REMAINDER allows us to pass in params that begin with `--`
15+ parser .add_argument ('--params' , nargs = argparse .REMAINDER , help = 'Parameters for signing' )
16+ args = parser .parse_args ()
17+
918esrp_tool = os .path .join ("esrp" , "tools" , "EsrpClient.exe" )
1019
1120aad_id = os .environ ['AZURE_AAD_ID' ].strip ()
21+ # We temporarily need two AAD IDs, as we're using an SSL certificate associated
22+ # with an older App Registration until we have the required hardware to approve
23+ # the new certificate in SSL Admin.
24+ aad_id_ssl = os .environ ['AZURE_AAD_ID_SSL' ].strip ()
1225workspace = os .environ ['GITHUB_WORKSPACE' ].strip ()
1326
14- source_root_location = os .path .join (workspace , "deb" , "Release" )
15- destination_location = os .path .join (workspace )
16-
17- files = glob .glob (os .path .join (source_root_location , "*.deb" ))
27+ source_location = args .path
28+ files = glob .glob (os .path .join (source_location , "*" ))
1829
1930print ("Found files:" )
2031pprint .pp (files )
2132
22- if len (files ) < 1 or not files [0 ].endswith (".deb" ):
23- print ("Error: cannot find .deb to sign" )
24- exit (1 )
25-
26- file_to_sign = os .path .basename (files [0 ])
27-
2833auth_json = {
29- "Version" : "1.0.0" ,
30- "AuthenticationType" : "AAD_CERT" ,
31- "TenantId" : "72f988bf-86f1-41af-91ab-2d7cd011db47" ,
32- "ClientId" : aad_id ,
33- "AuthCert" : {
34- "SubjectName" : f"CN={ aad_id } .microsoft.com" ,
35- "StoreLocation" : "LocalMachine" ,
36- "StoreName" : "My" ,
37- },
38- "RequestSigningCert" : {
39- "SubjectName" : f"CN={ aad_id } " ,
40- "StoreLocation" : "LocalMachine" ,
41- "StoreName" : "My" ,
42- }
34+ "Version" : "1.0.0" ,
35+ "AuthenticationType" : "AAD_CERT" ,
36+ "TenantId" : "72f988bf-86f1-41af-91ab-2d7cd011db47" ,
37+ "ClientId" : f" { aad_id } " ,
38+ "AuthCert" : {
39+ "SubjectName" : f"CN={ aad_id_ssl } .microsoft.com" ,
40+ "StoreLocation" : "LocalMachine" ,
41+ "StoreName" : "My"
42+ },
43+ "RequestSigningCert" : {
44+ "SubjectName" : f"CN={ aad_id } " ,
45+ "StoreLocation" : "LocalMachine" ,
46+ "StoreName" : "My"
47+ }
4348}
4449
4550input_json = {
4651 "Version" : "1.0.0" ,
4752 "SignBatches" : [
4853 {
4954 "SourceLocationType" : "UNC" ,
50- "SourceRootDirectory" : source_root_location ,
55+ "SourceRootDirectory" : source_location ,
5156 "DestinationLocationType" : "UNC" ,
52- "DestinationRootDirectory" : destination_location ,
53- "SignRequestFiles" : [
54- {
55- "CustomerCorrelationId" : "01A7F55F-6CDD-4123-B255-77E6F212CDAD" ,
56- "SourceLocation" : file_to_sign ,
57- "DestinationLocation" : os .path .join ("Signed" , file_to_sign ),
58- }
59- ],
57+ "DestinationRootDirectory" : workspace ,
58+ "SignRequestFiles" : [],
6059 "SigningInfo" : {
6160 "Operations" : [
6261 {
63- "KeyCode" : "CP-450779-Pgp " ,
64- "OperationCode" : "LinuxSign " ,
62+ "KeyCode" : f" { args . keycode } " ,
63+ "OperationCode" : f" { args . opcode } " ,
6564 "Parameters" : {},
6665 "ToolName" : "sign" ,
6766 "ToolVersion" : "1.0" ,
7271 ]
7372}
7473
74+ # add files to sign
75+ for f in files :
76+ name = os .path .basename (f )
77+ input_json ["SignBatches" ][0 ]["SignRequestFiles" ].append (
78+ {
79+ "SourceLocation" : name ,
80+ "DestinationLocation" : os .path .join ("signed" , name ),
81+ }
82+ )
83+
84+ # add parameters to input.json (e.g. enabling the hardened runtime for macOS)
85+ if args .params is not None :
86+ i = 0
87+ while i < len (args .params ):
88+ input_json ["SignBatches" ][0 ]["SigningInfo" ]["Operations" ][0 ]["Parameters" ][args .params [i ]] = args .params [i + 1 ]
89+ i += 2
90+
7591policy_json = {
7692 "Version" : "1.0.0" ,
7793 "Intent" : "production release" ,
78- "ContentType" : "Debian package " ,
94+ "ContentType" : "binary " ,
7995}
8096
8197configs = [
106122 '***' ,
107123 result .stdout ,
108124 flags = re .IGNORECASE | re .MULTILINE )
109- printf (log )
125+ print (log )
110126
111127if result .returncode != 0 :
112128 print ("Failed to run ESRPClient.exe" )
117133 with open (esrp_out , 'r' ) as fp :
118134 pprint .pp (json .load (fp ))
119135
120- signed_file = os . path . join ( destination_location , "Signed" , file_to_sign )
121- if os .path .isfile (signed_file ):
122- print (f"Success!\n Signed { signed_file } " )
136+ for file in files :
137+ if os .path .isfile (os . path . join ( "signed" , file ) ):
138+ print (f"Success!\n Signed { file } " )
0 commit comments