| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- //
- // SecurityAlgorithmSuiteTest.cs
- //
- // Author:
- // Atsushi Enomoto <[email protected]>
- //
- // Copyright (C) 2006 Novell, Inc. http://www.novell.com
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using System;
- using System.Collections.ObjectModel;
- using System.IdentityModel.Tokens;
- using System.Net;
- using System.Net.Security;
- using System.ServiceModel;
- using System.ServiceModel.Channels;
- using System.ServiceModel.Security;
- using System.ServiceModel.Security.Tokens;
- using System.Security.Cryptography.Xml;
- using NUnit.Framework;
- namespace MonoTests.System.ServiceModel
- {
- [TestFixture]
- public class SecurityAlgorithmSuiteTest
- {
- static void AssertSecurityAlgorithmSuite (
- string defaultAsymmetricKeyWrapAlgorithm,
- string defaultAsymmetricSignatureAlgorithm,
- string defaultCanonicalizationAlgorithm,
- string defaultDigestAlgorithm,
- string defaultEncryptionAlgorithm,
- int defaultEncryptionKeyDerivationLength,
- int defaultSignatureKeyDerivationLength,
- int defaultSymmetricKeyLength,
- string defaultSymmetricKeyWrapAlgorithm,
- string defaultSymmetricSignatureAlgorithm,
- SecurityAlgorithmSuite target,
- string label)
- {
- Assert.AreEqual (defaultAsymmetricKeyWrapAlgorithm,
- target.DefaultAsymmetricKeyWrapAlgorithm,
- label + ".DefaultAsymmetricKeyWrapAlgorithm");
- Assert.AreEqual (defaultAsymmetricSignatureAlgorithm,
- target.DefaultAsymmetricSignatureAlgorithm,
- label + ".DefaultAsymmetricSignatureAlgorithm");
- Assert.AreEqual (defaultCanonicalizationAlgorithm,
- target.DefaultCanonicalizationAlgorithm,
- label + ".DefaultCanonicalizationAlgorithm");
- Assert.AreEqual (defaultDigestAlgorithm,
- target.DefaultDigestAlgorithm,
- label + ".DefaultDigestAlgorithm");
- Assert.AreEqual (defaultEncryptionAlgorithm,
- target.DefaultEncryptionAlgorithm,
- label + ".DefaultEncryptionAlgorithm");
- Assert.AreEqual (defaultEncryptionKeyDerivationLength,
- target.DefaultEncryptionKeyDerivationLength,
- label + ".DefaultEncryptionKeyDerivationLength");
- Assert.AreEqual (defaultSignatureKeyDerivationLength,
- target.DefaultSignatureKeyDerivationLength,
- label + ".DefaultSignatureKeyDerivationLength");
- Assert.AreEqual (defaultSymmetricKeyLength,
- target.DefaultSymmetricKeyLength,
- label + ".DefaultSymmetricKeyLength");
- Assert.AreEqual (defaultSymmetricKeyWrapAlgorithm,
- target.DefaultSymmetricKeyWrapAlgorithm,
- label + ".DefaultSymmetricKeyWrapAlgorithm");
- Assert.AreEqual (defaultSymmetricSignatureAlgorithm,
- target.DefaultSymmetricSignatureAlgorithm,
- label + ".DefaultSymmetricSignatureAlgorithm");
- }
- [Test]
- public void DefaultAlgorithm ()
- {
- Assert.AreEqual (
- SecurityAlgorithmSuite.Basic256,
- SecurityAlgorithmSuite.Default, "#1");
- }
- [Test]
- public void StaticPropertyValues ()
- {
- AssertSecurityAlgorithmSuite (
- EncryptedXml.XmlEncRSAOAEPUrl,
- SignedXml.XmlDsigRSASHA1Url,
- SignedXml.XmlDsigExcC14NTransformUrl,
- SignedXml.XmlDsigSHA1Url,
- EncryptedXml.XmlEncAES128Url,
- // enc, sig, sym
- 128, 128, 128,
- EncryptedXml.XmlEncAES128KeyWrapUrl,
- SignedXml.XmlDsigHMACSHA1Url,
- SecurityAlgorithmSuite.Basic128,
- "Basic128");
- AssertSecurityAlgorithmSuite (
- EncryptedXml.XmlEncRSA15Url,
- SignedXml.XmlDsigRSASHA1Url,
- SignedXml.XmlDsigExcC14NTransformUrl,
- SignedXml.XmlDsigSHA1Url,
- EncryptedXml.XmlEncAES128Url,
- // enc, sig, sym
- 128, 128, 128,
- EncryptedXml.XmlEncAES128KeyWrapUrl,
- SignedXml.XmlDsigHMACSHA1Url,
- SecurityAlgorithmSuite.Basic128Rsa15,
- "Basic128Rsa15");
- AssertSecurityAlgorithmSuite (
- EncryptedXml.XmlEncRSAOAEPUrl,
- SecurityAlgorithms.RsaSha256Signature,
- SignedXml.XmlDsigExcC14NTransformUrl,
- EncryptedXml.XmlEncSHA256Url,
- EncryptedXml.XmlEncAES128Url,
- // enc, sig, sym
- 128, 128, 128,
- EncryptedXml.XmlEncAES128KeyWrapUrl,
- // Can't we get the same string from some const?
- SecurityAlgorithms.HmacSha256Signature,
- SecurityAlgorithmSuite.Basic128Sha256,
- "Basic128Sha256");
- AssertSecurityAlgorithmSuite (
- EncryptedXml.XmlEncRSA15Url,
- SecurityAlgorithms.RsaSha256Signature,
- SignedXml.XmlDsigExcC14NTransformUrl,
- EncryptedXml.XmlEncSHA256Url,
- EncryptedXml.XmlEncAES128Url,
- // enc, sig, sym
- 128, 128, 128,
- EncryptedXml.XmlEncAES128KeyWrapUrl,
- // Can't we get the same string from some const?
- SecurityAlgorithms.HmacSha256Signature,
- SecurityAlgorithmSuite.Basic128Sha256Rsa15,
- "Basic128Sha256Rsa15");
- // ...192
- AssertSecurityAlgorithmSuite (
- EncryptedXml.XmlEncRSA15Url,
- SecurityAlgorithms.RsaSha256Signature,
- SignedXml.XmlDsigExcC14NTransformUrl,
- EncryptedXml.XmlEncSHA256Url,
- EncryptedXml.XmlEncAES192Url,
- // enc, sig, sym
- 192, 192, 192,
- EncryptedXml.XmlEncAES192KeyWrapUrl,
- // Can't we get the same string from some const?
- SecurityAlgorithms.HmacSha256Signature,
- SecurityAlgorithmSuite.Basic192Sha256Rsa15,
- "Basic192Sha256Rsa15");
- // ...256
- AssertSecurityAlgorithmSuite (
- EncryptedXml.XmlEncRSAOAEPUrl,
- SecurityAlgorithms.RsaSha256Signature,
- SignedXml.XmlDsigExcC14NTransformUrl,
- EncryptedXml.XmlEncSHA256Url,
- EncryptedXml.XmlEncAES256Url,
- // enc, sig, sym
- 256, 192, 256, // hmm, why 192 here?
- EncryptedXml.XmlEncAES256KeyWrapUrl,
- // Can't we get the same string from some const?
- SecurityAlgorithms.HmacSha256Signature,
- SecurityAlgorithmSuite.Basic256Sha256,
- "Basic256Sha256");
- // 3DES
- AssertSecurityAlgorithmSuite (
- EncryptedXml.XmlEncRSAOAEPUrl,
- SignedXml.XmlDsigRSASHA1Url,
- SignedXml.XmlDsigExcC14NTransformUrl,
- SignedXml.XmlDsigSHA1Url,
- EncryptedXml.XmlEncTripleDESUrl,
- // enc, sig, sym
- 192, 192, 192,
- EncryptedXml.XmlEncTripleDESKeyWrapUrl,
- SignedXml.XmlDsigHMACSHA1Url,
- SecurityAlgorithmSuite.TripleDes,
- "TripleDes");
- AssertSecurityAlgorithmSuite (
- EncryptedXml.XmlEncRSA15Url,
- SignedXml.XmlDsigRSASHA1Url,
- SignedXml.XmlDsigExcC14NTransformUrl,
- SignedXml.XmlDsigSHA1Url,
- EncryptedXml.XmlEncTripleDESUrl,
- // enc, sig, sym
- 192, 192, 192,
- EncryptedXml.XmlEncTripleDESKeyWrapUrl,
- SignedXml.XmlDsigHMACSHA1Url,
- SecurityAlgorithmSuite.TripleDesRsa15,
- "TripleDesRsa15");
- AssertSecurityAlgorithmSuite (
- EncryptedXml.XmlEncRSAOAEPUrl,
- SecurityAlgorithms.RsaSha256Signature,
- SignedXml.XmlDsigExcC14NTransformUrl,
- EncryptedXml.XmlEncSHA256Url,
- EncryptedXml.XmlEncTripleDESUrl,
- // enc, sig, sym
- 192, 192, 192,
- EncryptedXml.XmlEncTripleDESKeyWrapUrl,
- // Can't we get the same string from some const?
- SecurityAlgorithms.HmacSha256Signature,
- SecurityAlgorithmSuite.TripleDesSha256,
- "TripleDesSha256");
- AssertSecurityAlgorithmSuite (
- EncryptedXml.XmlEncRSA15Url,
- SecurityAlgorithms.RsaSha256Signature,
- SignedXml.XmlDsigExcC14NTransformUrl,
- EncryptedXml.XmlEncSHA256Url,
- EncryptedXml.XmlEncTripleDESUrl,
- // enc, sig, sym
- 192, 192, 192,
- EncryptedXml.XmlEncTripleDESKeyWrapUrl,
- // Can't we get the same string from some const?
- SecurityAlgorithms.HmacSha256Signature,
- SecurityAlgorithmSuite.TripleDesSha256Rsa15,
- "TripleDesSha256Rsa15");
- }
- }
- }
|