lsnepomuceno / laravel-a1-pdf-sign

Sign PDF files with valid x509 certificate
https://laravel-a1-pdf-sign.netlify.app/
MIT License
286 stars 56 forks source link

path management in windows #161

Open boehlim377 opened 1 month ago

boehlim377 commented 1 month ago

If the project is in a folder that contains a space, the openssl command will not work. Because then the Temp folder cannot be used. If the certificate to be used has a space (e.g. in the path), it won't work either

The problem occurs in the file \src\Sign\ManageCert.php in Line 81 $openSslCommand = "openssl pkcs12 -in {$pfxPath} -out {$output} -nodes -password pass:{$shellArgPassword} {$legacyFlag}";

In the a1TempDir function the slashes should be replaceced with DIRECTORY_SEPARATOR. (Helpers\helpers.php line 109 and 112)

To Reproduce

  1. Create an project in Windows (10) with "C:\projets\my Project\"
  2. $cert = new ManageCert;
  3. $cert->fromPfx("C:\projets\my Project\test.pfx", password)

Expected behavior All used paths (certificate, temp) should be escaped.

Versions involved:

possible fix

$openSslCommand = "openssl pkcs12 -in " . escapeshellarg($pfxPath) . " -out " . escapeshellarg($output) . " -nodes -password pass:{$shellArgPassword} {$legacyFlag}";
cpibia commented 1 month ago

The TCPDF documentation uses file:// to indicate an absolute path to the certificate file. In your case, it looks like you are using a Windows path.

Try changing the certificate path to this:

$certificate = 'file:///C:/projets/my Project/test.pfx'; 

file://: This tells TCPDF that you are providing an absolute path to the file. /C:/projets/my Project/test.pfx: This is the absolute path to your .pfx file on Windows, with slashes (/) instead of backslashes (). Important: Make sure that the test.pfx file actually exists in the specified path and that TCPDF has permissions to read it.

in any case, i suggest you not to work with Windows but to use a Linux machine for PHP development. WSL2 could be a solution.

Regards Cristian

boehlim377 commented 1 month ago

Hi Cristian,

It doesn't work even with "file://" at the beginning, because the path is still cut off.

You're certainly right that there are other ways to solve the problem. The simplest way is to put the project and the certificate etc. in a path without spaces.

But I think a package should be able to handle that. I've already described one possibility. It works for me like that.

Regards Max