Hi Josef,
thanks for the quick reaction! The constructor is called with SHA256withECDSA and 4161 when I use SHA256, SHA1withECDSA and 4162 when use SHA1.
The token seems to have both min and max keyLength set to 201 for all mechanisms (excerpt from OpenSC's Mechanism Info):
SHA-1, keySize={201,201}, digest
SHA256, keySize={201,201}, digest
SHA384, keySize={201,201}, digest
SHA512, keySize={201,201}, digest
RIPEMD160, keySize={201,201}, digest
ECDSA, keySize={201,201}, hw, sign, verify, EC F_P, EC OID, EC uncompressed
ECDSA-SHA1, keySize={201,201}, hw, sign, verify, EC F_P, EC OID, EC uncompressed
ECDH1-DERIVE, keySize={201,201}, hw, sign, verify, EC F_P, EC OID, EC uncompressed
A workaround would be awesome, but I'm not sure that disabling the checks would work: I can add a valid signature if I change the key length to 201 in P11KeyStore.java:1403 (at runtime), but when I just change the maxKeyLength (again at runtime) for the check to pass, I get another error:
java.security.ProviderException: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_SESSION_HANDLE_INVALID
at com.github.kwart.jsign.pkcs11.P11Signature.engineSign(P11Signature.java:662)
at java.security.Signature$Delegate.engineSign(Signature.java:1382)
at java.security.Signature.sign(Signature.java:698)
at com.lowagie.text.pdf.PdfPKCS7.getEncodedPKCS7(PdfPKCS7.java:1261)
at net.sf.jsignpdf.SignerLogic.signFile(SignerLogic.java:425)
at net.sf.jsignpdf.SignerLogic.run(SignerLogic.java:118)
at java.lang.Thread.run(Thread.java:748)
Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_SESSION_HANDLE_INVALID
at sun.security.pkcs11.wrapper.PKCS11.C_SignFinal(Native Method)
at com.github.kwart.jsign.pkcs11.P11Signature.engineSign(P11Signature.java:616)
... 6 more
Is there a way to somehow provide a "custom" key length? I don't understand yet where the 256 in P11KeyStore.java:1403 comes from, but it seems like if there was a way to change that, it'd work.
Again, thanks for your time, Josef!
Chris