libresign icon indicating copy to clipboard operation
libresign copied to clipboard

Error: PDFtk binary is invalid

Open stepcellwolf opened this issue 1 year ago • 4 comments

Describe the bug and to reproduce When I try to run the following command sudo -u nextcloud php8.2 --define apc.enable_cli=1 occ libresign:install --pdftk I do not get any error, where on the interface in NC version 28.0.5 and PHP Version: 8.2.18 on yunohost version 11.2.11.3 (stable).

Expected behavior It should install.

Screenshots image

Environment information (please complete the following information):

  • OS: Linux Debian
  • Browser either, safari, firefox and chrome
  • LibreSign Version 8.0.1
  • Nextcloud Server Version 28.0.5
  • No Logs

Additional context I also installed pdftk with apt install pdftk output:

pdftk port to java 3.2.2 a Handy Tool for Manipulating PDF Documents
Copyright (c) 2017-2018 Marc Vinyals - https://gitlab.com/pdftk-java/pdftk
Copyright (c) 2003-2013 Steward and Lee, LLC.
pdftk includes a modified version of the iText library.
Copyright (c) 1999-2009 Bruno Lowagie, Paulo Soares, et al.
This is free software; see the source code for copying conditions. There is
NO warranty, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Any idea what might be the problem? Thanks in advance.

stepcellwolf avatar May 10 '24 19:05 stepcellwolf

This is the point at code that throw this error:

https://github.com/LibreSign/libresign/blob/e2cc40313060e0e324e52be6c51dfd463c903dce/lib/Service/Install/ConfigureCheckService.php#L136-L162

You can try to mount the exec command with the path of downloaded files to check what's returned by --version.

Sounds that the return is empty or is an error in your case.

vitormattos avatar May 11 '24 02:05 vitormattos

I'm having this same issue, but am seeing a correct output from that command:

curtispf@server:~$ sudo -u www-data java -jar /var/www/cloud/data/appdata_PATH/libresign/pdftk.jar  --version
pdftk port to java 3.3.3 a Handy Tool for Manipulating PDF Documents
Copyright (c) 2017-2018 Marc Vinyals - https://gitlab.com/pdftk-java/pdftk
Copyright (c) 2003-2013 Steward and Lee, LLC.
pdftk includes a modified version of the iText library.
Copyright (c) 1999-2009 Bruno Lowagie, Paulo Soares, et al.
This is free software; see the source code for copying conditions. There is
NO warranty, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

mashedkeyboard avatar May 14 '24 12:05 mashedkeyboard

The way to identify the version of pdftk that I implemented is this regex that is applied at first row:

/pdftk port to java (?<version>.*) a Handy Tool/

The first row is: pdftk port to java 3.3.3 a Handy Tool for Manipulating PDF Documents

And the expected value for now is 3.3.3

The message PDFtk binary is invalid only is displayed when the return of --version is not a text or if the regex not match with the first row.

I think that will be necessary put more debugs/log points to identify what happening.

vitormattos avatar May 14 '24 13:05 vitormattos

I put points of log to be possible follow the code execution. If possible, would be good if you apply this changes adding the log rows at your ConfigureCheckService.php.

To check the log output, you can use a tail with grep:

tail -f data/nextcloud.log |grep libresign

I will need the output of tail to be possible check what's happening.

