Author: atsushi
Date: 2007-03-30 10:15:32 -0500 (Fri, 30 Mar 2007)
New Revision: 75203

Modified:
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/ChangeLog
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/SslnegoCookieResolver.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/Test/System.ServiceModel.Security/ChangeLog
   
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/WSSecurityTokenSerializerTest.cs
Log:
2007-03-30  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * SslnegoCookieResolver.cs : ResolveCookie() should simply return
          entire SecurityContextToken parsed by dnse:Cookie binary.

        * WSSecurityTokenSerializer.cs : when reading SCT from
          SecurityContextSecurityToken, return it from cookie binary.
          knownTypes argument can be null.

        * WSSecurityTokenSerializerTest.cs : removed SCT reader test which
          was DPAPI dependent, and added new DPAPI independent one.



Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChangeLog    
    2007-03-30 15:12:17 UTC (rev 75202)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChangeLog    
    2007-03-30 15:15:32 UTC (rev 75203)
@@ -1,3 +1,9 @@
+2007-03-30  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * WSSecurityTokenSerializer.cs : when reading SCT from
+         SecurityContextSecurityToken, return it from cookie binary.
+         knownTypes argument can be null.
+
 2007-03-27  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * SspiSecurityTokenProvider.cs : removed SspiCommunicationObject from

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/WSSecurityTokenSerializer.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/WSSecurityTokenSerializer.cs
     2007-03-30 15:12:17 UTC (rev 75202)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/WSSecurityTokenSerializer.cs
     2007-03-30 15:15:32 UTC (rev 75203)
@@ -75,7 +75,7 @@
                        bool emitBspRequiredAttributes,
                        SamlSerializer samlSerializer)
                        : this (securityVersion, emitBspRequiredAttributes, 
-                               samlSerializer, null, Type.EmptyTypes)
+                               samlSerializer, null, null)
                {
                }
 
@@ -106,7 +106,7 @@
                        emit_bsp = emitBspRequiredAttributes;
                        saml_serializer = samlSerializer;
                        encoder = securityStateEncoder;
-                       known_types = new List<Type> (knownTypes);
+                       known_types = new List<Type> (knownTypes ?? 
Type.EmptyTypes);
                        max_offset = maximumKeyDerivationOffset;
                        max_label_length = maximumKeyDerivationLabelLength;
                        max_nonce_length = maximumKeyDerivationNonceLength;
@@ -547,13 +547,7 @@
                                cookie != null && cookie.Length > 154 ?
                                encoder.DecodeSecurityState (cookie) :
                                cookie;
