From d97c052d085f677bebda6ce57ae730fa7c8c383d Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 14 Apr 2018 10:41:38 +0200 Subject: [PATCH 1/5] Fix: broken $pdf object ! --- htdocs/core/lib/pdf.lib.php | 8 +++++--- htdocs/core/modules/facture/doc/pdf_crabe.modules.php | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 573a562d467..41e53059fff 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -130,6 +130,10 @@ function pdf_getInstance($format='',$metric='mm',$pagetype='P') //$format=array($arrayformat['width'],$arrayformat['height']); //$metric=$arrayformat['unit']; + if (class_exists('TCPDI')) $pdf = new TCPDI($pagetype,$metric,$format); + else if (class_exists('FPDI')) $pdf = new FPDI($pagetype,$metric,$format); + else $pdf = new TCPDF($pagetype,$metric,$format); + // Protection and encryption of pdf if (! empty($conf->global->PDF_SECURITY_ENCRYPTION)) { @@ -144,9 +148,7 @@ function pdf_getInstance($format='',$metric='mm',$pagetype='P') - print-high : Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this is not set, printing is limited to a low-level representation of the appearance, possibly of degraded quality. - owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions. */ - if (class_exists('TCPDI')) $pdf = new TCPDI($pagetype,$metric,$format); - else if (class_exists('FPDI')) $pdf = new FPDI($pagetype,$metric,$format); - else $pdf = new TCPDF($pagetype,$metric,$format); + // For TCPDF, we specify permission we want to block $pdfrights = array('modify','copy'); diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index 17b652ed2db..b5ee2fba63b 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -108,7 +108,7 @@ class pdf_crabe extends ModelePDFFactures function __construct($db) { global $conf,$langs,$mysoc; - + // Translations $langs->loadLangs(array("main", "bills")); @@ -204,7 +204,7 @@ class pdf_crabe extends ModelePDFFactures if (! is_object($outputlangs)) $outputlangs=$langs; // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; - + // Translations $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies")); @@ -1543,7 +1543,7 @@ class pdf_crabe extends ModelePDFFactures function _pagehead(&$pdf, $object, $showaddress, $outputlangs) { global $conf, $langs; - + // Translations $outputlangs->loadLangs(array("main", "bills", "propal", "companies")); From 25a87507b9548646cebac902b7fdc24396102e35 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 14 Apr 2018 15:12:51 +0200 Subject: [PATCH 2/5] NEW add new parameters for tcpf encryption --- htdocs/core/lib/pdf.lib.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 41e53059fff..9de6dcd5c1c 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -150,11 +150,18 @@ function pdf_getInstance($format='',$metric='mm',$pagetype='P') */ // For TCPDF, we specify permission we want to block - $pdfrights = array('modify','copy'); + $pdfrights = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_RIGHTS)?$conf->global->PDF_SECURITY_ENCRYPTION_RIGHTS:array('modify','copy')); + + // For encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit + $encstrength = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_STRENGTH)?$conf->global->PDF_SECURITY_ENCRYPTION_STRENGTH:0); + + // Array of recipients containing public-key certificates ('c') and permissions ('p'). + // For example: array(array('c' => 'file://../examples/data/cert/tcpdf.crt', 'p' => array('print'))) + $pubkeys = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_PUBKEYS)?$conf->global->PDF_SECURITY_ENCRYPTION_PUBKEYS:null); $pdfuserpass = ''; // Password for the end user $pdfownerpass = NULL; // Password of the owner, created randomly if not defined - $pdf->SetProtection($pdfrights,$pdfuserpass,$pdfownerpass); + $pdf->SetProtection($pdfrights,$pdfuserpass,$pdfownerpass,$encstrength,$pubkeys); } return $pdf; From 732f019fb2194e12a05e9ddadad5c1ee394262d4 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 14 Apr 2018 15:17:51 +0200 Subject: [PATCH 3/5] Fix: json format in llx_const --- htdocs/core/lib/pdf.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 9de6dcd5c1c..8244622a545 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -150,14 +150,14 @@ function pdf_getInstance($format='',$metric='mm',$pagetype='P') */ // For TCPDF, we specify permission we want to block - $pdfrights = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_RIGHTS)?$conf->global->PDF_SECURITY_ENCRYPTION_RIGHTS:array('modify','copy')); + $pdfrights = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_RIGHTS)?json_decode($conf->global->PDF_SECURITY_ENCRYPTION_RIGHTS, true):array('modify','copy')); // Json format in llx_const // For encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit $encstrength = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_STRENGTH)?$conf->global->PDF_SECURITY_ENCRYPTION_STRENGTH:0); // Array of recipients containing public-key certificates ('c') and permissions ('p'). // For example: array(array('c' => 'file://../examples/data/cert/tcpdf.crt', 'p' => array('print'))) - $pubkeys = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_PUBKEYS)?$conf->global->PDF_SECURITY_ENCRYPTION_PUBKEYS:null); + $pubkeys = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_PUBKEYS)?json_decode($conf->global->PDF_SECURITY_ENCRYPTION_PUBKEYS, true):null); // Json format in llx_const $pdfuserpass = ''; // Password for the end user $pdfownerpass = NULL; // Password of the owner, created randomly if not defined From fb4765c4723fa7336b3e7c7ed5d54b8adfff7d4d Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 14 Apr 2018 15:24:52 +0200 Subject: [PATCH 4/5] Fix clean code --- htdocs/core/lib/pdf.lib.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 8244622a545..1b11c3fd803 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -152,6 +152,12 @@ function pdf_getInstance($format='',$metric='mm',$pagetype='P') // For TCPDF, we specify permission we want to block $pdfrights = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_RIGHTS)?json_decode($conf->global->PDF_SECURITY_ENCRYPTION_RIGHTS, true):array('modify','copy')); // Json format in llx_const + // Password for the end user + $pdfuserpass = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_USERPASS)?$conf->global->PDF_SECURITY_ENCRYPTION_USERPASS:''); + + // Password of the owner, created randomly if not defined + $pdfownerpass = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_OWNERPASS)?$conf->global->PDF_SECURITY_ENCRYPTION_OWNERPASS:null); + // For encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit $encstrength = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_STRENGTH)?$conf->global->PDF_SECURITY_ENCRYPTION_STRENGTH:0); @@ -159,8 +165,6 @@ function pdf_getInstance($format='',$metric='mm',$pagetype='P') // For example: array(array('c' => 'file://../examples/data/cert/tcpdf.crt', 'p' => array('print'))) $pubkeys = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_PUBKEYS)?json_decode($conf->global->PDF_SECURITY_ENCRYPTION_PUBKEYS, true):null); // Json format in llx_const - $pdfuserpass = ''; // Password for the end user - $pdfownerpass = NULL; // Password of the owner, created randomly if not defined $pdf->SetProtection($pdfrights,$pdfuserpass,$pdfownerpass,$encstrength,$pubkeys); } From da66e5c5a74d0731874c2fd9e311f6a6a9a03e68 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 15 Apr 2018 11:38:29 +0200 Subject: [PATCH 5/5] Update pdf.lib.php --- htdocs/core/lib/pdf.lib.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 1b11c3fd803..e238dc7054e 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -123,7 +123,7 @@ function pdf_getInstance($format='',$metric='mm',$pagetype='P') require_once TCPDF_PATH.'tcpdf.php'; // We need to instantiate tcpdi object (instead of tcpdf) to use merging features. But we can disable it (this will break all merge features). - if (empty($conf->global->MAIN_DISABLE_TCPDI)) require_once TCPDI_PATH.'tcpdi.php'; + if (empty($conf->global->MAIN_DISABLE_TCPDI)) require_once TCPDI_PATH.'tcpdi.php'; else if (empty($conf->global->MAIN_DISABLE_FPDI)) require_once FPDI_PATH.'fpdi.php'; //$arrayformat=pdf_getFormat(); @@ -131,7 +131,6 @@ function pdf_getInstance($format='',$metric='mm',$pagetype='P') //$metric=$arrayformat['unit']; if (class_exists('TCPDI')) $pdf = new TCPDI($pagetype,$metric,$format); - else if (class_exists('FPDI')) $pdf = new FPDI($pagetype,$metric,$format); else $pdf = new TCPDF($pagetype,$metric,$format); // Protection and encryption of pdf