JSignPdf / jsignpdf-php

This package is only wrapper of JSignPdf to use in PHP
21 stars 4 forks source link

fix: works with unicode password #21

Closed vitormattos closed 5 months ago

vitormattos commented 5 months ago

JSignPdf don't works as well at CLI interfaceif the password have unicode chars. As workaround, I changed the password certificate in memory.

Screenshot_20240423_172828

When we use a certificate with an unicode char at password will throw this error:

Exception: Error to sign PDF. [
    "FINE Default property file doesn't exists.",
    "FINE Default property file doesn't exists.",
    "INFO Checking input and output PDF paths.",
    "java.io.IOException: keystore password was incorrect",
    "\tat java.base\/sun.security.pkcs12.PKCS12KeyStore.engineLoad(Unknown Source)",
    "\tat java.base\/sun.security.util.KeyStoreDelegator.engineLoad(Unknown Source)",
    "\tat java.base\/java.security.KeyStore.load(Unknown Source)",
    "\tat net.sf.jsignpdf.utils.KeyStoreUtils.loadKeyStore(KeyStoreUtils.java:359)",
    "\tat net.sf.jsignpdf.utils.KeyStoreUtils.getPkInfo(KeyStoreUtils.java:411)",
    "\tat net.sf.jsignpdf.SignerLogic.signFile(SignerLogic.java:154)",
    "\tat net.sf.jsignpdf.Signer.signFiles(Signer.java:246)",
    "\tat net.sf.jsignpdf.Signer.main(Signer.java:139)",
    "Caused by: java.security.UnrecoverableKeyException: failed to decrypt safe contents entry: javax.crypto.BadPaddingException: Given final block not properly padded. Such issues can arise if a bad key is used during decryption.",
    "\t... 8 more",
    "WARNING Keystore was not loaded succesfully. Check if the keystore type, path and password are valid.",
    "SEVERE Problem occured",
    "java.lang.NullPointerException: Keystore was not loaded succesfully. Check if the keystore type, path and password are valid.",
    "\tat net.sf.jsignpdf.utils.KeyStoreUtils.getKeyAliasInternal(KeyStoreUtils.java:224)",
    "\tat net.sf.jsignpdf.utils.KeyStoreUtils.getPkInfo(KeyStoreUtils.java:413)",
    "\tat net.sf.jsignpdf.SignerLogic.signFile(SignerLogic.java:154)",
    "\tat net.sf.jsignpdf.Signer.signFiles(Signer.java:246)",
    "\tat net.sf.jsignpdf.Signer.main(Signer.java:139)",
    "",
    "INFO Finished: Creating of signature failed."
]
vitormattos commented 5 months ago

Wait to review, working to improve performance.

vitormattos commented 5 months ago

The new test use the method sign to call the validation method. To improve the performance of test, I called the validation method directly, to do this, was necessary make this method public.

After performance improvement, test execution time was reduced by half:

Screenshot_20240423_175436

vitormattos commented 5 months ago

@jeidison done! ready for review.

vitormattos commented 5 months ago

Done, I implemented now a mock to exec command and return the methods to be privated