From 22ed045ea70658038f0c2b65ce5bc68f56660f26 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Thu, 28 Oct 2021 07:04:29 +0530 Subject: Upgrade dependencies (#1526) * gradle: upgrade all dependencies * github: replace gradle-cache-action with official gradle-build-action * github: update wrapper-validation-action --- .../aps/util/git/sshj/SshjSessionFactory.kt | 30 ++++++++++++++-------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/dev/msfjarvis/aps/util/git/sshj/SshjSessionFactory.kt b/app/src/main/java/dev/msfjarvis/aps/util/git/sshj/SshjSessionFactory.kt index 79438bcc..50c146cc 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/git/sshj/SshjSessionFactory.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/git/sshj/SshjSessionFactory.kt @@ -13,6 +13,8 @@ import java.io.File import java.io.IOException import java.io.InputStream import java.io.OutputStream +import java.security.PublicKey +import java.util.Collections import java.util.concurrent.TimeUnit import kotlin.coroutines.Continuation import kotlin.coroutines.suspendCoroutine @@ -88,19 +90,25 @@ class SshjSessionFactory(private val authMethod: SshAuthMethod, private val host private fun makeTofuHostKeyVerifier(hostKeyFile: File): HostKeyVerifier { if (!hostKeyFile.exists()) { - return HostKeyVerifier { _, _, key -> - val digest = - runCatching { SecurityUtils.getMessageDigest("SHA-256") }.getOrElse { e -> - throw SSHRuntimeException(e) + return object : HostKeyVerifier { + override fun verify(hostname: String?, port: Int, key: PublicKey?): Boolean { + val digest = + runCatching { SecurityUtils.getMessageDigest("SHA-256") }.getOrElse { e -> + throw SSHRuntimeException(e) + } + digest.update(PlainBuffer().putPublicKey(key).compactData) + val digestData = digest.digest() + val hostKeyEntry = "SHA256:${Base64.encodeToString(digestData, Base64.NO_WRAP)}" + logcat(SshjSessionFactory::class.java.simpleName) { + "Trusting host key on first use: $hostKeyEntry" } - digest.update(PlainBuffer().putPublicKey(key).compactData) - val digestData = digest.digest() - val hostKeyEntry = "SHA256:${Base64.encodeToString(digestData, Base64.NO_WRAP)}" - logcat(SshjSessionFactory::class.java.simpleName) { - "Trusting host key on first use: $hostKeyEntry" + hostKeyFile.writeText(hostKeyEntry) + return true + } + + override fun findExistingAlgorithms(hostname: String?, port: Int): MutableList { + return Collections.emptyList() } - hostKeyFile.writeText(hostKeyEntry) - true } } else { val hostKeyEntry = hostKeyFile.readText() -- cgit v1.2.3