Author: atsushi
Date: 2007-01-12 10:28:57 -0500 (Fri, 12 Jan 2007)
New Revision: 70924

Modified:
   trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/SecureMessageGenerator.cs
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/WSSecurityMessageHeader.cs
Log:
2007-01-12  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * SecureMessageGenerator.cs : add wsu:Timestamp to signing target.
          Moved signing key generation code to non-HMACSHA1 signing part.
          Don't try to sign wss:Security.
          Pass document itself to SignedXml.ctor().
          Use temporary DataObjects to avoid adding Ids (not sure what is the
          expected processing yet).
        * WSSecurityMessageHeader.cs : to support timestamp signing, add
          WriteTo() method in WsuTimestamp.



Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog    
    2007-01-12 15:18:04 UTC (rev 70923)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog    
    2007-01-12 15:28:57 UTC (rev 70924)
@@ -1,5 +1,16 @@
 2007-01-12  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * SecureMessageGenerator.cs : add wsu:Timestamp to signing target.
+         Moved signing key generation code to non-HMACSHA1 signing part.
+         Don't try to sign wss:Security.
+         Pass document itself to SignedXml.ctor().
+         Use temporary DataObjects to avoid adding Ids (not sure what is the
+         expected processing yet).
+       * WSSecurityMessageHeader.cs : to support timestamp signing, add
+         WriteTo() method in WsuTimestamp.
+
+2007-01-12  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
        * SecureMessageGenerator.cs : wrong key was used for signing.
          Omit KeyInfo for now - it seems that .net (sometimes?) omits it.
 

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/SecureMessageGenerator.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/SecureMessageGenerator.cs
        2007-01-12 15:18:04 UTC (rev 70923)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/SecureMessageGenerator.cs
        2007-01-12 15:28:57 UTC (rev 70924)
@@ -243,9 +243,10 @@
                        // wss:Security
                        WSSecurityMessageHeader header =
                                new WSSecurityMessageHeader (serializer);
+                       WsuTimestamp timestamp = null;
                        // wss:Security/wsu:Timestamp
                        if (element.IncludeTimestamp) {
-                               WsuTimestamp timestamp = new WsuTimestamp ();
+                               timestamp = new WsuTimestamp ();
                                timestamp.Id = messageId + "-" + 
identForMessageId++;
                                timestamp.Created = DateTime.Now;
                                // FIXME: on service side, use 
element.LocalServiceSettings.TimestampValidityDuration
@@ -345,37 +346,43 @@
                        case 
MessageProtectionOrder.SignBeforeEncryptAndEncryptSignature:
 
                                // sign
-                               SignedXml sxml = new SignedXml (body);
+                               SignedXml sxml = new SignedXml (doc);
 
-                               HMACSHA1 sigHash = null;
-                               if (security.DefaultSignatureAlgorithm == 
SignedXml.XmlDsigHMACSHA1Url)
-                                       sigHash = new HMACSHA1 (aes.Key);
-                               else {
-                                       // not sure if it is correct ...
-                                       SecurityKeyIdentifierClause signClause =
-                                               
recipientParams.CallCreateKeyIdentifierClause (signToken, msgIncludesToken ? 
recipientParams.ReferenceStyle : SecurityTokenReferenceStyle.External);
-                                       AsymmetricSecurityKey signKey = 
(AsymmetricSecurityKey) signToken.ResolveKeyIdentifierClause (signClause);
-                                       sxml.SigningKey = 
signKey.GetAsymmetricAlgorithm (security.DefaultSignatureAlgorithm, true);
-                               }
-
                                sig = sxml.Signature;
                                sig.SignedInfo.CanonicalizationMethod =
                                        suite.DefaultCanonicalizationAlgorithm;
                                foreach (XmlNode n in doc.SelectNodes 
("/s:Envelope/s:Header/*", nsmgr)) {
                                        XmlElement el = n as XmlElement;
-                                       if (el == null)
+                                       if (el == null || el.LocalName == 
"Security" && el.NamespaceURI == Constants.WssNamespace)
                                                continue;
                                        if (sigSpec.HeaderTypes.Count == 0 ||
                                            sigSpec.HeaderTypes.Contains (new 
XmlQualifiedName (el.LocalName, el.NamespaceURI)))
-                                               sig.SignedInfo.AddReference 
(CreateReference (el, suite));
+                                               CreateReference (sig, el, 
suite);
                                }
                                if (sigSpec.IsBodyIncluded)
-                                       sig.SignedInfo.AddReference 
(CreateReference (body, suite));
+                                       CreateReference (sig, body, suite);
+                               if (timestamp != null) {
+                                       XmlElement dummy = doc.CreateElement 
("dummy");
+                                       using (XmlWriter w = 
dummy.CreateNavigator ().AppendChild ()) {
+                                               timestamp.WriteTo (w);
+                                       }
+                                       CreateReference (sig, dummy.FirstChild 
as XmlElement, suite);
+                               }
 
-                               if (sigHash != null)
-                                       sxml.ComputeSignature (sigHash);
-                               else
+                               if (security.DefaultSignatureAlgorithm == 
SignedXml.XmlDsigHMACSHA1Url)
+                                       sxml.ComputeSignature (new HMACSHA1 
(aes.Key));
+                               else {
+                                       SecurityKeyIdentifierClause signClause =
+                                               
recipientParams.CallCreateKeyIdentifierClause (signToken, msgIncludesToken ? 
recipientParams.ReferenceStyle : SecurityTokenReferenceStyle.External);
+                                       AsymmetricSecurityKey signKey = 
(AsymmetricSecurityKey) signToken.ResolveKeyIdentifierClause (signClause);
+                                       sxml.SigningKey = 
signKey.GetAsymmetricAlgorithm (security.DefaultSignatureAlgorithm, true);
                                        sxml.ComputeSignature ();
+                               }
+
+                               // FIXME: It is kind of hack that it uses and
+                               // clears temporary DataObjects.
+                               sxml.Signature.ObjectList.Clear ();
+
                                sxml.KeyInfo = new KeyInfo ();
                                SecurityTokenReferenceKeyInfo sigKeyInfo = new 
SecurityTokenReferenceKeyInfo (ekeyClause, serializer, doc);
                                sxml.KeyInfo.AddClause (sigKeyInfo);
@@ -430,15 +437,33 @@
                        return ret;
                }
 
