SecurityAlgorithmSuiteTest.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. //
  2. // SecurityAlgorithmSuiteTest.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2006 Novell, Inc. http://www.novell.com
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Collections.ObjectModel;
  30. using System.IdentityModel.Tokens;
  31. using System.Net;
  32. using System.Net.Security;
  33. using System.ServiceModel;
  34. using System.ServiceModel.Channels;
  35. using System.ServiceModel.Security;
  36. using System.ServiceModel.Security.Tokens;
  37. using System.Security.Cryptography.Xml;
  38. using NUnit.Framework;
  39. namespace MonoTests.System.ServiceModel
  40. {
  41. [TestFixture]
  42. public class SecurityAlgorithmSuiteTest
  43. {
  44. static void AssertSecurityAlgorithmSuite (
  45. string defaultAsymmetricKeyWrapAlgorithm,
  46. string defaultAsymmetricSignatureAlgorithm,
  47. string defaultCanonicalizationAlgorithm,
  48. string defaultDigestAlgorithm,
  49. string defaultEncryptionAlgorithm,
  50. int defaultEncryptionKeyDerivationLength,
  51. int defaultSignatureKeyDerivationLength,
  52. int defaultSymmetricKeyLength,
  53. string defaultSymmetricKeyWrapAlgorithm,
  54. string defaultSymmetricSignatureAlgorithm,
  55. SecurityAlgorithmSuite target,
  56. string label)
  57. {
  58. Assert.AreEqual (defaultAsymmetricKeyWrapAlgorithm,
  59. target.DefaultAsymmetricKeyWrapAlgorithm,
  60. label + ".DefaultAsymmetricKeyWrapAlgorithm");
  61. Assert.AreEqual (defaultAsymmetricSignatureAlgorithm,
  62. target.DefaultAsymmetricSignatureAlgorithm,
  63. label + ".DefaultAsymmetricSignatureAlgorithm");
  64. Assert.AreEqual (defaultCanonicalizationAlgorithm,
  65. target.DefaultCanonicalizationAlgorithm,
  66. label + ".DefaultCanonicalizationAlgorithm");
  67. Assert.AreEqual (defaultDigestAlgorithm,
  68. target.DefaultDigestAlgorithm,
  69. label + ".DefaultDigestAlgorithm");
  70. Assert.AreEqual (defaultEncryptionAlgorithm,
  71. target.DefaultEncryptionAlgorithm,
  72. label + ".DefaultEncryptionAlgorithm");
  73. Assert.AreEqual (defaultEncryptionKeyDerivationLength,
  74. target.DefaultEncryptionKeyDerivationLength,
  75. label + ".DefaultEncryptionKeyDerivationLength");
  76. Assert.AreEqual (defaultSignatureKeyDerivationLength,
  77. target.DefaultSignatureKeyDerivationLength,
  78. label + ".DefaultSignatureKeyDerivationLength");
  79. Assert.AreEqual (defaultSymmetricKeyLength,
  80. target.DefaultSymmetricKeyLength,
  81. label + ".DefaultSymmetricKeyLength");
  82. Assert.AreEqual (defaultSymmetricKeyWrapAlgorithm,
  83. target.DefaultSymmetricKeyWrapAlgorithm,
  84. label + ".DefaultSymmetricKeyWrapAlgorithm");
  85. Assert.AreEqual (defaultSymmetricSignatureAlgorithm,
  86. target.DefaultSymmetricSignatureAlgorithm,
  87. label + ".DefaultSymmetricSignatureAlgorithm");
  88. }
  89. [Test]
  90. public void DefaultAlgorithm ()
  91. {
  92. Assert.AreEqual (
  93. SecurityAlgorithmSuite.Basic256,
  94. SecurityAlgorithmSuite.Default, "#1");
  95. }
  96. [Test]
  97. public void StaticPropertyValues ()
  98. {
  99. AssertSecurityAlgorithmSuite (
  100. EncryptedXml.XmlEncRSAOAEPUrl,
  101. SignedXml.XmlDsigRSASHA1Url,
  102. SignedXml.XmlDsigExcC14NTransformUrl,
  103. SignedXml.XmlDsigSHA1Url,
  104. EncryptedXml.XmlEncAES128Url,
  105. // enc, sig, sym
  106. 128, 128, 128,
  107. EncryptedXml.XmlEncAES128KeyWrapUrl,
  108. SignedXml.XmlDsigHMACSHA1Url,
  109. SecurityAlgorithmSuite.Basic128,
  110. "Basic128");
  111. AssertSecurityAlgorithmSuite (
  112. EncryptedXml.XmlEncRSA15Url,
  113. SignedXml.XmlDsigRSASHA1Url,
  114. SignedXml.XmlDsigExcC14NTransformUrl,
  115. SignedXml.XmlDsigSHA1Url,
  116. EncryptedXml.XmlEncAES128Url,
  117. // enc, sig, sym
  118. 128, 128, 128,
  119. EncryptedXml.XmlEncAES128KeyWrapUrl,
  120. SignedXml.XmlDsigHMACSHA1Url,
  121. SecurityAlgorithmSuite.Basic128Rsa15,
  122. "Basic128Rsa15");
  123. AssertSecurityAlgorithmSuite (
  124. EncryptedXml.XmlEncRSAOAEPUrl,
  125. SecurityAlgorithms.RsaSha256Signature,
  126. SignedXml.XmlDsigExcC14NTransformUrl,
  127. EncryptedXml.XmlEncSHA256Url,
  128. EncryptedXml.XmlEncAES128Url,
  129. // enc, sig, sym
  130. 128, 128, 128,
  131. EncryptedXml.XmlEncAES128KeyWrapUrl,
  132. // Can't we get the same string from some const?
  133. SecurityAlgorithms.HmacSha256Signature,
  134. SecurityAlgorithmSuite.Basic128Sha256,
  135. "Basic128Sha256");
  136. AssertSecurityAlgorithmSuite (
  137. EncryptedXml.XmlEncRSA15Url,
  138. SecurityAlgorithms.RsaSha256Signature,
  139. SignedXml.XmlDsigExcC14NTransformUrl,
  140. EncryptedXml.XmlEncSHA256Url,
  141. EncryptedXml.XmlEncAES128Url,
  142. // enc, sig, sym
  143. 128, 128, 128,
  144. EncryptedXml.XmlEncAES128KeyWrapUrl,
  145. // Can't we get the same string from some const?
  146. SecurityAlgorithms.HmacSha256Signature,
  147. SecurityAlgorithmSuite.Basic128Sha256Rsa15,
  148. "Basic128Sha256Rsa15");
  149. // ...192
  150. AssertSecurityAlgorithmSuite (
  151. EncryptedXml.XmlEncRSA15Url,
  152. SecurityAlgorithms.RsaSha256Signature,
  153. SignedXml.XmlDsigExcC14NTransformUrl,
  154. EncryptedXml.XmlEncSHA256Url,
  155. EncryptedXml.XmlEncAES192Url,
  156. // enc, sig, sym
  157. 192, 192, 192,
  158. EncryptedXml.XmlEncAES192KeyWrapUrl,
  159. // Can't we get the same string from some const?
  160. SecurityAlgorithms.HmacSha256Signature,
  161. SecurityAlgorithmSuite.Basic192Sha256Rsa15,
  162. "Basic192Sha256Rsa15");
  163. // ...256
  164. AssertSecurityAlgorithmSuite (
  165. EncryptedXml.XmlEncRSAOAEPUrl,
  166. SecurityAlgorithms.RsaSha256Signature,
  167. SignedXml.XmlDsigExcC14NTransformUrl,
  168. EncryptedXml.XmlEncSHA256Url,
  169. EncryptedXml.XmlEncAES256Url,
  170. // enc, sig, sym
  171. 256, 192, 256, // hmm, why 192 here?
  172. EncryptedXml.XmlEncAES256KeyWrapUrl,
  173. // Can't we get the same string from some const?
  174. SecurityAlgorithms.HmacSha256Signature,
  175. SecurityAlgorithmSuite.Basic256Sha256,
  176. "Basic256Sha256");
  177. // 3DES
  178. AssertSecurityAlgorithmSuite (
  179. EncryptedXml.XmlEncRSAOAEPUrl,
  180. SignedXml.XmlDsigRSASHA1Url,
  181. SignedXml.XmlDsigExcC14NTransformUrl,
  182. SignedXml.XmlDsigSHA1Url,
  183. EncryptedXml.XmlEncTripleDESUrl,
  184. // enc, sig, sym
  185. 192, 192, 192,
  186. EncryptedXml.XmlEncTripleDESKeyWrapUrl,
  187. SignedXml.XmlDsigHMACSHA1Url,
  188. SecurityAlgorithmSuite.TripleDes,
  189. "TripleDes");
  190. AssertSecurityAlgorithmSuite (
  191. EncryptedXml.XmlEncRSA15Url,
  192. SignedXml.XmlDsigRSASHA1Url,
  193. SignedXml.XmlDsigExcC14NTransformUrl,
  194. SignedXml.XmlDsigSHA1Url,
  195. EncryptedXml.XmlEncTripleDESUrl,
  196. // enc, sig, sym
  197. 192, 192, 192,
  198. EncryptedXml.XmlEncTripleDESKeyWrapUrl,
  199. SignedXml.XmlDsigHMACSHA1Url,
  200. SecurityAlgorithmSuite.TripleDesRsa15,
  201. "TripleDesRsa15");
  202. AssertSecurityAlgorithmSuite (
  203. EncryptedXml.XmlEncRSAOAEPUrl,
  204. SecurityAlgorithms.RsaSha256Signature,
  205. SignedXml.XmlDsigExcC14NTransformUrl,
  206. EncryptedXml.XmlEncSHA256Url,
  207. EncryptedXml.XmlEncTripleDESUrl,
  208. // enc, sig, sym
  209. 192, 192, 192,
  210. EncryptedXml.XmlEncTripleDESKeyWrapUrl,
  211. // Can't we get the same string from some const?
  212. SecurityAlgorithms.HmacSha256Signature,
  213. SecurityAlgorithmSuite.TripleDesSha256,
  214. "TripleDesSha256");
  215. AssertSecurityAlgorithmSuite (
  216. EncryptedXml.XmlEncRSA15Url,
  217. SecurityAlgorithms.RsaSha256Signature,
  218. SignedXml.XmlDsigExcC14NTransformUrl,
  219. EncryptedXml.XmlEncSHA256Url,
  220. EncryptedXml.XmlEncTripleDESUrl,
  221. // enc, sig, sym
  222. 192, 192, 192,
  223. EncryptedXml.XmlEncTripleDESKeyWrapUrl,
  224. // Can't we get the same string from some const?
  225. SecurityAlgorithms.HmacSha256Signature,
  226. SecurityAlgorithmSuite.TripleDesSha256Rsa15,
  227. "TripleDesSha256Rsa15");
  228. }
  229. }
  230. }