@ -68,18 +68,21 @@ function analyzeSignedPDF() {
var pdfhash = calculateSHA256HashOfString ( pdfdata ) ;
verifyMessage ( sigdata , function ( msg , fprint ) {
parseAndDisplaySignature ( msg , pdfhash , true , fprint ) ;
} , function ( err ) {
var base64 = sigdata . split ( "\n\n" , 2 ) [ 1 ] . split ( "\n-----END PGP MESSAGE-----" ) [ 0 ] ;
base64 = base64 . substring ( 0 , base64 . lastIndexOf ( "\n" ) ) . replaceAll ( "\n" , "" ) ;
try {
var msg = atob ( base64 ) . split ( "START" , 2 ) [ 1 ] . split ( "END" , 2 ) [ 0 ] ;
parseAndDisplaySignature ( msg , pdfhash , false , null ) ;
} catch ( ex ) {
console . error ( ex ) ;
alert ( "Error: could not parse signature data." ) ;
}
loadKeyFromLocalStorage ( function ( ) {
verifyMessage ( sigdata , function ( msg , fprint ) {
parseAndDisplaySignature ( msg , pdfhash , true , fprint ) ;
} , function ( err ) {
console . error ( err ) ;
var base64 = sigdata . split ( "\n\n" , 2 ) [ 1 ] . split ( "\n-----END PGP MESSAGE-----" ) [ 0 ] ;
base64 = base64 . substring ( 0 , base64 . lastIndexOf ( "\n" ) ) . replaceAll ( "\n" , "" ) ;
try {
var msg = window . atob ( base64 ) . split ( "START" , 2 ) [ 1 ] . split ( "END" , 2 ) [ 0 ] ;
parseAndDisplaySignature ( msg , pdfhash , false , null ) ;
} catch ( ex ) {
console . error ( ex ) ;
alert ( "Error: could not parse signature data." ) ;
}
} ) ;
} ) ;
pdfjsLib . getDocument ( pdf ) . promise . then ( function ( pdfDoc _ ) {
@ -112,7 +115,7 @@ function parseAndDisplaySignature(msg, pdfhash, verified, fingerprint) {
$ ( "#verifyModalStatusMessage" ) . html ( "<i class=\"fas fa-question-circle\" > < / i > F i l e c o n t e n t s m a t c h s i g n a t u r e ; h o w e v e r , \
could not verify signature authenticity . It ' s possible the file was changed then re - signed by an unknown person . If you have the \
public key file for the notary that signed the file , < span class = \ "btn btn-outline-secondary btn-sm\"onclick=\"openPublicKeyFile()\" > click here < / s p a n > t o u s e i t , \
then try run ning the analyze tool agai n. " ) ;
then run the analyze tool agai n to prove if it was changed since notarizatio n. " ) ;
$ ( "#verifyModalStatusMessage" ) . removeClass ( ) ;
$ ( "#verifyModalStatusMessage" ) . addClass ( [ "alert" , "alert-warning" ] ) ;
}
@ -138,6 +141,33 @@ then try running the analyze tool again.");
if ( typeof msgparts [ "STATE" ] == "string" ) {
$ ( "#verifyModalDetailedInfoList" ) . append ( '<li class="list-group-item"><i class="fas fa-map-marked-alt fa-fw"></i> State: ' + sanitizeHTMLString ( msgparts [ "STATE" ] ) . toUpperCase ( ) + '</li>' ) ;
}
if ( typeof msgparts [ "OTS" ] == "string" ) {
var bytearray = [ ] ;
var bytestrarray = msgparts [ "OTS" ] . match ( /.{1,3}/g ) ;
for ( var i = 0 ; i < bytestrarray . length ; i ++ ) {
bytearray . push ( bytestrarray [ i ] * 1 ) ;
}
const detached = OpenTimestamps . DetachedTimestampFile . fromHash ( new OpenTimestamps . Ops . OpSHA256 ( ) , Uint8Array . from ( Buffer . from ( pdfhash , 'hex' ) ) ) ;
const detachedOts = OpenTimestamps . DetachedTimestampFile . deserialize ( bytearray ) ;
let options = { } ;
OpenTimestamps . verify ( detachedOts , detached , options ) . then ( verifyResult => {
console . log ( verifyResult ) ;
if ( typeof verifyResult != "undefined" ) {
if ( typeof verifyResult . bitcoin != undefined ) {
$ ( "#verifyModalDetailedInfoList" ) . append ( '<li class="list-group-item"><i class="fas fa-clock fa-fw"></i> Signing time independently verified on the Bitcoin blockchain. Signed at ' + formatTimestamp ( "F j, Y g:i a" , verifyResult . bitcoin . timestamp ) + '</li>' ) ;
}
if ( typeof verifyResult . litecoin != undefined ) {
$ ( "#verifyModalDetailedInfoList" ) . append ( '<li class="list-group-item"><i class="fas fa-clock fa-fw"></i> Signing time independently verified on the Litecoin blockchain. Signed at ' + formatTimestamp ( "F j, Y g:i a" , verifyResult . bitcoin . timestamp ) + '</li>' ) ;
}
}
} ) ;
}
$ ( "#verifyModalDetailedInfoList" ) . append ( '<li class="list-group-item"><i class="far fa-file fa-fw"></i> Actual file hash: ' + pdfhash + '</li>' ) ;
if ( typeof msgparts [ "HASH" ] == "string" ) {
$ ( "#verifyModalDetailedInfoList" ) . append ( '<li class="list-group-item"><i class="far fa-file fa-fw"></i> Signed file hash: ' + sanitizeHTMLString ( msgparts [ "HASH" ] ) + '</li>' ) ;
}
if ( typeof fingerprint == "string" ) {
$ ( "#verifyModalDetailedInfoList" ) . append ( '<li class="list-group-item"><i class="fas fa-fingerprint fa-fw"></i> Signature fingerprint: ' + fingerprint + '</li>' ) ;
@ -190,23 +220,42 @@ function getPDFAsByteArray(pdf) {
function makeAndSaveSignedPDF ( pdf , savepath , callback ) {
var pdfbuffer = pdf . output ( "arraybuffer" ) ;
var hashstr = calculateSHA256HashOfBuffer ( pdfbuffer ) ;
var message = "START"
+ "\nHASH:" + hashstr
+ "\nDATE:" + time ( )
+ "\nNOTARY:" + getStorage ( "notary_name" )
+ "\nSTATE:" + getStorage ( "notary_state" )
+ "\nEND\n" ;
signMessage ( message , keymgr , function ( sig ) {
writeToFile ( savepath , Buffer . from ( pdfbuffer ) ) ;
appendToFile ( savepath , sig ) ;
//writeToFile(savepath + ".notsigned.pdf", Buffer.from(pdfbuffer));
writeToFile ( savepath + ".sig" , sig ) ;
callback ( {
signature : sig ,
hash : hashstr
const hashstr = calculateSHA256HashOfBuffer ( pdfbuffer ) ;
var detached = OpenTimestamps . DetachedTimestampFile . fromHash ( new OpenTimestamps . Ops . OpSHA256 ( ) , Uint8Array . from ( Buffer . from ( hashstr , 'hex' ) ) ) ;
var otsbytes = "" ;
var sign = function ( ) {
var message = "START"
+ "\nHASH:" + hashstr
+ "\nDATE:" + time ( )
+ ( otsbytes != "" ? "\nOTS:" + otsbytes : "" )
+ "\nNOTARY:" + getStorage ( "notary_name" )
+ "\nSTATE:" + getStorage ( "notary_state" )
+ "\nEND\n" ;
signMessage ( message , keymgr , function ( sig ) {
writeToFile ( savepath , Buffer . from ( pdfbuffer ) ) ;
appendToFile ( savepath , sig ) ;
//writeToFile(savepath + ".notsigned.pdf", Buffer.from(pdfbuffer));
writeToFile ( savepath + ".sig" , sig ) ;
callback ( {
signature : sig ,
hash : hashstr
} ) ;
} ) ;
} ;
OpenTimestamps . stamp ( detached ) . then ( ( ) => {
var bytearray = detached . serializeToBytes ( ) ;
var bytestr = "" ;
for ( var i = 0 ; i < bytearray . length ; i ++ ) {
bytestr += ( bytearray [ i ] + "" ) . padStart ( 3 , "0" ) ;
}
otsbytes = bytestr ;
sign ( ) ;
} ) . catch ( ( ) => {
sign ( ) ;
} ) ;
}