-               Reference CreateReference (XmlElement el, 
SecurityAlgorithmSuite suite)
+               string GetId (XmlElement el)
                {
-                       string id = el.GetAttribute ("Id");
+                       string id = el.GetAttribute ("Id", 
Constants.WsuNamespace);
                        if (id == String.Empty)
+                               id = el.GetAttribute ("Id");
+                       return id;
+               }
+
+               void CreateReference (Signature sig, XmlElement el, 
SecurityAlgorithmSuite suite)
+               {
+                       string id = GetId (el);
+                       if (id == String.Empty)
                                id = GenerateId (el.OwnerDocument);
                        Reference r = new Reference ("#" + id);
                        r.AddTransform (CreateTransform 
(suite.DefaultCanonicalizationAlgorithm));
                        r.DigestMethod = suite.DefaultDigestAlgorithm;
-                       return r;
+#if true
+                       DataObject d = new DataObject ();
+                       // FIXME: creating my own XmlNodeList would be much 
better
+                       d.Data = el.SelectNodes (".");
+                       d.Id = id;
+                       sig.AddObject (d);
+#else
+                       if (GetId (el) != id)
+                               el.SetAttribute ("Id", id);
+#endif
+                       sig.SignedInfo.AddReference (r);
                }
 
                Transform CreateTransform (string url)

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/WSSecurityMessageHeader.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/WSSecurityMessageHeader.cs
       2007-01-12 15:18:04 UTC (rev 70923)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/WSSecurityMessageHeader.cs
       2007-01-12 15:28:57 UTC (rev 70924)
@@ -229,27 +229,12 @@
                        get { return Constants.WssNamespace; }
                }
 
-               string FormatAsUtc (DateTime date)
-               {
-                       return date.ToUniversalTime ().ToString (
-                               "yyyy-MM-dd'T'HH:mm:ss.fff'Z'",
-                               CultureInfo.InvariantCulture);
-               }
-
                protected override void OnWriteHeaderContents 
(XmlDictionaryWriter writer, MessageVersion version)
                {
                        foreach (object obj in Contents) {
                                if (obj is WsuTimestamp) {
                                        WsuTimestamp ts = (WsuTimestamp) obj;
-                                       writer.WriteStartElement ("u", 
"Timestamp", Constants.WsuNamespace);
-                                       writer.WriteAttributeString ("u", "Id", 
Constants.WsuNamespace, ts.Id);
-                                       writer.WriteStartElement ("u", 
"Created", Constants.WsuNamespace);
-                                       writer.WriteValue (FormatAsUtc 
(ts.Created));
-                                       writer.WriteEndElement ();
-                                       writer.WriteStartElement ("u", 
"Expires", Constants.WsuNamespace);
-                                       writer.WriteValue (FormatAsUtc 
(ts.Expires));
-                                       writer.WriteEndElement ();
-                                       writer.WriteEndElement ();
+                                       ts.WriteTo (writer);
                                } else if (obj is WsscDerivedKeyToken) {
                                        WsscDerivedKeyToken dk = 
(WsscDerivedKeyToken) obj;
                                        writer.WriteStartElement ("c", 
"DerivedKeyToken", Constants.WsscNamespace);
@@ -311,6 +296,27 @@
                        get { return expires; }
                        set { expires = value; }
                }
+
+               public void WriteTo (XmlWriter writer)
+               {
+                       writer.WriteStartElement ("u", "Timestamp", 
Constants.WsuNamespace);
+                       //writer.WriteAttributeString ("Id", Id);
+                       writer.WriteAttributeString ("u", "Id", 
Constants.WsuNamespace, Id);
+                       writer.WriteStartElement ("u", "Created", 
Constants.WsuNamespace);
+                       writer.WriteValue (FormatAsUtc (Created));
+                       writer.WriteEndElement ();
+                       writer.WriteStartElement ("u", "Expires", 
Constants.WsuNamespace);
+                       writer.WriteValue (FormatAsUtc (Expires));
+                       writer.WriteEndElement ();
+                       writer.WriteEndElement ();
+               }
+
+               string FormatAsUtc (DateTime date)
+               {
+                       return date.ToUniversalTime ().ToString (
+                               "yyyy-MM-dd'T'HH:mm:ss.fff'Z'",
+                               CultureInfo.InvariantCulture);
+               }
        }
 
        internal class WsscDerivedKeyToken

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

Reply via email to