2010-05-25 Jb Evain <jbevain@novell.com>
[mcs.git] / tools / security / TESTS
blob121e9364bfc2cdcfc4610f3d0e385dc500c021aa
1 Mono's Security Tools - TESTS
2 Last updated: August 17, 2006
4 -------------------------------------------------------------------------------
6 * AUTHENTICODE
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.
11 This is a _minimal_ sequence. Each input/output could be tested under Linux 
12 and Windows to ensure maximum compatibility.
15 0. Setup
17         % cd /mcs/tools/security
18         % make
19         % mono setreg.exe 1 TRUE
20         % cp signcode.exe test.exe
22 1. Create a test certificate for code-signing
24         % mono makecert.exe -n "CN=careful tester" -sv test.pvk test.cer
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.
30         Success
32 2. Convert the test certificate to the SPC format
34         % mono cert2spc.exe test.cer test.spc
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.
40         Success
42 3. Sign a PE binary (without a timestamp)
44         % mono signcode.exe -v test.pvk -spc test.spc test.exe
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.
50         Success
52 4. Verify the binary from step 3
54         % mono chktrust.exe test.exe
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.
60         WARNING! test.exe is not timestamped!
61         SUCCESS: test.exe signature is valid
62         and can be traced back to a trusted root!
64         *** note the warning about the missing timestamp ***
66 5. Verify the binary from step 3 using MS tools [1]
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;
79 6. Add a timestamp the binary from step 3
81         % mono signcode.exe -x -t http://timestamp.verisign.com/scripts/timstamp.dll test.exe
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.
87         Success
89 7. Verify the binary from step 6
91         % mono chktrust.exe test.exe
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.
97         SUCCESS: test.exe signature is valid
98         and can be traced back to a trusted root!
100         *** note that there is NO warning this time ***
102 8. Verify the binary from step 6 on Windows [1]
104         a. Follow step 5 from 'a' to 'd'
105         b. This time you should see a countersignature;
107 9. Sign a PE binary with a timestamp
109         % mono signcode.exe -v test.pvk -spc test.spc -t http://timestamp.verisign.com/scripts/timstamp.dll test.exe
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.
115         Success
117 10. Verify the binary from step 9
119         % mono chktrust.exe test.exe
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.
125         SUCCESS: test.exe signature is valid
126         and can be traced back to a trusted root!
128 11. Verify the binary from step 9 on Windows [1]
130         a. Follow step 5 from 'a' to 'd'
131         b. This time you should see a countersignature;
133 12. Add (another) timestamp the binary from step 9
135         % mono signcode.exe -x -t http://timestamp.verisign.com/scripts/timstamp.dll test.exe
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.
141         Success
143 13. Verify the binary from step 12
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.
149         SUCCESS: test.exe signature is valid
150         and can be traced back to a trusted root!
152 14. Verify the binary from step 12 on Windows [1]
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;
158 15. Clean up
160         % rm test.*
161         % mono setreg.exe 1 FALSE
164 [1] this step must be done on Windows using MS Authenticode(r) tools.
166 -------------------------------------------------------------------------------
168 * STRONGNAME
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.
174 0. Setup
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
183         [...]
184         tmp.exe is not a strongly named assembly.
187 1. Create a SNK file (default size is 1024 bits)
189         % sn -k 1024.snk
191         [...]
192         A new 1024 bits strong name keypair has been generated in file '1024.snk'.
194         % mcs -delaysign+ -keyfile:1024.snk tmp.cs -out:tmp1024.exe
195         % sn -v tmp1024.exe
197         [...]
198         Assembly tmp1024.exe isn't strongnamed
200         % mcs -keyfile:1024.snk tmp.cs -out:tmp1024.exe
201         % sn -v tmp1024.exe
203         [...]
204         Assembly tmp1024.exe is strongnamed.
207 2. Create a large SNK file (supported by Fx 2.0 and later)
209         % sn -k 2048 2048.snk
211         [...]
212         A new 2048 bits strong name keypair has been generated in file '2048.snk'.
214         % mcs -delaysign+ -keyfile:2048.snk tmp.cs -out:tmp2048.exe
215         % sn -v tmp2048.exe
217         [...]
218         Assembly tmp2048.exe isn't strongnamed
220         % sn -R tmp2048.exe 2048.snk
222         [...]
223         Assembly tmp2048.exe signed.
225         % sn -v tmp2048.exe
227         [...]
228         Assembly tmp2048.exe is strongnamed.
231 3. Create a PFX (PKCS#12) file
233         % makecert -r -n "CN=mono" -p12 tmp.pfx mono
235         [...]
236         Success
238         % sn -p tmp.pfx tmp.pub
240         [...]
241         Enter password for private key (will be visible when typed): mono
242         Public Key extracted to file tmp.pub
244         % sn -tp tmp.pub
246         Public Key:
247         0024000004800000940000000602000000240000525341310004000011000000137d8a780901ce
248         3ceeb3aa9c813d9027d96e8be0cae633d0f64e584eb50685adb063b72fe3395f681ffda8a7c940
249         d0a8c76b1670c3a54cd354af82fe3995f6784a30c14a106d02f4150d0b370479a2cae574f4bce1
250         bf97a41e59f855a3d0062918861e55afacf9e4934365ea61718ba460dcb46143fee7278414a683
251         85336ace
253         Public Key Token: de950f189632e7d9
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...
258         % mcs -delaysign+ -keyfile:tmp.pub tmp.cs -out:tmppfx.exe
259         % sn -R tmppfx.exe tmp.pfx
261         [...]
262         Enter password for private key (will be visible when typed): mono
263         Assembly tmppfx.exe signed.
265         % sn -v tmppfx.exe
267         [...]
268         Assembly tmppfx.exe is strongnamed.
271 4. Test using the "well known" files
273         % sn -tp ../../class/mono.snk
275         [...]
277         Public Key:
278         002400000480000094000000060200000024000052534131000400000100010079159977d2d03a
279         8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c
280         3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fd
281         dafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef00
282         65d016df
284         Public Key Token: 0738eb9f132ed756
287         % sn -Tp ../../class/lib/default/Mono.Security.dll
289         [...]
291         Public Key:
292         002400000480000094000000060200000024000052534131000400000100010079159977d2d03a
293         8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c
294         3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fd
295         dafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef00
296         65d016df
298         Public Key Token: 0738eb9f132ed756
301         % sn -p ../../class/mono.snk tmp.pub
303         [...]
304         Public Key extracted to file tmp.pub
306         % md5sum tmp.pub
308         b35461067e0e8e00941d68bd55e38582  tmp.pub
311         % sn -tp tmp.pub
313         [...]
315         Public Key:
316         002400000480000094000000060200000024000052534131000400000100010079159977d2d03a
317         8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c
318         3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fd
319         dafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef00
320         65d016df
322         Public Key Token: 0738eb9f132ed756
325 5. Cleanup
327         % rm tmp*.*
329 -------------------------------------------------------------------------------
330 Send any bug or suggestions to sebastien at ximian.com