diff --git a/Gopkg.toml b/Gopkg.toml index 349b503370d11addf17bca0a46703d4e5aa98825..6449b9c5ae9617c36a2e298d392eb6367e2d4ba3 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -25,7 +25,7 @@ # unused-packages = true [[constraint]] - branch = "master" + branch = "SSJ-1-signing-service-java-initial" name = "code.vereign.com/code/restful-api" [prune] diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js index 428d5ea7b0312c7ef7c918c3e3908e6cfebf01d3..608ef567839bb3190f534dad6a08bfcac5e7df93 100644 --- a/javascript/src/iframe/viamapi-iframe.js +++ b/javascript/src/iframe/viamapi-iframe.js @@ -1271,6 +1271,80 @@ const connection = Penpal.connectToParent({ return encodeResponse("200", "", "Document signed"); }, + signDocumentJava: async (passportUUID, documentUUID, documentContentType) => { + const authenticationPublicKey = localStorage.getItem( + "authenticatedIdentity" + ); + + if ( + !authenticationPublicKey || + !window.loadedIdentities[authenticationPublicKey] || + !extendPinCodeTtl(authenticationPublicKey) + ) { + return encodeResponse("400", "", "Identity not authenticated"); + } + + const certResponse = await getCertificateForPassport(passportUUID, true); + + if (certResponse.code !== "200") { + return encodeResponse("400", "", certResponse.status); + } + + const { + x509Certificate: passportCertificate, + privateKey: passportPrivateKey, + chain: passportChain + } = certResponse.data; + + const keys = await createOneTimePassportCertificate( + makeid() + "-" + passportUUID, + null, + passportPrivateKey, + passportCertificate + ); + + const { + privateKeyPEM: privateKeyOneTime, + certificatePEM: certificateOneTime + } = keys; + + passportChain.push(passportCertificate); + passportChain.push(certificateOneTime); + + const pdfContentType = "application/pdf"; + + if (documentContentType !== pdfContentType) { + const convResponse = await executeRestfulFunction( + "private", + window.viamApi, + window.viamApi.documentConvertDocumentByUUID, + null, + documentUUID, + documentContentType, + pdfContentType + ); + if (convResponse.code !== "200") { + return encodeResponse("400", "", convResponse.status); + } + } + + const signResponse = await executeRestfulFunction( + "private", + window.viamApi, + window.viamApi.documentSignDocumentJavaService, + null, + privateKeyOneTime, + passportChain, + passportUUID, + documentUUID, + pdfContentType + ); + if (signResponse.code !== "200") { + return encodeResponse("400", "", signResponse.status); + } + + return encodeResponse("200", "", "Document signed"); + }, documentCreateDocument: async (passportUUID, path, contentType, title) => { const authenticationPublicKey = localStorage.getItem( "authenticatedIdentity"