Skip to content

fix: works with unicode password#21

Merged
jeidison merged 4 commits intomasterfrom
fix/works-with-unicode-password
Apr 24, 2024
Merged

fix: works with unicode password#21
jeidison merged 4 commits intomasterfrom
fix/works-with-unicode-password

Conversation

@vitormattos
Copy link
Copy Markdown
Contributor

@vitormattos vitormattos commented Apr 23, 2024

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 vitormattos requested a review from jeidison April 23, 2024 20:29
@vitormattos vitormattos self-assigned this Apr 23, 2024
@vitormattos vitormattos force-pushed the fix/works-with-unicode-password branch from b427217 to 0bc7dec Compare April 23, 2024 20:37
@vitormattos vitormattos marked this pull request as draft April 23, 2024 20:38
@vitormattos
Copy link
Copy Markdown
Contributor Author

Wait to review, working to improve performance.

@vitormattos
Copy link
Copy Markdown
Contributor Author

vitormattos commented Apr 23, 2024

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 vitormattos marked this pull request as ready for review April 23, 2024 20:55
@vitormattos
Copy link
Copy Markdown
Contributor Author

@jeidison done!
ready for review.

@vitormattos vitormattos marked this pull request as draft April 23, 2024 21:38
@vitormattos vitormattos force-pushed the fix/works-with-unicode-password branch from 4e36b69 to 44f92f6 Compare April 23, 2024 21:56
JSignPdf don't works as well at CLI interfaceif the password have unicode
chars. As workaround, I changed the password certificate in memory.

Signed-off-by: Vitor Mattos <vitor@php.rio>
Test validate method directly to dont run jsignpdf when we only need to
test the validate method

Signed-off-by: Vitor Mattos <vitor@php.rio>
Signed-off-by: Vitor Mattos <vitor@php.rio>
Signed-off-by: Vitor Mattos <vitor@php.rio>
@vitormattos vitormattos force-pushed the fix/works-with-unicode-password branch from 44f92f6 to 740cea1 Compare April 23, 2024 21:57
@vitormattos
Copy link
Copy Markdown
Contributor Author

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

@vitormattos vitormattos marked this pull request as ready for review April 23, 2024 21:58
@jeidison jeidison merged commit 3596031 into master Apr 24, 2024
@vitormattos vitormattos deleted the fix/works-with-unicode-password branch August 4, 2025 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants