diff --git a/app/build.gradle b/app/build.gradle index ae2bed1b4..85554781e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -93,7 +93,8 @@ dependencies { implementation 'com.android.support:multidex:1.0.3' implementation 'me.toptas.fancyshowcase:fancyshowcaseview:1.3.3' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'org.connectbot:sshlib:2.2.9' + implementation 'org.connectbot:sshlib:2.2.23' + implementation 'net.i2p.crypto:eddsa:0.3.0' implementation "androidx.core:core-splashscreen:1.0.1" def lifecycle_version = "2.8.7" @@ -109,6 +110,6 @@ repositories { maven { url "https://maven.aliyun.com/repository/jcenter" } } -android.sourceSets.all { +android.sourceSets.configureEach { java.srcDir("src/$name/kotlin") } diff --git a/app/local.properties b/app/local.properties new file mode 100644 index 000000000..3120d00ee --- /dev/null +++ b/app/local.properties @@ -0,0 +1,8 @@ +## This file must *NOT* be checked into Version Control Systems, +# as it contains information specific to your local configuration. +# +# Location of the SDK. This is only used by Gradle. +# For customization when using a Version Control System, please read the +# header note. +#Fri Dec 13 17:45:08 EAT 2024 +sdk.dir=/Users/gideonokuro/Library/Android/sdk diff --git a/app/src/main/kotlin/io/treehouses/remote/bases/BaseSSH.kt b/app/src/main/kotlin/io/treehouses/remote/bases/BaseSSH.kt index 10b63f8aa..1093dce3a 100644 --- a/app/src/main/kotlin/io/treehouses/remote/bases/BaseSSH.kt +++ b/app/src/main/kotlin/io/treehouses/remote/bases/BaseSSH.kt @@ -173,7 +173,7 @@ open class BaseSSH : ConnectionMonitor, InteractiveCallback, AuthAgentCallback { private fun onHostKeyChanged(algorithmName: String, fingerprint: String) { val header = String.format("@ %s @", - manager!!.res!!.getString(R.string.host_verification_failure_warning_header)) + manager!!.res!!.getString(R.string.host_verification_failure_warning_header)) val atsigns = CharArray(header.length) Arrays.fill(atsigns, '@') val border = String(atsigns) @@ -439,6 +439,10 @@ open class BaseSSH : ConnectionMonitor, InteractiveCallback, AuthAgentCallback { return responses } + fun setUseAuthAgent(useAuthAgent: String) { + this.useAuthAgent = useAuthAgent + } + // fun createHost(uri: Uri): HostBean { // val host = HostBean() // host.protocol = protocolName @@ -457,20 +461,19 @@ open class BaseSSH : ConnectionMonitor, InteractiveCallback, AuthAgentCallback { // return host // } - fun setUseAuthAgent(useAuthAgent: String) { - this.useAuthAgent = useAuthAgent - } - override fun retrieveIdentities(): Map { val pubKeys: MutableMap = HashMap(manager!!.loadedKeypairs.size) for ((key, value) in manager!!.loadedKeypairs) { val pair = value?.pair try { pubKeys[key] = when (pair?.private) { - is RSAPrivateKey -> RSASHA1Verify.encodeSSHRSAPublicKey(pair.public as RSAPublicKey) - is DSAPrivateKey -> DSASHA1Verify.encodeSSHDSAPublicKey(pair.public as DSAPublicKey) - is ECPrivateKey -> ECDSASHA2Verify.encodeSSHECDSAPublicKey(pair.public as ECPublicKey) - is EdDSAPrivateKey -> Ed25519Verify.encodeSSHEd25519PublicKey(pair.public as EdDSAPublicKey) + is RSAPrivateKey -> RSASHA1Verify.get().encodePublicKey(pair.public as RSAPublicKey) + is DSAPrivateKey -> DSASHA1Verify.get().encodePublicKey(pair.public as DSAPublicKey) + is ECPrivateKey -> { + val verifier = ECDSASHA2Verify.getVerifierForKey(pair.public as ECPublicKey) + verifier.encodePublicKey(pair.public as ECPublicKey) + } + is EdDSAPrivateKey -> Ed25519Verify.get().encodePublicKey(pair.public as EdDSAPublicKey) else -> ByteArray(0) } } catch (e: IOException) { diff --git a/app/src/main/kotlin/io/treehouses/remote/ssh/PubKeyUtils.kt b/app/src/main/kotlin/io/treehouses/remote/ssh/PubKeyUtils.kt index 8749310ab..8f9789e53 100644 --- a/app/src/main/kotlin/io/treehouses/remote/ssh/PubKeyUtils.kt +++ b/app/src/main/kotlin/io/treehouses/remote/ssh/PubKeyUtils.kt @@ -232,17 +232,26 @@ object PubKeyUtils { /* * OpenSSH compatibility methods */ - fun convertToOpenSSHFormat(pk: PublicKey, nickName: String) : String { - val rsaKey = if (pk is RSAPublicKey) String(Base64.encode(RSASHA1Verify.encodeSSHRSAPublicKey(pk))) else "" + fun convertToOpenSSHFormat(pk: PublicKey, nickName: String): String { return when (pk) { - is RSAPublicKey -> "ssh-rsa $rsaKey $nickName" - is DSAPublicKey -> "ssh-dss ${String(Base64.encode(DSASHA1Verify.encodeSSHDSAPublicKey(pk)))} $nickName" + is RSAPublicKey -> { + val rsaKey = String(Base64.encode(RSASHA1Verify.get().encodePublicKey(pk))) + "ssh-rsa $rsaKey $nickName" + } + is DSAPublicKey -> { + val dsaKey = String(Base64.encode(DSASHA1Verify.get().encodePublicKey(pk))) + "ssh-dss $dsaKey $nickName" + } is ECPublicKey -> { - val keyType = ECDSASHA2Verify.getCurveName(pk.params.curve.field.fieldSize) - val data = String(Base64.encode(ECDSASHA2Verify.encodeSSHECDSAPublicKey(pk))) - "${ECDSASHA2Verify.ECDSA_SHA2_PREFIX} $keyType $data $nickName" + val verifier = ECDSASHA2Verify.getVerifierForKey(pk) + val keyType = verifier.keyFormat + val data = String(Base64.encode(verifier.encodePublicKey(pk))) + "$keyType $data $nickName" + } + is EdDSAPublicKey -> { + val edKey = String(Base64.encode(Ed25519Verify.get().encodePublicKey(pk))) + "${Ed25519Verify.get().keyFormat} $edKey $nickName" } - is EdDSAPublicKey -> "${Ed25519Verify.ED25519_ID} ${String(Base64.encode(Ed25519Verify.encodeSSHEd25519PublicKey(pk)))} $nickName" else -> throw InvalidKeyException("Unknown Key Type") } } @@ -256,10 +265,10 @@ object PubKeyUtils { fun extractOpenSSHPublic(pair: KeyPair?): ByteArray? { return try { when (val pubKey = pair?.public) { - is RSAPublicKey -> RSASHA1Verify.encodeSSHRSAPublicKey(pubKey) - is DSAPublicKey -> DSASHA1Verify.encodeSSHDSAPublicKey(pubKey) - is ECPublicKey -> ECDSASHA2Verify.encodeSSHECDSAPublicKey(pubKey) - is EdDSAPublicKey -> Ed25519Verify.encodeSSHEd25519PublicKey(pubKey) + is RSAPublicKey -> RSASHA1Verify.get().encodePublicKey(pubKey) + is DSAPublicKey -> DSASHA1Verify.get().encodePublicKey(pubKey) + is ECPublicKey -> ECDSASHA2Verify.getVerifierForKey(pubKey).encodePublicKey(pubKey) + is EdDSAPublicKey -> Ed25519Verify.get().encodePublicKey(pubKey) else -> null } } catch (e: IOException) { diff --git a/build.gradle b/build.gradle index accf7497d..e715dc085 100644 --- a/build.gradle +++ b/build.gradle @@ -3,8 +3,8 @@ buildscript { ext.kotlin_version = '2.1.0' repositories { - jcenter() google() + mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:8.7.2' @@ -24,8 +24,7 @@ allprojects { repositories { google() maven { url "https://jitpack.io" } - jcenter() - + mavenCentral() } }