Skip to content

Migrate to org.bouncycastle.bcpkix-jdk18on #8

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

Merged
merged 1 commit into from
Apr 13, 2025
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@
</dependency>

<dependency>
<groupId>net.i2p.crypto</groupId>
<artifactId>eddsa</artifactId>
<version>0.3.0</version>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
<version>1.78</version>
</dependency>
</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import jakarta.mail.Header;
import jakarta.mail.MessagingException;
import net.i2p.crypto.eddsa.EdDSAPrivateKey;
import net.markenwerk.utils.data.fetcher.BufferedDataFetcher;
import net.markenwerk.utils.data.fetcher.DataFetchException;

import org.bouncycastle.jcajce.interfaces.EdDSAPrivateKey;
import org.eclipse.angus.mail.util.CRLFOutputStream;
import org.eclipse.angus.mail.util.QPEncoderStream;

Expand Down
19 changes: 8 additions & 11 deletions src/main/java/org/simplejavamail/utils/mail/dkim/DomainKey.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.simplejavamail.utils.mail.dkim;

import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Signature;
Expand All @@ -20,12 +20,10 @@
import java.util.StringTokenizer;
import java.util.regex.Pattern;

import net.i2p.crypto.eddsa.EdDSAPublicKey;
import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable;
import net.i2p.crypto.eddsa.spec.EdDSAPublicKeySpec;

import static java.nio.charset.StandardCharsets.UTF_8;

import org.bouncycastle.jcajce.interfaces.EdDSAPublicKey;

/**
* A {@code DomainKey} holds the information about a domain key.
*
Expand Down Expand Up @@ -151,11 +149,10 @@ private RSAPublicKey getRsaPublicKey(String publicKeyTagValue) {

private EdDSAPublicKey getEd25519PublicKey(String publicKeyTagValue) {
try {
KeyFactory keyFactory = KeyFactory.getInstance(KeyPairType.ED25519.getJavaNotation());
EdDSAPublicKeySpec publicKeySpec = new EdDSAPublicKeySpec(Base64.getDecoder().decode(publicKeyTagValue),
EdDSANamedCurveTable.ED_25519_CURVE_SPEC);
return (EdDSAPublicKey) keyFactory.generatePublic(publicKeySpec);
} catch (NoSuchAlgorithmException nsae) {
byte[] keyBytes = Base64.getDecoder().decode(publicKeyTagValue);
KeyFactory keyFactory = KeyFactory.getInstance(KeyPairType.ED25519.getJavaNotation(), "BC");
return (EdDSAPublicKey) keyFactory.generatePublic(new X509EncodedKeySpec(keyBytes));
} catch (NoSuchAlgorithmException | NoSuchProviderException nsae) {
throw new DkimException("Ed25519 algorithm not found by JVM");
} catch (IllegalArgumentException e) {
throw new DkimException("The public key " + publicKeyTagValue + " couldn't be read.", e);
Expand Down Expand Up @@ -297,4 +294,4 @@ private void checkKeyCompatiblilty(PrivateKey privateKey)

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.Arrays;
import java.util.List;

import net.i2p.crypto.eddsa.EdDSASecurityProvider;
import org.bouncycastle.jce.provider.BouncyCastleProvider;

public enum KeyPairType {

Expand All @@ -25,7 +25,7 @@ protected void initialize() {
@Override
protected void initialize() {
if (!initailized) {
Security.addProvider(new EdDSASecurityProvider());
Security.addProvider(new BouncyCastleProvider());
initailized = true;
}
}
Expand Down