Skip to content
Open
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
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
- name: Build
run: |
export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)
export TOKEN_SIGNING_BACKWARDS_COMPATIBILITY=true
npm run test clean build package

- name: Generate SBOM
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ The Web eID extension for Safari is built as a [Safari web extension](https://de
SOURCE_DATE_EPOCH=$(cat ../previous-build/dist/firefox/SOURCE_DATE_EPOCH) npm run clean build package
```

For backwards compatibility with TokenSigning API, set the `TOKEN_SIGNING_BACKWARDS_COMPATIBILITY` environment variable to `true`.
```bash
TOKEN_SIGNING_BACKWARDS_COMPATIBILITY=true npm run clean build package
```

5. Load in Firefox as a Temporary Extension
1. Open `about:debugging#/runtime/this-firefox`
2. Click "Load temporary Add-on..." and open `/web-eid-webextension/dist/manifest.json`
Expand Down
7 changes: 0 additions & 7 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ import { fileURLToPath } from "url";

import alias from "@rollup/plugin-alias";
import cleanup from "rollup-plugin-cleanup";
import injectProcessEnv from "rollup-plugin-inject-process-env";
import license from "rollup-plugin-license";
import polyfill from "rollup-plugin-polyfill";
import resolve from "@rollup/plugin-node-resolve";

// List of browsers to build for.
const browsers = ["chrome", "firefox", "safari"];

const processEnvConf = {
TOKEN_SIGNING_BACKWARDS_COMPATIBILITY: process.env.TOKEN_SIGNING_BACKWARDS_COMPATIBILITY,
}

const pluginsConf = (environment) => [
alias({
entries: [{
Expand All @@ -37,7 +32,6 @@ const pluginsConf = (environment) => [
}),

...(environment === "chrome" ? [ polyfill(["webextension-polyfill"]) ] : []),
...(environment !== "page-script" ? [ injectProcessEnv(processEnvConf) ] : []),
];

// Use flatMap() to create a configuration for each browser and each of the "content" and "background" scripts.
Expand All @@ -63,7 +57,6 @@ const tokenSigningPageConfig = {
file: `dist/${browser}/token-signing-page-script.js`,
format: "iife",
})),
plugins: pluginsConf("page-script"),
context: "window",
};

Expand Down
4 changes: 0 additions & 4 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ const targets = {
},

async build() {
rem(
"Environment variables affecting the build:",
`TOKEN_SIGNING_BACKWARDS_COMPATIBILITY=${process.env.TOKEN_SIGNING_BACKWARDS_COMPATIBILITY?.toUpperCase() === "TRUE"} (hwcrypto support enabled)`
);
await this.compile();

await this.bundle();
Expand Down
8 changes: 3 additions & 5 deletions src/background/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import sign from "./actions/sign";
import status from "./actions/status";

import Logger from "../shared/Logger";
import { loadConfigFromStorage } from "../shared/configManager";

const configLoaded = loadConfigFromStorage();
import { configInitialized } from "../shared/configManager";

async function onAction(message: ExtensionRequest, sender: MessageSender): Promise<void | object> {
switch (message.action) {
Expand Down Expand Up @@ -102,7 +100,7 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
// Fire-and-forget: DevTools logging must not block message handling, using void to ignore Promise is the standard solution.
void logger.devToolsEvent("request", "Extension (content)", "Extension (background)", message);

void configLoaded
void configInitialized
.then(() => onAction(message, sender))
.then((response) => {
void logger.devToolsEvent("response", "Extension (content)", "Extension (background)", response);
Expand All @@ -117,7 +115,7 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
} else if ((message as TokenSigningMessage).type) {
void logger.devToolsEvent("request", "Extension (content)", "Extension (background)", message);

void configLoaded
void configInitialized
.then(() => onTokenSigningAction(message, sender))
.then((response) => {
void logger.devToolsEvent("response", "Extension (content)", "Extension (background)", response);
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default Object.freeze({
* @see https://github.com/open-eid/chrome-token-signing
* @see https://github.com/hwcrypto/hwcrypto.js/wiki
*/
TOKEN_SIGNING_BACKWARDS_COMPATIBILITY: process.env.TOKEN_SIGNING_BACKWARDS_COMPATIBILITY?.toUpperCase() === "TRUE",
TOKEN_SIGNING_BACKWARDS_COMPATIBILITY: true as boolean,
TOKEN_SIGNING_USER_INTERACTION_TIMEOUT: 1000 * 60 * 5, // 5 minutes

/**
Expand Down
20 changes: 14 additions & 6 deletions src/content/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import Action from "@web-eid.js/models/Action";
import ContextInsecureError from "@web-eid.js/errors/ContextInsecureError";

import { config, configInitialized } from "../shared/configManager";
import { TokenSigningErrorResponse } from "../models/TokenSigning/TokenSigningResponse";
import config from "../config";
import injectPageScript from "./TokenSigning/injectPageScript";
import tokenSigningResponse from "../shared/tokenSigningResponse";

Expand Down Expand Up @@ -56,7 +56,7 @@ async function ack(
window.postMessage(message, origin);
}

window.addEventListener("message", async (event) => {
async function handleMessage(event: MessageEvent): Promise<void> {
if (isWebeidEvent(event)) {
if (isWebeidResponseEvent(event)) return;

Expand Down Expand Up @@ -126,9 +126,17 @@ window.addEventListener("message", async (event) => {
window.postMessage(response, event.origin);
}
}
});
}

async function initializeContentScript(): Promise<void> {
await configInitialized;

window.addEventListener("message", handleMessage);

// --[ chrome-token-signing backwards compatibility ]---------------------------
if (config.TOKEN_SIGNING_BACKWARDS_COMPATIBILITY) {
injectPageScript();
// --[ chrome-token-signing backwards compatibility ]-------------------------
if (config.TOKEN_SIGNING_BACKWARDS_COMPATIBILITY) {
injectPageScript();
}
}

void initializeContentScript();
7 changes: 5 additions & 2 deletions src/shared/configManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import defaultConfig from "../config";
import isBrowserStorageEnabled from "./utils/isBrowserStorageEnabled";

type Config = {
-readonly [key in keyof typeof defaultConfig]: typeof defaultConfig[key];
-readonly [key in keyof typeof defaultConfig]: (typeof defaultConfig)[key];
};

const config = JSON.parse(JSON.stringify(defaultConfig)) as Config;
const configInitialized = loadConfigFromStorage();

const overrideableConfigKeys: Array<keyof typeof defaultConfig> = [
"NATIVE_MESSAGE_MAX_BYTES",
"NATIVE_GRACEFUL_DISCONNECT_TIMEOUT",
"TOKEN_SIGNING_BACKWARDS_COMPATIBILITY",
"TOKEN_SIGNING_USER_INTERACTION_TIMEOUT",
"ALLOW_HTTP_LOCALHOST"
];
Expand Down Expand Up @@ -67,7 +69,8 @@ async function saveToStorageOrRemoveOnNull<K extends keyof typeof defaultConfig>

export {
config,
configInitialized,
defaultConfig,
loadConfigFromStorage,
setConfigOverride,
setConfigOverride
};
4 changes: 2 additions & 2 deletions src/shared/devToolsBridge.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: Estonian Information System Authority
// SPDX-License-Identifier: MIT

import { config, defaultConfig, loadConfigFromStorage, setConfigOverride } from "./configManager";
import { config, configInitialized, defaultConfig, setConfigOverride } from "./configManager";
import { Port } from "../models/Browser/Runtime";

class DevToolsBridge extends EventTarget {
Expand Down Expand Up @@ -39,7 +39,7 @@ class DevToolsBridge extends EventTarget {
this.devToolPorts = this.devToolPorts.filter((connectedPort) => connectedPort !== port);
});

await loadConfigFromStorage();
await configInitialized;
port.postMessage({ devtools: "settings", config, defaultConfig });
}

Expand Down
3 changes: 2 additions & 1 deletion static/views/devtools/panels/webeid-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
const includedSettings = [
"NATIVE_MESSAGE_MAX_BYTES",
"NATIVE_GRACEFUL_DISCONNECT_TIMEOUT",
"TOKEN_SIGNING_BACKWARDS_COMPATIBILITY",
"TOKEN_SIGNING_USER_INTERACTION_TIMEOUT",
"ALLOW_HTTP_LOCALHOST"
"ALLOW_HTTP_LOCALHOST",
];

const ui = {
Expand Down