From e2a6cceafdbd08e3d33d176c3700230d24cb6b95 Mon Sep 17 00:00:00 2001 From: hstyi Date: Sun, 30 Mar 2025 15:52:10 +0800 Subject: [PATCH] chore: upgrade jgit version --- build.gradle.kts | 1 + gradle/libs.versions.toml | 4 +++- .../kotlin/app/termora/keymgr/KeyManagerPanel.kt | 15 +++------------ .../termora/keymgr/OhKeyPairKeyPairProvider.kt | 7 +++---- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index a3b8b3d..534585c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -105,6 +105,7 @@ dependencies { implementation(libs.jgit) implementation(libs.jgit.sshd) { exclude(group = "*", module = "sshd-osgi") } implementation(libs.jgit.agent) { exclude(group = "*", module = "sshd-osgi") } + implementation(libs.eddsa) implementation(libs.jnafilechooser) implementation(libs.xodus.vfs) implementation(libs.xodus.openAPI) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0c48305..50643d8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -26,7 +26,7 @@ jsch = "0.2.21" okhttp = "4.12.0" sshj = "0.39.0" sshd-core = "2.14.0" -jgit = "7.1.0.202411261347-r" +jgit = "7.2.0.202503040940-r" commonmark = "0.24.0" jnafilechooser = "1.1.2" xodus = "2.0.1" @@ -39,6 +39,7 @@ mixpanel = "1.5.3" jSerialComm = "2.11.0" ini4j = "0.5.5-2" restart4j = "0.0.1" +eddsa = "0.3.0" [libraries] kotlinx-coroutines-swing = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-swing", version.ref = "kotlinx-coroutines" } @@ -91,6 +92,7 @@ delight-rhino-sandbox = { module = "org.javadelight:delight-rhino-sandbox", vers colorpicker = { module = "org.drjekyll:colorpicker", version.ref = "colorpicker" } mixpanel = { module = "com.mixpanel:mixpanel-java", version.ref = "mixpanel" } jSerialComm = { module = "com.fazecast:jSerialComm", version.ref = "jSerialComm" } +eddsa = { module = "net.i2p.crypto:eddsa", version.ref = "eddsa" } [plugins] kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } diff --git a/src/main/kotlin/app/termora/keymgr/KeyManagerPanel.kt b/src/main/kotlin/app/termora/keymgr/KeyManagerPanel.kt index b624b71..fe52ea2 100644 --- a/src/main/kotlin/app/termora/keymgr/KeyManagerPanel.kt +++ b/src/main/kotlin/app/termora/keymgr/KeyManagerPanel.kt @@ -1,7 +1,6 @@ package app.termora.keymgr import app.termora.* -import app.termora.AES.decodeBase64 import app.termora.actions.AnAction import app.termora.actions.AnActionEvent import app.termora.native.FileChooser @@ -13,7 +12,6 @@ import com.formdev.flatlaf.ui.FlatTextBorder import com.formdev.flatlaf.util.SystemInfo import com.jgoodies.forms.builder.FormBuilder import com.jgoodies.forms.layout.FormLayout -import net.i2p.crypto.eddsa.EdDSAPublicKey import org.apache.commons.codec.binary.Base64 import org.apache.commons.io.IOUtils import org.apache.commons.io.file.PathUtils @@ -33,7 +31,6 @@ import java.io.File import java.nio.charset.StandardCharsets import java.nio.file.Files import java.security.KeyPair -import java.security.spec.X509EncodedKeySpec import java.util.* import java.util.zip.ZipEntry import java.util.zip.ZipOutputStream @@ -313,15 +310,9 @@ class KeyManagerPanel : JPanel(BorderLayout()) { nameTextField.text = ohKeyPair.name remarkTextField.text = ohKeyPair.remark val baos = ByteArrayOutputStream() - if (ohKeyPair.type == "RSA") { - OpenSSHKeyPairResourceWriter.INSTANCE - .writePublicKey(RSA.generatePublic(ohKeyPair.publicKey.decodeBase64()), null, baos) - } else if (ohKeyPair.type == "ED25519") { - OpenSSHKeyPairResourceWriter.INSTANCE.writePublicKey( - EdDSAPublicKey(X509EncodedKeySpec(ohKeyPair.publicKey.decodeBase64())), - null, baos - ) - } + val keyPair = OhKeyPairKeyPairProvider.generateKeyPair(ohKeyPair) + OpenSSHKeyPairResourceWriter.INSTANCE + .writePublicKey(keyPair.public, null, baos) publicKeyTextArea.text = baos.toString() savePublicKeyBtn.isEnabled = true } else { diff --git a/src/main/kotlin/app/termora/keymgr/OhKeyPairKeyPairProvider.kt b/src/main/kotlin/app/termora/keymgr/OhKeyPairKeyPairProvider.kt index d3f2447..f6e67c0 100644 --- a/src/main/kotlin/app/termora/keymgr/OhKeyPairKeyPairProvider.kt +++ b/src/main/kotlin/app/termora/keymgr/OhKeyPairKeyPairProvider.kt @@ -2,10 +2,9 @@ package app.termora.keymgr import app.termora.AES.decodeBase64 import app.termora.RSA -import net.i2p.crypto.eddsa.EdDSAPrivateKey -import net.i2p.crypto.eddsa.EdDSAPublicKey import org.apache.sshd.common.keyprovider.AbstractResourceKeyPairProvider import org.apache.sshd.common.session.SessionContext +import org.apache.sshd.common.util.security.eddsa.Ed25519PublicKeyDecoder import org.slf4j.LoggerFactory import java.security.Key import java.security.KeyPair @@ -25,7 +24,7 @@ class OhKeyPairKeyPairProvider(private val id: String) : AbstractResourceKeyPair val publicKey = cache.getOrPut(ohKeyPair.publicKey) { when (ohKeyPair.type) { "RSA" -> RSA.generatePublic(ohKeyPair.publicKey.decodeBase64()) - "ED25519" -> EdDSAPublicKey(X509EncodedKeySpec(ohKeyPair.publicKey.decodeBase64())) + "ED25519" -> Ed25519PublicKeyDecoder.INSTANCE.generatePublicKey((X509EncodedKeySpec(ohKeyPair.publicKey.decodeBase64()))) else -> throw UnsupportedOperationException("${ohKeyPair.type} is not supported") } } as PublicKey @@ -33,7 +32,7 @@ class OhKeyPairKeyPairProvider(private val id: String) : AbstractResourceKeyPair val privateKey = cache.getOrPut(ohKeyPair.privateKey) { when (ohKeyPair.type) { "RSA" -> RSA.generatePrivate(ohKeyPair.privateKey.decodeBase64()) - "ED25519" -> EdDSAPrivateKey(PKCS8EncodedKeySpec(ohKeyPair.privateKey.decodeBase64())) + "ED25519" -> Ed25519PublicKeyDecoder.INSTANCE.generatePrivateKey(PKCS8EncodedKeySpec(ohKeyPair.privateKey.decodeBase64())) else -> throw UnsupportedOperationException("${ohKeyPair.type} is not supported") } } as PrivateKey