From 4767f6924dc3343d4399211c8dc4d74be9b6fc90 Mon Sep 17 00:00:00 2001 From: Richard Kosegi Date: Sun, 28 Apr 2024 08:35:21 +0200 Subject: [PATCH] Add support for ed25519 ssh keys Let's use bouncycastle lib to handle public key encoding Fixes #79 --- pom.xml | 5 +++ .../jenkins/plugins/hetzner/Helper.java | 35 ++++++++++++------- .../jenkins/plugins/hetzner/HelperTest.java | 9 ++++- src/test/resources/id_ed25519 | 7 ++++ src/test/resources/id_ed25519.pub | 1 + 5 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 src/test/resources/id_ed25519 create mode 100644 src/test/resources/id_ed25519.pub diff --git a/pom.xml b/pom.xml index e3aadae..ecaa177 100644 --- a/pom.xml +++ b/pom.xml @@ -119,6 +119,11 @@ com.google.guava guava + + org.jenkins-ci.plugins + bouncycastle-api + 2.20 + cloud.dnation.integration hetzner-cloud-client-java diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/Helper.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/Helper.java index 23e38ee..c15283d 100644 --- a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/Helper.java +++ b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/Helper.java @@ -26,17 +26,20 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.experimental.UtilityClass; +import net.i2p.crypto.eddsa.EdDSAPublicKey; +import org.bouncycastle.crypto.params.AsymmetricKeyParameter; +import org.bouncycastle.crypto.params.Ed25519PublicKeyParameters; +import org.bouncycastle.crypto.params.RSAKeyParameters; +import org.bouncycastle.crypto.util.OpenSSHPublicKeyUtil; import org.slf4j.Logger; import retrofit2.Response; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; import java.io.IOException; import java.io.PrintStream; -import java.nio.charset.StandardCharsets; import java.security.KeyPair; +import java.security.PublicKey; import java.security.interfaces.RSAPublicKey; import java.time.Duration; import java.time.LocalDateTime; @@ -60,6 +63,7 @@ public class Helper { private static final Pattern LABEL_VALUE_RE = Pattern.compile("^(?![0-9]+$)(?!-)[a-zA-Z0-9-_.]{0,63}(?