Author: atsushi
Date: 2007-01-11 11:31:42 -0500 (Thu, 11 Jan 2007)
New Revision: 70864

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

        * SecureMessageGenerator.cs : some reordering to handle signing and
          encryption with supporting tokens. Fixed XPath query bug for
          soap header contents (we want s:Header/*, not s:Header).



Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog    
    2007-01-11 16:24:19 UTC (rev 70863)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog    
    2007-01-11 16:31:42 UTC (rev 70864)
@@ -1,5 +1,11 @@
 2007-01-11  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * SecureMessageGenerator.cs : some reordering to handle signing and
+         encryption with supporting tokens. Fixed XPath query bug for
+         soap header contents (we want s:Header/*, not s:Header).
+
+2007-01-11  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
        * MessageSecurityBindingSupport.cs : more refactoring.
          Made it abstract and added Initiator- and Recipient- classes.
          Several members were moved to those derived types.

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/SecureMessageGenerator.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/SecureMessageGenerator.cs
        2007-01-11 16:24:19 UTC (rev 70863)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/SecureMessageGenerator.cs
        2007-01-11 16:31:42 UTC (rev 70864)
@@ -229,40 +229,31 @@
                                Direction == MessageDirection.Input ?
                                initiatorParams : recipientParams;
 
-                       SupportingTokenInfoCollection tokens =
-                               CollectInitiatorSupportingTokens ();
-
-                       // SecurityTokenInclusionMode
-                       // - Initiator or Recipient
-                       // - done or notyet. FIXME: not implemented yet
-                       // It also affects on key reference output
-
-                       SecurityTokenInclusionMode appliedMode =
-                               securingParams.InclusionMode;
-                       bool msgIncludesToken = ShouldIncludeToken 
(appliedMode, false);
-
-                       SecurityKeyIdentifierClause encClause =
-                               initiatorParams.CallCreateKeyIdentifierClause 
(encToken, msgIncludesToken ? initiatorParams.ReferenceStyle : 
SecurityTokenReferenceStyle.External);
-                       SecurityKeyIdentifierClause signClause =
-                               recipientParams.CallCreateKeyIdentifierClause 
(signToken, msgIncludesToken ? recipientParams.ReferenceStyle : 
SecurityTokenReferenceStyle.External);
-
-                       AsymmetricSecurityKey encKey = (AsymmetricSecurityKey) 
-                               encToken.ResolveKeyIdentifierClause (encClause);
-                       AsymmetricSecurityKey signKey = (AsymmetricSecurityKey) 
-                               signToken.ResolveKeyIdentifierClause 
(signClause);
                        string messageId = "uuid:" + Guid.NewGuid ();
+                       msg.Headers.Add (MessageHeader.CreateHeader 
("MessageID", msg.Version.Addressing.Namespace, messageId));
                        int identForMessageId = 1;
 
-                       msg.Headers.Add (MessageHeader.CreateHeader 
("MessageID", msg.Version.Addressing.Namespace, messageId));
-
                        // FIXME: get correct ReplyTo value
                        msg.Headers.Add (MessageHeader.CreateHeader ("ReplyTo", 
msg.Version.Addressing.Namespace, EndpointAddress10.FromEndpointAddress (new 
EndpointAddress (Constants.WsaAnonymousUri))));
 
                        if (MessageTo != null)
                                msg.Headers.Add (MessageHeader.CreateHeader 
("To", msg.Version.Addressing.Namespace, MessageTo.Uri.AbsoluteUri, true));
 
-                       // addition except for wsse:Security is done. Start 
securing...
+                       // wss:Security
+                       WSSecurityMessageHeader header =
+                               new WSSecurityMessageHeader (serializer);
+                       // wss:Security/wsu:Timestamp
+                       if (element.IncludeTimestamp) {
+                               WsuTimestamp timestamp = new WsuTimestamp ();
+                               timestamp.Id = messageId + "-" + 
identForMessageId++;
+                               timestamp.Created = DateTime.Now;
+                               // FIXME: on service side, use 
element.LocalServiceSettings.TimestampValidityDuration
+                               timestamp.Expires = timestamp.Created.Add 
(element.LocalClientSettings.TimestampValidityDuration);
+                               header.Contents.Add (timestamp);
+                       }
+                       msg.Headers.Add (header);
 
+
                        XmlDocument doc = new XmlDocument ();
                        doc.PreserveWhitespace = true;
                        XPathNavigator nav = doc.CreateNavigator ();
@@ -277,20 +268,31 @@
                        Signature sig = null;
                        EncryptedData sigenc = null;
 
-                       // wss:Security
-                       WSSecurityMessageHeader header =
-                               new WSSecurityMessageHeader (serializer);
-                       // wss:Security/wsu:Timestamp
-                       if (element.IncludeTimestamp) {
-                               WsuTimestamp timestamp = new WsuTimestamp ();
-                               timestamp.Id = messageId + "-" + 
identForMessageId++;
-                               timestamp.Created = DateTime.Now;
-                               // FIXME: on service side, use 
element.LocalServiceSettings.TimestampValidityDuration
-                               timestamp.Expires = timestamp.Created.Add 
(element.LocalClientSettings.TimestampValidityDuration);
-                               header.Contents.Add (timestamp);
-                       }
-                       msg.Headers.Add (header);
 
+                       SupportingTokenInfoCollection tokens =
+                               CollectInitiatorSupportingTokens ();
+
+{
+
+                       // SecurityTokenInclusionMode
+                       // - Initiator or Recipient
+                       // - done or notyet. FIXME: not implemented yet
+                       // It also affects on key reference output
+
+                       SecurityTokenInclusionMode appliedMode =
+                               securingParams.InclusionMode;
+                       bool msgIncludesToken = ShouldIncludeToken 
(appliedMode, false);
+
+                       SecurityKeyIdentifierClause encClause =
+                               initiatorParams.CallCreateKeyIdentifierClause 
(encToken, msgIncludesToken ? initiatorParams.ReferenceStyle : 
SecurityTokenReferenceStyle.External);
+                       SecurityKeyIdentifierClause signClause =
+                               recipientParams.CallCreateKeyIdentifierClause 
(signToken, msgIncludesToken ? recipientParams.ReferenceStyle : 
SecurityTokenReferenceStyle.External);
+
+                       AsymmetricSecurityKey encKey = (AsymmetricSecurityKey) 
+                               encToken.ResolveKeyIdentifierClause (encClause);
+                       AsymmetricSecurityKey signKey = (AsymmetricSecurityKey) 
+                               signToken.ResolveKeyIdentifierClause 
(signClause);
+
                        // FIXME: it needs to choose message parts by 
                        // ChannelProtectionRequirements.
                        XmlElement body = doc.SelectSingleNode 
("/s:Envelope/s:Body/*", nsmgr) as XmlElement;
@@ -323,7 +325,7 @@
                                sig = sxml.Signature;
                                sig.SignedInfo.CanonicalizationMethod =
                                        suite.DefaultCanonicalizationAlgorithm;
-                               foreach (XmlNode n in doc.SelectNodes 
("/s:Envelope/s:Header", nsmgr)) {
+                               foreach (XmlNode n in doc.SelectNodes 
("/s:Envelope/s:Header/*", nsmgr)) {
                                        XmlElement el = n as XmlElement;
                                        if (el == null)
                                                continue;
@@ -353,35 +355,40 @@
                                        suite.DefaultAsymmetricKeyWrapAlgorithm,
                                        encToken,
                                        new SecurityKeyIdentifier (encClause));
-                               encRefList = new ReferenceList ();
+                               ReferenceList refList = new ReferenceList ();
                                if (!initiatorParams.RequireDerivedKeys)
-                                       ekey.ReferenceList = encRefList;
+                                       ekey.ReferenceList = refList;
+                               else
+                                       encRefList = refList;
 
-                               EncryptedData edata = Encrypt (body, aes, 
ekeyId, encRefList, encClause, exml, doc);
+                               EncryptedData edata = Encrypt (body, aes, 
ekeyId, refList, encClause, exml, doc);
                                edata.KeyInfo = null;
                                EncryptedXml.ReplaceElement (body, edata, 
false);
 
                                // encrypt signature
                                if (protectionOrder == 
MessageProtectionOrder.SignBeforeEncryptAndEncryptSignature) {
                                        XmlElement sigxml = sig.GetXml ();
-                                       sigenc = Encrypt (sigxml, aes, ekeyId, 
encRefList, encClause, exml, doc);
+                                       sigenc = Encrypt (sigxml, aes, ekeyId, 
refList, encClause, exml, doc);
                                }
                                break;
                        }
 
+                       if (sig != null && msgIncludesToken)
+                               header.Contents.Add (signToken);
+                       if (signToken != encToken && msgIncludesToken)
+                               header.Contents.Add (encToken);
+
+}
+
                        Message ret = Message.CreateMessage (msg.Version, 
msg.Headers.Action, new XmlNodeReader (doc.SelectSingleNode 
("/s:Envelope/s:Body/*", nsmgr) as XmlElement));
 
                        ret.Headers.Clear ();
                        ret.Headers.CopyHeadersFrom (msg);
 
-                       if (sig != null && msgIncludesToken)
-                               header.Contents.Add (signToken);
-                       if (signToken != encToken && msgIncludesToken)
-                               header.Contents.Add (encToken);
-
                        if (ekey != null)
                                header.Contents.Add (ekey);
 
+                       // FIXME: it should be moved to encryption loop inside.
                        // generate derived key if needed
                        if (initiatorParams.RequireDerivedKeys) {
                                RijndaelManaged deriv = new RijndaelManaged ();
@@ -399,8 +406,6 @@
                                        derivedKey.SecurityTokenReference =
                                                new LocalIdKeyIdentifierClause 
(ekey.Id);
                                header.Contents.Add (derivedKey);
-                               if (encRefList != null)
-                                       header.Contents.Add (encRefList);
                        }
 
                        if (sigenc != null)
@@ -408,6 +413,9 @@
                        else if (sig != null)
                                header.Contents.Add (sig);
 
+                       if (encRefList != null)
+                               header.Contents.Add (encRefList);
+
                        return ret;
                }
 

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

Reply via email to