Skip to content
This repository was archived by the owner on Mar 19, 2025. It is now read-only.

Commit baf7204

Browse files
taneltmmetsma
authored andcommitted
Enhanced token-signing extension check
1 parent a7bff8d commit baf7204

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/hwcrypto.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ var hwcrypto = (function hwcrypto() {
5858
// Important constants
5959
var digidoc_mime = 'application/x-digidoc';
6060
var digidoc_chrome = 'TokenSigning';
61+
var EXTENSION_CHECK_TIMEOUT = 1000;
6162
// Some error strings
6263
var USER_CANCEL = "user_cancel";
6364
var NO_CERTIFICATES = "no_certificates";
@@ -187,8 +188,21 @@ var hwcrypto = (function hwcrypto() {
187188
}
188189
// FIXME: remove this from content script!
189190
p = new window[digidoc_chrome]();
191+
190192
if (p) {
191-
resolve(true);
193+
// The global TokenSigning function can be defined either by
194+
// the extension or, to workaround a CSP issue, by the website.
195+
// Requesting the extension version to make sure the extension is installed.
196+
var versionCheckTimeout = new Promise(function (resolve, reject) {
197+
setTimeout(reject, EXTENSION_CHECK_TIMEOUT);
198+
});
199+
200+
resolve(
201+
Promise
202+
.race([ p.getVersion(), versionCheckTimeout ])
203+
.then(function () { return true; })
204+
.catch(function () { return false; })
205+
);
192206
} else {
193207
resolve(false);
194208
}

0 commit comments

Comments
 (0)