1 Mono's Security Tools - TESTS
2 Last updated: August 17, 2006
4 -------------------------------------------------------------------------------
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.
17 % cd /mcs/tools/security
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.
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.
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.
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
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.
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.
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.
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;
161 % mono setreg.exe 1 FALSE
164 [1] this step must be done on Windows using MS Authenticode(r) tools.
166 -------------------------------------------------------------------------------
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.
176 % cd /mcs/tools/security
179 % echo "class Program { static void Main () { System.Console.WriteLine (\"hello world\"); } }" > tmp.cs
180 % mcs tmp.cs -out:tmp.exe
184 tmp.exe is not a strongly named assembly.
187 1. Create a SNK file (default size is 1024 bits)
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
198 Assembly tmp1024.exe isn't strongnamed
200 % mcs -keyfile:1024.snk tmp.cs -out:tmp1024.exe
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
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
218 Assembly tmp2048.exe isn't strongnamed
220 % sn -R tmp2048.exe 2048.snk
223 Assembly tmp2048.exe signed.
228 Assembly tmp2048.exe is strongnamed.
231 3. Create a PFX (PKCS#12) file
233 % makecert -r -n "CN=mono" -p12 tmp.pfx mono
238 % sn -p tmp.pfx tmp.pub
241 Enter password for private key (will be visible when typed): mono
242 Public Key extracted to file tmp.pub
247 0024000004800000940000000602000000240000525341310004000011000000137d8a780901ce
248 3ceeb3aa9c813d9027d96e8be0cae633d0f64e584eb50685adb063b72fe3395f681ffda8a7c940
249 d0a8c76b1670c3a54cd354af82fe3995f6784a30c14a106d02f4150d0b370479a2cae574f4bce1
250 bf97a41e59f855a3d0062918861e55afacf9e4934365ea61718ba460dcb46143fee7278414a683
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
262 Enter password for private key (will be visible when typed): mono
263 Assembly tmppfx.exe signed.
268 Assembly tmppfx.exe is strongnamed.
271 4. Test using the "well known" files
273 % sn -tp ../../class/mono.snk
278 002400000480000094000000060200000024000052534131000400000100010079159977d2d03a
279 8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c
280 3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fd
281 dafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef00
284 Public Key Token: 0738eb9f132ed756
287 % sn -Tp ../../class/lib/default/Mono.Security.dll
292 002400000480000094000000060200000024000052534131000400000100010079159977d2d03a
293 8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c
294 3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fd
295 dafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef00
298 Public Key Token: 0738eb9f132ed756
301 % sn -p ../../class/mono.snk tmp.pub
304 Public Key extracted to file tmp.pub
308 b35461067e0e8e00941d68bd55e38582 tmp.pub
316 002400000480000094000000060200000024000052534131000400000100010079159977d2d03a
317 8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c
318 3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fd
319 dafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef00
322 Public Key Token: 0738eb9f132ed756
329 -------------------------------------------------------------------------------
330 Send any bug or suggestions to sebastien at ximian.com