Skip to content

Commit 6a11ca4

Browse files
author
Weiwu Zhang
committed
adding the first js xmldsig verifier code that actually works for demo purpose - more work needs to be done to bridge it to production use
1 parent 3ab5e7c commit 6a11ca4

File tree

4 files changed

+59
-18
lines changed

4 files changed

+59
-18
lines changed

xmldsig/js/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Demonstrating verifying XML Digital Signature (xmldsig)
2+
====
3+
4+
xmldsig is used to sign every TokenScript file. This directory contains a
5+
demonstration of how to verify xmldsig with JavaScript code.

xmldsig/js/package.json

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
{
2-
"name": "tokenscript",
3-
"version": "1.0.0",
4-
"description": "",
5-
"main": "index.js",
6-
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
2+
"engines": {
3+
"node": ">=0.15"
84
},
9-
"keywords": [],
10-
"author": "",
11-
"license": "ISC",
5+
"engineStric": true,
126
"dependencies": {
13-
"webcrypto": "",
14-
"node-webcrypto-ossl": "",
15-
"xmldsigjs": "^2.0.27"
7+
"xmldsigjs": "^2.1.3"
168
}
179
}

xmldsig/js/xmldom.patch

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
diff -ru node_modules/xmldom.old/lib/dom.js node_modules/xmldom/lib/dom.js
2+
--- node_modules/xmldom.old/lib/dom.js 1985-10-26 18:15:00.000000000 +1000
3+
+++ node_modules/xmldom/lib/dom.js 2021-04-07 17:52:51.494473360 +1000
4+
@@ -23,7 +23,7 @@
5+
pt.constructor = Class
6+
}
7+
}
8+
-var htmlns = 'http://www.w3.org/1999/xhtml' ;
9+
+var htmlns = 'http://www.w3.org/1999/html' ;
10+
// Node Types
11+
var NodeType = {}
12+
var ELEMENT_NODE = NodeType.ELEMENT_NODE = 1;
13+
diff -ru node_modules/xmldom.old/lib/sax.js node_modules/xmldom/lib/sax.js
14+
--- node_modules/xmldom.old/lib/sax.js 1985-10-26 18:15:00.000000000 +1000
15+
+++ node_modules/xmldom/lib/sax.js 2021-04-07 17:53:56.875198887 +1000
16+
@@ -195,7 +195,7 @@
17+
18+
19+
20+
- if(el.uri === 'http://www.w3.org/1999/xhtml' && !el.closed){
21+
+ if(el.uri === 'http://www.w3.org/1999/html' && !el.closed){
22+
end = parseHtmlSpecialContent(source,end,el.tagName,entityReplacer,domBuilder)
23+
}else{
24+
end++;
25+
@@ -333,7 +333,7 @@
26+
errorHandler.warning('attribute "'+value+'" missed quot(")!');
27+
addAttribute(attrName, value.replace(/&#?\w+;/g,entityReplacer), start)
28+
}else{
29+
- if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !value.match(/^(?:disabled|checked|selected)$/i)){
30+
+ if(currentNSMap[''] !== 'http://www.w3.org/1999/html' || !value.match(/^(?:disabled|checked|selected)$/i)){
31+
errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!')
32+
}
33+
addAttribute(value, value, start)
34+
@@ -381,7 +381,7 @@
35+
//case S_ATTR_NOQUOT_VALUE:void();break;
36+
case S_ATTR_SPACE:
37+
var tagName = el.tagName;
38+
- if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !attrName.match(/^(?:disabled|checked|selected)$/i)){
39+
+ if(currentNSMap[''] !== 'http://www.w3.org/1999/html' || !attrName.match(/^(?:disabled|checked|selected)$/i)){
40+
errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead2!!')
41+
}
42+
addAttribute(attrName, attrName, start);

xmldsig/js/xmldsigverifier.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
"use strict";
22

3-
var WebCrypto = require("node-webcrypto-ossl");
4-
var crypto = new WebCrypto.Crypto();
5-
6-
var args = process.argv.slice(2);
3+
const crypto = require('crypto').webcrypto;
74

85
const XmlDSigJs = require("xmldsigjs");
96
const fs = require('fs');
107

118
XmlDSigJs.Application.setEngine("WebCrypto", crypto);
129

10+
if (process.argv.length == 2) {
11+
console.log("xmldsigverifier demonstration script. Need parameters - xml files with enveloped signatures")
12+
}
13+
1314
for (var i=2; i<process.argv.length; i++) {
1415
verify(process.argv[i]);
1516
}
@@ -30,7 +31,8 @@ function verify(xml_file) {
3031
}
3132
})
3233
.catch(e => {
33-
console.log("[FAILED] " + xml_file);
34-
//console.log(e)
34+
console.log("[ERROR ] " + xml_file);
35+
console.log(e)
3536
});
3637
}
38+

0 commit comments

Comments
 (0)