EnvelopedCmsTest.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. //
  2. // EnvelopedCmsTest.cs - NUnit tests for EnvelopedCms
  3. //
  4. // Author:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
  8. // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_2_0
  30. using NUnit.Framework;
  31. using System;
  32. using System.Collections;
  33. using System.IO;
  34. using System.Security.Cryptography;
  35. using System.Security.Cryptography.Pkcs;
  36. using System.Security.Cryptography.X509Certificates;
  37. namespace MonoTests.System.Security.Cryptography.Pkcs {
  38. [TestFixture]
  39. public class EnvelopedCmsTest : Assertion {
  40. static byte[] asnNull = { 0x05, 0x00 };
  41. static string tdesOid = "1.2.840.113549.3.7";
  42. static string tdesName = "3des";
  43. static string p7DataOid = "1.2.840.113549.1.7.1";
  44. static string p7DataName = "PKCS 7 Data";
  45. static public byte [] farscape_p12_pfx = {
  46. 0x30, 0x82, 0x07, 0x17, 0x02, 0x01, 0x03, 0x30, 0x82, 0x06, 0xD3, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0xA0, 0x82, 0x06, 0xC4, 0x04, 0x82, 0x06, 0xC0, 0x30, 0x82, 0x06, 0xBC, 0x30, 0x82, 0x03, 0xCD, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0xA0, 0x82, 0x03, 0xBE, 0x04, 0x82, 0x03, 0xBA, 0x30, 0x82, 0x03, 0xB6, 0x30, 0x82, 0x03, 0xB2, 0x06, 0x0B, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x0C, 0x0A, 0x01, 0x02, 0xA0, 0x82, 0x02, 0xB6, 0x30, 0x82, 0x02, 0xB2, 0x30, 0x1C, 0x06, 0x0A, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x0C, 0x01, 0x03, 0x30,
  47. 0x0E, 0x04, 0x08, 0x86, 0x2A, 0xA9, 0x71, 0x6D, 0xA4, 0xB8, 0x2D, 0x02, 0x02, 0x07, 0xD0, 0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, 0x00, 0x31, 0x00, 0x64, 0x00, 0x2D, 0x00, 0x32, 0x00, 0x36, 0x00, 0x30, 0x00, 0x34, 0x00, 0x2D, 0x00, 0x34, 0x00, 0x32, 0x00, 0x35, 0x00, 0x66, 0x00, 0x2D, 0x00, 0x38, 0x00, 0x31, 0x00, 0x35, 0x00, 0x66, 0x00, 0x2D, 0x00, 0x34, 0x00, 0x39, 0x00, 0x35, 0x00, 0x61, 0x00, 0x37, 0x00, 0x64, 0x00, 0x65, 0x00, 0x65, 0x00, 0x37, 0x00, 0x61, 0x00,
  55. 0x64, 0x00, 0x30, 0x30, 0x69, 0x06, 0x09, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x11, 0x01, 0x31, 0x5C, 0x1E, 0x5A, 0x00, 0x4D, 0x00, 0x69, 0x00, 0x63, 0x00, 0x72, 0x00, 0x6F, 0x00, 0x73, 0x00, 0x6F, 0x00, 0x66, 0x00, 0x74, 0x00, 0x20, 0x00, 0x52, 0x00, 0x53, 0x00, 0x41, 0x00, 0x20, 0x00, 0x53, 0x00, 0x43, 0x00, 0x68, 0x00, 0x61, 0x00, 0x6E, 0x00, 0x6E, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x20, 0x00, 0x43, 0x00, 0x72, 0x00, 0x79, 0x00, 0x70, 0x00, 0x74, 0x00, 0x6F, 0x00, 0x67, 0x00, 0x72, 0x00, 0x61, 0x00, 0x70, 0x00, 0x68, 0x00, 0x69, 0x00, 0x63, 0x00, 0x20, 0x00, 0x50, 0x00, 0x72, 0x00, 0x6F,
  56. 0x00, 0x76, 0x00, 0x69, 0x00, 0x64, 0x00, 0x65, 0x00, 0x72, 0x30, 0x82, 0x02, 0xE7, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x06, 0xA0, 0x82, 0x02, 0xD8, 0x30, 0x82, 0x02, 0xD4, 0x02, 0x01, 0x00, 0x30, 0x82, 0x02, 0xCD, 0x06, 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x1A, 0x04, 0x14, 0xDC, 0x3A, 0xAB, 0x36, 0xD7, 0x3E, 0xF4, 0x6C, 0x52, 0xC9, 0x89, 0x37, 0xFE, 0x71, 0x71, 0x83, 0xC6, 0x09, 0x88, 0xDD, 0x04, 0x14, 0xF5, 0x76, 0xC2, 0xCC, 0xB9, 0xE5,
  64. 0xF5, 0x28, 0xA3, 0x2D, 0x55, 0xDC, 0xDE, 0x3B, 0xCF, 0x53, 0xEE, 0x4B, 0x8F, 0x6F, 0x02, 0x02, 0x07, 0xD0 };
  65. private void DefaultProperties (EnvelopedCms ep, int contentLength, int version)
  66. {
  67. AssertEquals ("Certificates", 0, ep.Certificates.Count);
  68. AssertEquals ("ContentEncryptionAlgorithm.KeyLength", 0, ep.ContentEncryptionAlgorithm.KeyLength);
  69. AssertEquals ("ContentEncryptionAlgorithm.Oid.FriendlyName", tdesName, ep.ContentEncryptionAlgorithm.Oid.FriendlyName);
  70. AssertEquals ("ContentEncryptionAlgorithm.Oid.Value", tdesOid, ep.ContentEncryptionAlgorithm.Oid.Value);
  71. AssertEquals ("ContentEncryptionAlgorithm.Parameters", 0, ep.ContentEncryptionAlgorithm.Parameters.Length);
  72. AssertEquals ("ContentInfo.ContentType.FriendlyName", p7DataName, ep.ContentInfo.ContentType.FriendlyName);
  73. AssertEquals ("ContentInfo.ContentType.Value", p7DataOid, ep.ContentInfo.ContentType.Value);
  74. AssertEquals ("ContentInfo.Content", contentLength, ep.ContentInfo.Content.Length);
  75. AssertEquals ("RecipientInfos", 0, ep.RecipientInfos.Count);
  76. AssertEquals ("UnprotectedAttributes", 0, ep.UnprotectedAttributes.Count);
  77. AssertEquals ("Version", version, ep.Version);
  78. }
  79. private X509Certificate2 GetCertificate (bool includePrivateKey)
  80. {
  81. return new X509Certificate2 (farscape_p12_pfx, "farscape");
  82. }
  83. [Test]
  84. public void ConstructorEmpty ()
  85. {
  86. EnvelopedCms ep = new EnvelopedCms ();
  87. DefaultProperties (ep, 0, 0);
  88. }
  89. [Test]
  90. public void ConstructorContentInfo ()
  91. {
  92. ContentInfo ci = new ContentInfo (asnNull);
  93. EnvelopedCms ep = new EnvelopedCms (ci);
  94. DefaultProperties (ep, asnNull.Length, 0);
  95. }
  96. [Test]
  97. [ExpectedException (typeof (ArgumentNullException))]
  98. public void ConstructorContentInfoNull ()
  99. {
  100. EnvelopedCms ep = new EnvelopedCms (null);
  101. }
  102. [Test]
  103. public void ConstructorContentInfoAlgorithmIdentifier ()
  104. {
  105. AlgorithmIdentifier ai = new AlgorithmIdentifier ();
  106. ContentInfo ci = new ContentInfo (asnNull);
  107. EnvelopedCms ep = new EnvelopedCms (ci, ai);
  108. DefaultProperties (ep, 2, 0);
  109. }
  110. [Test]
  111. [ExpectedException (typeof (ArgumentNullException))]
  112. public void ConstructorContentInfoNullAlgorithmIdentifier ()
  113. {
  114. AlgorithmIdentifier ai = new AlgorithmIdentifier ();
  115. EnvelopedCms ep = new EnvelopedCms (null, ai);
  116. }
  117. [Test]
  118. [ExpectedException (typeof (ArgumentNullException))]
  119. public void ConstructorContentInfoAlgorithmIdentifierNull ()
  120. {
  121. ContentInfo ci = new ContentInfo (asnNull);
  122. EnvelopedCms ep = new EnvelopedCms (ci, null);
  123. }
  124. [Test]
  125. public void ConstructorSubjectIdentifierTypeIssuerAndSerialNumberContentInfoAlgorithmIdentifier ()
  126. {
  127. AlgorithmIdentifier ai = new AlgorithmIdentifier ();
  128. ContentInfo ci = new ContentInfo (asnNull);
  129. EnvelopedCms ep = new EnvelopedCms (SubjectIdentifierType.IssuerAndSerialNumber, ci, ai);
  130. DefaultProperties (ep, 2, 0);
  131. }
  132. [Test]
  133. public void ConstructorSubjectIdentifierTypeSubjectKeyIdentifierContentInfoAlgorithmIdentifier ()
  134. {
  135. AlgorithmIdentifier ai = new AlgorithmIdentifier ();
  136. ContentInfo ci = new ContentInfo (asnNull);
  137. EnvelopedCms ep = new EnvelopedCms (SubjectIdentifierType.SubjectKeyIdentifier, ci, ai);
  138. DefaultProperties (ep, 2, 2);
  139. }
  140. [Test]
  141. public void ConstructorSubjectIdentifierTypeUnknownContentInfoAlgorithmIdentifier ()
  142. {
  143. AlgorithmIdentifier ai = new AlgorithmIdentifier ();
  144. ContentInfo ci = new ContentInfo (asnNull);
  145. EnvelopedCms ep = new EnvelopedCms (SubjectIdentifierType.Unknown, ci, ai);
  146. DefaultProperties (ep, 2, 0);
  147. }
  148. [Test]
  149. public void ConstructorSubjectIdentifierTypeIssuerAndSerialNumberContentInfo ()
  150. {
  151. ContentInfo ci = new ContentInfo (asnNull);
  152. EnvelopedCms ep = new EnvelopedCms (SubjectIdentifierType.IssuerAndSerialNumber, ci);
  153. DefaultProperties (ep, 2, 0);
  154. }
  155. [Test]
  156. public void ConstructorSubjectIdentifierTypeSubjectKeyIdentifierContentInfo ()
  157. {
  158. ContentInfo ci = new ContentInfo (asnNull);
  159. EnvelopedCms ep = new EnvelopedCms (SubjectIdentifierType.SubjectKeyIdentifier, ci);
  160. DefaultProperties (ep, 2, 2);
  161. }
  162. [Test]
  163. public void ConstructorSubjectIdentifierTypeUnknownContentInfo ()
  164. {
  165. ContentInfo ci = new ContentInfo (asnNull);
  166. EnvelopedCms ep = new EnvelopedCms (SubjectIdentifierType.Unknown, ci);
  167. DefaultProperties (ep, 2, 0);
  168. }
  169. [Test]
  170. [Category ("NotWorking")]
  171. public void Decode ()
  172. {
  173. byte[] encoded = { 0x30, 0x82, 0x01, 0x1C, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x03, 0xA0, 0x82, 0x01, 0x0D, 0x30, 0x82, 0x01, 0x09, 0x02, 0x01, 0x00, 0x31, 0x81, 0xD6, 0x30, 0x81, 0xD3, 0x02, 0x01, 0x00, 0x30, 0x3C, 0x30, 0x28, 0x31, 0x26, 0x30, 0x24, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x1D, 0x4D, 0x6F, 0x74, 0x75, 0x73, 0x20, 0x54, 0x65, 0x63,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, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0x30, 0x14, 0x06, 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x03, 0x07, 0x04, 0x08, 0x8C, 0x5D, 0xC9, 0x87, 0x88, 0x9C, 0x05, 0x72, 0x80, 0x08, 0x2C, 0xAF, 0x82, 0x91, 0xEC, 0xAD, 0xC5, 0xB5 };
  174. EnvelopedCms ep = new EnvelopedCms ();
  175. ep.Decode (encoded);
  176. // properties
  177. AssertEquals ("Certificates", 0, ep.Certificates.Count);
  178. AssertEquals ("ContentEncryptionAlgorithm.KeyLength", 192, ep.ContentEncryptionAlgorithm.KeyLength);
  179. AssertEquals ("ContentEncryptionAlgorithm.Oid.FriendlyName", tdesName, ep.ContentEncryptionAlgorithm.Oid.FriendlyName);
  180. AssertEquals ("ContentEncryptionAlgorithm.Oid.Value", tdesOid, ep.ContentEncryptionAlgorithm.Oid.Value);
  181. AssertEquals ("ContentEncryptionAlgorithm.Parameters", 16, ep.ContentEncryptionAlgorithm.Parameters.Length);
  182. AssertEquals ("ContentInfo.ContentType.FriendlyName", p7DataName, ep.ContentInfo.ContentType.FriendlyName);
  183. AssertEquals ("ContentInfo.ContentType.Value", p7DataOid, ep.ContentInfo.ContentType.Value);
  184. AssertEquals ("ContentInfo.Content", 14, ep.ContentInfo.Content.Length);
  185. AssertEquals ("RecipientInfos", 1, ep.RecipientInfos.Count);
  186. RecipientInfo ri = ep.RecipientInfos [0];
  187. Assert ("RecipientInfos is KeyTransRecipientInfo", (ri is KeyTransRecipientInfo));
  188. AssertEquals ("UnprotectedAttributes", 0, ep.UnprotectedAttributes.Count);
  189. AssertEquals ("Version", 0, ep.Version);
  190. }
  191. [Test]
  192. [ExpectedException (typeof (ArgumentNullException))]
  193. public void DecodeNull ()
  194. {
  195. EnvelopedCms ep = new EnvelopedCms ();
  196. ep.Decode (null);
  197. }
  198. [Test]
  199. [ExpectedException (typeof (InvalidOperationException))]
  200. public void EncodeEmpty ()
  201. {
  202. EnvelopedCms ep = new EnvelopedCms ();
  203. byte[] encoded = ep.Encode ();
  204. }
  205. [Test]
  206. [Category ("NotWorking")]
  207. public void Decrypt ()
  208. {
  209. byte[] encoded = { 0x30, 0x82, 0x01, 0x1C, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x03, 0xA0, 0x82, 0x01, 0x0D, 0x30, 0x82, 0x01, 0x09, 0x02, 0x01, 0x00, 0x31, 0x81, 0xD6, 0x30, 0x81, 0xD3, 0x02, 0x01, 0x00, 0x30, 0x3C, 0x30, 0x28, 0x31, 0x26, 0x30, 0x24, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x1D, 0x4D, 0x6F, 0x74, 0x75, 0x73, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, 0x69, 0x65, 0x73, 0x20, 0x69, 0x6E, 0x63, 0x2E, 0x28, 0x74, 0x65, 0x73, 0x74, 0x29, 0x02, 0x10, 0x91, 0xC4, 0x4B, 0x0D, 0xB7, 0xD8, 0x10, 0x84, 0x42, 0x26, 0x71, 0xB3, 0x97, 0xB5, 0x00, 0x97, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x81, 0x80, 0xCA, 0x4B, 0x97, 0x9C, 0xAB, 0x79, 0xC6, 0xDF, 0x6A, 0x27, 0xC7, 0x24, 0xC4, 0x5E, 0x3B, 0x31, 0xAD, 0xBC, 0x25, 0xE6, 0x38, 0x5E, 0x79, 0x26, 0x0E, 0x68, 0x46, 0x1D, 0x21, 0x81, 0x38, 0x92, 0xEC, 0xCB, 0x7C, 0x91, 0xD6, 0x09, 0x38, 0x91, 0xCE, 0x50, 0x5B, 0x70, 0x31, 0xB0, 0x9F, 0xFC, 0xE2, 0xEE, 0x45, 0xBC, 0x4B, 0xF8, 0x9A, 0xD9, 0xEE, 0xE7, 0x4A, 0x3D, 0xCD, 0x8D, 0xFF, 0x10, 0xAB, 0xC8, 0x19, 0x05, 0x54, 0x5E, 0x40, 0x7A, 0xBE, 0x2B, 0xD7, 0x22, 0x97, 0xF3, 0x23, 0xAF, 0x50, 0xF5, 0xEB, 0x43, 0x06, 0xC3, 0xFB, 0x17, 0xCA, 0xBD, 0xAD, 0x28, 0xD8, 0x10, 0x0F, 0x61, 0xCE, 0xF8, 0x25, 0x70, 0xF6, 0xC8, 0x1E, 0x7F, 0x82, 0xE5, 0x94, 0xEB, 0x11, 0xBF, 0xB8, 0x6F, 0xEE, 0x79, 0xCD, 0x63, 0xDD, 0x59, 0x8D, 0x25, 0x0E, 0x78, 0x55, 0xCE, 0x21, 0xBA, 0x13, 0x6B, 0x30, 0x2B, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0x30, 0x14, 0x06, 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x03, 0x07, 0x04, 0x08, 0x8C, 0x5D, 0xC9, 0x87, 0x88, 0x9C, 0x05, 0x72, 0x80, 0x08, 0x2C, 0xAF, 0x82, 0x91, 0xEC, 0xAD, 0xC5, 0xB5 };
  210. EnvelopedCms ep = new EnvelopedCms ();
  211. ep.Decode (encoded);
  212. X509Certificate2 x509 = GetCertificate (true);
  213. X509Certificate2Collection xc = new X509Certificate2Collection ();
  214. xc.Add (x509);
  215. ep.Decrypt (xc);
  216. // properties
  217. AssertEquals ("Certificates", 0, ep.Certificates.Count);
  218. AssertEquals ("ContentEncryptionAlgorithm.KeyLength", 192, ep.ContentEncryptionAlgorithm.KeyLength);
  219. AssertEquals ("ContentEncryptionAlgorithm.Oid.FriendlyName", tdesName, ep.ContentEncryptionAlgorithm.Oid.FriendlyName);
  220. AssertEquals ("ContentEncryptionAlgorithm.Oid.Value", tdesOid, ep.ContentEncryptionAlgorithm.Oid.Value);
  221. AssertEquals ("ContentEncryptionAlgorithm.Parameters", 16, ep.ContentEncryptionAlgorithm.Parameters.Length);
  222. AssertEquals ("ContentInfo.ContentType.FriendlyName", p7DataName, ep.ContentInfo.ContentType.FriendlyName);
  223. AssertEquals ("ContentInfo.ContentType.Value", p7DataOid, ep.ContentInfo.ContentType.Value);
  224. AssertEquals ("ContentInfo.Content", "05-00", BitConverter.ToString (ep.ContentInfo.Content));
  225. AssertEquals ("RecipientInfos", 1, ep.RecipientInfos.Count);
  226. AssertEquals ("UnprotectedAttributes", 0, ep.UnprotectedAttributes.Count);
  227. AssertEquals ("Version", 0, ep.Version);
  228. }
  229. [Test]
  230. [ExpectedException (typeof (InvalidOperationException))]
  231. public void DecryptEmpty ()
  232. {
  233. EnvelopedCms ep = new EnvelopedCms ();
  234. ep.Decrypt ();
  235. }
  236. [Test]
  237. [ExpectedException (typeof (ArgumentNullException))]
  238. public void DecryptRecipientInfoNull ()
  239. {
  240. EnvelopedCms ep = new EnvelopedCms ();
  241. RecipientInfo ri = null; // do not confuse compiler
  242. ep.Decrypt (ri);
  243. }
  244. [Test]
  245. [ExpectedException (typeof (ArgumentNullException))]
  246. public void DecryptX509CertificateExCollectionNull ()
  247. {
  248. EnvelopedCms ep = new EnvelopedCms ();
  249. X509Certificate2Collection xec = null; // do not confuse compiler
  250. ep.Decrypt (xec);
  251. }
  252. [Test]
  253. [ExpectedException (typeof (ArgumentNullException))]
  254. public void DecryptRecipientInfoX509CertificateExCollectionNull ()
  255. {
  256. EnvelopedCms ep = new EnvelopedCms ();
  257. X509Certificate2Collection xec = new X509Certificate2Collection ();
  258. ep.Decrypt (null, xec);
  259. }
  260. /* [Test]
  261. [ExpectedException (typeof (ArgumentNullException))]
  262. public void DecryptX509CertificateExCollectionNull ()
  263. {
  264. EnvelopedPkcs7 ep = new EnvelopedPkcs7 ();
  265. RecipientInfo ri =
  266. ep.Decrypt (ri, null);
  267. }*/
  268. private void RoundTrip (byte[] encoded)
  269. {
  270. X509Certificate2Collection xc = new X509Certificate2Collection ();
  271. xc.Add (GetCertificate (true));
  272. EnvelopedCms ep = new EnvelopedCms ();
  273. ep.Decode (encoded);
  274. ep.Decrypt (xc);
  275. AssertEquals ("ContentInfo.Content", "05-00", BitConverter.ToString (ep.ContentInfo.Content));
  276. }
  277. [Test]
  278. [Category ("NotWorking")]
  279. public void EncryptCmsRecipientIssuerAndSerialNumber ()
  280. {
  281. ContentInfo ci = new ContentInfo (asnNull);
  282. EnvelopedCms ep = new EnvelopedCms (SubjectIdentifierType.IssuerAndSerialNumber, ci);
  283. X509Certificate2 x509 = GetCertificate (false);
  284. CmsRecipient p7r = new CmsRecipient (SubjectIdentifierType.IssuerAndSerialNumber, x509);
  285. ep.Encrypt (p7r);
  286. byte[] encoded = ep.Encode ();
  287. #if DEBUG
  288. FileStream fs = File.OpenWrite ("EncryptCmsRecipientIssuerAndSerialNumber.der");
  289. fs.Write (encoded, 0, encoded.Length);
  290. fs.Close ();
  291. #endif
  292. RoundTrip (encoded);
  293. }
  294. [Test]
  295. [Category ("NotWorking")]
  296. public void EncryptCmsRecipientSubjectKeyIdentifier ()
  297. {
  298. ContentInfo ci = new ContentInfo (asnNull);
  299. EnvelopedCms ep = new EnvelopedCms (SubjectIdentifierType.IssuerAndSerialNumber, ci);
  300. X509Certificate2 x509 = GetCertificate (false);
  301. CmsRecipient p7r = new CmsRecipient (SubjectIdentifierType.SubjectKeyIdentifier, x509);
  302. ep.Encrypt (p7r);
  303. byte[] encoded = ep.Encode ();
  304. #if DEBUG
  305. FileStream fs = File.OpenWrite ("EncryptCmsRecipientSubjectKeyIdentifier.der");
  306. fs.Write (encoded, 0, encoded.Length);
  307. fs.Close ();
  308. #endif
  309. RoundTrip (encoded);
  310. }
  311. [Test]
  312. [Category ("NotWorking")]
  313. public void EncryptCmsRecipientUnknown ()
  314. {
  315. ContentInfo ci = new ContentInfo (asnNull);
  316. EnvelopedCms ep = new EnvelopedCms (SubjectIdentifierType.IssuerAndSerialNumber, ci);
  317. X509Certificate2 x509 = GetCertificate (false);
  318. CmsRecipient p7r = new CmsRecipient (SubjectIdentifierType.Unknown, x509);
  319. ep.Encrypt (p7r);
  320. byte[] encoded = ep.Encode ();
  321. #if DEBUG
  322. FileStream fs = File.OpenWrite ("EncryptCmsRecipientUnknown.der");
  323. fs.Write (encoded, 0, encoded.Length);
  324. fs.Close ();
  325. #endif
  326. RoundTrip (encoded);
  327. }
  328. [Test]
  329. [Category ("NotWorking")]
  330. [ExpectedException (typeof (CryptographicException))]
  331. public void EncryptEmpty ()
  332. {
  333. EnvelopedCms ep = new EnvelopedCms ();
  334. ep.Encrypt ();
  335. }
  336. [Test]
  337. [ExpectedException (typeof (ArgumentNullException))]
  338. public void EnvelopedCmsRecipientNull ()
  339. {
  340. EnvelopedCms ep = new EnvelopedCms ();
  341. CmsRecipient p7r = null; // do not confuse compiler
  342. ep.Encrypt (p7r);
  343. }
  344. [Test]
  345. [ExpectedException (typeof (ArgumentNullException))]
  346. public void EnvelopedCmsRecipientCollectionNull ()
  347. {
  348. EnvelopedCms ep = new EnvelopedCms ();
  349. CmsRecipientCollection p7rc = null; // do not confuse compiler
  350. ep.Encrypt (p7rc);
  351. }
  352. }
  353. }
  354. #endif