Author: atsushi
Date: 2007-01-10 22:36:54 -0500 (Wed, 10 Jan 2007)
New Revision: 70831

Added:
   
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/CalcSampleProxy.cs
   
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/SecurityTokenSpeficicationTest.cs
Modified:
   trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/MessageSecurityBindingSupport.cs
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/MessageSecurityUtility.cs
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Description/ChangeLog
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Description/ClientCredentials.cs
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Description/ServiceCredentials.cs
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/ChangeLog
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/WrappedKeySecurityToken.cs
   trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChangeLog
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/WSSecurityTokenSerializer.cs
   trunk/olive/class/System.ServiceModel/System.ServiceModel_test.dll.sources
   
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/AsymmetricSecurityBindingElementTest.cs
   
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/ChangeLog
   
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/SecurityBindingElementTest.cs
   
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ChangeLog
   
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/WSSecurityTokenSerializerTest.cs
   trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/ChangeLog
   
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/ClientCredentialsSecurityTokenManagerTest.cs
Log:
2007-01-11  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * WrappedKeySecurityToken.cs : added internal ReferenceList, to
          output e:ReferenceList (kind of compromised solution; see comments).

        * WSSecurityTokenSerializer.cs : add e:ReferenceList output.

        * MessageSecurityUtility.cs: acctually ReferenceList was inside
          EncryptedKey. So, when a key itself is used to encrypt data,
          ReferenceList is contained by itself.
        * MessageSecurityBindingSupport.cs :
          added CollectInitiatorSupportingTokens().

        * ClientCredentials.cs, ServiceCredentials.cs : Clone() throws
          NotImplementedException when it returns an instance of different
          type.

        * AsymmetricSecurityBindingElement.cs, CalcSampleProxy.cs : moved
          sample proxy type to new file.
        * SecurityBindingElementTest.cs : some tests for
          SupportingTokenParameters.

        * WSSecurityTokenSerializerTest.cs : some tests for 
          SecurityContextSecurityToken.
        * SecurityTokenSpeficicationTest.cs : new test.

        * ClientCredentialsSecurityTokenManagerTest.cs : added custom token
          classes and non-finished test. Added Clone() test.



Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog    
    2007-01-11 03:20:44 UTC (rev 70830)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog    
    2007-01-11 03:36:54 UTC (rev 70831)
@@ -1,3 +1,11 @@
+2007-01-11  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * MessageSecurityUtility.cs: acctually ReferenceList was inside
+         EncryptedKey. So, when a key itself is used to encrypt data,
+         ReferenceList is contained by itself.
+       * MessageSecurityBindingSupport.cs :
+         added CollectInitiatorSupportingTokens().
+
 2007-01-10  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * MessageSecurityUtility.cs: it should support ReferenceList-less

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/MessageSecurityBindingSupport.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/MessageSecurityBindingSupport.cs
 2007-01-11 03:20:44 UTC (rev 70830)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/MessageSecurityBindingSupport.cs
 2007-01-11 03:36:54 UTC (rev 70831)
@@ -4,7 +4,7 @@
 // Author:
 //     Atsushi Enomoto <[EMAIL PROTECTED]>
 //
