Skip to content

Commit 3878139

Browse files
taneltmmrts
authored andcommitted
feat: Automatic removal of OpenEID PKCS#11 modules
WE2-664 Signed-off-by: Tanel Metsar <[email protected]>
1 parent a6fc56e commit 3878139

File tree

5 files changed

+51
-23
lines changed

5 files changed

+51
-23
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web-eid-webextension",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "",
55
"main": "src/index.js",
66
"scripts": {

src/background/background.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { ExtensionRequest } from "@web-eid.js/models/message/ExtensionRequest";
2525
import libraryConfig from "@web-eid.js/config";
2626

2727
import { MessageSender } from "../models/Browser/Runtime";
28+
import Pkcs11Service from "./services/Pkcs11Service";
2829
import TokenSigningAction from "./actions/TokenSigning";
2930
import { TokenSigningMessage } from "../models/TokenSigning/TokenSigningMessage";
3031
import authenticate from "./actions/authenticate";
@@ -112,22 +113,5 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
112113
return true;
113114
});
114115

115-
(async function () {
116-
if (typeof browser.pkcs11 === "undefined")
117-
return;
118-
async function unload(modname: string) {
119-
try {
120-
const isInstalled = await browser.pkcs11.isModuleInstalled(modname);
121-
if (!isInstalled) {
122-
console.log("module is not installed: " + modname);
123-
return;
124-
}
125-
await browser.pkcs11.uninstallModule(modname);
126-
console.log("Unloaded module " + modname);
127-
} catch (e) {
128-
console.error("Unable to unload module: ", e);
129-
}
130-
}
131-
unload("onepinopenscpkcs11");
132-
unload("idemiaawppkcs11");
133-
})();
116+
Pkcs11Service.unload("onepinopenscpkcs11");
117+
Pkcs11Service.unload("idemiaawppkcs11");
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2020-2022 Estonian Information System Authority
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
import config from "../../config";
24+
25+
export default class Pkcs11Service {
26+
static async unload(moduleName: string) {
27+
if (!browser.pkcs11) return;
28+
29+
config.DEBUG && console.log(`Pkcs11Service.unload '${moduleName}'`);
30+
31+
try {
32+
if (await browser.pkcs11.isModuleInstalled(moduleName)) {
33+
await browser.pkcs11.uninstallModule(moduleName);
34+
console.log(`Unloaded PKCS #11 module '${moduleName}'`);
35+
} else {
36+
config.DEBUG && console.log(`PKCS #11 module not installed '${moduleName}'`);
37+
}
38+
} catch (error) {
39+
console.error(error);
40+
console.error(`Failed to unload PKCS #11 module '${moduleName}'`);
41+
}
42+
}
43+
}

static/firefox/manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
},
3333
"permissions": [
3434
"*://*/*",
35-
"nativeMessaging"
35+
"nativeMessaging",
36+
"pkcs11"
3637
]
3738
}

0 commit comments

Comments
 (0)