crypto 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. * Cryptography
  2. In the .NET framework cryptography can be found under a number of
  3. namespaces in several assemblies.
  4. ** Assembly: corlib
  5. *** Namespace: <b>System.Security.Cryptography</b>
  6. Thanks to the work of many people this namespace is almost complete.
  7. **** Status
  8. <ul>
  9. * All classes are present.
  10. * Most classes have their unit tests. Some tests like <code>
  11. SymmetricAlgorithmTest</code> are generated by external
  12. tools.
  13. </ul>
  14. **** TODO
  15. <ul>
  16. * <code>PasswordDeriveBytes.CryptDeriveKey</code> is included
  17. in MS BCL to provide compatibility with existing Windows
  18. applications. The main problem is that the key derivation
  19. algorithm can be different for every CSP (Crypto Service
  20. Provider). However for compatibility we should provide an
  21. implementation compatible with the MS CSP (most likely used).
  22. </ul>
  23. **** Notes
  24. <ul>
  25. * All cryptographic algorithms are entirely managed, including
  26. classes named <code>*CryptoServiceProvider</code>, with the
  27. exception of <code>RNGCryptoServiceProvider</code> for which
  28. parts of the implementation resides in the runtime.
  29. * There is a bug in the <code>PKCS1MaskGenerationMethod</code>
  30. class (in both framework 1.0 and 1.1). This means our
  31. implementation isn't compatible with MS (but is compatible with
  32. PKCS#1 v.2.1). However we get OAEP padding for every platform!
  33. * Look at assembly Mono.Security.Win32 if you require more
  34. compatiblity with the Microsoft implementation (like accessing
  35. a particuliar keypair container inside a specific CSP).
  36. </ul>
  37. *** Namespace: <b>System.Security.Cryptography.X509Certificates</b>
  38. **** Status
  39. <ul>
  40. * X.509 certificates are parsed using 100% managed code
  41. (using the Mono.Security.ASN1 class).
  42. * Software Publisher Certificates (SPC) used by Authenticode
  43. (tm) to sign assemblies are supported and <b>minimally</b>
  44. validated.
  45. * Unit tests are generated from a set of existing certificates
  46. (about a dozen) each having different properties. Another
  47. set of certificates (more than 700) are used for a more
  48. complete test (but isn't part of the standard test suite for
  49. size and time consideration, i.e. a 7.5Mb C# source file).
  50. </ul>
  51. **** Notes
  52. <ul>
  53. * Except for their structure <b>there are no validation of the
  54. certificates</b> done by this class (this is by design and
  55. isn't a restriction of Mono!). This means that certificate
  56. signatures and validity dates are <b>never</b> checked
  57. (except when used for Authenticode, i.e.
  58. <code>CreateFromSignedFile</code>).
  59. * The newer X509Certificate class included in Microsoft's Web
  60. Service Enhancement (WSE) is a little better (as it includes
  61. CryptoAPI's validation) when <code>IsCurrent</code> is called.
  62. See assembly <b>Microsoft.Web.Services</b> for more details.
  63. * The class Mono.Security.X509.X509Certificate (in Mono.Security
  64. assembly) is becoming a much better alternative - and will
  65. continue to evolve to support the security tools.
  66. * Microsoft implementation of <code>X509Certificate</code> is
  67. done by using CryptoAPI (unmanaged code). Based on the
  68. exceptions thrown, Authenticode(tm) support is done via COM.
  69. </ul>
  70. <hr>
  71. ** Assembly: System.Security
  72. *** Namespace: <b>System.Security.Cryptography.Xml</b>
  73. This namespace implements the <a href="http://www.w3.org/TR/xmldsig-core/">
  74. XML Digital Signature</a> specification from
  75. <a href="http://www.w3.org/">W3C</a>.
  76. **** Status
  77. <ul>
  78. * We pass the fifteen tests from Merlin's xmldsig suite with
  79. success. Which is funny because Microsoft fails in one case
  80. where both a X509Certificate and an X509CRL are present in
  81. an X509Data.
  82. * We now have a fully managed C14N implementation.
  83. * Most classes have their unit tests.
  84. </ul>
  85. <hr>
  86. ** Assembly: Mono.Security
  87. <b>Rational: </b>
  88. This assembly provides the missing pieces to .NET security. On Windows
  89. CryptoAPI is often used to provide much needed functionalities (like
  90. some cryptographic algorithms, code signing, X.509 certificates). Mono,
  91. for platform independance, implements these functionalities in 100%
  92. managed code.
  93. *** Namespace: Mono.Security
  94. <ul>
  95. * Structures (ASN1, PKCS7) and primitives (PKCS1).
  96. </ul>
  97. *** Namespace: Mono.Security.Authenticode
  98. <ul>
  99. * Code signing and verification.
  100. * Support for SPC (Software Publisher Certificate) files and
  101. PVK (Private Key) files.
  102. </ul>
  103. *** Namespace: Mono.Security.Cryptography
  104. <ul>
  105. * Additional algorithms: MD2, MD4, ARCFOUR (required for SSL)
  106. * Convertion helpers
  107. </ul>
  108. *** Namespace: Mono.Security.Protocol.*
  109. <ul>
  110. * Tls: An 100% managed SSLv3 and TLSv1 implementation from
  111. Carlos Guzman Alvarez.
  112. * Ntlm: NTLM authentication (used for HTTP and SQL Server).
  113. </ul>
  114. *** Namespace: Mono.Security.X509
  115. <ul>
  116. * X.509 structures (certificate, CRL...) building and decoding.
  117. * PKCS#12 decoding and encoding.
  118. </ul>
  119. *** Namespace: Mono.Security.X509.Extensions
  120. <ul>
  121. * X.509 extensions (from public X.509 to private PKIX, Netsapce,
  122. Microsoft, Entrust...).
  123. </ul>
  124. **** Status
  125. <ul>
  126. * A big part of this assembly is also included inside Mono's
  127. corlib. The classes are duplicated in this assembly so the
  128. functionalities can be used without a dependency on Mono's
  129. corlib (which depends on Mono's runtime).
  130. * Unit test coverage isn't (yet) complete.
  131. </ul>
  132. <hr>
  133. ** Assembly: Mono.Security.Win32
  134. <b>Rational: </b>
  135. This assembly goal is to provide maximum compatibility with CryptoAPI
  136. to application running with Mono's runtime on the Windows operating
  137. system.
  138. <b>This assembly should NEVER be used directly by any application</b>
  139. (e.g. referecing the assembly from a project).
  140. The classes should only be used by modifying the <code>machine.config
  141. </code> configuration file (and then only if this increased
  142. compatibility is required by an application).
  143. See the file <code><a href="http://cvs.hispalinux.es/cgi-bin/cvsweb/~checkout~/mcs/class/Mono.Security.Win32/README?rev=1.1&content-type=text/plain&cvsroot=mono">/mcs/class/Mono.Security.Win32/README</a></code>
  144. for complete instructions.
  145. *** Namespace: Mono.Security.Cryptography
  146. **** Status
  147. <ul>
  148. * A RNGCryptoServiceProvider built on top of CryptoAPI. This
  149. allows Windows users to get around the limitation of the
  150. runtime RNG (which requires <code>/dev/[u]random/</code>).
  151. * Wrapper classes for unmanaged versions of hash algorithms:
  152. MD2, MD4, MD5 and SHA1 are supported. <b>note</b>: some
  153. algorithms shouldn't be used in new design (MD4 is broken,
  154. MD2 and MD5 aren't considered safe for some usage). They are
  155. included to preserve interoperability with older applications
  156. (e.g. some old, but still valid, X.509 certificates use MD2,
  157. MD4 is required for NTLM authentication ...).
  158. </ul>
  159. **** TODO
  160. <ul>
  161. * Wrapper classes for unmanaged versions of symmetric
  162. encryption algorithms (like DES, TripleDES, RC2 and others
  163. present in default CSP).
  164. * Wrapper classes for unmanaged versions of asymmetric
  165. algorithms (like DSA and RSA) which persist their keypair
  166. into the specified CSP.
  167. </ul>
  168. **** Ideas
  169. <ul>
  170. * Similar assemblies (e.g. <code>Mono.Security.XXX</code>)
  171. could be created for <a href="http://www.openssl.org">OpenSSL</a>,
  172. <a href="http://www.mozilla.org/projects/security/pki/nss/">NSS</a>,
  173. <a href="http://www.eskimo.com/~weidai/cryptlib.html">crypto++</a>,
  174. <a href="http://www.cryptlib.orion.co.nz/">cryptlib</a> ... for
  175. improved performance and/or HSM (Hardware Security Module) support
  176. under Linux and/or Windows.
  177. </ul>
  178. <hr>
  179. ** Assembly: Microsoft.Web.Services
  180. Microsoft Web Service Enhancement (WSE), known as Web Service
  181. Development Kit (WSDK) in it's beta days, is an add-on the .NET
  182. framework that implements WS-Security (and other WS-* specifications).
  183. It also includes improved support for XML Signature (replacing and/or
  184. extending <code>System.Security.Cryptography.Xml</code>) and X.509
  185. certificates classes.
  186. Note: WSE is distributed as an add-on because some specifications,
  187. like WS-Security, aren't yet completed by
  188. <a href="http://www.oasis-open.org/committees/wss/">OASIS</a> or
  189. other committees.
  190. *** Namespace: Microsoft.Web.Services.Security
  191. **** Status
  192. <ul>
  193. * Most WSE 1.0 classes are implemented.
  194. </ul>
  195. **** TODO
  196. <ul>
  197. * Some classes from System.Security assembly need to be
  198. duplicated (and somewhat fixed) in WSE for XMLDSIG.
  199. * There are still missing classes and <b>many</b> missing
  200. unit tests.
  201. </ul>
  202. *** Namespace: Microsoft.Web.Services.Timestamp
  203. **** Status
  204. <ul>
  205. * This seems complete for WSE 1.0 but some new classes were
  206. introduced in WSE 2.0.
  207. </ul>
  208. *** Namespace: Microsoft.Web.Services.Security.X509
  209. **** Status
  210. <ul>
  211. * X509Certificate support is complete for both WSE 1.0 and 2.0.
  212. </ul>
  213. **** TODO
  214. <ul>
  215. * We need to define certificate stores (for both users and
  216. machines). These sames stores must be linked with asymmetric
  217. keypairs. This could also be used to store the SPC roots.
  218. </ul>
  219. *** Notes
  220. <ul>
  221. * Microsoft has <a href="http://microsoft.com/downloads/details.aspx?FamilyId=21FB9B9A-C5F6-4C95-87B7-FC7AB49B3EDD&displaylang=en">released</a>
  222. a technical preview of WSE 2. <b>Note that WSDK (the technical
  223. preview of WSE) had A LOT of changes before it's initial
  224. release!</b>
  225. </ul>
  226. <hr>
  227. ** Tools
  228. There are many tools in the .NET framework that indirectly interacts
  229. with some cryptographic classes. Mono will eventually need these tools.
  230. Unless noted the tools should work on any CLR (tested with both Mono
  231. and Microsoft).
  232. **** Status
  233. The following tools are complete (or mostly complete):
  234. <ul>
  235. * <code>secutil</code> is a tool to extract certificates and
  236. strongnames from assemblies in a format that can be easily
  237. re-used in source code (C# or VB.NET syntax).
  238. * <code>cert2spc</code> is a tool to transform multiple X.509
  239. certificates and CRLs into a Software Publisher Certificate
  240. (SPC) file - which is a long name for a simple PKCS#7 file.
  241. * <code>makecert</code> to create X.509 test certificates that
  242. can be used (once transformed in SPC) to sign assemblies. It's
  243. now possible to generate SSL certificates for web servers.
  244. * <code>sn</code> is a clone of the <code>sn</code> to manage
  245. strongnames. Current version can create, convert, sign and
  246. verify strongnames signatures. Some configuration options
  247. are still missing.
  248. * <code>signcode</code> and <code>chktrust</code> for signing
  249. and validating Authenticode(tm) signatures on assemblies (or
  250. any PE file) are now working (signature and timestamps) but
  251. some options aren't yet supported.
  252. * <code>setreg</code> can change some cryptographic parameters
  253. of the runtime. Currently it can add or remove two root test
  254. certificates (the one used by Mono's <code>makecert</code>,
  255. the other used by Microsoft's <code>makecert</code>).
  256. * <code>certmgr</code> can add and remove certificates from
  257. the stores. Most common use is to add new trusted certificates
  258. or remove them.
  259. </ul>
  260. Somewhat usable, somewhat incomplete:
  261. <ul>
  262. * <code>certview</code> is a certificate viewer for
  263. <code>System.Windows.Forms</code> (right now only working on
  264. Windows), while <code>gcertview</code> is the same viewer
  265. implemented for GTK# (working on both Windows and Linux).
  266. * <code>monosn</code> is a clone of the <code>sn</code> to manage
  267. strongnames. This tools is part of the runtime (not the class
  268. library) and as such is written in C and won't run without Mono.
  269. </ul>
  270. **** TODO
  271. The following tools are still missing or largely incomplete:
  272. <ul>
  273. * Other tools like a, GUI-based, certificate manager...
  274. </ul>
  275. Note that many of the tools requires the class library and/or the
  276. runtime to be ready for them. E.g. StrongName and Authenticode signatures
  277. tools are of limited use until supported by the runtime.
  278. <hr>
  279. ** References
  280. <ul>
  281. * RSA Laboratories' <a href="http://www.rsasecurity.com/rsalabs/faq/index.html">
  282. Frequently Asked Questions</a> About Today's Cryptography, Version 4.1
  283. * Public-Key Cryptography Standards (<a href="http://www.rsasecurity.com/rsalabs/pkcs/index.html">
  284. PKCS</a>)
  285. * National Institute of Standards and Technology - Federal
  286. Information Processing Standards <a href="http://csrc.nist.gov/publications/fips/index.html">
  287. NIST FIPS</a>
  288. </ul>
  289. <hr>
  290. ** How to Help
  291. <ul>
  292. * Complete any of the TODO (and feel good about it ;-).
  293. * Analyse the current coverage of the unit tests on the
  294. cryptographic classes and complete the unit tests. <b><code>
  295. monocov</code> does a great job at this! Now we just need to
  296. complete the missing unit tests.</b>
  297. * Optimization can also be done on most algorithms as crypto
  298. is never fast enough. Some have been done using the
  299. Community Edition of BoundChecker (a free VisualStudio
  300. addon) - recommanded! Just be sure to test every optimization
  301. (using the unit tests) carefully - it's so fast to break an
  302. algorithm ;-).
  303. * Write some documentation on the cryptographic classes for
  304. <b>monodoc</b>.
  305. </ul>
  306. <hr>
  307. Last reviewed: March 20, 2004 (mono 0.31)