Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ECDSA support to PdfPKCS7 #682

Merged
merged 1 commit into from
May 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions openpdf/src/main/java/com/lowagie/text/pdf/PdfPKCS7.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public class PdfPKCS7 {
private static final String ID_PKCS7_SIGNED_DATA = "1.2.840.113549.1.7.2";
private static final String ID_RSA = "1.2.840.113549.1.1.1";
private static final String ID_DSA = "1.2.840.10040.4.1";
private static final String ID_ECDSA = "1.2.840.10045.2.1";
private static final String ID_CONTENT_TYPE = "1.2.840.113549.1.9.3";
private static final String ID_MESSAGE_DIGEST = "1.2.840.113549.1.9.4";
private static final String ID_SIGNING_TIME = "1.2.840.113549.1.9.5";
Expand Down Expand Up @@ -225,6 +226,7 @@ public class PdfPKCS7 {
algorithmNames.put("1.3.36.3.3.1.3", "RSA");
algorithmNames.put("1.3.36.3.3.1.2", "RSA");
algorithmNames.put("1.3.36.3.3.1.4", "RSA");
algorithmNames.put(ID_ECDSA, "ECDSA");

allowedDigests.put("MD5", "1.2.840.113549.2.5");
allowedDigests.put("MD2", "1.2.840.113549.2.2");
Expand Down Expand Up @@ -611,6 +613,8 @@ public PdfPKCS7(PrivateKey privKey, Certificate[] certChain, CRL[] crlList,
digestEncryptionAlgorithm = ID_RSA;
} else if (digestEncryptionAlgorithm.equals("DSA")) {
digestEncryptionAlgorithm = ID_DSA;
} else if (digestEncryptionAlgorithm.equals("EC")) {
digestEncryptionAlgorithm = ID_ECDSA;
} else {
throw new NoSuchAlgorithmException(
MessageLocalization.getComposedMessage("unknown.key.algorithm.1",
Expand Down Expand Up @@ -1195,6 +1199,8 @@ public void setExternalDigest(byte[] digest, byte[] RSAdata,
this.digestEncryptionAlgorithm = ID_RSA;
} else if (digestEncryptionAlgorithm.equals("DSA")) {
this.digestEncryptionAlgorithm = ID_DSA;
} else if (digestEncryptionAlgorithm.equals("EC")) {
digestEncryptionAlgorithm = ID_ECDSA;
} else
throw new ExceptionConverter(new NoSuchAlgorithmException(
MessageLocalization.getComposedMessage("unknown.key.algorithm.1",
Expand Down