Author: atsushi
Date: 2006-12-09 07:41:36 -0500 (Sat, 09 Dec 2006)
New Revision: 69259

Modified:
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/ChangeLog
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/SecureConversationSecurityTokenParameters.cs
   
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/ChannelProtectionRequirements.cs
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/WSSecurityTokenSerializer.cs
   trunk/olive/class/System.ServiceModel/System.ServiceModel/ChangeLog
   
trunk/olive/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs
   
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security.Tokens/ChangeLog
   
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security.Tokens/SecureConversationSecurityTokenParametersTest.cs
   
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ChangeLog
   
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/WSSecurityTokenSerializerTest.cs
Log:
2006-12-09  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * ClientRuntimeChannel.cs : moved ChannelProtectionRequirements
          population to ChannelProtectionRequirements.cs with some fixes.

        * ChannelProtectionRequirements.cs : moved code for population from
          ContractDescription, from ClientRuntimeChannel.cs. Parts should be
          created from headers, not body parts. Fill IsBodyIncluded flag
          from ContractDescription.[Has]ProtectionLevel.
        * WSSecurityTokenSerializer.cs : implemented writer for
          WrappedKeySecurityToken.

        * WrappedKeySecurityToken.cs : implemented missing members, except for
          incomplete MatchKeyIdentifierClause().
        * SecureConversationSecurityTokenParameters.cs : default
          ChannelProtectionRequirements should cover all body parts i.e.
          IsBodyIncluded should be true.

        * SecureConversationSecurityTokenParametersTest.cs :
          test ChannelProtectionRequirements properties.

        * WSSecurityTokenSerializerTest.cs : finished incomplete
          WriteWrappedKeySecurityToken() test.



Modified: trunk/olive/class/System.ServiceModel/System.ServiceModel/ChangeLog
===================================================================
--- trunk/olive/class/System.ServiceModel/System.ServiceModel/ChangeLog 
2006-12-09 10:16:53 UTC (rev 69258)
+++ trunk/olive/class/System.ServiceModel/System.ServiceModel/ChangeLog 
2006-12-09 12:41:36 UTC (rev 69259)
@@ -1,3 +1,8 @@
+2006-12-09  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * ClientRuntimeChannel.cs : moved ChannelProtectionRequirements
+         population to ChannelProtectionRequirements.cs with some fixes.
+
 2006-12-05  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * Constants.cs : added WS-Security X509 thumbprint identifier

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs
   2006-12-09 10:16:53 UTC (rev 69258)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs
   2006-12-09 12:41:36 UTC (rev 69259)
@@ -26,14 +26,11 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 using System;
-using System.Collections.Generic;
-using System.Net.Security;
 using System.Reflection;
 using System.ServiceModel.Channels;
 using System.ServiceModel.Description;
 using System.ServiceModel.Dispatcher;
 using System.ServiceModel.Security;
