diff options
author | MS <ms@taler.net> | 2023-10-18 12:36:45 +0200 |
---|---|---|
committer | MS <ms@taler.net> | 2023-10-18 12:36:45 +0200 |
commit | 6f8d453230a17eff62d760e7ef442433923f8ac5 (patch) | |
tree | f18ea0b7e6351883b8e3f7f870d6341331b93fdd | |
parent | 40ee7cb79813c524fd622ac9d61990f447fd38d3 (diff) | |
download | libeufin-6f8d453230a17eff62d760e7ef442433923f8ac5.tar.gz libeufin-6f8d453230a17eff62d760e7ef442433923f8ac5.tar.bz2 libeufin-6f8d453230a17eff62d760e7ef442433923f8ac5.zip |
formatting the bank keys fingerprints
-rw-r--r-- | nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 30 | ||||
-rw-r--r-- | nexus/src/test/kotlin/Ebics.kt | 3 | ||||
-rw-r--r-- | nexus/src/test/kotlin/Keys.kt | 12 |
3 files changed, 31 insertions, 14 deletions
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt index 770945b7..8416cc4b 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt @@ -55,6 +55,7 @@ import net.taler.wallet.crypto.Base32Crockford import tech.libeufin.nexus.ebics.* import tech.libeufin.util.* import tech.libeufin.util.ebics_h004.EbicsTypes +import java.io.StringWriter import java.security.interfaces.RSAPrivateCrtKey import java.security.interfaces.RSAPublicKey import java.time.Instant @@ -359,6 +360,20 @@ enum class KeysOrderType { } /** + * @return the "this" string with a space every two characters. + */ +fun String.spaceEachTwo() = + buildString { + this@spaceEachTwo.forEachIndexed { pos, c -> + when { + (pos == 0) -> this.append(c) + (pos % 2 == 0) -> this.append(" $c") + else -> this.append(c) + } + } + } + +/** * Asks the user to accept the bank public keys. * * @param bankKeys bank public keys, in format stored on disk. @@ -368,8 +383,8 @@ fun askUserToAcceptKeys(bankKeys: BankPublicKeysFile): Boolean { val encHash = CryptoUtil.getEbicsPublicKeyHash(bankKeys.bank_encryption_public_key).toHexString() val authHash = CryptoUtil.getEbicsPublicKeyHash(bankKeys.bank_authentication_public_key).toHexString() println("Bank has the following keys, type 'yes, accept' to accept it") - println("Encryption key: $encHash") - println("Authentication key: $authHash") + println("Encryption key: ${encHash.spaceEachTwo()}") + println("Authentication key: ${authHash.spaceEachTwo()}") val userResponse: String? = readlnOrNull() if (userResponse != "yes, accept") return true @@ -541,11 +556,11 @@ private fun extractConfig(configFile: String?): EbicsSetupConfig { private fun findIban(maybeList: List<EbicsTypes.AccountInfo>?): String? { if (maybeList == null) { - logger.warn("Bank did not give any account list for us.") + logger.warn("Looking for IBAN: bank did not give any account list for us.") return null } if (maybeList.size != 1) { - logger.warn("Bank gave account list, but it was not a singleton.") + logger.warn("Looking for IBAN: bank gave account list, but it was not a singleton.") return null } val accountNumberList = maybeList[0].accountNumberList @@ -561,11 +576,11 @@ private fun findIban(maybeList: List<EbicsTypes.AccountInfo>?): String? { } private fun findBic(maybeList: List<EbicsTypes.AccountInfo>?): String? { if (maybeList == null) { - logger.warn("Bank did not give any account list for us.") + logger.warn("Looking for BIC: bank did not give any account list for us.") return null } if (maybeList.size != 1) { - logger.warn("Bank gave account list, but it was not a singleton.") + logger.warn("Looking for BIC: bank gave account list, but it was not a singleton.") return null } val bankCodeList = maybeList[0].bankCodeList @@ -578,7 +593,6 @@ private fun findBic(maybeList: List<EbicsTypes.AccountInfo>?): String? { return null } return maybeExtractBic(bankCodeList) - } /** @@ -715,7 +729,7 @@ class EbicsSetup: CliktCommand() { logger.warn("Bank did not show any IBAN for us, defaulting to the one we configured.") return@iban cfg.accountNumber }, bank_code = foundBic ?: run bic@ { - logger.warn("Bank did not show any BIC for us, it remains null.") + logger.warn("Bank did not show any BIC for us, setting it as null.") return@bic null } ) if (!syncJsonToDisk(accountMetaData, cfg.bankAccountMetadataFilename)) { diff --git a/nexus/src/test/kotlin/Ebics.kt b/nexus/src/test/kotlin/Ebics.kt index ee515a17..c921e007 100644 --- a/nexus/src/test/kotlin/Ebics.kt +++ b/nexus/src/test/kotlin/Ebics.kt @@ -101,8 +101,7 @@ class PostFinance { cfg, keys, HttpClient(), - KeysOrderType.HPB, - autoAcceptBankKeys = true + KeysOrderType.HPB )) } } diff --git a/nexus/src/test/kotlin/Keys.kt b/nexus/src/test/kotlin/Keys.kt index e79d385b..db598d44 100644 --- a/nexus/src/test/kotlin/Keys.kt +++ b/nexus/src/test/kotlin/Keys.kt @@ -2,13 +2,17 @@ import org.junit.Test import tech.libeufin.nexus.* import tech.libeufin.util.CryptoUtil import java.io.File -import kotlin.test.assertFalse -import kotlin.test.assertNotNull -import kotlin.test.assertNull -import kotlin.test.assertTrue +import kotlin.test.* class PublicKeys { + // Tests intermittent spaces in public keys fingerprint. + @Test + fun splitTest() { + assertEquals("0099887766".spaceEachTwo(), "00 99 88 77 66") // even + assertEquals("ZZYYXXWWVVU".spaceEachTwo(), "ZZ YY XX WW VV U") // odd + } + // Tests loading the bank public keys from disk. @Test fun loadBankKeys() { |