@@ -140,7 +140,7 @@ function SignedXml(idMode, options) {
140
140
this . signingKey = null
141
141
this . signatureAlgorithm = this . options . signatureAlgorithm || "http://www.w3.org/2000/09/xmldsig#rsa-sha1" ;
142
142
this . keyInfoProvider = null
143
- this . canonicalizationAlgorithm = "http://www.w3.org/2001/10/ xml-exc- c14n# "
143
+ this . canonicalizationAlgorithm = "http://www.w3.org/TR/ 2001/REC- xml-c14n-20010315 "
144
144
this . signedXml = ""
145
145
this . signatureXml = ""
146
146
this . signatureXmlDoc = null
@@ -153,7 +153,7 @@ function SignedXml(idMode, options) {
153
153
}
154
154
155
155
SignedXml . CanonicalizationAlgorithms = {
156
- 'http://www.w3.org/2001/10/ xml-exc- c14n# ' : ExclusiveCanonicalization ,
156
+ 'http://www.w3.org/TR/ 2001/REC- xml-c14n-20010315 ' : ExclusiveCanonicalization ,
157
157
'http://www.w3.org/2000/09/xmldsig#enveloped-signature' : EnvelopedSignature
158
158
}
159
159
@@ -247,7 +247,8 @@ SignedXml.prototype.validateReferences = function(doc) {
247
247
ref . uri + " but could not find such element in the xml" )
248
248
return false
249
249
}
250
- var canonXml = this . getCanonXml ( ref . transforms , elem [ 0 ] , { inclusiveNamespacesPrefixList : ref . inclusiveNamespacesPrefixList } ) ;
250
+ var canonXml = this . getCanonXml ( ref . transforms , elem [ 0 ] , { inclusiveNamespacesPrefixList : ref . inclusiveNamespacesPrefixList } ) ;
251
+ fs . writeFileSync ( "../canon.xml" , canonXml ) ;
251
252
252
253
var hash = this . findHashAlgorithm ( ref . digestAlgorithm )
253
254
var digest = hash . getHash ( canonXml )
@@ -334,15 +335,15 @@ SignedXml.prototype.loadReference = function(ref) {
334
335
335
336
//***workaround for validating windows mobile store signatures - it uses c14n but does not state it in the transforms
336
337
if ( transforms . length == 1 && transforms [ 0 ] == "http://www.w3.org/2000/09/xmldsig#enveloped-signature" )
337
- transforms . push ( "http://www.w3.org/2001/10/ xml-exc- c14n# " )
338
+ transforms . push ( "http://www.w3.org/TR/ 2001/REC- xml-c14n-20010315 " )
338
339
339
340
this . addReference ( null , transforms , digestAlgo , utils . findAttr ( ref , "URI" ) . value , digestValue , inclusiveNamespacesPrefixList , false )
340
341
}
341
342
342
343
SignedXml . prototype . addReference = function ( xpath , transforms , digestAlgorithm , uri , digestValue , inclusiveNamespacesPrefixList , isEmptyUri ) {
343
344
this . references . push ( {
344
345
"xpath" : xpath ,
345
- "transforms" : transforms ? transforms : [ "http://www.w3.org/2001/10/ xml-exc- c14n# " ] ,
346
+ "transforms" : transforms ? transforms : [ "http://www.w3.org/TR/ 2001/REC- xml-c14n-20010315 " ] ,
346
347
"digestAlgorithm" : digestAlgorithm ? digestAlgorithm : "http://www.w3.org/2000/09/xmldsig#sha1" ,
347
348
"uri" : uri ,
348
349
"digestValue" : digestValue ,
@@ -447,10 +448,16 @@ SignedXml.prototype.createReferences = function(doc) {
447
448
448
449
SignedXml . prototype . getCanonXml = function ( transforms , node , options ) {
449
450
var canonXml = node
450
- for ( var t in transforms ) {
451
- if ( ! transforms . hasOwnProperty ( t ) ) continue ;
452
451
453
- var transform = this . findCanonicalizationAlgorithm ( transforms [ t ] )
452
+ //***workaround for creating signatures that can be validated by .NET's SignedXml class - it uses c14n but does not state it in the transforms
453
+ var transformsCopy = transforms . slice ( )
454
+ if ( transformsCopy . length == 1 && transformsCopy [ 0 ] == "http://www.w3.org/2000/09/xmldsig#enveloped-signature" )
455
+ transformsCopy . push ( "http://www.w3.org/TR/2001/REC-xml-c14n-20010315" )
456
+
457
+ for ( var t in transformsCopy ) {
458
+ if ( ! transformsCopy . hasOwnProperty ( t ) ) continue ;
459
+
460
+ var transform = this . findCanonicalizationAlgorithm ( transformsCopy [ t ] )
454
461
canonXml = transform . process ( canonXml , options ) ;
455
462
//TODO: currently transform.process may return either Node or String value (enveloped transformation returns Node, exclusive-canonicalization returns String).
456
463
//This eitehr needs to be more explicit in the API, or all should return the same.
0 commit comments