Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Consent screen only on Firefox extension #53

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web-eid-webextension",
"version": "2.2.1",
"version": "2.2.2",
"description": "",
"main": "src/index.js",
"scripts": {
Expand Down
34 changes: 34 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,40 @@ const libraryAlias = alias({
});

export default [
...["content", "background"].map((name) => ({
input: `./dist/chrome/${name}/${name}.js`,

output: [
{
file: `dist/chrome/${name}.js`,
format: "iife",
sourcemap: name === "background",
},
],

plugins: [
libraryAlias,
resolve({ rootDir: "./dist" }),
polyfill(["webextension-polyfill"]),
cleanup({ comments: ["jsdoc"] }), // Keep jsdoc comments
injectProcessEnv({
DEBUG: process.env.DEBUG,
TOKEN_SIGNING_BACKWARDS_COMPATIBILITY: process.env.TOKEN_SIGNING_BACKWARDS_COMPATIBILITY,
}),
license({
banner: {
content: {
// eslint-disable-next-line no-undef
file: path.join(__dirname, "LICENSE"),
encoding: "utf-8",
},
},
}),
],

context: "window",
})),

...["content", "background"].map((name) => ({
input: `./dist/firefox/${name}/${name}.js`,

Expand Down
30 changes: 20 additions & 10 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,32 @@ const targets = {

await replace("./dist/src/config.js", "{{package.version}}", pkg.version);

rem(
"Preparing the Chrome dist directory for:",
"- Google Chrome",
"- Chromium",
"- Microsoft Edge",
"- Opera",
);
await cp("./dist/src", "./dist/chrome");
await rm("./dist/chrome/background-safari");
await rm("./dist/chrome/background-firefox");

rem(
"Preparing the Firefox dist directory"
);
await cp("./dist/src", "./dist/firefox");
await cp("./dist/firefox/background-firefox", "./dist/firefox/background");
await rm("./dist/firefox/background-safari");
await rm("./dist/firefox/background-firefox");

rem(
"Preparing the Safari dist directory"
);
await cp("./dist/src", "./dist/safari");
await cp("./dist/safari/background-safari", "./dist/safari/background");
await rm("./dist/safari/background-safari");
await rm("./dist/safari/background-firefox");

await this.bundle();

Expand All @@ -66,6 +81,8 @@ const targets = {
);
await rm("./dist/lib");
await rm("./dist/src");
await rm("./dist/chrome/*/");
await rm("./dist/chrome/config.*");
await rm("./dist/firefox/*/");
await rm("./dist/firefox/config.*");
await rm("./dist/safari/*/");
Expand All @@ -75,30 +92,23 @@ const targets = {
"Setting up SOURCE_DATE_EPOCH for reproducible builds"
);
sourceDateEpoch = await getSourceDateEpoch();
await write("./dist/chrome/SOURCE_DATE_EPOCH", sourceDateEpoch.epoch);
await write("./dist/firefox/SOURCE_DATE_EPOCH", sourceDateEpoch.epoch);

rem(
"Copying icons"
);
await cp("./static/icons", "./dist/chrome/icons");
await cp("./static/icons", "./dist/firefox/icons");
await cp("./static/icons", "./dist/safari");

rem(
"Copying static pages"
"Copying Firefox static pages"
);
await cp("./static/_locales", "./dist/firefox/_locales");
await cp("./static/views", "./dist/firefox/views");
await cp("./node_modules/bootstrap/dist/css/bootstrap.min.css", "./dist/firefox/views/bootstrap.min.css");

rem(
"Preparing the Chrome dist directory for:",
"- Google Chrome",
"- Chromium",
"- Microsoft Edge",
"- Opera",
);
await cp("./dist/firefox", "./dist/chrome");

rem(
"Setting up the Firefox manifest"
);
Expand Down
125 changes: 125 additions & 0 deletions src/background-firefox/background.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Copyright (c) 2020-2023 Estonian Information System Authority
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

import Action from "@web-eid.js/models/Action";
import { ExtensionRequest } from "@web-eid.js/models/message/ExtensionRequest";
import libraryConfig from "@web-eid.js/config";

import { MessageSender } from "../models/Browser/Runtime";
import TokenSigningAction from "../background/actions/TokenSigning";
import { TokenSigningMessage } from "../models/TokenSigning/TokenSigningMessage";
import authenticate from "../background/actions/authenticate";
import getSigningCertificate from "../background/actions/getSigningCertificate";
import sign from "../background/actions/sign";
import status from "../background/actions/status";

async function showConsent() {
const url = browser.runtime.getURL("views/installed.html");
return await browser.tabs.create({ url, active: true });
}

async function onAction(message: ExtensionRequest, sender: MessageSender): Promise<void | object> {
switch (message.action) {
case Action.AUTHENTICATE:
return await authenticate(
message.challengeNonce,

sender,
message.libraryVersion,
message.options?.userInteractionTimeout || libraryConfig.DEFAULT_USER_INTERACTION_TIMEOUT,
message.options?.lang
);

case Action.GET_SIGNING_CERTIFICATE:
return await getSigningCertificate(
sender,
message.libraryVersion,
message.options?.userInteractionTimeout || libraryConfig.DEFAULT_USER_INTERACTION_TIMEOUT,
message.options?.lang
);

case Action.SIGN:
return await sign(
message.certificate,
message.hash,
message.hashFunction,

sender,
message.libraryVersion,
message.options?.userInteractionTimeout || libraryConfig.DEFAULT_USER_INTERACTION_TIMEOUT,
message.options?.lang
);

case Action.STATUS:
return await status(
message.libraryVersion,
);
}
}

async function onTokenSigningAction(message: TokenSigningMessage, sender: MessageSender): Promise<void | object> {
if (!sender.url) return;

switch (message.type) {
case "VERSION": {
return await TokenSigningAction.status(
message.nonce,
);
}

case "CERT": {
return await TokenSigningAction.getCertificate(
message.nonce,
sender.url,
message.lang,
message.filter,
);
}

case "SIGN": {
return await TokenSigningAction.sign(
message.nonce,
sender.url,
message.cert,
message.hash,
message.hashtype,
message.lang,
);
}
}
}

browser.runtime.onInstalled.addListener(async ({ reason, temporary }) => {
if (temporary) return;
if (reason == "install") {
await showConsent();
}
});

browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
if ((message as ExtensionRequest).action) {
onAction(message, sender).then(sendResponse);
} else if ((message as TokenSigningMessage).type) {
onTokenSigningAction(message, sender).then(sendResponse);
}
return true;
});
12 changes: 0 additions & 12 deletions src/background/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ import getSigningCertificate from "./actions/getSigningCertificate";
import sign from "./actions/sign";
import status from "./actions/status";

async function showConsent() {
const url = browser.runtime.getURL("views/installed.html");
return await browser.tabs.create({ url, active: true });
}

async function onAction(message: ExtensionRequest, sender: MessageSender): Promise<void | object> {
switch (message.action) {
case Action.AUTHENTICATE:
Expand Down Expand Up @@ -108,13 +103,6 @@ async function onTokenSigningAction(message: TokenSigningMessage, sender: Messag
}
}

browser.runtime.onInstalled.addListener(async ({ reason, temporary }) => {
if (temporary) return;
if (reason == "install") {
await showConsent();
}
});

browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
if ((message as ExtensionRequest).action) {
onAction(message, sender).then(sendResponse);
Expand Down