1- using System ;
2- using System . IO ;
3- using System . Text . Json ;
4-
5- namespace SignToolGUI . Class
6- {
7- internal sealed class SignerTrustedSigning : SignerBase
8- {
9- public string DlibPath { get ; set ; }
10- public string DmdfPath { get ; set ; }
11-
12- private readonly string _timestampServer ; // Always "http://timestamp.acs.microsoft.com"
13- private readonly string _codeSigningAccountName ;
14- private readonly string _certificateProfileName ;
15- private readonly string _correlationIdData ;
16- private readonly string _endpointServer ; // Regional Azure endpoint for signing
17-
18- public SignerTrustedSigning ( string executable , string timestampServer , string dlibPath , string codeSigningAccountName , string certificateProfileName , string correlationIdData , string endpointServer , TimestampManager timestampManager = null )
19- : base ( executable , timestampManager )
20- {
21- _timestampServer = timestampServer ; // Should always be "http://timestamp.acs.microsoft.com"
22- DlibPath = dlibPath ;
23- _codeSigningAccountName = codeSigningAccountName ;
24- _certificateProfileName = certificateProfileName ;
25- _correlationIdData = correlationIdData ;
26- _endpointServer = endpointServer ; // Regional endpoint from TimestampManager
27- DmdfPath = CreateTempJsonFile ( ) ;
28- }
29-
30- // Destructor to clean up the temporary JSON file
31- ~ SignerTrustedSigning ( )
32- {
33- try
34- {
35- if ( ! string . IsNullOrEmpty ( DmdfPath ) && File . Exists ( DmdfPath ) )
36- {
37- File . Delete ( DmdfPath ) ;
38- }
39- }
40- catch ( Exception )
41- {
42- // Ignore exceptions during cleanup
43- }
44- }
45-
46- private string CreateTempJsonFile ( )
47- {
48- // Create a JSON file with the required parameters
49- var jsonContent = new
50- {
51- Endpoint = _endpointServer , // Use the regional endpoint here
52- CodeSigningAccountName = _codeSigningAccountName ,
53- CertificateProfileName = _certificateProfileName ,
54- CorrelationIdData = _correlationIdData
55- // You can add "CorrelationId" here if needed
56- } ;
57-
58- // Serialize the JSON content
59- var options = new JsonSerializerOptions
60- {
61- WriteIndented = true // This will format the JSON with indentation and new lines
62- } ;
63-
64- // Create a temporary file with the JSON content
65- string tempFilePath = Path . GetTempFileName ( ) ;
66- string jsonFilePath = Path . ChangeExtension ( tempFilePath , ".json" ) ;
67-
68- // Write the JSON content to the file
69- File . WriteAllText ( jsonFilePath , JsonSerializer . Serialize ( jsonContent , options ) ) ;
70-
71- // Return the path to the JSON file
72- return jsonFilePath ;
73- }
74-
75- protected override string BuildSigningArguments ( string targetAssembly , string timestampUrl = null )
76- {
77- // Check if the Dlib path is set
78- if ( string . IsNullOrEmpty ( DlibPath ) )
79- {
80- throw new InvalidOperationException ( "Dlib path is not set!" ) ;
81- }
82-
83- // Check if the Dlib file exists
84- if ( ! File . Exists ( DlibPath ) )
85- {
86- throw new InvalidOperationException ( $ "Dlib file not found at: { DlibPath } ") ;
87- }
88-
89- // Check if the Dmdf path is set
90- if ( string . IsNullOrEmpty ( DmdfPath ) )
91- {
92- throw new InvalidOperationException ( "Dmdf path is not set!" ) ;
93- }
94-
95- // Check if the Dmdf file exists
96- if ( ! File . Exists ( DmdfPath ) )
97- {
98- throw new InvalidOperationException ( $ "Dmdf file not found at: { DmdfPath } ") ;
99- }
100-
101- // For Trusted Signing, always use the fixed timestamp server
102- // The timestampUrl parameter is ignored because Trusted Signing uses a fixed timestamp URL
103- var arguments = $@ "sign { GlobalOptionSwitches ( ) } /fd sha256 /tr ""{ _timestampServer } "" /td sha256 /dlib ""{ DlibPath } "" /dmdf ""{ DmdfPath } "" ""{ targetAssembly } """;
104-
105- return arguments;
106- }
107-
108- // Override the base method to handle endpoint switching for Trusted Signing
109- public void UpdateEndpoint(string newEndpoint)
110- {
111- // Recreate the JSON file with the new endpoint
112- var jsonContent = new
113- {
114- Endpoint = newEndpoint ,
115- CodeSigningAccountName = _codeSigningAccountName ,
116- CertificateProfileName = _certificateProfileName ,
117- CorrelationIdData = _correlationIdData
118- } ;
119-
120- var options = new JsonSerializerOptions
121- {
122- WriteIndented = true
123- } ;
124-
125- // Delete old file if it exists
126- if ( ! string . IsNullOrEmpty ( DmdfPath ) && File . Exists ( DmdfPath ) )
127- {
128- File . Delete ( DmdfPath ) ;
129- }
130-
131- // Create new JSON file with updated endpoint
132- string tempFilePath = Path . GetTempFileName ( ) ;
133- string jsonFilePath = Path. ChangeExtension ( tempFilePath , ".json" ) ;
1+ using System ;
2+ using System . IO ;
3+ using System . Text . Json ;
4+
5+ namespace SignToolGUI . Class
6+ {
7+ internal sealed class SignerTrustedSigning : SignerBase
8+ {
9+ public string DlibPath { get ; set ; }
10+ public string DmdfPath { get ; set ; }
11+
12+ private readonly string _timestampServer ; // Always "http://timestamp.acs.microsoft.com"
13+ private readonly string _codeSigningAccountName ;
14+ private readonly string _certificateProfileName ;
15+ private readonly string _correlationIdData ;
16+ private readonly string _endpointServer ; // Regional Azure endpoint for signing
17+
18+ public SignerTrustedSigning ( string executable , string timestampServer , string dlibPath , string codeSigningAccountName , string certificateProfileName , string correlationIdData , string endpointServer , TimestampManager timestampManager = null )
19+ : base ( executable , timestampManager )
20+ {
21+ _timestampServer = timestampServer ; // Should always be "http://timestamp.acs.microsoft.com"
22+ DlibPath = dlibPath ;
23+ _codeSigningAccountName = codeSigningAccountName ;
24+ _certificateProfileName = certificateProfileName ;
25+ _correlationIdData = correlationIdData ;
26+ _endpointServer = endpointServer ; // Regional endpoint from TimestampManager
27+ DmdfPath = CreateTempJsonFile ( ) ;
28+ }
29+
30+ // Destructor to clean up the temporary JSON file
31+ ~ SignerTrustedSigning ( )
32+ {
33+ try
34+ {
35+ if ( ! string . IsNullOrEmpty ( DmdfPath ) && File . Exists ( DmdfPath ) )
36+ {
37+ File . Delete ( DmdfPath ) ;
38+ }
39+ }
40+ catch ( Exception )
41+ {
42+ // Ignore exceptions during cleanup
43+ }
44+ }
45+
46+ private string CreateTempJsonFile ( )
47+ {
48+ // Create a JSON file with the required parameters
49+ var jsonContent = new
50+ {
51+ Endpoint = _endpointServer , // Use the regional endpoint here
52+ CodeSigningAccountName = _codeSigningAccountName ,
53+ CertificateProfileName = _certificateProfileName ,
54+ CorrelationIdData = _correlationIdData
55+ // You can add "CorrelationId" here if needed
56+ } ;
57+
58+ // Serialize the JSON content
59+ var options = new JsonSerializerOptions
60+ {
61+ WriteIndented = true // This will format the JSON with indentation and new lines
62+ } ;
63+
64+ // Create a temporary file with the JSON content
65+ string tempFilePath = Path . GetTempFileName ( ) ;
66+ string jsonFilePath = Path . ChangeExtension ( tempFilePath , ".json" ) ;
67+
68+ // Write the JSON content to the file
69+ File . WriteAllText ( jsonFilePath , JsonSerializer . Serialize ( jsonContent , options ) ) ;
70+
71+ // Return the path to the JSON file
72+ return jsonFilePath ;
73+ }
74+
75+ protected override string BuildSigningArguments ( string targetAssembly , string timestampUrl = null )
76+ {
77+ // Check if the Dlib path is set
78+ if ( string . IsNullOrEmpty ( DlibPath ) )
79+ {
80+ throw new InvalidOperationException ( "Dlib path is not set!" ) ;
81+ }
82+
83+ // Check if the Dlib file exists
84+ if ( ! File . Exists ( DlibPath ) )
85+ {
86+ throw new InvalidOperationException ( $ "Dlib file not found at: { DlibPath } ") ;
87+ }
88+
89+ // Check if the Dmdf path is set
90+ if ( string . IsNullOrEmpty ( DmdfPath ) )
91+ {
92+ throw new InvalidOperationException ( "Dmdf path is not set!" ) ;
93+ }
94+
95+ // Check if the Dmdf file exists
96+ if ( ! File . Exists ( DmdfPath ) )
97+ {
98+ throw new InvalidOperationException ( $ "Dmdf file not found at: { DmdfPath } ") ;
99+ }
100+
101+ // For Trusted Signing, always use the fixed timestamp server
102+ // The timestampUrl parameter is ignored because Trusted Signing uses a fixed timestamp URL
103+ var arguments = $@ "sign { GlobalOptionSwitches ( ) } /fd sha256 /tr ""{ _timestampServer } "" /td sha256 /dlib ""{ DlibPath } "" /dmdf ""{ DmdfPath } "" ""{ targetAssembly } """;
104+
105+ return arguments;
106+ }
107+
108+ // Override the base method to handle endpoint switching for Trusted Signing
109+ public void UpdateEndpoint(string newEndpoint)
110+ {
111+ // Recreate the JSON file with the new endpoint
112+ var jsonContent = new
113+ {
114+ Endpoint = newEndpoint ,
115+ CodeSigningAccountName = _codeSigningAccountName ,
116+ CertificateProfileName = _certificateProfileName ,
117+ CorrelationIdData = _correlationIdData
118+ } ;
119+
120+ var options = new JsonSerializerOptions
121+ {
122+ WriteIndented = true
123+ } ;
124+
125+ // Delete old file if it exists
126+ if ( ! string . IsNullOrEmpty ( DmdfPath ) && File . Exists ( DmdfPath ) )
127+ {
128+ File . Delete ( DmdfPath ) ;
129+ }
130+
131+ // Create new JSON file with updated endpoint
132+ string tempFilePath = Path . GetTempFileName ( ) ;
133+ string jsonFilePath = Path. ChangeExtension ( tempFilePath , ".json" ) ;
134134 File. WriteAllText ( jsonFilePath , JsonSerializer . Serialize ( jsonContent , options ) ) ;
135135
136- DmdfPath = jsonFilePath;
137- }
138- }
136+ DmdfPath = jsonFilePath;
137+ }
138+ }
139139}
0 commit comments