[ 
https://issues.apache.org/jira/browse/PDFBOX-6348?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Simon Steiner closed PDFBOX-6348.
---------------------------------
    Resolution: Not A Problem

> Support EC cert
> ---------------
>
>                 Key: PDFBOX-6348
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-6348
>             Project: PDFBox
>          Issue Type: Bug
>            Reporter: Simon Steiner
>            Priority: Major
>
> CreateSignatureBase.sign() chooses the CMS signature algorithm with 
> cert.getSigAlgName():
>   ContentSigner sha1Signer = new 
> JcaContentSignerBuilder(cert.getSigAlgName()).build(privateKey);
>   getSigAlgName() returns the algorithm the issuer used to sign the 
> certificate, not the algorithm of the signer's key. When the two differ, 
> signing fails. That's normal for an EC end-entity certificate issued
>   by an RSA CA, which is common with commercial CAs. The comment above that 
> line and mkl's note on PDFBOX-5940 already describe this limitation.
>   Steps to reproduce:
>   1. Create an RSA CA and an EC P-256 key pair.
>   2. Issue a certificate for the EC public key, signed by the CA with 
> SHA256withRSA.
>   3. Put the EC private key and the chain [EC cert, CA cert] in a PKCS12 
> keystore.
>   4. new CreateSignature(keystore, pin).sign(inputStream)
>   Actual result:
>   java.io.IOException: org.bouncycastle.operator.OperatorCreationException: 
> cannot create signer: No installed provider supports this key: 
> sun.security.ec.ECPrivateKeyImpl
>     caused by: org.bouncycastle.operator.OperatorCreationException: cannot 
> create signer: No installed provider supports this key: 
> sun.security.ec.ECPrivateKeyImpl
>     caused by: java.security.InvalidKeyException: No installed provider 
> supports this key: sun.security.ec.ECPrivateKeyImpl
>   Expected result: a valid SHA256withECDSA CMS signature.
>   A self-signed EC certificate works, because there the issuer algorithm 
> happens to match the key.
>   Suggested fix: derive the algorithm from privateKey.getAlgorithm():
>   - EC → SHA256withECDSA
>   - RSA → SHA256withRSA
>   - any other key type keeps using cert.getSigAlgName()
>   Also rename the misleading sha1Signer variable.
>   Affected: every example built on CreateSignatureBase (CreateSignature, 
> CreateVisibleSignature, CreateVisibleSignature2, and others).



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to