Skip to content

Commit

Permalink
Updated fortify demos to version 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximilianKresse committed Aug 27, 2024
1 parent a7ddc73 commit bcdb830
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,16 @@
ca: true
};

fortifyComp.addEventListener('cancel', function () {
fortifyComp.addEventListener('selectionCancel', function () {
hide('fortifyContainer');
show('signButtonContainer');
});
fortifyComp.addEventListener('continue', async function (event) {
fortifyComp.addEventListener('selectionSuccess', async function (event) {
let signature;
try {
show('loader');
document.getElementById('loader').setAttribute('data-text', 'Signing document');
let provider = await event.detail.server.getCrypto(event.detail.providerId);
let provider = await event.detail.socketProvider.getCrypto(event.detail.providerId);

let cert = await provider.certStorage.getItem(event.detail.certificateId);
let certPem = await provider.certStorage.exportCert('pem', cert);
Expand Down Expand Up @@ -130,7 +131,15 @@
hash: "SHA-256",
};

let signature = await provider.subtle.sign(alg, privateKey, message);
signature = await provider.subtle.sign(alg, privateKey, message);
} catch (error) {
hide('loader');
console.info(error);
alert('An error occured: ' + error);
return;
}

try {
let completeResponseText = await postRequest(
controllerPath + '?action=complete',
JSON.stringify({signature: toHex(signature)})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>SetaPDF-Signer meets Fortify</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css-loader.css">
<link rel="stylesheet" href="https://unpkg.com/@peculiar/fortify-webcomponents@^1.0.0/dist/peculiar/peculiar.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@peculiar/fortify-webcomponents@4/dist/peculiar/peculiar.css">
<style>
* {
box-sizing: border-box;
Expand Down Expand Up @@ -165,7 +165,7 @@ function loadScript(src, module) {
}

try {
loadScript('https://unpkg.com/@peculiar/fortify-webcomponents@^1.0.0/dist/peculiar/peculiar.esm.js', true)
loadScript('https://cdn.jsdelivr.net/npm/@peculiar/fortify-webcomponents@4/dist/peculiar/peculiar.esm.js', true)
.then(function () {return loadScript('https://verify.ink/webcomponent/index.js', true)})
.then(function () {return loadScript('js/main.js')})
.catch(function (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,16 @@
ca: true
};

fortifyComp.addEventListener('cancel', function () {
fortifyComp.addEventListener('selectionCancel', function () {
hide('fortifyContainer');
show('signButtonContainer');
});
fortifyComp.addEventListener('continue', async function (event) {
fortifyComp.addEventListener('selectionSuccess', async function (event) {
let signatures = {};
try {
show('loader');
document.getElementById('loader').setAttribute('data-text', 'Signing document');
let provider = await event.detail.server.getCrypto(event.detail.providerId);
let provider = await event.detail.socketProvider.getCrypto(event.detail.providerId);

let cert = await provider.certStorage.getItem(event.detail.certificateId);
let certPem = await provider.certStorage.exportCert('pem', cert);
Expand Down Expand Up @@ -144,7 +145,6 @@
document.getElementById('tsUrl').innerHTML = 'No timestamp server found.';
}

let signatures = {};
for (const key in startJson.dataToSign) {
if (!startJson.dataToSign.hasOwnProperty(key)) {
continue;
Expand All @@ -159,7 +159,14 @@
let signature = await provider.subtle.sign(alg, privateKey, message);
signatures[key] = toHex(signature);
}
} catch (error) {
hide('loader');
console.info(error);
alert('An error occured: ' + error);
return;
}

try {
let completeResponseText = await postRequest(
controllerPath + '?action=complete',
JSON.stringify({signatures})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>SetaPDF-Signer meets Fortify</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css-loader.css">
<link rel="stylesheet" href="https://unpkg.com/@peculiar/fortify-webcomponents@^1.0.0/dist/peculiar/peculiar.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@peculiar/fortify-webcomponents@4/dist/peculiar/peculiar.css">
<style>
* {
box-sizing: border-box;
Expand Down Expand Up @@ -165,7 +165,7 @@ function loadScript(src, module) {
}

try {
loadScript('https://unpkg.com/@peculiar/fortify-webcomponents@^1.0.0/dist/peculiar/peculiar.esm.js', true)
loadScript('https://cdn.jsdelivr.net/npm/@peculiar/fortify-webcomponents@4/dist/peculiar/peculiar.esm.js', true)
.then(function () {return loadScript('https://verify.ink/webcomponent/index.js', true)})
.then(function () {return loadScript('js/main.js')})
.catch(function (e) {
Expand Down

0 comments on commit bcdb830

Please sign in to comment.