[gacutil] Use IKVM.Reflection instead of System.Reflection (#3582)
[mono.git] / mcs / tools / security / TESTS
1 Mono's Security Tools - TESTS
2 Last updated: August 17, 2006
3
4 -------------------------------------------------------------------------------
5
6 * AUTHENTICODE
7
8 Here's a short description on how to test any changes in the Authenticode tool
9 set. This set includes makecert, cert2spc, signcode and chktrust.
10
11 This is a _minimal_ sequence. Each input/output could be tested under Linux 
12 and Windows to ensure maximum compatibility.
13
14
15 0. Setup
16
17         % cd /mcs/tools/security
18         % make
19         % mono setreg.exe 1 TRUE
20         % cp signcode.exe test.exe
21
22 1. Create a test certificate for code-signing
23
24         % mono makecert.exe -n "CN=careful tester" -sv test.pvk test.cer
25
26         Mono MakeCert - version 1.1.15.0
27         X.509 Certificate Builder
28         Copyright 2002, 2003 Motus Technologies. Copyright 2004-2006 Novell. BSD licensed.
29  
30         Success
31
32 2. Convert the test certificate to the SPC format
33
34         % mono cert2spc.exe test.cer test.spc
35
36         Mono Cert2Spc - version 1.1.15.0
37         Transform a set of X.509 certificates and CRLs into an Authenticode(TM) "Software Publisher Certificate"
38         Copyright 2002, 2003 Motus Technologies. Copyright 2004-2006 Novell. BSD licensed.
39  
40         Success
41
42 3. Sign a PE binary (without a timestamp)
43
44         % mono signcode.exe -v test.pvk -spc test.spc test.exe
45
46         Mono SignCode - version 1.1.15.0
47         Sign assemblies and PE files using Authenticode(tm).
48         Copyright 2002, 2003 Motus Technologies. Copyright 2004-2006 Novell. BSD licensed.
49
50         Success
51
52 4. Verify the binary from step 3
53
54         % mono chktrust.exe test.exe
55
56         Mono CheckTrust - version 1.1.15.0
57         Verify if an PE executable has a valid Authenticode(tm) signature
58         Copyright 2002, 2003 Motus Technologies. Copyright 2004-2006 Novell. BSD licensed.
59  
60         WARNING! test.exe is not timestamped!
61         SUCCESS: test.exe signature is valid
62         and can be traced back to a trusted root!
63
64         *** note the warning about the missing timestamp ***
65
66 5. Verify the binary from step 3 using MS tools [1]
67
68         a. Using Windows Explorer, right click on the test.exe file and select
69         the "Properties" menu item;
70         b. From the "test.exe Properties" windows select the "Digital 
71         Signatures" tab;
72         c. You should see "careful tester" as the "Name of signer", select it
73         and click on the "Details" button;
74         d. Unless you have created your test certificate with MS tools you 
75         should see an error (white X on a red circle) with a description 
76         saying "The certificate in the signature cannot be verified.";
77         e. You should NOT see any countersignature;
78
79 6. Add a timestamp the binary from step 3
80
81         % mono signcode.exe -x -t http://timestamp.verisign.com/scripts/timstamp.dll test.exe
82
83         Mono SignCode - version 1.1.15.0
84         Sign assemblies and PE files using Authenticode(tm).
85         Copyright 2002, 2003 Motus Technologies. Copyright 2004-2006 Novell. BSD licensed.
86  
87         Success
88
89 7. Verify the binary from step 6
90
91         % mono chktrust.exe test.exe
92
93         Mono CheckTrust - version 1.1.15.0
94         Verify if an PE executable has a valid Authenticode(tm) signature
95         Copyright 2002, 2003 Motus Technologies. Copyright 2004-2006 Novell. BSD licensed.
96  
97         SUCCESS: test.exe signature is valid
98         and can be traced back to a trusted root!
99
100         *** note that there is NO warning this time ***
101
102 8. Verify the binary from step 6 on Windows [1]
103
104         a. Follow step 5 from 'a' to 'd'
105         b. This time you should see a countersignature;
106
107 9. Sign a PE binary with a timestamp
108
109         % mono signcode.exe -v test.pvk -spc test.spc -t http://timestamp.verisign.com/scripts/timstamp.dll test.exe
110
111         Mono SignCode - version 1.1.15.0
112         Sign assemblies and PE files using Authenticode(tm).
113         Copyright 2002, 2003 Motus Technologies. Copyright 2004-2006 Novell. BSD licensed.
114  
115         Success
116
117 10. Verify the binary from step 9
118
119         % mono chktrust.exe test.exe
120
121         Mono CheckTrust - version 1.1.15.0
122         Verify if an PE executable has a valid Authenticode(tm) signature
123         Copyright 2002, 2003 Motus Technologies. Copyright 2004-2006 Novell. BSD licensed.
124  
125         SUCCESS: test.exe signature is valid
126         and can be traced back to a trusted root!
127
128 11. Verify the binary from step 9 on Windows [1]
129
130         a. Follow step 5 from 'a' to 'd'
131         b. This time you should see a countersignature;
132
133 12. Add (another) timestamp the binary from step 9
134
135         % mono signcode.exe -x -t http://timestamp.verisign.com/scripts/timstamp.dll test.exe
136
137         Mono SignCode - version 1.1.15.0
138         Sign assemblies and PE files using Authenticode(tm).
139         Copyright 2002, 2003 Motus Technologies. Copyright 2004-2006 Novell. BSD licensed.
140  
141         Success
142
143 13. Verify the binary from step 12
144
145         Mono CheckTrust - version 1.1.15.0
146         Verify if an PE executable has a valid Authenticode(tm) signature
147         Copyright 2002, 2003 Motus Technologies. Copyright 2004-2006 Novell. BSD licensed.
148  
149         SUCCESS: test.exe signature is valid
150         and can be traced back to a trusted root!
151
152 14. Verify the binary from step 12 on Windows [1]
153
154         a. Follow step 5 from 'a' to 'd'
155         b. This time you should see TWO (2) countersignature, the same one as
156         step 11 and a new one;
157
158 15. Clean up
159
160         % rm test.*
161         % mono setreg.exe 1 FALSE
162
163
164 [1] this step must be done on Windows using MS Authenticode(r) tools.
165
166 -------------------------------------------------------------------------------
167
168 * STRONGNAME
169
170 Here's a minimal test sequence for any change in SN source code (or in the 
171 RSA source code). If/when possible all verification should also be done using
172 the MS runtime and tools to ensure full interoperability.
173
174 0. Setup
175
176         % cd /mcs/tools/security
177         % make
178         % sudo make install
179         % echo "class Program { static void Main () { System.Console.WriteLine (\"hello world\"); } }" > tmp.cs
180         % mcs tmp.cs -out:tmp.exe
181         % sn -v tmp.exe
182
183         [...]
184         tmp.exe is not a strongly named assembly.
185
186
187 1. Create a SNK file (default size is 1024 bits)
188
189         % sn -k 1024.snk
190
191         [...]
192         A new 1024 bits strong name keypair has been generated in file '1024.snk'.
193
194         % mcs -delaysign+ -keyfile:1024.snk tmp.cs -out:tmp1024.exe
195         % sn -v tmp1024.exe
196
197         [...]
198         Assembly tmp1024.exe isn't strongnamed
199
200         % mcs -keyfile:1024.snk tmp.cs -out:tmp1024.exe
201         % sn -v tmp1024.exe
202
203         [...]
204         Assembly tmp1024.exe is strongnamed.
205
206
207 2. Create a large SNK file (supported by Fx 2.0 and later)
208
209         % sn -k 2048 2048.snk
210
211         [...]
212         A new 2048 bits strong name keypair has been generated in file '2048.snk'.
213
214         % mcs -delaysign+ -keyfile:2048.snk tmp.cs -out:tmp2048.exe
215         % sn -v tmp2048.exe
216
217         [...]
218         Assembly tmp2048.exe isn't strongnamed
219
220         % sn -R tmp2048.exe 2048.snk
221
222         [...]
223         Assembly tmp2048.exe signed.
224
225         % sn -v tmp2048.exe
226
227         [...]
228         Assembly tmp2048.exe is strongnamed.
229
230
231 3. Create a PFX (PKCS#12) file
232
233         % makecert -r -n "CN=mono" -p12 tmp.pfx mono
234
235         [...]
236         Success
237
238         % sn -p tmp.pfx tmp.pub
239
240         [...]
241         Enter password for private key (will be visible when typed): mono
242         Public Key extracted to file tmp.pub
243
244         % sn -tp tmp.pub
245
246         Public Key:
247         0024000004800000940000000602000000240000525341310004000011000000137d8a780901ce
248         3ceeb3aa9c813d9027d96e8be0cae633d0f64e584eb50685adb063b72fe3395f681ffda8a7c940
249         d0a8c76b1670c3a54cd354af82fe3995f6784a30c14a106d02f4150d0b370479a2cae574f4bce1
250         bf97a41e59f855a3d0062918861e55afacf9e4934365ea61718ba460dcb46143fee7278414a683
251         85336ace
252
253         Public Key Token: de950f189632e7d9
254
255         *** Note: your public won't match this one - but it will identical to
256         ***       the one we'll extract from the EXE in a few steps...
257
258         % mcs -delaysign+ -keyfile:tmp.pub tmp.cs -out:tmppfx.exe
259         % sn -R tmppfx.exe tmp.pfx
260
261         [...]
262         Enter password for private key (will be visible when typed): mono
263         Assembly tmppfx.exe signed.
264
265         % sn -v tmppfx.exe
266
267         [...]
268         Assembly tmppfx.exe is strongnamed.
269
270
271 4. Test using the "well known" files
272
273         % sn -tp ../../class/mono.snk
274
275         [...]
276
277         Public Key:
278         002400000480000094000000060200000024000052534131000400000100010079159977d2d03a
279         8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c
280         3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fd
281         dafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef00
282         65d016df
283
284         Public Key Token: 0738eb9f132ed756
285
286
287         % sn -Tp ../../class/lib/default/Mono.Security.dll
288
289         [...]
290
291         Public Key:
292         002400000480000094000000060200000024000052534131000400000100010079159977d2d03a
293         8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c
294         3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fd
295         dafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef00
296         65d016df
297
298         Public Key Token: 0738eb9f132ed756
299
300
301         % sn -p ../../class/mono.snk tmp.pub
302
303         [...]
304         Public Key extracted to file tmp.pub
305
306         % md5sum tmp.pub
307
308         b35461067e0e8e00941d68bd55e38582  tmp.pub
309
310
311         % sn -tp tmp.pub
312
313         [...]
314
315         Public Key:
316         002400000480000094000000060200000024000052534131000400000100010079159977d2d03a
317         8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c
318         3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fd
319         dafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef00
320         65d016df
321
322         Public Key Token: 0738eb9f132ed756
323
324
325 5. Cleanup
326
327         % rm tmp*.*
328
329 -------------------------------------------------------------------------------
330 Send any bug or suggestions to sebastien at ximian.com