Skip to content
Snippets Groups Projects

Implement pdf signing on the client

Merged Damyan Mitev requested to merge 32-sign-pdf-document-on-the-client-side into master
1 unresolved thread
Files
5
@@ -16,6 +16,9 @@ import {
decryptMessage,
encryptMessage, signEmail
} from '../utilities/signingUtilities';
import {
signPdf
} from '../utilities/pdfUtilities';
import CryptoData from '../CryptoData';
import Identity from '../Identity';
import {STATUS_DEVICE_REVOKED} from '../constants/statuses';
@@ -935,6 +938,64 @@ const connection = Penpal.connectToParent({
return encodeResponse("200", response.data, "Email signed");
},
signPdf: async (passportUUID, pdfRaw /*array buffer*/) => {
//TODO api is not finished
const authenticationPublicKey = localStorage.getItem("authenticatedIdentity");
if (
!authenticationPublicKey ||
!window.loadedIdentities[authenticationPublicKey] ||
!extendPinCodeTtl(authenticationPublicKey)
) {
return encodeResponse("400", "", "Identity not authenticated");
}
let response = await getCertificateForPassport(passportUUID, true);
if (response.code !== "200") {
return encodeResponse("400", "", response.status);
}
const {
x509Certificate: passportCertificate,
privateKey: passportPrivateKey,
chain: passportChain
} = response.data;
const keys =
await createOneTimePassportCertificate(
makeid() + "-" + passportUUID, null, passportPrivateKey, passportCertificate);
const { privateKeyPEM: privateKeyOneTime, certificatePEM: certificateOneTime } = keys;
passportChain.push(passportCertificate);
const signedPdf = await signPdf(pdfRaw, certificateOneTime, passportChain, privateKeyOneTime);
//for test
response.data.signedPdf = signedPdf;
//for test
// response = await executeRestfulFunction(
// "private", window.viamApi, window.viamApi.passportGetEmailWithHeaderByPassport, null, passportUUID, emailMessage);
//
// if (response.code !== "200") {
// return encodeResponse("400", "", response.status);
// }
//
// const signedEmail = await signEmail(response.data, certificateOneTime, passportChain, privateKeyOneTime);
//
// response = await executeRestfulFunction(
// "private", window.viamApi, window.viamApi.signResignEmail, null, passportUUID, signedEmail);
//
// if (response.code !== "200") {
// return encodeResponse("400", "", response.status);
// }
return encodeResponse("200", response.data, "PDF signed");
},
documentCreateDocument: async (path, passportUUID, contenttype) => {
const authenticationPublicKey = localStorage.getItem("authenticatedIdentity");
if (
Loading