-// Copyright (C) 2005-2006 Novell, Inc.  http://www.novell.com
+// Copyright (C) 2005-2007 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
@@ -39,6 +39,33 @@
 
 namespace System.ServiceModel.Channels
 {
+       internal class SupportingTokenInfo
+       {
+               public SupportingTokenInfo (SecurityToken token,
+                       SecurityTokenAttachmentMode mode,
+                       bool isOptional)
+               {
+                       Token = token;
+                       Mode = mode;
+                       IsOptional = isOptional;
+               }
+
+               public SecurityToken Token;
+               public SecurityTokenAttachmentMode Mode;
+               public bool IsOptional;
+       }
+
+       internal class SupportingTokenInfoCollection : 
Collection<SupportingTokenInfo>
+       {
+               protected override void InsertItem (int index, 
SupportingTokenInfo item)
+               {
+                       foreach (SupportingTokenInfo i in this)
+                               if (i.Token.GetType () == item.Token.GetType ())
+                                       throw new ArgumentException 
(String.Format ("Supporting tokens do not allow multiple SecurityTokens of the 
same type: {0}", i.Token.GetType ()));
+                       base.InsertItem (index, item);
+               }
+       }
+
        internal abstract class MessageSecurityBindingSupport
        {
                SecurityTokenManager manager;
@@ -233,6 +260,41 @@
                        this.listener = null;
                }
 
+               public SupportingTokenInfoCollection 
CollectInitiatorSupportingTokens (
+                       string action,
+                       EndpointAddress to)
+               {
+                       SupportingTokenInfoCollection tokens =
+                               new SupportingTokenInfoCollection ();
+
+                       SupportingTokenParameters supp;
+
+                       CollectInitiatorSupportingTokensCore (tokens, 
Element.EndpointSupportingTokenParameters, to, true);
+                       if 
(!Element.OperationSupportingTokenParameters.TryGetValue (action, out supp))
+                               CollectInitiatorSupportingTokensCore (tokens, 
supp, to, true);
+                       CollectInitiatorSupportingTokensCore (tokens, 
Element.OptionalEndpointSupportingTokenParameters, to, false);
+                       if 
(!Element.OptionalOperationSupportingTokenParameters.TryGetValue (action, out 
supp))
+                               CollectInitiatorSupportingTokensCore (tokens, 
supp, to, false);
+
+                       return tokens;
+               }
+
+               void CollectInitiatorSupportingTokensCore (
+                       SupportingTokenInfoCollection l,
+                       SupportingTokenParameters s,
+                       EndpointAddress to,
+                       bool required)
+               {
+                       foreach (SecurityTokenParameters p in s.Signed)
+                               l.Add (new SupportingTokenInfo 
(GetEncryptionToken (to, p), SecurityTokenAttachmentMode.Signed, required));
+                       foreach (SecurityTokenParameters p in s.Endorsing)
+                               l.Add (new SupportingTokenInfo 
(GetEncryptionToken (to, p), SecurityTokenAttachmentMode.Endorsing, required));
+                       foreach (SecurityTokenParameters p in s.SignedEndorsing)
+                               l.Add (new SupportingTokenInfo 
(GetEncryptionToken (to, p), SecurityTokenAttachmentMode.SignedEndorsing, 
required));
+                       foreach (SecurityTokenParameters p in s.SignedEncrypted)
+                               l.Add (new SupportingTokenInfo 
(GetEncryptionToken (to, p), SecurityTokenAttachmentMode.SignedEncrypted, 
required));
+               }
+
                SecurityToken GetSigningToken (Uri listenUri, 
SecurityTokenParameters targetParams)
                {
                        SecurityTokenRequirement requirement =

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/MessageSecurityUtility.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/MessageSecurityUtility.cs
        2007-01-11 03:20:44 UTC (rev 70830)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/MessageSecurityUtility.cs
        2007-01-11 03:36:54 UTC (rev 70831)
@@ -103,6 +103,10 @@
                                direction == MessageDirection.Input ?
                                initiatorParams : recipientParams;
 
+                       SupportingTokenInfoCollection tokens =
+                               security.CollectInitiatorSupportingTokens 
(msg.Headers.Action, messageTo);
+
+
                        // SecurityTokenInclusionMode
                        // - Initiator or Recipient
                        // - done or notyet. FIXME: not implemented yet
@@ -220,7 +224,7 @@
                                sxml.KeyInfo.AddClause (sigKeyInfo);
 
                                // encrypt
-                               string ekeyId = messageId + "-" + 
identForMessageId++;;
+                               string ekeyId = messageId + "-" + 
identForMessageId++;
 
                                EncryptedXml exml = new EncryptedXml ();
                                ekey = new WrappedKeySecurityToken (ekeyId,
@@ -229,7 +233,8 @@
                                        encToken,
                                        new SecurityKeyIdentifier (encClause));
                                encRefList = new ReferenceList ();
-                               SecurityTokenReferenceKeyInfo encKeyInfo = new 
SecurityTokenReferenceKeyInfo (encClause, serializer, doc);
+                               if (!initiatorParams.RequireDerivedKeys)
+                                       ekey.ReferenceList = encRefList;
 
                                EncryptedData edata = Encrypt (body, aes, 
suite, ekeyId, encRefList, encClause, serializer, exml, doc);
                                edata.KeyInfo = null;
@@ -273,9 +278,9 @@
                                        derivedKey.SecurityTokenReference =
                                                new LocalIdKeyIdentifierClause 
(ekey.Id);
                                header.Contents.Add (derivedKey);
+                               if (encRefList != null)
+                                       header.Contents.Add (encRefList);
                        }
-                       if (encRefList != null)
-                               header.Contents.Add (encRefList);
 
                        if (sigenc != null)
                                header.Contents.Add (sigenc);
@@ -477,13 +482,12 @@
                        aes.Mode = CipherMode.CBC;
 
                        // decrypt the body with the decrypted key
-                       bool hasReferenceList = false;
                        Collection<string> references = new Collection<string> 
();
-                       foreach (XmlElement rlist in security.SelectNodes 
("e:ReferenceList", nsmgr)) {
-                               hasReferenceList = true;
+                       foreach (XmlElement rlist in security.SelectNodes 
("e:ReferenceList", nsmgr))
                                foreach (XmlElement encref in rlist.SelectNodes 
("e:DataReference | e:KeyReference", nsmgr))
                                        references.Add (StripUri 
(encref.GetAttribute ("URI")));
-                       }
+                       foreach (EncryptedReference er in 
encryptedKey.ReferenceList)
+                               references.Add (StripUri (er.Uri));
 
                        Collection<XmlElement> list = new 
Collection<XmlElement> ();
                        foreach (string uri in references) {
@@ -493,12 +497,6 @@
                                else
                                        throw new MessageSecurityException 
(String.Format ("On decryption, EncryptedData with Id '{0}', referenced by 
ReferenceData, was not found.", uri));
                        }
-                       // sometimes .net does not seem to give ReferenceList
-                       // (not sure if it is spec requirement; reading WS-
-                       // buzzspec is too boring)
-                       if (!hasReferenceList)
-                               foreach (XmlElement el in doc.SelectNodes 
("//e:EncryptedData", nsmgr))
-                                       list.Add (el);
 
                        foreach (XmlElement el in list) {
                                EncryptedData ed2 = new EncryptedData ();
@@ -508,9 +506,12 @@
                                if (ed2.GetXml () == null) throw new Exception 
("Gyabo");
                                encXml.ReplaceData (el, DecryptLax (encXml, 
ed2, aes));
                        }
-//Console.WriteLine ("======== Decrypted Document ========");
-//doc.Save (Console.Out);
-
+/*
+Console.WriteLine ("======== Decrypted Document ========");
+doc.PreserveWhitespace = false;
+doc.Save (Console.Out);
+doc.PreserveWhitespace = true;
+*/
                        if (security.SelectSingleNode ("dsig:Signature", nsmgr) 
== null)
                                throw new MessageSecurityException ("The the 
message signature is expected but not found.");
                }

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Description/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Description/ChangeLog 
    2007-01-11 03:20:44 UTC (rev 70830)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Description/ChangeLog 
    2007-01-11 03:36:54 UTC (rev 70831)
@@ -1,3 +1,9 @@
+2007-01-11  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * ClientCredentials.cs, ServiceCredentials.cs : Clone() throws
+         NotImplementedException when it returns an instance of different
+         type.
+
 2006-12-14  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * ServiceMetadataExtension.cs : raising an NIE than returning null

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Description/ClientCredentials.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Description/ClientCredentials.cs
  2007-01-11 03:20:44 UTC (rev 70830)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Description/ClientCredentials.cs
  2007-01-11 03:36:54 UTC (rev 70831)
@@ -100,7 +100,10 @@
 
                public ClientCredentials Clone ()
                {
-                       return CloneCore ();
+                       ClientCredentials ret = CloneCore ();
+                       if (ret.GetType () != GetType ())
+                               throw new NotImplementedException ("CloneCore() 
must be implemented to return an instance of the same type in this custom 
ClientCredentials type.");
+                       return ret;
                }
 
                protected virtual ClientCredentials CloneCore ()

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Description/ServiceCredentials.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Description/ServiceCredentials.cs
 2007-01-11 03:20:44 UTC (rev 70830)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Description/ServiceCredentials.cs
 2007-01-11 03:36:54 UTC (rev 70831)
@@ -95,7 +95,10 @@
 
                public ServiceCredentials Clone ()
                {
-                       return CloneCore ();
+                       ClientCredentials ret = CloneCore ();
+                       if (ret.GetType () != GetType ())
+                               throw new NotImplementedException ("CloneCore() 
must be implemented to return an instance of the same type in this custom 
ServiceCredentials type.");
+                       return ret;
                }
 
                protected virtual ServiceCredentials CloneCore ()

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChangeLog    
    2007-01-11 03:20:44 UTC (rev 70830)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChangeLog    
    2007-01-11 03:36:54 UTC (rev 70831)
@@ -1,3 +1,7 @@
+2007-01-11  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * WSSecurityTokenSerializer.cs : add e:ReferenceList output.
+
 2007-01-09  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * WSSecurityTokenSerializer.cs : X509Thumbprint is not supported

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/WSSecurityTokenSerializer.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/WSSecurityTokenSerializer.cs
     2007-01-11 03:20:44 UTC (rev 70830)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/WSSecurityTokenSerializer.cs
     2007-01-11 03:36:54 UTC (rev 70831)
@@ -554,6 +554,15 @@
                        w.WriteString (Convert.ToBase64String 
(token.GetWrappedKey ()));
                        w.WriteEndElement ();
                        w.WriteEndElement ();
+                       if (token.ReferenceList != null) {
+                               w.WriteStartElement ("e", "ReferenceList", 
encNS);
+                               foreach (DataReference er in 
token.ReferenceList) {
+                                       w.WriteStartElement ("DataReference", 
encNS);
+                                       w.WriteAttributeString ("URI", er.Uri);
+                                       w.WriteEndElement ();
+                               }
+                               w.WriteEndElement ();
+                       }
                        w.WriteEndElement ();
                }
        }

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/ChangeLog
 2007-01-11 03:20:44 UTC (rev 70830)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/ChangeLog
 2007-01-11 03:36:54 UTC (rev 70831)
@@ -1,3 +1,8 @@
+2007-01-11  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * WrappedKeySecurityToken.cs : added internal ReferenceList, to
+         output e:ReferenceList (kind of compromised solution; see comments).
+
 2007-01-09  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * WrappedKeySecurityToken.cs : GetWrappedKey() return value should

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/WrappedKeySecurityToken.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/WrappedKeySecurityToken.cs
        2007-01-11 03:20:44 UTC (rev 70830)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/WrappedKeySecurityToken.cs
        2007-01-11 03:36:54 UTC (rev 70831)
@@ -27,6 +27,7 @@
 //
 using System;
 using System.Collections.ObjectModel;
+using System.Security.Cryptography.Xml;
 using System.Xml;
 using System.IdentityModel.Policy;
 using System.IdentityModel.Tokens;
@@ -42,6 +43,7 @@
                SecurityKeyIdentifier wrap_token_ref;
                DateTime valid_from = DateTime.Now.ToUniversalTime ();
                ReadOnlyCollection<SecurityKey> keys;
+               ReferenceList reference_list;
 
                public WrappedKeySecurityToken (
                        string id,
@@ -76,6 +78,14 @@
                                throw new ArgumentException (String.Format 
("None of the security keys in the argument token supports specified wrapping 
algorithm '{0}'", wrappingAlgorithm));
                }
 
+               // FIXME: it is kind of compromised solution to output
+               // ReferenceList inside e:EncryptedKey and might disappear
+               // when non-wrapped key is represented by another token type.
+               internal ReferenceList ReferenceList {
+                       get { return reference_list; }
+                       set { reference_list = value; }
+               }
+
                public override DateTime ValidFrom {
                        get { return valid_from; }
                }

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel_test.dll.sources
===================================================================
--- trunk/olive/class/System.ServiceModel/System.ServiceModel_test.dll.sources  
2007-01-11 03:20:44 UTC (rev 70830)
+++ trunk/olive/class/System.ServiceModel/System.ServiceModel_test.dll.sources  
2007-01-11 03:36:54 UTC (rev 70831)
@@ -4,6 +4,7 @@
 System.ServiceModel.Channels/BindingContextTest.cs
 System.ServiceModel.Channels/BindingElementTest.cs
 System.ServiceModel.Channels/BindingTest.cs
+System.ServiceModel.Channels/CalcSampleProxy.cs
 System.ServiceModel.Channels/CommunicationObjectTest.cs
 System.ServiceModel.Channels/CustomBindingTest.cs
 System.ServiceModel.Channels/DebugBindingElement.cs
@@ -69,6 +70,7 @@
 System.ServiceModel.Security/ScopedMessagePartSpecificationTest.cs
 System.ServiceModel.Security/SecurityAlgorithmSuiteTest.cs
 System.ServiceModel.Security/SecurityMessagePropertyTest.cs
+System.ServiceModel.Security/SecurityTokenSpeficicationTest.cs
 System.ServiceModel.Security/ServiceCredentialsSecurityTokenManagerTest.cs
 System.ServiceModel.Security/ServiceSecurityContextTest.cs
 System.ServiceModel.Security/SupportingTokenParametersTest.cs

Modified: 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/ChangeLog
===================================================================
--- trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/ChangeLog    
2007-01-11 03:20:44 UTC (rev 70830)
+++ trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/ChangeLog    
2007-01-11 03:36:54 UTC (rev 70831)
@@ -1,3 +1,8 @@
+2007-01-11  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * ClientCredentialsSecurityTokenManagerTest.cs : added custom token
+         classes and non-finished test. Added Clone() test.
+
 2006-12-04  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * ServiceHostTest.cs : added test for ServiceMetadataBehavior

Modified: 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/ClientCredentialsSecurityTokenManagerTest.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/ClientCredentialsSecurityTokenManagerTest.cs
 2007-01-11 03:20:44 UTC (rev 70830)
+++ 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel/ClientCredentialsSecurityTokenManagerTest.cs
 2007-01-11 03:36:54 UTC (rev 70831)
@@ -28,6 +28,7 @@
 using System;
 using System.IdentityModel.Selectors;
 using System.IdentityModel.Tokens;
+using System.Security.Cryptography;
 using System.Security.Cryptography.X509Certificates;
 using System.ServiceModel;
 using System.ServiceModel.Channels;
@@ -46,25 +47,12 @@
        [TestFixture]
        public class ClientCredentialsSecurityTokenManagerTest
        {
-               class MyManager : ClientCredentialsSecurityTokenManager
-               {
-                       public MyManager ()
-                               : base (new ClientCredentials ())
-                       {
-                       }
-
-                       public bool IsIssued (SecurityTokenRequirement r)
-                       {
-                               return IsIssuedSecurityTokenRequirement (r);
-                       }
-               }
-
                MyManager def_c;
 
                [SetUp]
                public void Initialize ()
                {
-                       def_c = new MyManager ();
+                       def_c = new MyManager (new MyClientCredentials ());
                }
 
 /*
@@ -576,5 +564,149 @@
                                as RsaSecurityTokenAuthenticator;
                        Assert.IsNotNull (rsa, "#1");
                }
+
+               [Test]
+               [Ignore ("this test is not fully written yet.")]
+               public void OtherParameterInEndorsingSupport ()
+               {
+                       SymmetricSecurityBindingElement be =
+                               new SymmetricSecurityBindingElement ();
+                       be.ProtectionTokenParameters =
+                               new X509SecurityTokenParameters ();
+                       be.EndpointSupportingTokenParameters.Endorsing.Add (
+                               new MyEndorsingTokenParameters ());
+                       Binding b = new CustomBinding (be, new 
HttpTransportBindingElement ());
+                       X509Certificate2 cert = new X509Certificate2 
("Test/Resources/test.pfx", "mono");
+                       EndpointAddress ea = new EndpointAddress (new Uri 
("http://localhost:37564";), new X509CertificateEndpointIdentity (cert));
+                       CalcProxy client = new CalcProxy (b, ea);
+                       client.Endpoint.Behaviors.RemoveAll<ClientCredentials> 
();
+                       client.Endpoint.Behaviors.Add (new MyClientCredentials 
());
+                       client.Sum (1, 2);
+               }
+
+               [Test]
+               [ExpectedException (typeof (NotImplementedException))]
+               public void MissingCloneCore ()
+               {
+                       new MyClientCredentials2 ().Clone ();
+               }
        }
+
+       class MyClientCredentials : ClientCredentials
+       {
+               public override SecurityTokenManager CreateSecurityTokenManager 
()
+               {
+                       return new MyManager (this);
+               }
+
+               protected override ClientCredentials CloneCore ()
+               {
+                       return new MyClientCredentials ();
+               }
+       }
+
+       class MyClientCredentials2 : ClientCredentials
+       {
+               public override SecurityTokenManager CreateSecurityTokenManager 
()
+               {
+                       return null;
+               }
+       }
+
+       class MyManager : ClientCredentialsSecurityTokenManager
+       {
+               public MyManager (MyClientCredentials cred)
+                       : base (cred)
+               {
+               }
+
+               public bool IsIssued (SecurityTokenRequirement r)
+               {
+                       return IsIssuedSecurityTokenRequirement (r);
+               }
+
+               public override SecurityTokenProvider 
CreateSecurityTokenProvider (SecurityTokenRequirement tokenRequirement
+)
+               {
+                       if (tokenRequirement.TokenType == "urn:my")
+                               return new MySecurityTokenProvider ();
+                       return base.CreateSecurityTokenProvider 
(tokenRequirement);
+               }
+
+               public override SecurityTokenSerializer 
CreateSecurityTokenSerializer (SecurityTokenVersion ver)
+               {
+                       return new MySecurityTokenSerializer ();
+               }
+       }
+
+       class MySecurityTokenProvider : SecurityTokenProvider
+       {
+               public MySecurityTokenProvider ()
+               {
+               }
+
+               protected override SecurityToken GetTokenCore (TimeSpan timeout)
+               {
+                       return new RsaSecurityToken (RSA.Create ());
+               }
+       }
+
+       class MySecurityTokenSerializer : WSSecurityTokenSerializer
+       {
+               protected override void WriteTokenCore (XmlWriter w, 
SecurityToken token)
+               {
+                       RsaSecurityToken r = token as RsaSecurityToken;
+                       w.Flush ();
+                       if (r != null)
+                               w.WriteRaw (r.Rsa.ToXmlString (false));
+                       else
+                               base.WriteTokenCore (w, token);
+               }
+       }
+
+       class MyEndorsingTokenParameters : SecurityTokenParameters
+       {
+               public MyEndorsingTokenParameters ()
+               {
+               }
+
+               protected MyEndorsingTokenParameters 
(MyEndorsingTokenParameters source)
+               {
+               }
+
+               protected override bool HasAsymmetricKey {
+                       get { return true; }
+               }
+
+               protected override bool SupportsClientAuthentication {
+                       get { return true; }
+               }
+
+               protected override bool SupportsClientWindowsIdentity {
+                       get { return false; }
+               }
+
+               protected override bool SupportsServerAuthentication {
+                       get { return true; }
+               }
+
+               protected override SecurityTokenParameters CloneCore ()
+               {
+                       return new MyEndorsingTokenParameters (this);
+               }
+
+               protected override SecurityKeyIdentifierClause 
CreateKeyIdentifierClause (
+                       SecurityToken token, SecurityTokenReferenceStyle 
referenceStyle)
+               {
+                       RsaSecurityToken r = token as RsaSecurityToken;
+                       return r.CreateKeyIdentifierClause 
<RsaKeyIdentifierClause> ();
+               }
+
+               protected override void InitializeSecurityTokenRequirement 
(SecurityTokenRequirement requirement)
+               {
+                       // If there were another token type that supports 
protection
+                       // and does not require X509, it should be used instead 
...
+                       requirement.TokenType = "urn:my";
+               }
+       }
 }

Modified: 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/AsymmetricSecurityBindingElementTest.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/AsymmetricSecurityBindingElementTest.cs
     2007-01-11 03:20:44 UTC (rev 70830)
+++ 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/AsymmetricSecurityBindingElementTest.cs
     2007-01-11 03:36:54 UTC (rev 70831)
@@ -51,91 +51,6 @@
                static X509Certificate2 cert = new X509Certificate2 
("Test/Resources/test.pfx", "mono");
                static X509Certificate2 cert2 = new X509Certificate2 
("Test/Resources/test.cer");
 
-               [ServiceContract]
-               public interface ICalc
-               {
-                       [OperationContract]
-                       int Sum (int a, int b);
-
-                       [OperationContract (AsyncPattern = true)]
-                       IAsyncResult BeginSum (int a, int b, AsyncCallback cb, 
object state);
-
-                       int EndSum (IAsyncResult result);
-               }
-
-               public class CalcProxy : ClientBase<ICalc>, ICalc
-               {
-                       public CalcProxy (Binding binding, EndpointAddress 
address)
-                               : base (binding, address)
-                       {
-                       }
-
-                       public int Sum (int a, int b)
-                       {
-                               return Channel.Sum (a, b);
-                       }
-
-                       public IAsyncResult BeginSum (int a, int b, 
AsyncCallback cb, object state)
-                       {
-                               return Channel.BeginSum (a, b, cb, state);
-                       }
-
-                       public int EndSum (IAsyncResult result)
-                       {
-                               return Channel.EndSum (result);
-                       }
-               }
-
-               public class CalcService : ICalc
-               {
-                       public int Sum (int a, int b)
-                       {
-                               return a + b;
-                       }
-
-                       public IAsyncResult BeginSum (int a, int b, 
AsyncCallback cb, object state)
-                       {
-                               return new CalcAsyncResult (a, b, cb, state);
-                       }
-
-                       public int EndSum (IAsyncResult result)
-                       {
-                               CalcAsyncResult c = (CalcAsyncResult) result;
-                               return c.A + c.B;
-                       }
-               }
-
-               class CalcAsyncResult : IAsyncResult
-               {
-                       public int A, B;
-                       AsyncCallback callback;
-                       object state;
-
-                       public CalcAsyncResult (int a, int b, AsyncCallback cb, 
object state)
-                       {
-                               A = a;
-                               B = b;
-                               callback = cb;
-                               this.state = state;
-                       }
-
-                       public object AsyncState {
-                               get { return state; }
-                       }
-
-                       public WaitHandle AsyncWaitHandle {
-                               get { return null; }
-                       }
-
-                       public bool CompletedSynchronously {
-                               get { return true; }
-                       }
-
-                       public bool IsCompleted {
-                               get { return true; }
-                       }
-               }
-
                // InitiatorTokenParameters should have asymmetric key.
                [Test]
                [ExpectedException (typeof (InvalidOperationException))]

Added: 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/CalcSampleProxy.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/CalcSampleProxy.cs
  2007-01-11 03:20:44 UTC (rev 70830)
+++ 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/CalcSampleProxy.cs
  2007-01-11 03:36:54 UTC (rev 70831)
@@ -0,0 +1,132 @@
+//
+// CalcSampleProxy.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.Generic;
+using System.Collections.ObjectModel;
+using System.IO;
+using System.Net;
+using System.Net.Security;
+using System.Security.Cryptography.X509Certificates;
+using System.IdentityModel.Selectors;
+using System.IdentityModel.Tokens;
+using System.ServiceModel;
+using System.ServiceModel.Channels;
+using System.ServiceModel.Description;
+using System.ServiceModel.Security;
+using System.ServiceModel.Security.Tokens;
+using System.Threading;
+using System.Xml;
+using NUnit.Framework;
+
+namespace MonoTests.System.ServiceModel.Channels
+{
+       [ServiceContract]
+       public interface ICalc
+       {
+               [OperationContract]
+               int Sum (int a, int b);
+
+               [OperationContract (AsyncPattern = true)]
+               IAsyncResult BeginSum (int a, int b, AsyncCallback cb, object 
state);
+
+               int EndSum (IAsyncResult result);
+       }
+
+       public class CalcProxy : ClientBase<ICalc>, ICalc
+       {
+               public CalcProxy (Binding binding, EndpointAddress address)
+                       : base (binding, address)
+               {
+               }
+
+               public int Sum (int a, int b)
+               {
+                       return Channel.Sum (a, b);
+               }
+
+               public IAsyncResult BeginSum (int a, int b, AsyncCallback cb, 
object state)
+               {
+                       return Channel.BeginSum (a, b, cb, state);
+               }
+
+               public int EndSum (IAsyncResult result)
+               {
+                       return Channel.EndSum (result);
+               }
+       }
+
+       public class CalcService : ICalc
+       {
+               public int Sum (int a, int b)
+               {
+                       return a + b;
+               }
+
+               public IAsyncResult BeginSum (int a, int b, AsyncCallback cb, 
object state)
+               {
+                       return new CalcAsyncResult (a, b, cb, state);
+               }
+
+               public int EndSum (IAsyncResult result)
+               {
+                       CalcAsyncResult c = (CalcAsyncResult) result;
+                       return c.A + c.B;
+               }
+       }
+
+       class CalcAsyncResult : IAsyncResult
+       {
+               public int A, B;
+               AsyncCallback callback;
+               object state;
+
+               public CalcAsyncResult (int a, int b, AsyncCallback cb, object 
state)
+               {
+                       A = a;
+                       B = b;
+                       callback = cb;
+                       this.state = state;
+               }
+
+               public object AsyncState {
+                       get { return state; }
+               }
+
+               public WaitHandle AsyncWaitHandle {
+                       get { return null; }
+               }
+
+               public bool CompletedSynchronously {
+                       get { return true; }
+               }
+
+               public bool IsCompleted {
+                       get { return true; }
+               }
+       }
+}

Modified: 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/ChangeLog
   2007-01-11 03:20:44 UTC (rev 70830)
+++ 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/ChangeLog
   2007-01-11 03:36:54 UTC (rev 70831)
@@ -1,3 +1,10 @@
+2007-01-11  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * AsymmetricSecurityBindingElement.cs, CalcSampleProxy.cs : moved
+         sample proxy type to new file.
+       * SecurityBindingElementTest.cs : some tests for
+         SupportingTokenParameters.
+
 2006-12-08  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * InterceptorBindingElement.cs : new utility binding element for

Modified: 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/SecurityBindingElementTest.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/SecurityBindingElementTest.cs
       2007-01-11 03:20:44 UTC (rev 70830)
+++ 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/SecurityBindingElementTest.cs
       2007-01-11 03:36:54 UTC (rev 70831)
@@ -408,7 +408,7 @@
                [Test]
                [ExpectedException (typeof (ArgumentException))]
                [Category ("NotWorking")]
-               public void CheckDuplicateAuthenticatorTypes ()
+               public void CheckDuplicateAuthenticatorTypesClient ()
                {
                        SymmetricSecurityBindingElement be =
                                new SymmetricSecurityBindingElement ();
@@ -421,6 +421,31 @@
                        
be.OptionalEndpointSupportingTokenParameters.Endorsing.Add (
                                new X509SecurityTokenParameters ());
                        Binding b = new CustomBinding (be, new 
HttpTransportBindingElement ());
+                       ClientCredentials cred = new ClientCredentials ();
+                       cred.ClientCertificate.Certificate =
+                               new X509Certificate2 
("Test/Resources/test.pfx", "mono");
+                       IChannelFactory<IReplyChannel> ch = 
b.BuildChannelFactory<IReplyChannel> (new Uri ("http://localhost:37564";), cred);
+                       ch.Open ();
+                       // in case Open() failed to raise an error...
+                       ch.Close ();
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               [Category ("NotWorking")]
+               public void CheckDuplicateAuthenticatorTypesService ()
+               {
+                       SymmetricSecurityBindingElement be =
+                               new SymmetricSecurityBindingElement ();
+                       be.ProtectionTokenParameters =
+                               new X509SecurityTokenParameters ();
+                       be.EndpointSupportingTokenParameters.Endorsing.Add (
+                               new X509SecurityTokenParameters ());
+                       // This causes multiple supporting token authenticator
+                       // of the same type.
+                       
be.OptionalEndpointSupportingTokenParameters.Endorsing.Add (
+                               new X509SecurityTokenParameters ());
+                       Binding b = new CustomBinding (be, new 
HttpTransportBindingElement ());
                        ServiceCredentials cred = new ServiceCredentials ();
                        cred.ServiceCertificate.Certificate =
                                new X509Certificate2 
("Test/Resources/test.pfx", "mono");
@@ -429,5 +454,23 @@
                        // in case Open() failed to raise an error...
                        ch.Close ();
                }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void NonEndorsibleParameterInEndorsingSupport ()
+               {
+                       SymmetricSecurityBindingElement be =
+                               new SymmetricSecurityBindingElement ();
+                       be.ProtectionTokenParameters =
+                               new X509SecurityTokenParameters ();
+                       be.EndpointSupportingTokenParameters.Endorsing.Add (
+                               new UserNameSecurityTokenParameters ());
+                       Binding b = new CustomBinding (be, new 
HttpTransportBindingElement ());
+                       X509Certificate2 cert = new X509Certificate2 
("Test/Resources/test.pfx", "mono");
+                       EndpointAddress ea = new EndpointAddress (new Uri 
("http://localhost:37564";), new X509CertificateEndpointIdentity (cert));
+                       CalcProxy client = new CalcProxy (b, ea);
+                       client.ClientCredentials.UserName.UserName = "rupert";
+                       client.Sum (1, 2);
+               }
        }
 }

Modified: 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ChangeLog
   2007-01-11 03:20:44 UTC (rev 70830)
+++ 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ChangeLog
   2007-01-11 03:36:54 UTC (rev 70831)
@@ -1,3 +1,9 @@
+2007-01-11  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * WSSecurityTokenSerializerTest.cs : some tests for 
+         SecurityContextSecurityToken.
+       * SecurityTokenSpeficicationTest.cs : new test.
+
 2007-01-10  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * WSSecurityTokenSerializerTest.cs : added a few x509 tests for

Added: 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/SecurityTokenSpeficicationTest.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/SecurityTokenSpeficicationTest.cs
   2007-01-11 03:20:44 UTC (rev 70830)
+++ 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/SecurityTokenSpeficicationTest.cs
   2007-01-11 03:36:54 UTC (rev 70831)
@@ -0,0 +1,52 @@
+//
+// SecurityTokenSpeficicationTest.cs
+//
+// Author:
+//     Atsushi Enomoto <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 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.Policy;
+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 SecurityTokenSpeficicationTest
+       {
+               [Test]
+               public void ConstructorNullPolicies ()
+               {
+                       new SecurityTokenSpecification (new 
UserNameSecurityToken ("mono", "monopass"), new 
ReadOnlyCollection<IAuthorizationPolicy> (new IAuthorizationPolicy [0]));
+               }
+       }
+}

Modified: 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/WSSecurityTokenSerializerTest.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/WSSecurityTokenSerializerTest.cs
    2007-01-11 03:20:44 UTC (rev 70830)
+++ 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/WSSecurityTokenSerializerTest.cs
    2007-01-11 03:36:54 UTC (rev 70831)
@@ -355,7 +355,6 @@
                                WSSecurityTokenSerializer.DefaultInstance;
                        using (XmlReader xr = XmlReader.Create (new 
StringReader (derived_key_token1))) {
                                SecurityToken token = serializer.ReadToken (xr, 
null);
-                               Assert.IsTrue (token is 
SecurityContextSecurityToken, "#1");
                        }
                }
 
@@ -367,9 +366,7 @@
                        WSSecurityTokenSerializer serializer =
                                WSSecurityTokenSerializer.DefaultInstance;
                        using (XmlReader xr = XmlReader.Create (new 
StringReader (derived_key_token1))) {
-                               SecurityToken token = serializer.ReadToken (xr,
-                                       
SecurityTokenResolver.CreateDefaultSecurityTokenResolver (new 
ReadOnlyCollection<SecurityToken> (new SecurityToken [0]), false));
-                               Assert.IsTrue (token is 
SecurityContextSecurityToken, "#1");
+                               SecurityToken token = serializer.ReadToken (xr, 
GetResolver ());
                        }
                }
 
@@ -381,11 +378,34 @@
                                WSSecurityTokenSerializer.DefaultInstance;
                        using (XmlReader xr = XmlReader.Create (new 
StringReader (derived_key_token1))) {
                                SecurityToken token = serializer.ReadToken (xr,
-                                       new MyResolver ());
+                                       GetResolver (new X509SecurityToken 
(cert, "uuid:urn:abc")));
                                Assert.IsTrue (token is 
SecurityContextSecurityToken, "#1");
                        }
                }
 
+               [Test]
+               [Category ("NotWorking")]
+               public void ReadSecurityContextSecurityTokenNoRegisteredToken ()
+               {
+                       try {
+                               
ReadSecurityContextSecurityTokenNoRegisteredTokenCore ();
+                               Assert.Fail ("Exception expected.");
+                       } catch (SecurityTokenException) {
+                       }
+               }
+
+               void ReadSecurityContextSecurityTokenNoRegisteredTokenCore ()
+               {
+                       string xml = "<c:SecurityContextToken 
u:Id=\"urn:securitycontext:1\" 
xmlns:u=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\";
 
xmlns:c=\"http://schemas.xmlsoap.org/ws/2005/02/sc\";><c:Identifier>urn:unique-id:securitycontext:1</c:Identifier></c:SecurityContextToken>";
+
+                       WSSecurityTokenSerializer serializer =
+                               WSSecurityTokenSerializer.DefaultInstance;
+                       using (XmlReader xr = XmlReader.Create (new 
StringReader (xml))) {
+                               SecurityToken token = serializer.ReadToken (xr, 
GetResolver (new X509SecurityToken (cert, "urn:unique-id:securitycontext:1")));
+                               Assert.IsTrue (token is 
SecurityContextSecurityToken, "#1");
+                       }
+               }
+
                class MyResolver : SecurityTokenResolver
                {
                        protected override bool TryResolveTokenCore 
(SecurityKeyIdentifier ident, out SecurityToken token)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to