-using System.Xml;
 
 namespace System.ServiceModel
 {
@@ -233,63 +230,14 @@
                                new BindingParameterCollection ();
 
                        ContractDescription cd = factory.Endpoint.Contract;
-                       ChannelProtectionRequirements cp =
-                               new ChannelProtectionRequirements ();
-                       List<XmlQualifiedName> enc = new List<XmlQualifiedName> 
();
-                       List<XmlQualifiedName> sig = new List<XmlQualifiedName> 
();
-                       foreach (OperationDescription od in cd.Operations) {
-                               foreach (MessageDescription md in od.Messages) {
-                                       enc.Clear ();
-                                       sig.Clear ();
-                                       ProtectionLevel mplv =
-                                               md.HasProtectionLevel ? 
md.ProtectionLevel :
-                                               od.HasProtectionLevel ? 
od.ProtectionLevel :
-                                               cd.HasProtectionLevel ? 
cd.ProtectionLevel :
-                                               ProtectionLevel.EncryptAndSign; 
// default
-                                       foreach (MessagePartDescription pd in 
md.Body.Parts)
-                                               AddPartProtectionRequirements 
(enc, sig, pd, cp);
-                                       if (md.Body.ReturnValue != null)
-                                               AddPartProtectionRequirements 
(enc, sig, md.Body.ReturnValue, cp);
+                       pl.Add 
(ChannelProtectionRequirements.CreateFromContract (cd));
 
-                                       ScopedMessagePartSpecification spec;
-                                       bool includeBodyEnc = mplv == 
ProtectionLevel.EncryptAndSign;
-                                       bool includeBodySig = mplv != 
ProtectionLevel.None;
-
-                                       // enc
-                                       spec = md.Direction == 
MessageDirection.Input ?
-                                               cp.IncomingEncryptionParts :
-                                               cp.OutgoingEncryptionParts;
-                                       spec.AddParts (new 
MessagePartSpecification (includeBodyEnc, enc.ToArray ()), md.Action);
-                                       // sig
-                                       spec = md.Direction == 
MessageDirection.Input ?
-                                               cp.IncomingSignatureParts :
-                                               cp.OutgoingSignatureParts;
-                                       spec.AddParts (new 
MessagePartSpecification (includeBodySig, sig.ToArray ()), md.Action);
-                               }
-                       }
-                       pl.Add (cp);
-
                        foreach (IEndpointBehavior behavior in 
factory.Endpoint.Behaviors)
                                behavior.AddBindingParameters 
(factory.Endpoint, pl);
 
                        return pl;
                }
 
