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
2 changes: 1 addition & 1 deletion example/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
version: '2'
services:
web-eid-springboot-example:
image: web-eid-springboot-example:3.2.2
image: web-eid-springboot-example:3.2.3
restart: always
environment:
JAVA_TOOL_OPTIONS: '-Dspring.profiles.active=prod'
Expand Down
19 changes: 11 additions & 8 deletions example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@

<properties>
<java.version>17</java.version>
<maven-surefire-plugin.version>3.6.0</maven-surefire-plugin.version>
<webeid.version>3.2.2</webeid.version>
<maven-surefire-plugin.version>3.6.1</maven-surefire-plugin.version>
<webeid.version>3.2.3</webeid.version>
<digidoc4j.version>6.2.0</digidoc4j.version>
<bouncycastle.version>1.86</bouncycastle.version> <!-- The explicit bcutil dependency can be removed once DigiDoc4j supports BC 1.86. -->
<!-- Align shared dependencies with authtoken-validation rather than Spring Boot's older defaults. -->
<jackson-bom.version>2.23.0</jackson-bom.version>
<slf4j.version>2.0.20</slf4j.version>
<bouncycastle.version>1.87</bouncycastle.version> <!-- The explicit bcutil dependency can be removed once DigiDoc4j supports BC 1.87. -->
<jmockit.version>1.44</jmockit.version> <!-- Keep version 1.44, otherwise mocking will fail. -->
<jib.version>3.5.2</jib.version>
<maven-enforcer-plugin.version>3.6.3</maven-enforcer-plugin.version>
<maven-enforcer-plugin.version>3.7.0</maven-enforcer-plugin.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -57,10 +60,10 @@
<version>${webeid.version}</version>
</dependency>
<!--
DigiDoc4j 6.2.0 pins Bouncy Castle 1.84 because using BC 1.86 can make invalid PDF/PAdES signatures appear valid.
This example does not process PDF/PAdES, so we want to use BC 1.86 to include security fixes missing from 1.84;
keep authtoken-validation before digidoc4j and declare bcutil 1.86 directly so all BC modules use 1.86.
The explicit bcutil dependency can be removed once DigiDoc4j supports BC 1.86.
DigiDoc4j 6.2.0 pins Bouncy Castle 1.84 because newer BC versions can make invalid PDF/PAdES signatures appear valid.
This example does not process PDF/PAdES, so we want to use BC 1.87 to include security fixes missing from 1.84;
keep authtoken-validation before digidoc4j and declare bcutil 1.87 directly so all BC modules use 1.87.
The explicit bcutil dependency can be removed once DigiDoc4j supports BC 1.87.
-->
<dependency>
<groupId>org.bouncycastle</groupId>
Expand Down
113 changes: 70 additions & 43 deletions example/src/main/resources/static/js/web-eid.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,17 @@ var ErrorCode;
})(ErrorCode || (ErrorCode = {}));
var ErrorCode$1 = ErrorCode;

