Skip to content

Commit 72fcad4

Browse files
author
Yaron Naveh
committed
add test for empty URI
1 parent 1b5a9a1 commit 72fcad4

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

lib/signed-xml.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,8 @@ SignedXml.prototype.checkSignature = function(xml) {
185185
if (!this.validateReferences(doc)) {
186186
return false;
187187
}
188-
189-
190-
if (!this.validateSignatureValue(doc)) {
188+
189+
if (!this.validateSignatureValue(doc)) {
191190
return false;
192191
}
193192

@@ -197,8 +196,8 @@ SignedXml.prototype.checkSignature = function(xml) {
197196
SignedXml.prototype.validateSignatureValue = function(doc) {
198197
var signedInfo = utils.findChilds(this.signatureXmlDoc.documentElement, "SignedInfo")
199198
if (signedInfo.length==0) throw new Error("could not find SignedInfo element in the message")
200-
var signedInfoCanon = this.getCanonXml([this.canonicalizationAlgorithm], signedInfo[0])
201-
var signer = this.findSignatureAlgorithm(this.signatureAlgorithm)
199+
var signedInfoCanon = this.getCanonXml([this.canonicalizationAlgorithm], signedInfo[0])
200+
var signer = this.findSignatureAlgorithm(this.signatureAlgorithm)
202201
var res = signer.verifySignature(signedInfoCanon, this.signingKey, this.signatureValue)
203202
if (!res) this.validationErrors.push("invalid signature: the signature value " +
204203
this.signatureValue + " is incorrect")
@@ -251,6 +250,10 @@ SignedXml.prototype.validateReferences = function(doc) {
251250

252251
var hash = this.findHashAlgorithm(ref.digestAlgorithm)
253252
var digest = hash.getHash(canonXml)
253+
254+
//console.log(digest)
255+
//console.log(ref.digestValue)
256+
254257
if (digest!=ref.digestValue) {
255258
this.validationErrors.push("invalid signature: for uri " + ref.uri +
256259
" calculated digest is " + digest +
@@ -321,7 +324,7 @@ SignedXml.prototype.loadReference = function(ref) {
321324
}
322325
}
323326

324-
//workaround for validating windows mobile store signatures - it uses c14n but does not state it in the transforms
327+
//***workaround for validating windows mobile store signatures - it uses c14n but does not state it in the transforms
325328
//transforms.push("http://www.w3.org/2001/10/xml-exc-c14n#")
326329

327330
this.addReference(null, transforms, digestAlgo, utils.findAttr(ref, "URI").value, digestValue)

test/signature-integration-tests.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,37 @@ module.exports = {
2727

2828
verifySignature(test, xml, ["//*[local-name(.)='book']"])
2929
},
30+
3031
/*
32+
"empty URI reference should consider the whole document": function(test) {
33+
34+
var sampleXml=["<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
35+
"<root>",
36+
" <a>",
37+
" <b/>",
38+
" </a>",
39+
" <Seal><Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><SignedInfo><CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"/><SignatureMethod Algorithm=\"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256\"/><Reference URI=\"\"><Transforms><Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"/></Transforms><DigestMethod Algorithm=\"http://www.w3.org/2001/04/xmlenc#sha256\"/><DigestValue>FOezc5yb1O+LfQaD4UBKEUphrGzFAq5DM9B9ll37JOA=</DigestValue></Reference></SignedInfo><SignatureValue>AjkQ5NF71bwJ2YHIs8jbqva9qaNv66BYZiZw0JJZ1cW6jf3mjWShIMQZWcw78QGpzzr+ZspzUbs4",
40+
"6VAnHApJElOTDylSf3rDSvzsklKcFpHJ9yCJV+PnipEsY8qWhzKHlKCdtEn1xH0BCP/2JfMYgLQl",
41+
"PCvaR8XrgdODeQ2Gn6g=</SignatureValue><KeyInfo><KeyValue><RSAKeyValue><Modulus>t+qknJd/Kdo09fvQrRThqh/3EyDQj8zT1ZT7uXmivni4Vaysf6zHv+oORIvAt9ntZE2ZCif9v6CC",
42+
"W+hmRFkdgRoVpmD2TErjykzowx6Ffyf5BkVnVB89+g/ZqNyyvXiBe8SmpBrRLOMifnbacyrJcsrH",
43+
"fwlCnuyGKXj1LfzDcR8=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue></KeyValue></KeyInfo></Signature></Seal>",
44+
" <c>",
45+
" <d e=\"f\"/>",
46+
" </c>",
47+
"</root>"].join("\n");
48+
49+
var doc = new Dom().parseFromString(sampleXml);
50+
51+
var signature = crypto.xpath(doc, "//*//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0];
52+
var sig = new crypto.SignedXml();
53+
sig.keyInfoProvider = new crypto.FileKeyInfo("./test/static/empty_uri.pem");
54+
sig.loadSignature(signature.toString());
55+
var result = sig.checkSignature(sampleXml);
56+
test.equal(result, true);
57+
test.done();
58+
},
59+
60+
3161
"windows store signature": function(test) {
3262
3363
var xml = fs.readFileSync('./test/static/windows_store_signature.xml', 'utf-8');

test/static/empty_uri.pem

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIICcTCCAVmgAwIBAgIBATANBgkqhkiG9w0BAQQFADA+MQswCQYDVQQGEwJFUzEbMBkGA1UEChMS
3+
U2N5dGwgVU5JVCBURVNUIENBMRIwEAYDVQQLEwlVTklUIFRFU1QwHhcNMDYwMzAyMTEwOTEyWhcN
4+
MzAwNDA2MTEwOTEyWjA+MQswCQYDVQQGEwJFUzEbMBkGA1UEChMSU2N5dGwgVU5JVCBURVNUIENB
5+
MRIwEAYDVQQLEwlVTklUIFRFU1QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALfqpJyXfyna
6+
NPX70K0U4aof9xMg0I/M09WU+7l5or54uFWsrH+sx7/qDkSLwLfZ7WRNmQon/b+gglvoZkRZHYEa
7+
FaZg9kxK48pM6MMehX8n+QZFZ1QfPfoP2ajcsr14gXvEpqQa0SzjIn522nMqyXLKx38JQp7shil4
8+
9S38w3EfAgMBAAEwDQYJKoZIhvcNAQEEBQADggEBAJrtSsuqdB3RvGZMriETpO0pqQsBhZ+JRYqs
9+
5dFIiC+bdJE+dUB6v8fpv1exSQ0+i+e1oTs2I9Wd4eIQ4rlZCG9K6EYBKP9Z59OBDTf6luaisoul
10+
6gnKW7+kUfQQkBfJJw/4RA7FbaAmYNGEEfXTwDMU+ZoqIO/PV+JsfOtFUdPcwv1hPQHTE+KR1DtR
11+
AC+A4Ak+fOoaRnyTprvbT4inaPdn6D9fBrIpO6hQSAtM5K9+/VaskMSFqw03DkADRyxHacdz9JLp
12+
5ChDbRrXCDdT/a832acPDViS3nG/GhuSTK8mlrXeHjpG6vaSbKiXNXwrwz80k/XoNh3k5jlfrzUM
13+
CQ4=
14+
-----END CERTIFICATE-----

0 commit comments

Comments
 (0)