-               void AddPartProtectionRequirements (List<XmlQualifiedName> enc,
-                       List<XmlQualifiedName> sig,
-                       MessagePartDescription pd,
-                       ChannelProtectionRequirements cp)
-               {
-                       switch (pd.ProtectionLevel) {
-                       case ProtectionLevel.EncryptAndSign:
-                               enc.Add (new XmlQualifiedName (pd.Name, 
pd.Namespace));
-                               goto case ProtectionLevel.Sign;
-                       case ProtectionLevel.Sign:
-                               sig.Add (new XmlQualifiedName (pd.Name, 
pd.Namespace));
-                               break;
-                       }
-               }
-
                void SetupOutputChannel ()
                {
                        if (output_channel != null)

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChangeLog    
    2006-12-09 10:16:53 UTC (rev 69258)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChangeLog    
    2006-12-09 12:41:36 UTC (rev 69259)
@@ -1,3 +1,12 @@
+2006-12-09  Atsushi Emomoto  <[EMAIL PROTECTED]>
+
+       * ChannelProtectionRequirements.cs : moved code for population from
+         ContractDescription, from ClientRuntimeChannel.cs. Parts should be
+         created from headers, not body parts. Fill IsBodyIncluded flag
+         from ContractDescription.[Has]ProtectionLevel.
+       * WSSecurityTokenSerializer.cs : implemented writer for
+         WrappedKeySecurityToken.
+
 2006-12-08  Atsushi Emomoto  <[EMAIL PROTECTED]>
 
        * SecurityMessageProperty.cs : initialize SenderIdPrefix as "_".

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChannelProtectionRequirements.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChannelProtectionRequirements.cs
 2006-12-09 10:16:53 UTC (rev 69258)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChannelProtectionRequirements.cs
 2006-12-09 12:41:36 UTC (rev 69259)
@@ -4,7 +4,7 @@
 // Author:
 //     Atsushi Enomoto <[EMAIL PROTECTED]>
 //
-// Copyright (C) 2005 Novell, Inc.  http://www.novell.com
+// Copyright (C) 2005-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
@@ -26,7 +26,11 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 using System;
+using System.Net.Security;
+using System.Collections.Generic;
 using System.ServiceModel;
+using System.ServiceModel.Description;
+using System.Xml;
 
 namespace System.ServiceModel.Security
 {
@@ -80,25 +84,127 @@
                        Add (protectionRequirements, false);
                }
 
-               [MonoTODO]
                public void Add (
                        ChannelProtectionRequirements protectionRequirements,
                        bool channelScopeOnly)
                {
                        if (is_readonly)
                                throw new InvalidOperationException ("This 
ChannelProtectionRequirements is read-only.");
-                       throw new NotImplementedException ();
+
+                       AddScopedParts (
+                               protectionRequirements.IncomingEncryptionParts, 
+                               IncomingEncryptionParts,
+                               channelScopeOnly);
+                       AddScopedParts (
+                               protectionRequirements.IncomingSignatureParts, 
+                               IncomingSignatureParts,
+                               channelScopeOnly);
+                       AddScopedParts (
+                               protectionRequirements.OutgoingEncryptionParts, 
+                               OutgoingEncryptionParts,
+                               channelScopeOnly);
+                       AddScopedParts (
+                               protectionRequirements.OutgoingSignatureParts, 
+                               OutgoingSignatureParts,
+                               channelScopeOnly);
                }
 
-               [MonoTODO]
+               void AddScopedParts (ScopedMessagePartSpecification src, 
ScopedMessagePartSpecification dst, bool channelOnly)
+               {
+                       dst.AddParts (src.ChannelParts);
+                       if (channelOnly)
+                               return;
+
+                       foreach (string a in src.Actions) {
+                               MessagePartSpecification m;
+                               src.TryGetParts (a, out m);
+                               src.AddParts (m);
+                       }
+               }
+
                public ChannelProtectionRequirements CreateInverse ()
                {
-                       throw new NotImplementedException ();
+                       ChannelProtectionRequirements r =
+                               new ChannelProtectionRequirements ();
+                       AddScopedParts (in_enc, r.out_enc, false);
+                       AddScopedParts (in_sign, r.out_sign, false);
+                       AddScopedParts (out_enc, r.in_enc, false);
+                       AddScopedParts (out_sign, r.in_sign, false);
+                       return r;
                }
 
                public void MakeReadOnly ()
                {
                        is_readonly = true;
+                       in_enc.MakeReadOnly ();
+                       in_sign.MakeReadOnly ();
+                       out_enc.MakeReadOnly ();
+                       out_sign.MakeReadOnly ();
                }
+
+               internal static ChannelProtectionRequirements 
CreateFromContract (ContractDescription cd)
+               {
+                       ChannelProtectionRequirements cp =
+                               new ChannelProtectionRequirements ();
+                       List<XmlQualifiedName> enc = new List<XmlQualifiedName> 
();
+                       List<XmlQualifiedName> sig = new List<XmlQualifiedName> 
();
+                       if (cd.HasProtectionLevel) {
+                               switch (cd.ProtectionLevel) {
+                               case ProtectionLevel.EncryptAndSign:
+                                       
cp.IncomingEncryptionParts.ChannelParts.IsBodyIncluded = true;
+                                       
cp.OutgoingEncryptionParts.ChannelParts.IsBodyIncluded = true;
+                                       goto case ProtectionLevel.Sign;
+                               case ProtectionLevel.Sign:
+                                       
cp.IncomingSignatureParts.ChannelParts.IsBodyIncluded = true;
+                                       
cp.OutgoingSignatureParts.ChannelParts.IsBodyIncluded = true;
+                                       break;
+                               }
+                       }
+                       foreach (OperationDescription od in cd.Operations) {
+                               foreach (MessageDescription md in od.Messages) {
+                                       enc.Clear ();
+                                       sig.Clear ();
+                                       ProtectionLevel mplv =
+                                               md.HasProtectionLevel ? 
md.ProtectionLevel :
+                                               od.HasProtectionLevel ? 
od.ProtectionLevel :
+                                               ProtectionLevel.EncryptAndSign; 
// default
+                                       foreach (MessageHeaderDescription hd in 
md.Headers)
+                                               AddPartProtectionRequirements 
(enc, sig, hd, cp);
+
+                                       ScopedMessagePartSpecification spec;
+                                       bool includeBodyEnc = mplv == 
ProtectionLevel.EncryptAndSign;
+                                       bool includeBodySig = mplv != 
ProtectionLevel.None;
+
+                                       // enc
+                                       spec = md.Direction == 
MessageDirection.Input ?
+                                               cp.IncomingEncryptionParts :
+                                               cp.OutgoingEncryptionParts;
+                                       spec.AddParts (new 
MessagePartSpecification (includeBodyEnc, enc.ToArray ()), md.Action);
+                                       // sig
+                                       spec = md.Direction == 
MessageDirection.Input ?
+                                               cp.IncomingSignatureParts :
+                                               cp.OutgoingSignatureParts;
+                                       spec.AddParts (new 
MessagePartSpecification (includeBodySig, sig.ToArray ()), md.Action);
+                               }
+                       }
+                       return cp;
+               }
+
+               static void AddPartProtectionRequirements 
(List<XmlQualifiedName> enc,
+                       List<XmlQualifiedName> sig,
+                       MessageHeaderDescription pd,
+                       ChannelProtectionRequirements cp)
+               {
+                       if (!pd.HasProtectionLevel)
+                               return; // no specific part indication
+                       switch (pd.ProtectionLevel) {
+                       case ProtectionLevel.EncryptAndSign:
+                               enc.Add (new XmlQualifiedName (pd.Name, 
pd.Namespace));
+                               goto case ProtectionLevel.Sign;
+                       case ProtectionLevel.Sign:
+                               sig.Add (new XmlQualifiedName (pd.Name, 
pd.Namespace));
+                               break;
+                       }
+               }
        }
 }

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/WSSecurityTokenSerializer.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/WSSecurityTokenSerializer.cs
     2006-12-09 10:16:53 UTC (rev 69258)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/WSSecurityTokenSerializer.cs
     2006-12-09 12:41:36 UTC (rev 69259)
