-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DSigner ActiveX API emulator.user.js
102 lines (93 loc) · 3.67 KB
/
DSigner ActiveX API emulator.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// ==UserScript==
// @name DSigner ActiveX API emulator
// @version 1
// @include https://www.slovensko.sk/Services/Ives/*
// @grant none
// ==/UserScript==
let disig_prefix = 'https://www.slovensko.sk/static/zep/dbridge_js/v1.0'
for (let m of ["config.js", "dCommon.min.js", "dSigXades.min.js", "dSigXadesBp.min.js"]) {
let script = document.createElement('script')
script.type = "text/javascript"
script.async = false
script.src = disig_prefix + "/" + m
document.head.appendChild(script)
}
console.log("DSigner JS API loaded")
window.eval('(' + (() => {
window.ActiveXObject = function (name) {
let promisify = function (f) {
return function (...args) {
return new Promise((resolve, reject) => {
let callback = {
onSuccess: (x) => {
resolve(x || 0)
},
onFailure: (x) => {
reject(x || -1)
}
}
console.log("calling", f, args, callback)
f.call(ditec.dSigXadesJs, ...args, callback)
})
}
}
console.log("Requested ActiveXObject " + name);
if (name == "DSig.XadesSigAtl") {
let deploy = promisify(ditec.dSigXadesJs.deploy)
let initialize = promisify(ditec.dSigXadesJs.initialize)
let setSigningTimeProcessing = promisify(ditec.dSigXadesJs.setSigningTimeProcessing)
let sign = promisify(ditec.dSigXadesJs.sign)
let addXmlObject = promisify(ditec.dSigXadesJs.addXmlObject)
let getSignedXmlWithEnvelope = promisify(ditec.dSigXadesJs.getSignedXmlWithEnvelope)
this.AddObject = async function (args) {
console.log("Deploy")
await deploy({})
console.log("Initialize")
await initialize()
console.log("AddObject", args)
return await addXmlObject(...args)
}
this.SetSigningTimeProcessing = async function (...args) {
console.log("(disabled) SetSigningTimeProcessing", args)
return 0
}
this.Sign = async function (a, b, c) {
args = [a, 'http://www.w3.org/2001/04/xmlenc#' + b, c]
console.log("Sign", args)
await sign(...args)
return 0
}
this.SignedXMLWithEnvelope = async function () {
console.log("SignedXMLWithEnvelope", args)
return await getSignedXmlWithEnvelope()
}
return this
}
if (name == "DSig.XmlPluginAtl") {
this.CreateObject = function (...args) {
return args
}
return this
}
}
if ("dsignerDoSign" in window) {
window.eval(' async ' + dsignerDoSign.toString().replace("dsignerDoSign", "asyncDsignerDoSign").replace(/oXML\./g, "await oXML.").replace("SignedXMLWithEnvelope", "SignedXMLWithEnvelope()"))
dsignerDoSign = function (ev) {
try {
(async function () {
if (await asyncDsignerDoSign()) {
let b = ev.target
b.onclick = () => true
b.click()
}
})()
} catch (e) {
console.log(e)
}
return false
}
let b = $("input#ctl00_MainContentPlaceHolder_btnDsignerSign")[0]
b.onclick = dsignerDoSign
}
}) + ')()')
console.log("DSigner ActiveX API emulation enabled")