Feat/support jsignpdf 3 - #59
Conversation
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
…ration group Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
…stant Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
… path Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
…meters Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
… a plain executable Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
| * @param list<string> $parameters | ||
| * @return list<string> | ||
| */ | ||
| private function takePasswords(array $parameters): array |
There was a problem hiding this comment.
I think - should be handled as a real password when it comes from the PHP API.
Today takePasswords() treats - in a special way and keeps it in the command line. Then JSignPdf receives -tsp - and waits for one more password from stdin, but the wrapper does not store or send this value.
Now the wrapper controls the stdin password handling, so the caller should not need to know about the JSignPdf - special value.
Maybe takePasswords() can always save the password value, including -.
For example, both cases:
['-tsp', '-']
['-tsp=-']can mean that the real TSA password is -.
The wrapper can still generate:
-tsp -
and send - in the correct stdin position.
It would also be good to update the current test and cover both cases.
| public function getVersion(JSignParam $params): string | ||
| { | ||
| $java = $this->javaCommand($params); | ||
| $jSignPdf = $this->getjSignPdfJarPath($params); | ||
| $jSignPdf = $params->getjSignPdfJarPath(); | ||
| $java = escapeshellarg($this->javaCommand($params)); | ||
| $jSignPdf = $this->jSignPdfInvocation($params); | ||
|
|
||
| $command = "$java -jar $jSignPdf --version 2>&1"; | ||
| $command = implode(' ', array_merge([$java], $this->javaOptions($params), [$jSignPdf, '--version'])) . ' 2>&1'; | ||
| exec($command, $output); | ||
| $lastRow = end($output); | ||
| if (empty($output) || strpos($lastRow, 'version') === false) { |
There was a problem hiding this comment.
getVersion() also runs JSignPdf, but it does not use the environment configured with setEnvironmentVariables().
The signing path correctly passes these variables through proc_open(), while the version path still uses exec().
I suggest using the same process execution mechanism for both operations, so Java options and environment variables have the same behavior whenever this package runs JSignPdf.
This is especially relevant for externally managed installations such as LibreSign, where JSIGNPDF_HOME is explicitly configured.
Related issue #52
Updates the wrapper to the current stable JSignPdf (3.1.0) and keeps every password out of the command line.
CLI differences between 2.3 and 3.1
--enable-stdin-passwordsplus-as the option value, read one line each in the fixed order-ksp,-kp,-opwd,-upwd,-tscp,-tspexec()toproc_open(), writing the passwords to stdinlib/directorycom.intoolswetrust.jsignpdf.Bootstrap), keeping-jaras a fallback for 3.0.x--overwritewas added and-akept as a no-opexample/index.phpnow passes--overwrite--versionoutput and theFinished: Signature succesfully created.messageWhat changed
Every value reaching the shell goes through
escapeshellarg(): the java binary, the jar or classpath, the PDF,-ksfand-d.No password is passed as an argument any more. Besides
setPassword(), the key, owner, user and TSA passwords have their own setters and are sent through stdin:Passing them to
setJSignParameters()as a list works too — the value is taken out of the command line just the same.setJSignParameters()accepts a list of options and values, which the package escapes.jsignpdf-3.1.0-minimal.zip.Compatibility
setJSignPdfDownloadUrl()orsetjSignPdfJarPath()at a 2.x release stops working. JSignPdf 3.x needs a Java 21+ runtime.--overwriteor a hash algorithm the PDF version supports.setJSignParameters()is still passed through unparsed, so a password written there does reach the command line. The README points to the setters and to the list form instead.Testing
integrationgroup runs the real JSignPdf — version, signing, visible signature with page and coordinates, explicit hash algorithm, more than one password on stdin, and the pre-1.6 failure. It runs in its own CI job and is excluded fromtest:unitand from coverage.