@@ -475,7 +475,7 @@
                        else if (token is GenericXmlSecurityToken)
                                throw new NotImplementedException 
("WriteTokenCore() is not implemented for " + token);
                        else if (token is WrappedKeySecurityToken)
-                               throw new NotImplementedException 
("WriteTokenCore() is not implemented for " + token);
+                               WriteWrappedKeySecurityToken (writer, 
(WrappedKeySecurityToken) token);
                        else if (token is SecurityContextSecurityToken)
                                throw new NotImplementedException 
("WriteTokenCore() is not implemented for " + token);
                        else if (token is SspiSecurityToken)
@@ -517,5 +517,32 @@
                        w.WriteString (Convert.ToBase64String 
(token.GetKeyBytes ()));
                        w.WriteEndElement ();
                }
+
+               void WriteWrappedKeySecurityToken (XmlWriter w, 
WrappedKeySecurityToken token)
+               {
+                       string encNS = EncryptedXml.XmlEncNamespaceUrl;
+                       w.WriteStartElement ("e", "EncryptedKey", encNS);
+                       w.WriteAttributeString ("Id", token.Id);
+                       w.WriteStartElement ("EncryptionMethod", encNS);
+                       w.WriteAttributeString ("Algorithm", 
token.WrappingAlgorithm);
+                       w.WriteStartElement ("DigestMethod", 
SignedXml.XmlDsigNamespaceUrl);
+                       w.WriteAttributeString ("Algorithm", 
SignedXml.XmlDsigSHA1Url);
+                       w.WriteEndElement ();
+                       w.WriteEndElement ();
+
+                       w.WriteStartElement ("KeyInfo", 
SignedXml.XmlDsigNamespaceUrl);
+                       if (token.WrappingTokenReference != null)
+                               foreach (SecurityKeyIdentifierClause kic in 
token.WrappingTokenReference)
+                                       WriteKeyIdentifierClause (w, kic);
+                       else if (token.WrappingToken != null)
+                               WriteToken (w, token.WrappingToken);
+                       w.WriteEndElement ();
+                       w.WriteStartElement ("CipherData", encNS);
+                       w.WriteStartElement ("CipherValue", encNS);
+                       w.WriteString ("blah");
+                       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
 2006-12-09 10:16:53 UTC (rev 69258)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/ChangeLog
 2006-12-09 12:41:36 UTC (rev 69259)
@@ -1,3 +1,11 @@
+2006-12-09  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * WrappedKeySecurityToken.cs : implemented missing members, except for
+         incomplete MatchKeyIdentifierClause().
+       * SecureConversationSecurityTokenParameters.cs : default
+         ChannelProtectionRequirements should cover all body parts i.e.
+         IsBodyIncluded should be true.
+
 2006-12-06  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * SupportingTokenParameters.cs : implemented SetKeyDerivation().

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/SecureConversationSecurityTokenParameters.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/SecureConversationSecurityTokenParameters.cs
      2006-12-09 10:16:53 UTC (rev 69258)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/SecureConversationSecurityTokenParameters.cs
      2006-12-09 12:41:36 UTC (rev 69259)
@@ -36,6 +36,20 @@
 {
        public class SecureConversationSecurityTokenParameters : 
SecurityTokenParameters
        {
+               static readonly ChannelProtectionRequirements 
default_channel_protection_requirements;
+
+               static SecureConversationSecurityTokenParameters ()
+               {
+                       ChannelProtectionRequirements r =
+                               new ChannelProtectionRequirements ();
+                       r.IncomingSignatureParts.ChannelParts.IsBodyIncluded = 
true;
+                       r.OutgoingSignatureParts.ChannelParts.IsBodyIncluded = 
true;
+                       r.IncomingEncryptionParts.ChannelParts.IsBodyIncluded = 
true;
+                       r.OutgoingEncryptionParts.ChannelParts.IsBodyIncluded = 
true;
+                       r.MakeReadOnly ();
+                       default_channel_protection_requirements = r;
+               }
+
                SecurityBindingElement element;
                ChannelProtectionRequirements requirements;
                bool cancellable;
@@ -66,7 +80,7 @@
                        this.element = element;
                        this.cancellable = requireCancellation;
                        if (requirements == null)
-                               this.requirements = new 
ChannelProtectionRequirements ();
+                               this.requirements = new 
ChannelProtectionRequirements (default_channel_protection_requirements);
                        else
                                this.requirements = new 
ChannelProtectionRequirements (requirements);
                }

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/WrappedKeySecurityToken.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/WrappedKeySecurityToken.cs
        2006-12-09 10:16:53 UTC (rev 69258)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/WrappedKeySecurityToken.cs
        2006-12-09 12:41:36 UTC (rev 69259)
@@ -37,9 +37,9 @@
        {
                string id;
                byte [] key;
-               string wrapper_alg;
-               SecurityToken wrapper_token;
-               SecurityKeyIdentifier wrapper_token_ref;
+               string wrap_alg;
+               SecurityToken wrap_token;
+               SecurityKeyIdentifier wrap_token_ref;
                DateTime valid_from = DateTime.Now.ToUniversalTime ();
                ReadOnlyCollection<SecurityKey> keys;
 
@@ -52,9 +52,9 @@
                {
                        this.id = id;
                        this.key = keyToWrap;
-                       wrapper_alg = wrappingAlgorithm;
-                       wrapper_token = wrappingToken;
-                       wrapper_token_ref = wrappingTokenReference;
+                       wrap_alg = wrappingAlgorithm;
+                       wrap_token = wrappingToken;
+                       wrap_token_ref = wrappingTokenReference;
                        keys = new ReadOnlyCollection<SecurityKey> (
                                new SecurityKey [] {new 
InMemorySymmetricSecurityKey (key)});
                }
@@ -75,5 +75,52 @@
                public override ReadOnlyCollection<SecurityKey> SecurityKeys {
                        get { return keys; }
                }
+
+               public string WrappingAlgorithm {
+                       get { return wrap_alg; }
+               }
+
+               public SecurityToken WrappingToken {
+                       get { return wrap_token; }
+               }
+
+               public SecurityKeyIdentifier WrappingTokenReference {
+                       get { return wrap_token_ref; }
+               }
+
+               public byte [] GetWrappedKey ()
+               {
+                       return (byte []) key.Clone ();
+               }
+
+               public override bool CanCreateKeyIdentifierClause<T> ()
+               {
+                       foreach (SecurityKeyIdentifierClause k in 
WrappingTokenReference) {
+                               Type t = k.GetType ();
+                               if (t == typeof (T) || t.IsSubclassOf (typeof 
(T)))
+                                       return true;
+                       }
+                       return false;
+               }
+
+               public override T CreateKeyIdentifierClause<T> ()
+               {
+                       foreach (SecurityKeyIdentifierClause k in 
WrappingTokenReference) {
+                               Type t = k.GetType ();
+                               if (t == typeof (T) || t.IsSubclassOf (typeof 
(T)))
+                                       return (T) k;
+                       }
+                       throw new InvalidOperationException (String.Format 
("WrappedKeySecurityToken cannot create '{0}'. The WrappingTokenReference type 
is '{1}'.", typeof (T), WrappingTokenReference.GetType ()));
+               }
+
+               [MonoTODO]
+               public override bool MatchesKeyIdentifierClause 
(SecurityKeyIdentifierClause keyIdentifierClause)
+               {
+                       if (keyIdentifierClause is LocalIdKeyIdentifierClause &&
+                           ((LocalIdKeyIdentifierClause) 
keyIdentifierClause).LocalId == Id)
+                               return true;
+                       // FIXME: no other possibilities to match?
+                       return false;
+               }
        }
 }

Modified: 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ChangeLog
   2006-12-09 10:16:53 UTC (rev 69258)
+++ 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ChangeLog
   2006-12-09 12:41:36 UTC (rev 69259)
@@ -1,3 +1,8 @@
+2006-12-09  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * WSSecurityTokenSerializerTest.cs : finished incomplete
+         WriteWrappedKeySecurityToken() test.
+
 2006-12-08  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * SecurityMessagePropertyTest.cs : test SenderIdPrefix as well.

Modified: 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/WSSecurityTokenSerializerTest.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/WSSecurityTokenSerializerTest.cs
    2006-12-09 10:16:53 UTC (rev 69258)
+++ 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/WSSecurityTokenSerializerTest.cs
    2006-12-09 12:41:36 UTC (rev 69259)
@@ -159,28 +159,40 @@
                }
 
                [Test]
-               [Ignore ("it's just not working")]
-               [Category ("NotWorking")]
                public void WriteWrappedKeySecurityToken ()
                {
                        StringWriter sw = new StringWriter ();
-                       byte [] bytes = new byte [] {0, 1, 2, 3, 4, 5, 6, 7};
+                       byte [] bytes = new byte [64];
+                       for (byte i = 1; i < 64; i++)
+                               bytes [i] = i;
 
-                       SecurityToken wt = new RsaSecurityToken (RSA.Create ());
-                       SecurityKeyIdentifierClause skic =
-                               wt.CreateKeyIdentifierClause< 
RsaKeyIdentifierClause> ();
-                       Assert.IsNotNull (skic.ClauseType, "ClauseType is 
null");
-                       // FIXME: there are very few identifier clauses that
-                       // can be created, and this one is still not supported.
+                       SecurityToken wt = new X509SecurityToken (cert);
+                       SecurityKeyIdentifier ski = new SecurityKeyIdentifier (
+                               wt.CreateKeyIdentifierClause< 
X509ThumbprintKeyIdentifierClause> ());
                        WrappedKeySecurityToken t = new WrappedKeySecurityToken 
(
-                               "urn:wrapper-key:1", bytes, skic.ClauseType, wt,
-                               new SecurityKeyIdentifier (skic));
+                               "urn:wrapper-key:1", bytes, 
SecurityAlgorithms.RsaOaepKeyWrap, wt, ski);
 
                        using (XmlWriter w = XmlWriter.Create (sw, 
GetWriterSettings ())) {
                                
WSSecurityTokenSerializer.DefaultInstance.WriteToken (w, t);
                        }
-                       string rawdata = Convert.ToBase64String (cert.RawData);
-                       Assert.AreEqual ("", sw.ToString ());
+                       string actual = sw.ToString ();
+                       int idx = actual.IndexOf ("<e:CipherValue>", 
StringComparison.Ordinal);
+                       Assert.IsTrue (idx >= 0, "No <CipherValue>");
+                       actual = 
+                               actual.Substring (0, idx) +
+                               "<e:CipherValue>removed here" +
+                               actual.Substring (actual.IndexOf 
("</e:CipherValue>", StringComparison.Ordinal));
+                       Assert.AreEqual ("GQ3YHlGQhDF1bvMixHliX4uLjlY=", 
Convert.ToBase64String (cert.GetCertHash ()), "premise#1");
+                       Assert.AreEqual (
+                               String.Format ("<e:EncryptedKey 
Id=\"urn:wrapper-key:1\" xmlns:e=\"{0}\"><e:EncryptionMethod 
Algorithm=\"{1}\"><DigestMethod Algorithm=\"{2}\" xmlns=\"{3}\" 
/></e:EncryptionMethod><KeyInfo xmlns=\"{3}\"><o:SecurityTokenReference 
xmlns:o=\"{4}\"><o:KeyIdentifier 
ValueType=\"{5}\">{6}</o:KeyIdentifier></o:SecurityTokenReference></KeyInfo><e:CipherData><e:CipherValue>removed
 here</e:CipherValue></e:CipherData></e:EncryptedKey>",
+                                       EncryptedXml.XmlEncNamespaceUrl,
+                                       SecurityAlgorithms.RsaOaepKeyWrap,
+                                       SignedXml.XmlDsigSHA1Url,
+                                       SignedXml.XmlDsigNamespaceUrl,
+                                       
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";,
+                                       
"http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#ThumbprintSHA1";,
+                                       Convert.ToBase64String 
(cert.GetCertHash ())),// "GQ3YHlGQhDF1bvMixHliX4uLjlY="
+                               actual);
                }
 
                [Test]

Modified: 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security.Tokens/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security.Tokens/ChangeLog
    2006-12-09 10:16:53 UTC (rev 69258)
+++ 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security.Tokens/ChangeLog
    2006-12-09 12:41:36 UTC (rev 69259)
@@ -1,3 +1,8 @@
+2006-12-09  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * SecureConversationSecurityTokenParametersTest.cs :
+         test ChannelProtectionRequirements properties.
+
 2006-10-12  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * X509SecurityTokenParametersTest.cs :

Modified: 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security.Tokens/SecureConversationSecurityTokenParametersTest.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security.Tokens/SecureConversationSecurityTokenParametersTest.cs
     2006-12-09 10:16:53 UTC (rev 69258)
+++ 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security.Tokens/SecureConversationSecurityTokenParametersTest.cs
     2006-12-09 12:41:36 UTC (rev 69259)
@@ -108,6 +108,13 @@
                        Assert.AreEqual (false, p.Client, "#2-5");
                        Assert.AreEqual (false, p.Win, "#2-6");
                        Assert.AreEqual (false, p.Server, "#2-7");
+
+                       ChannelProtectionRequirements r =
+                               p.BootstrapProtectionRequirements;
+                       Assert.IsTrue 
(r.IncomingSignatureParts.ChannelParts.IsBodyIncluded, "#3-1");
+                       Assert.IsTrue 
(r.OutgoingSignatureParts.ChannelParts.IsBodyIncluded, "#3-2");
+                       Assert.IsTrue 
(r.IncomingEncryptionParts.ChannelParts.IsBodyIncluded, "#3-3");
+                       Assert.IsTrue 
(r.OutgoingEncryptionParts.ChannelParts.IsBodyIncluded, "#3-4");
                }
 
                [Test]

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

Reply via email to