-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Implement TimeStamping feature #617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hidasw
wants to merge
44
commits into
tecnickcom:main
Choose a base branch
from
hidasw:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
28c747b
Update tcpdf.php
hidasw ff9e5a8
Create asn1_function_tcpdf.php
hidasw ff20f9f
Create asn1_parser_tcpdf.php
hidasw e998624
Create functionLog_tcpdf.php
hidasw ffce574
Create Local Root CA.crt
hidasw 15bf870
Create tcpdf test.pem
hidasw a295943
Create index.php
hidasw abfaeda
Update tcpdf.php
hidasw 01fb957
Update index.php
hidasw 1656d3c
reformatting and cleanup
hidasw 80f70d3
Update tcpdf_asn1.min.php
hidasw 3ab497a
Update tcpdf.php
hidasw c8e4c7b
major update
hidasw c16b58c
Update tcpdf.php
hidasw f1de348
Update include/tcpdf_cmssignature.php
hidasw 1499b2b
Remove type on properties.
evamtinez df74f95
Curl close was moved after curl_getinfo.
evamtinez 4a384cb
Fix indentation
evamtinez fe6c482
Merge pull request #2 from evamtinez/main
hidasw 3a741b6
Add TSA parameter
hidasw fe247a1
update to support LTV and TSA at once
hidasw 050eec1
Merge branch 'main' into main
hidasw 92f3539
significant improvement on signing process
hidasw 3ecc5ab
Merge branch 'main' of https://github.com/hidasw/TCPDF
hidasw 959052d
combines several functions
hidasw 9950510
Update example_052.php
hidasw e1297c2
Update tcpdf.php
hidasw a7b5ebc
Update tcpdf_cmssignature.php
hidasw 46ecd34
Update example_052.php
hidasw 6ab1ed7
Delete RootCATest.pem.crl
hidasw f166179
Delete RootCATest.der.crl
hidasw f7dc852
Delete Root CA Test.crt
hidasw 7a766b6
Delete Root CA Test OCSP Signer.pem
hidasw 2543e57
Delete PDF User.pem
hidasw 0913f4f
Create PDF Signing CA.crt
hidasw 58228d7
Create ocspTest.bat
hidasw 5ea1de8
Create longChain.pfx
hidasw d2f6c24
Create longChain.pem
hidasw ca7a5e3
Create long.pfx
hidasw 67ce271
Create b6ce4782.0
hidasw 42beeea
Create 7262ea48.0
hidasw 0884ea0
Create 71ab782e.0
hidasw 5d1c8ec
Create 5a0ce691.0
hidasw cbb1aac
Create 26a91b3f.0
hidasw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1274,7 +1274,8 @@ class TCPDF { | |
* @protected | ||
* @since 4.6.005 (2009-04-24) | ||
*/ | ||
protected $signature_max_length = 11742; | ||
// protected $signature_max_length = 11742; | ||
protected $signature_max_length = 20742; | ||
|
||
/** | ||
* Data for digital signature appearance. | ||
|
@@ -7692,12 +7693,14 @@ public function Output($name='doc.pdf', $dest='I') { | |
$signature = $tmparr[1]; | ||
// decode signature | ||
$signature = base64_decode(trim($signature)); | ||
// add TSA timestamp to signature | ||
$signature = $this->applyTSA($signature); | ||
// convert signature to hex | ||
$signature = current(unpack('H*', $signature)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should before $this->applyTSA($signature) |
||
// add TSA timestamp to signature | ||
$signature = $this->applyTSA($signature); | ||
|
||
$signature = str_pad($signature, $this->signature_max_length, '0'); | ||
// Add signature to the document | ||
|
||
$this->buffer = substr($pdfdoc, 0, $byte_range[1]).'<'.$signature.'>'.substr($pdfdoc, $byte_range[1]); | ||
$this->bufferlen = strlen($this->buffer); | ||
} | ||
|
@@ -13675,6 +13678,90 @@ protected function applyTSA($signature) { | |
return $signature; | ||
} | ||
//@TODO: implement this feature | ||
// start timestamping | ||
// by Hida since 5.9.128 (2011-10-06) | ||
if($this->tsa_timestamp) { | ||
//Include asn1 fuction script | ||
require_once(dirname(__FILE__).'/include/asn1_parser_tcpdf.php'); | ||
require_once(dirname(__FILE__).'/include/asn1_function_tcpdf.php'); | ||
require_once(dirname(__FILE__).'/include/functionLog_tcpdf.php'); | ||
|
||
$tsaLog = __FILE__." line:(".__LINE__."). Perform timestamping...\n"; | ||
//Parse TCPDF Signature structure to get signed hash sequence | ||
$p = asn1parse($signature); | ||
$p1 = asn1parse($p[0][1]); | ||
$p2 = asn1parse($p1[1][1]); | ||
$p3 = asn1parse($p2[0][1]); | ||
$p2 = asn1parse($p3[4][1]); | ||
$pa1 = asn1parse($p2[0][1]); | ||
$pa2 = asn1parse($pa1[3][1]); | ||
|
||
//Create timestamp request | ||
|
||
//Create hash of encrypted contents TCPDF signature | ||
$hash = hash('sha1', hex2bin($pa1[5][1])); | ||
//Build timestamp request data | ||
$tsReqData = seq( | ||
int(1). | ||
seq( | ||
seq( | ||
"06052B0E03021A". // Obj_sha1 | ||
"0500" // Null | ||
). | ||
oct($hash) | ||
). | ||
int(hash('crc32', rand())). | ||
'0101ff' | ||
); | ||
$raw_data = hex2bin($tsReqData); | ||
|
||
//Send request to TSA Server with Curl | ||
if(extension_loaded('curl')) { | ||
$tsaLog .= __FILE__." line:(".__LINE__."). Curl was already Loaded\n".__FILE__." line:(".__LINE__."). Curl is sending tsRequest to \"".$this->tsa_data['tsa_host']."\" ...\n"; | ||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_URL, $this->tsa_data['tsa_host']); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
curl_setopt($ch, CURLOPT_POST, 1); | ||
curl_setopt($ch, CURLOPT_USERAGENT, '1'); | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, $raw_data); | ||
|
||
$tsResponse = curl_exec($ch); | ||
if($tsResponse != false) { | ||
$tsaLog .= __FILE__." line:(".__LINE__."). tsRequest is sent.\n"; | ||
} else { | ||
tsaLog("$tsaLog".__FILE__." line:(".__LINE__."). can't send tsRequest, Timestamp failed!\n",'w'); | ||
} | ||
//parse ts response | ||
$hexTs = bin2hex($tsResponse); | ||
$tsparse = asn1parse($hexTs); | ||
|
||
$tsparse0 = asn1parse($tsparse[0][1]); | ||
if(count($tsparse0) > 1) { //Remove response status data, only take timeStampToken | ||
$timeStamp = seq($tsparse0[1][1]); | ||
} else { | ||
$timeStamp = seq($tsparse0[0][1]); | ||
} | ||
|
||
//Add timestamp to TCPDF Signature | ||
$timeStamp = seq("060B2A864886F70D010910020E".set($timeStamp)); | ||
$pkcs7 = int($pa1[0][1]).seq($pa1[1][1]).seq($pa1[2][1]).explicit(0, $pa1[3][1]).seq($pa1[4][1]).oct($pa1[5][1]); | ||
$time = seq($pkcs7.explicit(1,$timeStamp)); | ||
$aa=seq(int(1). set($p3[1][1]).seq($p3[2][1]).explicit(0, $p3[3][1]).set($time)); | ||
$hdaSignature = seq("06092A864886F70D010702".explicit(0,($aa)))."0000"; | ||
|
||
$signature = $hdaSignature; | ||
// $tsaLog .= $signature; | ||
tsaLog("$tsaLog".__FILE__." line:(".__LINE__."). Timestamp Success.\n"); | ||
} else { | ||
$tsaLog .= __FILE__." line:(".__LINE__."). Curl was not loaded, trying to load it...\n"; | ||
if(@dl('php_curl.dll')) { | ||
$tsaLog .= __FILE__." line:(".__LINE__."). Curl successfully Loaded.\n"; | ||
} else { | ||
tsaLog("$tsaLog\n".__FILE__." line:(".__LINE__."). Curl failed to load. Timestamping failed!", 'w'); | ||
} | ||
} | ||
} | ||
// end timestamping | ||
return $signature; | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i''m increasing this size to provide enough space to place tsa response data. and sometimes need more, depend on tsa response data size.