diff --git a/lib/Service/Install/ConfigureCheckService.php b/lib/Service/Install/ConfigureCheckService.php
index ccc79b20c..c73ca4dc5 100644
--- a/lib/Service/Install/ConfigureCheckService.php
+++ b/lib/Service/Install/ConfigureCheckService.php
@@ -131,13 +131,21 @@ class ConfigureCheckService {
         */
        public function checkPdftk(): array {
                $pdftkPath = $this->appConfig->getAppValue('pdftk_path');
+               \OC::$server->getLogger()->debug('Path of PDFTK', ['app' => 'libresign', 'pdftk_path' => $pdftkPath]);
                if ($pdftkPath) {
+                       \OC::$server->getLogger()->debug('PDFTK exists', ['app' => 'libresign']);
                        if (file_exists($pdftkPath)) {
                                $javaPath = $this->appConfig->getAppValue('java_path');
                                \exec($javaPath . ' -jar ' . $pdftkPath . " --version 2>&1", $version);
+                               \OC::$server->getLogger()->debug('executed command', ['app' => 'libresign', 'command' => $javaPath . ' -jar ' . $pdftkPath . " --version 2>&1"]);
+                               \OC::$server->getLogger()->debug('output of version', ['app' => 'libresign', 'version' => $version]);
+                               \OC::$server->getLogger()->debug('Exists first row', ['app' => 'libresign', 'exists' => isset($version[0]) ? 'yes': 'no']);
                                if (isset($version[0])) {
+                                       \OC::$server->getLogger()->debug('First row', ['app' => 'libresign', 'version' => $version[0]]);
                                        preg_match('/pdftk port to java (?<version>.*) a Handy Tool/', $version[0], $matches);
+                                       \OC::$server->getLogger()->debug('Return of regex', ['app' => 'libresign', 'version' => $matches]);
                                        if (isset($matches['version'])) {
+                                               \OC::$server->getLogger()->debug('Version identified', ['app' => 'libresign', 'version' => $matches['version']]);
                                                if ($matches['version'] === InstallService::PDFTK_VERSION) {
                                                        $return[] = (new ConfigureCheckHelper())
                                                                        ->setSuccessMessage('PDFtk version: ' . InstallService::PDFTK_VERSION)

vitormattos avatar May 14 '24 14:05 vitormattos

@vitormattos I'm getting the same issue, here's the debug logs with those statements added:

{"reqId":"XXXXXXXX","level":0,"time":"2024-05-30T19:46:33+00:00","remoteAddr":"XX.XX.XX.XX","user":"raymo","app":"libresign","method":"GET","url":"/nextcloud/ocs/v2.php/apps/libresign/api/v1/admin/configure-check","message":"Path of PDFTK","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36","version":"29.0.1.1","data":{"app":"libresign","pdftk_path":"/data/data/appdata_ocuvueakr11p/libresign/pdftk.jar"}}
{"reqId":"XXXXXXXX","level":0,"time":"2024-05-30T19:46:33+00:00","remoteAddr":"XX.XX.XX.XX","user":"raymo","app":"libresign","method":"GET","url":"/nextcloud/ocs/v2.php/apps/libresign/api/v1/admin/configure-check","message":"PDFTK exists","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36","version":"29.0.1.1","data":{"app":"libresign"}}
{"reqId":"XXXXXXXX","level":0,"time":"2024-05-30T19:46:33+00:00","remoteAddr":"XX.XX.XX.XX","user":"raymo","app":"libresign","method":"GET","url":"/nextcloud/ocs/v2.php/apps/libresign/api/v1/admin/configure-check","message":"executed command","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36","version":"29.0.1.1","data":{"app":"libresign","command":" -jar /data/data/appdata_ocuvueakr11p/libresign/pdftk.jar --version 2>&1"}}
{"reqId":"XXXXXXXX","level":0,"time":"2024-05-30T19:46:33+00:00","remoteAddr":"XX.XX.XX.XX","user":"raymo","app":"libresign","method":"GET","url":"/nextcloud/ocs/v2.php/apps/libresign/api/v1/admin/configure-check","message":"output of version","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36","version":"29.0.1.1","data":{"app":"libresign","version":"[\"sh: 1: -jar: not found\"]"}}
{"reqId":"XXXXXXXX","level":0,"time":"2024-05-30T19:46:33+00:00","remoteAddr":"XX.XX.XX.XX","user":"raymo","app":"libresign","method":"GET","url":"/nextcloud/ocs/v2.php/apps/libresign/api/v1/admin/configure-check","message":"Exists first row","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36","version":"29.0.1.1","data":{"app":"libresign","exists":"yes"}}
{"reqId":"XXXXXXXX","level":0,"time":"2024-05-30T19:46:33+00:00","remoteAddr":"XX.XX.XX.XX","user":"raymo","app":"libresign","method":"GET","url":"/nextcloud/ocs/v2.php/apps/libresign/api/v1/admin/configure-check","message":"First row","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36","version":"29.0.1.1","data":{"app":"libresign","version":"sh: 1: -jar: not found"}}
{"reqId":"XXXXXXXX","level":0,"time":"2024-05-30T19:46:33+00:00","remoteAddr":"XX.XX.XX.XX","user":"raymo","app":"libresign","method":"GET","url":"/nextcloud/ocs/v2.php/apps/libresign/api/v1/admin/configure-check","message":"Return of regex","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36","version":"29.0.1.1","data":{"app":"libresign","version":"[]"}}

Raymo111 avatar May 30 '24 19:05 Raymo111

Seems like javaPath is empty, and indeed if I add this:

$javaPath = $this->appConfig->getAppValue('java_path');
+ \OC::$server->getLogger()->debug('java path', ['app' => 'libresign', 'javaPath' => $javaPath]);

I get

{"reqId":"XXXXXXXX","level":0,"time":"2024-05-30T19:53:14+00:00","remoteAddr":"XX.XX.XX.XX","user":"raymo","app":"libresign","method":"GET","url":"/nextcloud/ocs/v2.php/apps/libresign/api/v1/admin/configure-check","message":"java path","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36","version":"29.0.1.1","data":{"app":"libresign","javaPath":""}}

Raymo111 avatar May 30 '24 19:05 Raymo111

I can fix it by installing java instead of using OS java, (occ libresign:install --java).

I see in @stepcellwolf's screenshot that he also didn't run that. Perhaps the java check should set java_path if OS java is detected, or OS java shouldn't be allowed at all?

Raymo111 avatar May 30 '24 19:05 Raymo111

if OS java is detected, or OS java shouldn't be allowed at all?

Will be complex to check if have Java installed at OS to use this and also could have side effects using a java version that isn't the same that is used by LibreSign.

vitormattos avatar May 31 '24 16:05 vitormattos