Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
Vereign Client Library
Manage
Activity
Members
Labels
Plan
Issues
24
Issue boards
Milestones
Wiki
Code
Merge requests
5
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Code
Vereign Client Library
Commits
c86529e3
Commit
c86529e3
authored
5 years ago
by
Damyan Mitev
Browse files
Options
Downloads
Patches
Plain Diff
Add more try/catch and logs
parent
c5763160
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!48
269 implement workflow for signing already uploaded document dev
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
javascript/src/utilities/pdfUtilities.js
+25
-9
25 additions, 9 deletions
javascript/src/utilities/pdfUtilities.js
with
25 additions
and
9 deletions
javascript/src/utilities/pdfUtilities.js
+
25
−
9
View file @
c86529e3
...
...
@@ -634,6 +634,7 @@ function loadPdf(pdfArray) {
//data must be Uint8Array
async
function
sign_pki
(
signingCert
,
certificateChain
,
privateKey
,
data
,
date
)
{
console
.
log
(
"
Calling sign_pki
"
);
const
crypto
=
getCrypto
();
...
...
@@ -719,6 +720,8 @@ async function sign_pki(signingCert, certificateChain, privateKey, data, date) {
async
function
signPdfObjects
(
pdfRaw
,
signingCert
,
certificateChain
,
privateKey
,
date
)
{
console
.
log
(
"
Calling signPdfObjects
"
);
date
=
((
typeof
date
!==
'
undefined
'
)
&&
(
date
!==
null
))
?
date
:
new
Date
();
if
(
pdfRaw
instanceof
Buffer
)
{
...
...
@@ -727,26 +730,39 @@ async function signPdfObjects (pdfRaw, signingCert, certificateChain, privateKey
if
(
pdfRaw
instanceof
ArrayBuffer
)
{
pdfRaw
=
new
Uint8Array
(
pdfRaw
);
}
console
.
log
(
"
Calling loadPdf
"
);
var
pdf
=
loadPdf
(
pdfRaw
);
var
root
=
findRootEntry
(
pdf
.
xref
);
var
rootSuccessor
=
findSuccessorEntry
(
pdf
.
xref
.
entries
,
root
);
if
(
!
isSigInRoot
(
pdf
))
{
console
.
log
(
"
Calling newSig
"
);
return
await
newSig
(
pdf
,
root
,
rootSuccessor
,
date
,
signingCert
,
certificateChain
,
privateKey
);
}
else
{
console
.
log
(
"
Calling appendSig
"
);
return
await
appendSig
(
pdf
,
root
,
rootSuccessor
,
date
,
signingCert
,
certificateChain
,
privateKey
);
}
}
export
function
signPdf
(
pdfRaw
,
signingCert
,
certificateChain
,
privateKey
)
{
const
signingCertObj
=
parseCertificate
(
signingCert
);
const
certificateChainObj
=
[];
certificateChainObj
[
0
]
=
parseCertificate
(
signingCert
);
for
(
let
i
=
0
;
i
<
certificateChain
.
length
;
i
++
)
{
certificateChainObj
[
i
+
1
]
=
parseCertificate
(
certificateChain
[
i
])
export
async
function
signPdf
(
pdfRaw
,
signingCert
,
certificateChain
,
privateKey
)
{
console
.
log
(
"
Calling signPdf
"
);
const
signingCertObj
=
parseCertificate
(
signingCert
);
const
certificateChainObj
=
[];
certificateChainObj
[
0
]
=
parseCertificate
(
signingCert
);
for
(
let
i
=
0
;
i
<
certificateChain
.
length
;
i
++
)
{
certificateChainObj
[
i
+
1
]
=
parseCertificate
(
certificateChain
[
i
])
}
let
privateKeyDecoded
;
try
{
console
.
log
(
"
Calling parsePrivateKey
"
);
privateKeyDecoded
=
await
parsePrivateKey
(
privateKey
);
}
catch
(
e
)
{
console
.
log
(
"
Error decoding private key:
"
,
e
);
throw
new
Error
(
'
Error decoding private key:
'
+
e
);
}
return
parsePrivateKey
(
privateKey
).
then
(
privateKeyDecoded
=>
{
return
signPdfObjects
(
pdfRaw
,
signingCertObj
,
certificateChainObj
,
privateKeyDecoded
);
});
return
await
signPdfObjects
(
pdfRaw
,
signingCertObj
,
certificateChainObj
,
privateKeyDecoded
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment