From 8d13ce519fb4ae33ba4773a6acfcbcc2759a5bb2 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Wed, 10 Feb 2021 13:00:30 +0530 Subject: Update to SSHJ 0.31.0 (#1314) Co-authored-by: Fabian Henneke (cherry picked from commit 7fbe4be71143e0d57a14d19f66496213d8248b1d) --- .../com/zeapo/pwdstore/git/sshj/OpenKeychainKeyProvider.kt | 12 ++++++++++-- .../git/sshj/OpenKeychainWrappedKeyAlgorithmFactory.kt | 5 ++++- app/src/main/java/com/zeapo/pwdstore/git/sshj/SshjConfig.kt | 12 +++++++++--- 3 files changed, 23 insertions(+), 6 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/com/zeapo/pwdstore/git/sshj/OpenKeychainKeyProvider.kt b/app/src/main/java/com/zeapo/pwdstore/git/sshj/OpenKeychainKeyProvider.kt index 97774d92..773b466c 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/sshj/OpenKeychainKeyProvider.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/sshj/OpenKeychainKeyProvider.kt @@ -8,15 +8,18 @@ import android.app.PendingIntent import android.content.Intent import androidx.activity.result.IntentSenderRequest import androidx.core.content.edit +import androidx.lifecycle.lifecycleScope import com.github.ajalt.timberkt.d import com.zeapo.pwdstore.utils.OPENPGP_PROVIDER import com.zeapo.pwdstore.utils.PreferenceKeys import com.zeapo.pwdstore.utils.sharedPrefs import java.io.Closeable import java.security.PublicKey +import java.security.interfaces.ECKey import kotlin.coroutines.resume import kotlin.coroutines.suspendCoroutine import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import net.schmizz.sshj.common.DisconnectReason import net.schmizz.sshj.common.KeyType @@ -175,11 +178,16 @@ class OpenKeychainKeyProvider private constructor(val activity: ContinuationCont } override fun getAlgorithm() = publicKey!!.algorithm + override fun getParams() = (publicKey as? ECKey)?.params } } override fun close() { - activity.continueAfterUserInteraction.unregister() + activity.lifecycleScope.launch { + withContext(Dispatchers.Main) { + activity.continueAfterUserInteraction.unregister() + } + } sshServiceConnection.disconnect() } @@ -187,5 +195,5 @@ class OpenKeychainKeyProvider private constructor(val activity: ContinuationCont override fun getPublic() = publicKey - override fun getType() = KeyType.fromKey(publicKey) + override fun getType(): KeyType = KeyType.fromKey(publicKey) } diff --git a/app/src/main/java/com/zeapo/pwdstore/git/sshj/OpenKeychainWrappedKeyAlgorithmFactory.kt b/app/src/main/java/com/zeapo/pwdstore/git/sshj/OpenKeychainWrappedKeyAlgorithmFactory.kt index 97b587fd..06b33af4 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/sshj/OpenKeychainWrappedKeyAlgorithmFactory.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/sshj/OpenKeychainWrappedKeyAlgorithmFactory.kt @@ -7,13 +7,16 @@ package com.zeapo.pwdstore.git.sshj import com.hierynomus.sshj.key.KeyAlgorithm import java.io.ByteArrayOutputStream import java.security.PrivateKey +import java.security.interfaces.ECKey +import java.security.interfaces.ECPrivateKey +import java.security.spec.ECParameterSpec import kotlinx.coroutines.runBlocking import net.schmizz.sshj.common.Buffer import net.schmizz.sshj.common.Factory import net.schmizz.sshj.signature.Signature import org.openintents.ssh.authentication.SshAuthenticationApi -interface OpenKeychainPrivateKey : PrivateKey { +interface OpenKeychainPrivateKey : PrivateKey, ECKey { suspend fun sign(challenge: ByteArray, hashAlgorithm: Int): ByteArray diff --git a/app/src/main/java/com/zeapo/pwdstore/git/sshj/SshjConfig.kt b/app/src/main/java/com/zeapo/pwdstore/git/sshj/SshjConfig.kt index cd280db5..c6ff0b57 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/sshj/SshjConfig.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/sshj/SshjConfig.kt @@ -9,6 +9,7 @@ import com.github.ajalt.timberkt.d import com.github.michaelbull.result.runCatching import com.hierynomus.sshj.key.KeyAlgorithms import com.hierynomus.sshj.transport.cipher.BlockCiphers +import com.hierynomus.sshj.transport.cipher.GcmCiphers import com.hierynomus.sshj.transport.kex.ExtInfoClientFactory import com.hierynomus.sshj.transport.mac.Macs import com.hierynomus.sshj.userauth.keyprovider.OpenSSHKeyV1KeyFile @@ -214,6 +215,9 @@ class SshjConfig : ConfigImpl() { keyExchangeFactories = listOf( Curve25519SHA256.Factory(), FactoryLibSsh(), + ECDHNistP.Factory521(), + ECDHNistP.Factory384(), + ECDHNistP.Factory256(), DHGexSHA256.Factory(), // Sends "ext-info-c" with the list of key exchange algorithms. This is needed to get // rsa-sha2-* key types to work with some servers (e.g. GitHub). @@ -225,12 +229,12 @@ class SshjConfig : ConfigImpl() { keyAlgorithms = listOf( KeyAlgorithms.SSHRSACertV01(), KeyAlgorithms.EdDSA25519(), - KeyAlgorithms.RSASHA512(), - KeyAlgorithms.RSASHA256(), - KeyAlgorithms.SSHRSA(), KeyAlgorithms.ECDSASHANistp521(), KeyAlgorithms.ECDSASHANistp384(), KeyAlgorithms.ECDSASHANistp256(), + KeyAlgorithms.RSASHA512(), + KeyAlgorithms.RSASHA256(), + KeyAlgorithms.SSHRSA(), ).map { OpenKeychainWrappedKeyAlgorithmFactory(it) } @@ -253,6 +257,8 @@ class SshjConfig : ConfigImpl() { private fun initCipherFactories() { cipherFactories = listOf( + GcmCiphers.AES128GCM(), + GcmCiphers.AES256GCM(), BlockCiphers.AES256CTR(), BlockCiphers.AES192CTR(), BlockCiphers.AES128CTR(), -- cgit v1.2.3