+2004-03-17 Atsushi Enomoto <atsushi@ximian.com>
+
+ * SignedXml.cs : the result from enveloped signature transform should
+ be canonicalized before getting its hash.
+ * XmlDsigEnvelopedSignatureTransform.cs : in XPath selection,
+ if the node is Signature itself it is not allowed.
+ PreserveWhitespace is required.
+
2004-03-16 Sebastien Pouliot <sebastien@ximian.com>
* SignedXml.cs: Changed (again). This time we use the Stream when
t.LoadInput (doc);
if (t is XmlDsigEnvelopedSignatureTransform) {
- object o = t.GetOutput ();
- MemoryStream ms = new MemoryStream ();
- XmlTextWriter xw = new XmlTextWriter (ms, Encoding.UTF8);
- XmlDocument d = o as XmlDocument;
- if (d != null)
- d.Save (xw);
- else {
- XmlNodeList nl = (XmlNodeList) o;
- foreach (XmlNode n in nl)
- n.WriteTo (xw);
- }
- // don't close xw (and thus ms).
- return ms;
+ // It returns XmlDocument for XmlDocument input.
+ doc = (XmlDocument) t.GetOutput ();
+ Transform c14n = GetC14NMethod ();
+ c14n.LoadInput (doc);
+ return (Stream) c14n.GetOutput ();
}
object obj = t.GetOutput ();
r.DigestValue = GetReferenceHash (r);
}
}
-
- private Stream SignedInfoTransformed ()
+
+ private Transform GetC14NMethod ()
{
Transform t = (Transform) CryptoConfig.CreateFromName (signature.SignedInfo.CanonicalizationMethod);
if (t == null)
throw new CryptographicException ("Unknown Canonicalization Method {0}", signature.SignedInfo.CanonicalizationMethod);
+ return t;
+ }
+
+ private Stream SignedInfoTransformed ()
+ {
+ Transform t = GetC14NMethod ();
if (signatureElement != null) {
// TODO - check signature.SignedInfo.Id
XmlNodeList xnl = signatureElement.GetElementsByTagName (XmlSignature.ElementNames.SignedInfo, XmlSignature.NamespaceURI);
-
byte[] si = Encoding.UTF8.GetBytes (xnl [0].OuterXml);
MemoryStream ms = new MemoryStream ();
ms.Write (si, 0, si.Length);
// possible input: Stream, XmlDocument, and XmlNodeList
if (inputObj is Stream) {
doc = new XmlDocument ();
+ doc.PreserveWhitespace = true;
doc.XmlResolver = GetResolver ();
doc.Load (inputObj as Stream);
return GetOutputFromNode (doc, GetNamespaceManager (doc), true);
{
XmlDocument doc = input is XmlDocument ? input as XmlDocument : input.OwnerDocument;
if (remove) {
- XmlNodeList nl = input.SelectNodes ("//dsig:Signature", nsmgr);
+ XmlNodeList nl = input.SelectNodes ("descendant-or-self::dsig:Signature", nsmgr);
foreach (XmlNode n in nl)
n.ParentNode.RemoveChild (n);
}