-                       // FIXME: turned out that it is just a proof token. So,
-                       // the token to be returned should be created entirely
-                       // from this decoded binary XML.
-                       byte [] key = SslnegoCookieResolver.ResolveCookie 
(decoded);
-
-                       return new SecurityContextSecurityToken (
-                               cid, id, key, DateTime.MinValue, 
DateTime.MaxValue);
+                       return SslnegoCookieResolver.ResolveCookie (decoded);
                }
 
                WrappedKeySecurityToken ReadWrappedKeySecurityTokenCore (

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/ChangeLog
 2007-03-30 15:12:17 UTC (rev 75202)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/ChangeLog
 2007-03-30 15:15:32 UTC (rev 75203)
@@ -1,3 +1,8 @@
+2007-03-30  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * SslnegoCookieResolver.cs : ResolveCookie() should simply return
+         entire SecurityContextToken parsed by dnse:Cookie binary.
+
 2007-03-27  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * SslSecurityTokenAuthenticator.cs, SslSecurityTokenProvider.cs :

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/SslnegoCookieResolver.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/SslnegoCookieResolver.cs
  2007-03-30 15:12:17 UTC (rev 75202)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security.Tokens/SslnegoCookieResolver.cs
  2007-03-30 15:15:32 UTC (rev 75203)
@@ -58,13 +58,13 @@
 42 00 
 42 02 
 83 
-42 06 99 2B 75 75 69 64 2D 31 65 38 33 62 63 37 39 2D 35 30 33 37 2D 34 61 32 
30 2D 38 32 66 37 2D 64 32 39 37 31 34 61 30 32 62 37 66 2D 31 // UniqueId
-42 04 AD 45 34 07 4E 38 D2 18 4D 8B 22 FD 6C E6 CE B2 17 // UniqueIdFromGuid
-42 08 9E 1E CA AC F2 71 6E 61 99 DA FB 71 B2 A8 DC 51 36 5B CD F3 F9 60 D2 B6 
67 BF 5D B0 CE ED 37 35 9F 02 DC 7D // Base64
-42 0E 8F F4 4C 9C 48 61 33 C9 08 // Int64
-42 10 8F F4 5C 48 1A B5 33 C9 08 // Int64
-42 14 8F F4 4C 9C 48 61 33 C9 08 // Int64
-42 16 8F F4 5C 48 1A B5 33 C9 08 // Int64
+42 06 99 2B 75 75 69 64 2D 31 65 38 33 62 63 37 39 2D 35 30 33 37 2D 34 61 32 
30 2D 38 32 66 37 2D 64 32 39 37 31 34 61 30 32 62 37 66 2D 31 // UniqueId 
wsu:Id
+42 04 AD 45 34 07 4E 38 D2 18 4D 8B 22 FD 6C E6 CE B2 17 // UniqueIdFromGuid 
ContextId
+42 08 9E 1E CA AC F2 71 6E 61 99 DA FB 71 B2 A8 DC 51 36 5B CD F3 F9 60 D2 B6 
67 BF 5D B0 CE ED 37 35 9F 02 DC 7D // Base64 Key
+42 0E 8F F4 4C 9C 48 61 33 C9 08 // Int64 KeyCreation
+42 10 8F F4 5C 48 1A B5 33 C9 08 // Int64 KeyExpiration
+42 14 8F F4 4C 9C 48 61 33 C9 08 // Int64 CookieCreatation
+42 16 8F F4 5C 48 1A B5 33 C9 08 // Int64 CookieExpiration
 01
 
 
@@ -85,8 +85,16 @@
 {
        internal class SslnegoCookieResolver
        {
-               public static byte [] ResolveCookie (byte [] bytes)
+               public static SecurityContextSecurityToken ResolveCookie (byte 
[] bytes)
                {
+                       string id = null;
+                       UniqueId context = null;
+                       DateTime validFrom = DateTime.MinValue,
+                                validTo = DateTime.MaxValue,
+                                keyEffective = DateTime.MinValue,
+                                keyExpired = DateTime.MaxValue;
+                       byte [] key = null;
+
                        XmlDictionary dic = new XmlDictionary ();
                        for (int i = 0; i < 12; i++)
                                dic.Add ("n" + i);
@@ -94,19 +102,51 @@
                        XmlDictionaryReaderQuotas quotas =
                                new XmlDictionaryReaderQuotas ();
                        XmlDictionaryReader cr = 
XmlDictionaryReader.CreateBinaryReader (bytes, 0, bytes.Length, dic, quotas);
-                       cr.Read (); // -> n1
-                       cr.Read (); // -> n2
-                       cr.Read (); // -> '1'
-                       cr.Read (); // -> /n2
-                       cr.Read (); // -> n4
-                       cr.Read (); // -> uid
-                       cr.Read (); // -> /n4
-                       cr.Read (); // -> n3
-                       cr.Read (); // -> uid
-                       cr.Read (); // -> /n3
-                       cr.Read (); // -> n5
-                       return cr.ReadElementContentAsBase64 ();
-                       //throw new NotImplementedException ();
+                       cr.MoveToContent (); // -> n1
+                       cr.ReadStartElement ("n0", String.Empty);
+                       do {
+                               cr.MoveToContent ();
+                               if (cr.NodeType == XmlNodeType.EndElement)
+                                       break;
+                               if (cr.NodeType != XmlNodeType.Element)
+                                       throw new Exception ("Unxpected 
non-element content:" + cr.NodeType);
+
+                               switch (cr.Name) {
+                               case "n1":
+                                       // FIXME: some integer here
+                                       int n1 = cr.ReadElementContentAsInt ();
+                                       if (n1 != 1)
+                                               throw new Exception ("INTERNAL 
ERROR: there was unexpected n2 content: " + n1);
+                                       break;
+                               case "n2":
+                                       context = 
cr.ReadElementContentAsUniqueId ();
+                                       break;
+                               case "n3":
+                                       id = cr.ReadElementContentAsString ();
+                                       break;
+                               case "n4":
+                                       key = cr.ReadElementContentAsBase64 ();
+                                       break;
+                               case "n7":
+                                       validFrom = new DateTime 
(cr.ReadElementContentAsLong ());
+                                       break;
+                               case "n8":
+                                       validTo = new DateTime 
(cr.ReadElementContentAsLong ());
+                                       break;
+                               case "n10":
+                                       keyEffective = new DateTime 
(cr.ReadElementContentAsLong ());
+                                       break;
+                               case "n11":
+                                       keyExpired = new DateTime 
(cr.ReadElementContentAsLong ());
+                                       break;
+                               default:
+                                       throw new Exception ("INTERNAL ERROR: 
there was an unhandled element: " + cr.Name);
+                               }
+                       } while (true);
+
+                       return new SecurityContextSecurityToken (
+                               context, id, key, validFrom, validTo,
+                               null, keyEffective, keyExpired, null);
                }
 
                public static byte [] CreateData (UniqueId contextId, UniqueId 
session, byte [] key, DateTime tokenSince, DateTime tokenUntil, DateTime 
keySince, DateTime keyUntil)

Modified: 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ChangeLog
   2007-03-30 15:12:17 UTC (rev 75202)
+++ 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ChangeLog
   2007-03-30 15:15:32 UTC (rev 75203)
@@ -1,3 +1,8 @@
+2007-03-30  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * WSSecurityTokenSerializerTest.cs : removed SCT reader test which
+         was DPAPI dependent, and added new DPAPI independent one.
+
 2007-03-20  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * WSSecurityTokenSerializerTest.cs : so, RequestedProofToken content

Modified: 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/WSSecurityTokenSerializerTest.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/WSSecurityTokenSerializerTest.cs
    2007-03-30 15:12:17 UTC (rev 75202)
+++ 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/WSSecurityTokenSerializerTest.cs
    2007-03-30 15:15:32 UTC (rev 75203)
@@ -725,27 +725,61 @@
                }
 
                [Test]
-               [Category ("NotWorking")]
-               public void ReadSecurityContextSecurityTokenSslnego ()
+               public void ReadSslnegoSCTNoStateEncoder ()
                {
-                       string xml = @"<c:SecurityContextToken 
u:Id='uuid-d699595c-8dac-4db4-9d7d-22bf0d900f6b-1' 
xmlns:c='http://schemas.xmlsoap.org/ws/2005/02/sc' 
xmlns:u='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'>
-  <c:Identifier>urn:uuid:bf4d319a-1386-45a4-bd54-8c7ebc5d418e</c:Identifier>
-  <dnse:Cookie 
xmlns:dnse='http://schemas.microsoft.com/ws/2006/05/security'>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAbwpVqF25WkyFYDXHavE7SwAAAAACAAAAAAADZgAAqAAAABAAAABhYEZd5XcsntVz0r+ZeOQtAAAAAASAAACgAAAAEAAAAGOGL0zkp8ZlDZEDdFvhOpmgAAAAA70hoWg30wr4v4A9zUYqOdw5AgQ+qS3C9lpLHH5vvVIyDZ++w+RjooLLbuhHfa4kGMxBaizAHqhHhhqsLczapTfkmLuNXZtdgtIkavUGcNkWOiGRs6ciZgXu2QLoCTRiQYDB5t2cWMzSDmzXO6yAzm2Zdik2sQ8CnOHzBTvFI8/tbE5/NHOCw2DXLWCi5ndyVEVcnLfvyV1Sk64A6pkQuBQAAAABerotvApVRg4/IJAsZwfzXL671Q==</dnse:Cookie>
-</c:SecurityContextToken>";
+                       string cookie = 
"QgBCAoNCBpkrdXVpZC03MDlhYjYwOC0yMDA0LTQ0ZDUtYjM5Mi1mM2M1YmY3YzY3ZmItMUIErZ3da7enifVFg+e0dObwRLNCCJ4egLowfrwP4Hgn0lOSqlA2fr0k4NAKgRZX+0BVs2EOnwJ6xkIOjzCAEnLHQMkIQhCPMJC+QxtByQhCFI8wgBJyx0DJCEIWjzCQvkMbQckIAQ==";
+                       string xml = String.Format (@"<c:SecurityContextToken 
u:Id='uuid-709ab608-2004-44d5-b392-f3c5bf7c67fb-1' 
xmlns:c='http://schemas.xmlsoap.org/ws/2005/02/sc' 
xmlns:u='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'>
+  <c:Identifier>urn:uuid:b76bdd9d-89a7-45f5-83e7-b474e6f044b3</c:Identifier>
+  <dnse:Cookie 
xmlns:dnse='http://schemas.microsoft.com/ws/2006/05/security'>{0}</dnse:Cookie>
+</c:SecurityContextToken>", cookie);
+                       string expectedKey = 
"gLowfrwP4Hgn0lOSqlA2fr0k4NAKgRZX+0BVs2EOesY=";
+
                        WSSecurityTokenSerializer serializer =
-                               WSSecurityTokenSerializer.DefaultInstance;
+                               new WSSecurityTokenSerializer 
(MessageSecurityVersion.Default.SecurityVersion,
+                                       false,
+                                       new SamlSerializer (),
+                                       new MyStateEncoder (),
+                                       null);
                        SecurityContextSecurityToken sct;
                        using (XmlReader xr = XmlReader.Create (new 
StringReader (xml))) {
                                // Token is not registered, but is restored 
from the cookie
                                sct = serializer.ReadToken (xr, null) as 
SecurityContextSecurityToken;
                        }
                        Assert.IsNotNull (sct, "#1");
-                       Assert.AreEqual (new UniqueId 
("urn:uuid:bf4d319a-1386-45a4-bd54-8c7ebc5d418e"), sct.ContextId, "#2");
+                       Assert.AreEqual (new UniqueId 
("urn:uuid:b76bdd9d-89a7-45f5-83e7-b474e6f044b3"), sct.ContextId, "#2");
                        Assert.IsNotNull (sct.AuthorizationPolicies.Count, 
"#3");
                        Assert.AreEqual (0, sct.AuthorizationPolicies.Count, 
"#4");
                        Assert.AreEqual (1, sct.SecurityKeys.Count, "#5");
+                       Assert.AreEqual (expectedKey, Convert.ToBase64String 
(((SymmetricSecurityKey) sct.SecurityKeys [0]).GetSymmetricKey ()), "#6");
+
+                       byte [] xmlbin = Convert.FromBase64String (cookie);
+                       XmlDictionary dic = new XmlDictionary ();
+                       for (int i = 0; i < 12; i++)
+                               dic.Add ("n" + i);
+                       XmlDictionaryReader br = 
XmlDictionaryReader.CreateBinaryReader (xmlbin, 0, xmlbin.Length, dic, new 
XmlDictionaryReaderQuotas ());
+                       while (br.LocalName != "n4")
+                               if (!br.Read ())
+                                       Assert.Fail ("Unxpected binary 
xmlreader failure.");
+                       byte [] key = br.ReadElementContentAsBase64 ();
+                       // Hmm, so, looks like the Cookie binary depends not
+                       // on SSL protection but on the state encoder ...
+                       // does it make sense, or is a different key resolved
+                       // as a result of TLS negotiation?
+                       Assert.AreEqual (expectedKey, Convert.ToBase64String 
(key), "#7");
                }
 
+               class MyStateEncoder : SecurityStateEncoder
+               {
+                       protected override byte [] DecodeSecurityState (byte [] 
src)
+                       {
+                               return src;
+                       }
+                       protected override byte [] EncodeSecurityState (byte [] 
src)
+                       {
+                               return src;
+                       }
+               }
+
                [Test]
                [ExpectedException (typeof (XmlException))]
                public void ReadSecurityContextSecurityTokenSslnego3 ()

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

Reply via email to