From 1656d3c9c35d7d9d76ce271229e8be9304070782 Mon Sep 17 00:00:00 2001 From: M N Hida Date: Tue, 16 May 2023 13:02:31 +0700 Subject: [PATCH] reformatting and cleanup also merge asn.1 function to one file, remove useless log function file. tested working trusted timestamp http://timestamp.apple.com/ts01 --- include/asn1_function_tcpdf.php | 43 ---- include/functionLog_tcpdf.php | 49 ----- ...n1_parser_tcpdf.php => tcpdf_asn1.min.php} | 43 ++++ tcpdf.php | 198 +++++++++++------- test/cert/Local Root CA.crt | 32 --- test/cert/tcpdf test.pem | 42 ---- test/index.php | 131 ------------ 7 files changed, 160 insertions(+), 378 deletions(-) delete mode 100644 include/asn1_function_tcpdf.php delete mode 100644 include/functionLog_tcpdf.php rename include/{asn1_parser_tcpdf.php => tcpdf_asn1.min.php} (75%) delete mode 100644 test/cert/Local Root CA.crt delete mode 100644 test/cert/tcpdf test.pem delete mode 100644 test/index.php diff --git a/include/asn1_function_tcpdf.php b/include/asn1_function_tcpdf.php deleted file mode 100644 index 502651f7..00000000 --- a/include/asn1_function_tcpdf.php +++ /dev/null @@ -1,43 +0,0 @@ - 127) { - $ret = "8".$headerLength.$ret; - } - return $ret; -} - -function SEQ($hex) { - $ret = "30".asn1_header($hex).$hex; - return $ret; -} -function OCT($hex) { - $ret = "04".asn1_header($hex).$hex; - return $ret; -} -function INT($int) { - if(strlen($int)%2 != 0) { - $int = "0$int"; - } - $int = "$int"; - $ret = "02".asn1_header($int).$int; - return $ret; -} -function SET($hex) { - $ret = "31".asn1_header($hex).$hex; - return $ret; -} -//function EXPLICIT($num="0", $hex) { -function EXPLICIT($num, $hex) { - $ret = "a$num".asn1_header($hex).$hex; - return $ret; -} -?> \ No newline at end of file diff --git a/include/functionLog_tcpdf.php b/include/functionLog_tcpdf.php deleted file mode 100644 index 2bef1e16..00000000 --- a/include/functionLog_tcpdf.php +++ /dev/null @@ -1,49 +0,0 @@ -$strLine) { - if($lineNum == 0) { - $strLog .= rtrim($strLine)."\r\n"; - } else { - $strLog .= $prependLogIdent.rtrim($strLine).$newLine; - } - } - $log = "$prependLog $strLog"; - if(is_writable(getcwd().'/tcpdf_tsa.log')) { - $handle = fopen(getcwd().'/tcpdf_tsa.log', 'a'); - fwrite($handle, $log); - fclose($handle); - } else { - $handle = @fopen(getcwd().'/tcpdf_tsa.log', 'a'); - fwrite($handle, $log); - fclose($handle); - if($type == 'e') { - echo "
\nCan't write log to file \"hdaLogs.log\", please check file permission. hdaLog return error, these error is:\n";
-      echo "$log\n
"; - } - } -} -?> \ No newline at end of file diff --git a/include/asn1_parser_tcpdf.php b/include/tcpdf_asn1.min.php similarity index 75% rename from include/asn1_parser_tcpdf.php rename to include/tcpdf_asn1.min.php index c304caea..a708708d 100644 --- a/include/asn1_parser_tcpdf.php +++ b/include/tcpdf_asn1.min.php @@ -8,6 +8,7 @@ // 17:51 Sore Jumat 27 Maret 2009 memecahkan explicit sampai 2097151 (65536 * 32) kurang 1 // 20:04 Sore Jumat 27 Maret 2009 ASN.1 Parser tlh jadi. Congratulation.... +// 12:15 Sore 16/05/2023 function asn1_first($hex) { $asn1_Id = substr($hex, 0, 2); $header = substr($hex, 2, 2); @@ -70,4 +71,46 @@ function asn1parse($hex) { } return $return; } + +// change at 22:37 Sore 04/09/2009 +// change at 12:15 Sore 16/05/2023 +function asn1_header($str) { + $len = strlen($str)/2; + $ret = dechex($len); + if(strlen($ret)%2 != 0) { + $ret = "0$ret"; + } + + $headerLength = strlen($ret)/2; + if($len > 127) { + $ret = "8".$headerLength.$ret; + } + return $ret; +} + +function SEQ($hex) { + $ret = "30".asn1_header($hex).$hex; + return $ret; +} +function OCT($hex) { + $ret = "04".asn1_header($hex).$hex; + return $ret; +} +function INT($int) { + if(strlen($int)%2 != 0) { + $int = "0$int"; + } + $int = "$int"; + $ret = "02".asn1_header($int).$int; + return $ret; +} +function SET($hex) { + $ret = "31".asn1_header($hex).$hex; + return $ret; +} +//function EXPLICIT($num="0", $hex) { +function EXPLICIT($num, $hex) { + $ret = "a$num".asn1_header($hex).$hex; + return $ret; +} ?> \ No newline at end of file diff --git a/tcpdf.php b/tcpdf.php index d67c127d..4bff8d47 100644 --- a/tcpdf.php +++ b/tcpdf.php @@ -13645,6 +13645,8 @@ protected function getSignatureAppearanceArray($x=0, $y=0, $w=0, $h=0, $page=-1, * @author Richard Stockinger * @since 6.0.090 (2014-06-16) */ + // other options suggested to be implement: reqPolicy, nonce, certReq, extensions + // Also option to abort signing if timestamping failed and LTV enable (embed crl and or ocsp revocation info) public function setTimeStamp($tsa_host='', $tsa_username='', $tsa_password='', $tsa_cert='') { $this->tsa_data = array(); if (!function_exists('curl_init')) { @@ -13679,92 +13681,126 @@ protected function applyTSA($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). + // by Hida (16 Mei 2023) + + // Include minimum asn.1 fuctional script + require_once(dirname(__FILE__).'/include/tcpdf_asn1.min.php'); + + // Parse TCPDF's pkcs#7 Signature structure to get sequence of signed hash + $pkcs7 = asn1parse($signature); + $pkcs7ContentInfo = asn1parse($pkcs7[0][1]); + + $pkcs7content = asn1parse($pkcs7ContentInfo[1][1]); + + $pkcs7SignedData = asn1parse($pkcs7content[0][1]); + + $pkcs7signerInfos = asn1parse($pkcs7SignedData[4][1]); + + $SignerInfo = asn1parse($pkcs7signerInfos[0][1]); + + $pkcs7EncryptedDigest = $SignerInfo[5][1]; + + // Create timestamp request + + // Create hash of encrypted contents TCPDF signature + // $this->setTimeStamp() have no options for change tsa req hash alg yet, so sha1 selected + $hash = hash('sha1', hex2bin($pkcs7EncryptedDigest)); + + // Build timestamp request data + $tsReqData = seq( + int(1). + seq( 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_HTTPHEADER, [ - 'Content-Type: application/timestamp-query', - 'User-Agent: TCPDF' - 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); + "06052B0E03021A". // Obj_sha1 + "0500" // Null + ). + oct($hash) + ). + int(hash('crc32', rand())). // Add random nonce request + '0101ff' // set certReq true to tell TSA server to include SigningCertificate + ); + + $raw_data = hex2bin($tsReqData); + + //Send request to TSA Server with Curl + if(extension_loaded('curl')) { + $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_HTTPHEADER, array( + 'Content-Type: application/timestamp-query', + 'User-Agent: TCPDF' + ) + ); + curl_setopt($ch, CURLOPT_POSTFIELDS, $raw_data); - $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'); - } + + // can't send tsRequest, Timestamp failed! + if(!$tsResponse = curl_exec($ch)) { + return $signature; + } + + // parse timestamp response data + $hexTsaResponse = bin2hex($tsResponse); + if(!$parseTimeStampResp = asn1parse($hexTsaResponse)) { // bad TSA Reponse + return $signature; } + + // verify tsa response PKIStatusInfo and TimeStampToken exists + if(!$TimeStampResp = asn1parse($parseTimeStampResp[0][1])) { + return $signature; + } + + // Select timeStampToken only. must ignore response status data (in first sequence if exist, select 2nd sequence) + if(count($TimeStampResp) > 1) { + $TSTInfo = $TimeStampResp[1][1]; // TSTInfo + } else if (count($TimeStampResp) == 1) { + $TSTInfo = $TimeStampResp[0][1]; // TSTInfo + } else { // TimeStampResp not containts 1 or 2 fields + return $signature; + } + + // Add timestamp in TCPDF Signature + // Create timestamp pkcs#7 data + $TimeStampToken = seq( + "060B2A864886F70D010910020E". // OBJ_id_smime_aa_timeStampToken + set( + seq( + $TSTInfo // TSTInfo + ) + ) + ); + + $time = seq( + $pkcs7signerInfos[0][1]. + explicit(1, + $TimeStampToken + ) + ); + + $pkcs7contentSignedData=seq( + int(1). // version + set($pkcs7SignedData[1][1]). // digestAlgorithms + seq($pkcs7SignedData[2][1]). // contentInfo + explicit(0, + $pkcs7SignedData[3][1] + ). // certificates [0] IMPLICIT ExtendedCertificatesAndCertificates + set( + $time + ) + ); + $pkcs7ContentInfo = seq( + "06092A864886F70D010702". // ContentType OBJ_pkcs7_signed + explicit(0,($pkcs7contentSignedData)) // content + ). + // "0000"; // sometime needed for backward compatibility + ""; + + $signature = $pkcs7ContentInfo; } - // end timestamping return $signature; + // End timestamping } /** diff --git a/test/cert/Local Root CA.crt b/test/cert/Local Root CA.crt deleted file mode 100644 index 322fb7d0..00000000 --- a/test/cert/Local Root CA.crt +++ /dev/null @@ -1,32 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIFfDCCA2SgAwIBAgIBCjANBgkqhkiG9w0BAQUFADBNMRYwFAYDVQQDEw1Mb2Nh -bCBSb290IENBMREwDwYDVQQKEwhteSwgT3JnLjEgMB4GA1UECxMXbXlzIFRydXN0 -IFdvcmsgU2VjdXJpdHkwIhgPMjAyMzA1MTMxODI2NTdaGA8yMDYzMDUxMzE4MjY1 -N1owTTEWMBQGA1UEAxMNTG9jYWwgUm9vdCBDQTERMA8GA1UEChMIbXksIE9yZy4x -IDAeBgNVBAsTF215cyBUcnVzdCBXb3JrIFNlY3VyaXR5MIICIjANBgkqhkiG9w0B -AQEFAAOCAg8AMIICCgKCAgEAlKoSYfMP1Jcx3Qzb3e7tb03LAPPhVVzJRVd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LuE3/OrqbYo5E04QmwNdBufpBQvbxohnDHIVFqjSOaAn7 -glwGuJjKShEYh0BoRuwR6cN85GcgR0SgwJPMiidSQ/e+0UeEm2CmQBuN4VWo/LIq -kBT1f7p4xLRdiSTLRK6vMkTn0SlzNtc8axI9ilWDQgVGoHc7BmGK1UZGsVDXyCGj -RguxBBYvS+hrKzym/AmBLW3qlHysoL2XgoPMZ3d6jrsY8HVcLNcrL2OG5DNN96sM -K1BaMuJex5IATxMwUOsHm80XY6x13uvIXfq0NoHH0rKNcaHVTDdVEQ9j3tUgLQe2 -hjBteYgJhH6W75sTQL99KxDTx0Jx9XtQMqgGswSHVmUm/ASy40C+31qH7MSd3Gxy -awXE23azjNjt8nUKXZpbweTGh1MixMgTckukuIFW8/oGPQHIQg51BfV5BdNxPDr/ -Fk0KsWn7PB5XeB86nKHGmA== ------END CERTIFICATE----- \ No newline at end of file diff --git a/test/cert/tcpdf test.pem b/test/cert/tcpdf test.pem deleted file mode 100644 index a2f3557b..00000000 --- a/test/cert/tcpdf test.pem +++ /dev/null @@ -1,42 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIETzCCAjegAwIBAgICCgMwDQYJKoZIhvcNAQENBQAwTTEWMBQGA1UEAxMNTG9j -YWwgUm9vdCBDQTERMA8GA1UEChMIbXksIE9yZy4xIDAeBgNVBAsTF215cyBUcnVz -dCBXb3JrIFNlY3VyaXR5MCIYDzIwMjMwNTE0MDkxNDQ2WhgPMjAzMzA1MTQwOTE0 -NDZaMHMxIDAeBgNVBAsTF215cyBUcnVzdCBXb3JrIFNlY3VyaXR5MScwJQYDVQQL -Ex5UZXJtcyBvZiB1c2UgYXQgLm5ldC9ycGEgKGMpMDkxETAPBgNVBAoTCG15LCBP -cmcuMRMwEQYDVQQDEwp0Y3BkZiB0ZXN0MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB -iQKBgQDQPsTVI4Wl+tP6FuhDCsmtN/d9bGvmHSl3c/9r+7zeQF0NHWlUihWV9FCS -vf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IN PRIVATE KEY----- -MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANA+xNUjhaX60/oW -6EMKya03931sa+YdKXdz/2v7vN5AXQ0daVSKFZX0UJK98VgVd+ahbyBpTbv+scQ4 -fzSsMH/5cC6M0WixHhYymwg1zEb2vWMGw1iHPTyYKT++yJNQZ1La7V5k3dznu1b1 -eTnGsgWahWJmbaCmY/vPwJgLk7zXAgMBAAECgYBD3zFoBlvY7ReJu02YDDwPKN6R -EnVYWsjZFgV5vGKiTXgGfj+GPjsq1KYuLZori1O454TAm5GqZCisO326PSTQ+hfs -VJpYOuTmwoMKG7aW73wyZzOaTwz5Ju2n99YFjUEcQvy67MRmZXBc0Vu3J3Wb8CTH -F9fgNgHlYKAHGKegAQJBAPlRMm/abDeQ471kW81cGabqwd7Z2C2ys2MhxOqZMbq+ -cZcT8ZrKd8MmcgowFTDaEla0BqS+spCSnZUOaulTaQECQQDV07zftpe85M/N4ZKJ -B3GyirJfpHMWJWFGNL+a33LNw/7wU2jXH6E82qr8ojWdK1NEk4ZeLA2PLUbN5zOM -sY3XAkEApfltF1OUiWVWh2XBS7RNi3ZrPB1QMhPuIkd/3SHBHm3cFtR7Gi5BjlQQ -xUF/SfdTEA9nANPG8kH40Bs6Bzy1AQJABtXY8NHWcexilDNEyuqZANscLqCEKU4S -mPrwsRO5iMheKvKPpGjXb6mR07efvSF4bPXGUtZXrJ8G52gfpry6SwJBAPaTOx0V -n7a9tTKJDgF2RL2YbBUUQzmjXlHa8NzcG55GSmTgvjhhKnncmm6s5Slw0WQruB10 -fh36J+34k5ZQIyM= ------END PRIVATE KEY----- diff --git a/test/index.php b/test/index.php deleted file mode 100644 index 245da16e..00000000 --- a/test/index.php +++ /dev/null @@ -1,131 +0,0 @@ -setCreator(PDF_CREATOR); -$pdf->setAuthor('Nicola Asuni'); -$pdf->setTitle('TCPDF Example 052'); -$pdf->setSubject('TCPDF Tutorial'); -$pdf->setKeywords('TCPDF, PDF, example, test, guide'); - -// set default header data -$pdf->setHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 052', PDF_HEADER_STRING); - -// set header and footer fonts -$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); -$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); - -// set default monospaced font -$pdf->setDefaultMonospacedFont(PDF_FONT_MONOSPACED); - -// set margins -$pdf->setMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); -$pdf->setHeaderMargin(PDF_MARGIN_HEADER); -$pdf->setFooterMargin(PDF_MARGIN_FOOTER); - -// set auto page breaks -$pdf->setAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); - -// set image scale factor -$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); - -// set some language-dependent strings (optional) -if (@file_exists(dirname(__FILE__).'/lang/eng.php')) { - require_once(dirname(__FILE__).'/lang/eng.php'); - $pdf->setLanguageArray($l); -} - -// --------------------------------------------------------- - -/* -NOTES: - - To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt - - To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12 - - To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes -*/ - -// set certificate file -//$certificate = 'file://data/cert/tcpdf.crt'; -$certificate = file_get_contents(realpath('.').'/cert/tcpdf test.pem'); - - -// set additional information -$info = array( - 'Name' => 'TCPDF', - 'Location' => 'Office', - 'Reason' => 'Testing TCPDF', - 'ContactInfo' => 'http://www.tcpdf.org', - ); - -echo "
";
-// $pdf->setTimeStamp($tsa_host='', $tsa_username='', $tsa_password='', $tsa_cert='');
-$pdf->setTimeStamp('http://timestamp.apple.com/ts01');
-
-
-// set document signature
-$pdf->setSignature($certificate, $certificate, 'tcpdfdemo',  realpath('.').'/cert/Local Root CA.crt', 2, $info);
-
-// set font. 'helvetica' MUST be used to avoid a PHP notice from PHP 7.4+
-$pdf->setFont('helvetica', '', 12);
-
-// add a page
-$pdf->AddPage();
-
-// print a line of text
-$text = 'This is a digitally signed document using the default (example) tcpdf.crt certificate.
To validate this signature you have to load the tcpdf.fdf on the Arobat Reader to add the certificate to List of Trusted Identities.

For more information check the source code of this example and the source code documentation for the setSignature() method.

www.tcpdf.org'; -$pdf->writeHTML($text, true, 0, true, 0); - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// *** set signature appearance *** - -// create content for signature (image and/or text) -$pdf->Image('images/tcpdf_signature.png', 180, 60, 15, 15, 'PNG'); - -// define active area for signature appearance -$pdf->setSignatureAppearance(180, 60, 15, 15); - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// *** set an empty signature appearance *** -$pdf->addEmptySignatureAppearance(180, 80, 15, 15); - -// --------------------------------------------------------- - -//Close and output PDF document -//$pdf->Output('example_052.pdf', 'D'); -$pdf->Output(realpath('.').'/result.pdf', 'F'); - -//============================================================+ -// END OF FILE -//============================================================+