class MissingParameterError extends Error {
class DeveloperError extends Error {
constructor(message) {
super(message);
this.name = this.constructor.name;
this.code = ErrorCode$1.ERR_WEBEID_MISSING_PARAMETER;
}
}

class ActionPendingError extends Error {
constructor(message = "same action for Web-eID browser extension is already pending") {
class MissingParameterError extends DeveloperError {
constructor(message) {
super(message);
this.name = this.constructor.name;
this.code = ErrorCode$1.ERR_WEBEID_ACTION_PENDING;
this.code = ErrorCode$1.ERR_WEBEID_MISSING_PARAMETER;
}
}

Expand Down Expand Up @@ -103,14 +101,6 @@ class ExtensionUnavailableError extends Error {
}
}

var config = Object.freeze({
VERSION: "2.0.2",
EXTENSION_HANDSHAKE_TIMEOUT: 1000,
NATIVE_APP_HANDSHAKE_TIMEOUT: 5 * 1000,
DEFAULT_USER_INTERACTION_TIMEOUT: 2 * 60 * 1000,
MAX_EXTENSION_LOAD_DELAY: 1000,
});

class NativeFatalError extends Error {
constructor(message = "native application terminated with a fatal error") {
super(message);
Expand All @@ -119,14 +109,6 @@ class NativeFatalError extends Error {
}
}

class NativeInvalidArgumentError extends Error {
constructor(message = "native application received an invalid argument") {
super(message);
this.name = this.constructor.name;
this.code = ErrorCode$1.ERR_WEBEID_NATIVE_INVALID_ARGUMENT;
}
}

class NativeUnavailableError extends Error {
constructor(message = "Web-eID native application is not available") {
super(message);
Expand Down Expand Up @@ -189,38 +171,78 @@ class VersionMismatchError extends Error {
super(message);
this.name = this.constructor.name;
this.code = ErrorCode$1.ERR_WEBEID_VERSION_MISMATCH;
this.requiresUpdate = requiresUpdate;
this.requiresUpdate = requiresUpdate ?? { nativeApp: false, extension: false };
if (versions) {
const { library, extension, nativeApp } = versions;
Object.assign(this, { library, extension, nativeApp });
}
}
}

class ActionPendingError extends DeveloperError {
constructor(message = "same action for Web-eID browser extension is already pending") {
super(message);
this.name = this.constructor.name;
this.code = ErrorCode$1.ERR_WEBEID_ACTION_PENDING;
}
}

var config = Object.freeze({
VERSION: "2.2.0",
EXTENSION_HANDSHAKE_TIMEOUT: 1000,
NATIVE_APP_HANDSHAKE_TIMEOUT: 5 * 1000,
DEFAULT_USER_INTERACTION_TIMEOUT: 2 * 60 * 1000,
MAX_EXTENSION_LOAD_DELAY: 1000,
});

class NativeInvalidArgumentError extends DeveloperError {
constructor(message = "native application received an invalid argument") {
super(message);
this.name = this.constructor.name;
this.code = ErrorCode$1.ERR_WEBEID_NATIVE_INVALID_ARGUMENT;
}
}

const errorCodeToErrorClass = {
[ErrorCode$1.ERR_WEBEID_ACTION_PENDING]: ActionPendingError,
[ErrorCode$1.ERR_WEBEID_ACTION_TIMEOUT]: ActionTimeoutError,
[ErrorCode$1.ERR_WEBEID_CONTEXT_INSECURE]: ContextInsecureError,
[ErrorCode$1.ERR_WEBEID_EXTENSION_UNAVAILABLE]: ExtensionUnavailableError,
[ErrorCode$1.ERR_WEBEID_MISSING_PARAMETER]: MissingParameterError,
[ErrorCode$1.ERR_WEBEID_NATIVE_INVALID_ARGUMENT]: NativeInvalidArgumentError,
[ErrorCode$1.ERR_WEBEID_NATIVE_FATAL]: NativeFatalError,
[ErrorCode$1.ERR_WEBEID_NATIVE_UNAVAILABLE]: NativeUnavailableError,
[ErrorCode$1.ERR_WEBEID_USER_CANCELLED]: UserCancelledError,
[ErrorCode$1.ERR_WEBEID_USER_TIMEOUT]: UserTimeoutError,
[ErrorCode$1.ERR_WEBEID_VERSION_INVALID]: VersionInvalidError,
[ErrorCode$1.ERR_WEBEID_VERSION_MISMATCH]: VersionMismatchError,
[ErrorCode$1.ERR_WEBEID_UNKNOWN_ERROR]: UnknownError,
};
function isSerializedError(obj) {
if (typeof obj !== "object" || obj === null) {
return false;
}
const errorObject = obj;
return (typeof errorObject.code === "string" &&
typeof errorObject.message === "string" &&
errorCodeToErrorClass[errorObject.code] != null);
}
function deserializeError(errorObject) {
let error;
if (typeof errorObject.code == "string" && errorObject.code in errorCodeToErrorClass) {
if (isSerializedError(errorObject)) {
const CustomError = errorCodeToErrorClass[errorObject.code];
error = new CustomError();
Object.entries(errorObject).forEach(([key, value]) => {
Reflect.set(error, key, value);
});
}
else {
error = new UnknownError();
}
for (const [key, value] of Object.entries(errorObject)) {
error[key] = value;
const unknownObject = errorObject;
if (unknownObject?.stack)
error.stack = unknownObject.stack;
if (unknownObject?.message)
error.message = unknownObject.message;
}
return error;
}
Expand All @@ -232,15 +254,20 @@ class WebExtensionService {
window.addEventListener("message", (event) => this.receive(event));
}
receive(event) {
var _a, _b, _c, _d, _e, _f;
if (!/^web-eid:/.test((_a = event.data) === null || _a === void 0 ? void 0 : _a.action))
if (event.source !== window)
return;
if (event.origin !== window.location.origin)
return;
const message = event.data;
const suffix = (_c = (_b = message.action) === null || _b === void 0 ? void 0 : _b.match(/success$|failure$|ack$/)) === null || _c === void 0 ? void 0 : _c[0];
if (typeof message?.action !== "string")
return;
if (!message.action.startsWith("web-eid:"))
return;
const suffix = ["success", "failure", "ack"].find((s) => message.action.endsWith(s));
const initialAction = this.getInitialAction(message.action);
const pending = this.getPendingMessage(initialAction);
if (message.action === Action$1.WARNING) {
(_d = message.warnings) === null || _d === void 0 ? void 0 : _d.forEach((warning) => {
message.warnings?.forEach((warning) => {
if (!this.loggedWarnings.includes(warning)) {
this.loggedWarnings.push(warning);
console.warn(warning.replace(/\n|\r/g, ""));
Expand All @@ -255,13 +282,13 @@ class WebExtensionService {
}
case "success": {
this.removeFromQueue(initialAction);
(_e = pending.resolve) === null || _e === void 0 ? void 0 : _e.call(pending, message);
pending.resolve?.(message);
break;
}
case "failure": {
const failureMessage = message;
this.removeFromQueue(initialAction);
(_f = pending.reject) === null || _f === void 0 ? void 0 : _f.call(pending, failureMessage.error ? deserializeError(failureMessage.error) : failureMessage);
pending.reject?.(deserializeError(failureMessage.error));
break;
}
}
Expand All @@ -288,15 +315,13 @@ class WebExtensionService {
}
}
onReplyTimeout(pending) {
var _a;
this.removeFromQueue(pending.message.action);
(_a = pending.reject) === null || _a === void 0 ? void 0 : _a.call(pending, new ActionTimeoutError());
pending.reject?.(new ActionTimeoutError());
}
onAckTimeout(pending) {
var _a;
clearTimeout(pending.replyTimer);
this.removeFromQueue(pending.message.action);
(_a = pending.reject) === null || _a === void 0 ? void 0 : _a.call(pending, new ExtensionUnavailableError());
pending.reject?.(new ExtensionUnavailableError());
}
getPendingMessage(action) {
return this.queue.find((pm) => {
Expand All @@ -308,7 +333,7 @@ class WebExtensionService {
}
removeFromQueue(action) {
const pending = this.getPendingMessage(action);
clearTimeout(pending === null || pending === void 0 ? void 0 : pending.replyTimer);
clearTimeout(pending?.replyTimer);
this.queue = this.queue.filter((pending) => (pending.message.action !== action));
}
}
Expand Down Expand Up @@ -348,7 +373,9 @@ async function status() {
};
}
catch (error) {
error.library = config.VERSION;
if (error instanceof Error) {
Reflect.set(error, "library", config.VERSION);
}
throw error;
}
}
Expand All @@ -359,7 +386,7 @@ async function authenticate(challengeNonce, options) {
}
const timeout = (config.EXTENSION_HANDSHAKE_TIMEOUT +
config.NATIVE_APP_HANDSHAKE_TIMEOUT +
((options === null || options === void 0 ? void 0 : options.userInteractionTimeout) || config.DEFAULT_USER_INTERACTION_TIMEOUT));
(options?.userInteractionTimeout ?? config.DEFAULT_USER_INTERACTION_TIMEOUT));
const message = {
action: Action$1.AUTHENTICATE,
libraryVersion: config.VERSION,
Expand All @@ -379,7 +406,7 @@ async function getSigningCertificate(options) {
await extensionLoadDelay();
const timeout = (config.EXTENSION_HANDSHAKE_TIMEOUT +
config.NATIVE_APP_HANDSHAKE_TIMEOUT +
((options === null || options === void 0 ? void 0 : options.userInteractionTimeout) || config.DEFAULT_USER_INTERACTION_TIMEOUT) * 2);
(options?.userInteractionTimeout ?? config.DEFAULT_USER_INTERACTION_TIMEOUT) * 2);
const message = {
action: Action$1.GET_SIGNING_CERTIFICATE,
libraryVersion: config.VERSION,
Expand All @@ -404,7 +431,7 @@ async function sign(certificate, hash, hashFunction, options) {
}
const timeout = (config.EXTENSION_HANDSHAKE_TIMEOUT +
config.NATIVE_APP_HANDSHAKE_TIMEOUT +
((options === null || options === void 0 ? void 0 : options.userInteractionTimeout) || config.DEFAULT_USER_INTERACTION_TIMEOUT) * 2);
(options?.userInteractionTimeout ?? config.DEFAULT_USER_INTERACTION_TIMEOUT) * 2);
const message = {
action: Action$1.SIGN,
libraryVersion: config.VERSION,
Expand All @@ -420,4 +447,4 @@ async function sign(certificate, hash, hashFunction, options) {
};
}

export { Action$1 as Action, ErrorCode$1 as ErrorCode, authenticate, config, getSigningCertificate, sign, status };
export { Action$1 as Action, ActionTimeoutError, ContextInsecureError, DeveloperError, ErrorCode$1 as ErrorCode, ExtensionUnavailableError, NativeFatalError, NativeUnavailableError, UnknownError, UserCancelledError, UserTimeoutError, VersionInvalidError, VersionMismatchError, authenticate, config, getSigningCertificate, sign, status };
18 changes: 9 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>authtoken-validation</artifactId>
<groupId>eu.webeid.security</groupId>
<version>3.2.2</version>
<version>3.2.3</version>
<packaging>jar</packaging>
<name>authtoken-validation</name>
<description>Web eID authentication token validation library for Java</description>

<properties>
<java.version>11</java.version>
<jjwt.version>0.13.0</jjwt.version>
<bouncycastle.version>1.86</bouncycastle.version>
<jackson.version>2.22.3</jackson.version>
<slf4j.version>2.0.19</slf4j.version>
<junit-jupiter.version>5.14.4</junit-jupiter.version>
<bouncycastle.version>1.87</bouncycastle.version>
<jackson.version>2.23.0</jackson.version>
<slf4j.version>2.0.20</slf4j.version>
<junit-jupiter.version>5.14.5</junit-jupiter.version>
<assertj.version>3.27.7</assertj.version>
<mockito.version>5.23.0</mockito.version>
<maven-surefire-plugin.version>3.6.0</maven-surefire-plugin.version>
<mockito.version>5.25.0</mockito.version>
<maven-surefire-plugin.version>3.6.1</maven-surefire-plugin.version>
<maven-source-plugin.version>3.4.0</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.12.0</maven-javadoc-plugin.version>
<maven-enforcer-plugin.version>3.6.3</maven-enforcer-plugin.version>
<jacoco.version>0.8.15</jacoco.version>
<maven-enforcer-plugin.version>3.7.0</maven-enforcer-plugin.version>
<jacoco.version>0.8.16</jacoco.version>
<sonar.coverage.jacoco.xmlReportPaths>
${project.basedir}/../jacoco-coverage-report/target/site/jacoco-aggregate/jacoco.xml
</sonar.coverage.jacoco.xmlReportPaths>
Expand Down
Loading