commit 5ce5347e053d1222a9ac929de2f5373dd22337ad
parent 32d23aef89e4e82f99a320327675548b1a7ddb49
Author: Antoine A <>
Date: Tue, 26 Mar 2024 20:03:28 +0100
Improve testbench and simplify EbicsKeyMng
Diffstat:
3 files changed, 37 insertions(+), 43 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSetup.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSetup.kt
@@ -110,14 +110,14 @@ suspend fun doKeysRequestAndUpdateState(
orderType: KeysOrderType
) {
logger.info("Doing key request ${orderType.name}")
- val impl = Ebics3KeyMng(cfg, privs)
+ val impl = EbicsKeyMng(cfg, privs)
val req = when(orderType) {
KeysOrderType.INI -> impl.INI()
KeysOrderType.HIA -> impl.HIA()
KeysOrderType.HPB -> impl.HPB()
}
val xml = client.postToBank(cfg.hostBaseUrl, req, "$orderType")
- val resp = Ebics3KeyMng.parseResponse(xml, privs.encryption_private_key)
+ val resp = EbicsKeyMng.parseResponse(xml, privs.encryption_private_key)
when (orderType) {
KeysOrderType.INI, KeysOrderType.HIA -> {
@@ -140,7 +140,7 @@ suspend fun doKeysRequestAndUpdateState(
val orderData = requireNotNull(orderData) {
"HPB: missing order data"
}
- val (authPub, encPub) = Ebics3KeyMng.parseHpbOrder(orderData)
+ val (authPub, encPub) = EbicsKeyMng.parseHpbOrder(orderData)
val bankKeys = BankPublicKeysFile(
bank_authentication_public_key = authPub,
bank_encryption_public_key = encPub,
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsKeyMng.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsKeyMng.kt
@@ -34,15 +34,15 @@ import javax.xml.datatype.DatatypeFactory
import java.security.interfaces.*
/** EBICS protocol for key management */
-class Ebics3KeyMng(
+class EbicsKeyMng(
private val cfg: EbicsSetupConfig,
private val clientKeys: ClientPrivateKeysFile
) {
fun INI(): ByteArray {
- val inner = XMLOrderData(cfg, "ns2:SignaturePubKeyOrderData", "http://www.ebics.org/S001") {
- el("ns2:SignaturePubKeyInfo") {
+ val inner = XMLOrderData(cfg, "SignaturePubKeyOrderData", "http://www.ebics.org/S001") {
+ el("SignaturePubKeyInfo") {
RSAKeyXml(clientKeys.signature_private_key)
- el("ns2:SignatureVersion", "A006")
+ el("SignatureVersion", "A006")
}
}
val doc = request("ebicsUnsecuredRequest") {
@@ -66,14 +66,14 @@ class Ebics3KeyMng(
}
fun HIA(): ByteArray {
- val inner = XMLOrderData(cfg, "ns2:HIARequestOrderData", "urn:org:ebics:H004") {
- el("ns2:AuthenticationPubKeyInfo") {
+ val inner = XMLOrderData(cfg, "HIARequestOrderData", "urn:org:ebics:H004") {
+ el("AuthenticationPubKeyInfo") {
RSAKeyXml(clientKeys.authentication_private_key)
- el("ns2:AuthenticationVersion", "X002")
+ el("AuthenticationVersion", "X002")
}
- el("ns2:EncryptionPubKeyInfo") {
+ el("EncryptionPubKeyInfo") {
RSAKeyXml(clientKeys.encryption_private_key)
- el("ns2:EncryptionVersion", "E002")
+ el("EncryptionVersion", "E002")
}
}
val doc = request("ebicsUnsecuredRequest") {
@@ -135,7 +135,7 @@ class Ebics3KeyMng(
}
private fun XmlBuilder.RSAKeyXml(key: RSAPrivateCrtKey) {
- el("ns2:PubKeyValue") {
+ el("PubKeyValue") {
el("ds:RSAKeyValue") {
el("ds:Modulus", key.modulus.encodeBase64())
el("ds:Exponent", key.publicExponent.encodeBase64())
@@ -146,10 +146,10 @@ class Ebics3KeyMng(
private fun XMLOrderData(cfg: EbicsSetupConfig, name: String, schema: String, build: XmlBuilder.() -> Unit): String {
return XmlBuilder.toBytes(name) {
attr("xmlns:ds", "http://www.w3.org/2000/09/xmldsig#")
- attr("xmlns:ns2", schema)
+ attr("xmlns", schema)
build()
- el("ns2:PartnerID", cfg.ebicsPartnerId)
- el("ns2:UserID", cfg.ebicsUserId)
+ el("PartnerID", cfg.ebicsPartnerId)
+ el("UserID", cfg.ebicsUserId)
}.inputStream().deflate().encodeBase64()
}
diff --git a/testbench/src/main/kotlin/Main.kt b/testbench/src/main/kotlin/Main.kt
@@ -41,6 +41,10 @@ fun step(name: String) {
println("\u001b[35m$name\u001b[0m")
}
+fun msg(msg: String) {
+ println("\u001b[33m$msg\u001b[0m")
+}
+
fun ask(question: String): String? {
print("\u001b[;1m$question\u001b[0m")
System.out.flush()
@@ -138,12 +142,14 @@ class Cli : CliktCommand("Run integration tests on banks provider") {
put("status", "Fetch CustomerPaymentStatusReport", "ebics-fetch $ebicsFlags status")
put("notification", "Fetch BankToCustomerDebitCreditNotification", "ebics-fetch $ebicsFlags notification")
put("submit", "Submit pending transactions", "ebics-submit $ebicsFlags")
- if (kind.test) {
- put("reset-keys", suspend {
+ put("reset-keys", suspend {
+ if (kind.test) {
clientKeysPath.deleteIfExists()
- bankKeysPath.deleteIfExists()
- Unit
- })
+ }
+ bankKeysPath.deleteIfExists()
+ Unit
+ })
+ if (kind.test) {
put("tx", suspend {
step("Submit one transaction")
nexusCmd.run("initiate-payment $flags \"$payto&amount=CHF:42&message=single%20transaction%20test\"")
@@ -168,41 +174,29 @@ class Cli : CliktCommand("Run integration tests on banks provider") {
})
}
}
-
while (true) {
- // EBICS setup
- while (true) {
- var clientKeys = loadClientKeys(clientKeysPath)
- var bankKeys = loadBankKeys(bankKeysPath)
- if (!kind.test && clientKeys == null) {
- throw Exception("Clients keys are required to run netzbon tests")
- } else if (clientKeys == null || !clientKeys.submitted_ini) {
- step("Run INI and HIA order")
- } else if (!clientKeys.submitted_hia) {
- step("Run HIA order")
- } else if (bankKeys == null || !bankKeys.accepted) {
- step("Run HPB order")
- if (kind.test)
- ask("Got to ${kind.settings} and click on 'Activate EBICS user'.\nPress Enter when done>")
- } else {
- break
- }
+ var clientKeys = loadClientKeys(clientKeysPath)
+ var bankKeys = loadBankKeys(bankKeysPath)
+ if (!kind.test && clientKeys == null) {
+ throw Exception("Clients keys are required to run netzbon tests")
+ } else if (clientKeys == null || !clientKeys.submitted_ini || !clientKeys.submitted_hia || bankKeys == null || !bankKeys.accepted) {
+ step("Run EBICS setup")
if (!nexusCmd.run("ebics-setup --auto-accept-keys $flags")) {
clientKeys = loadClientKeys(clientKeysPath)
if (kind.test) {
if (clientKeys == null || !clientKeys.submitted_ini || !clientKeys.submitted_hia) {
- ask("Got to ${kind.settings} and click on 'Reset EBICS user'.\nPress Enter when done>")
+ msg("Got to ${kind.settings} and click on 'Reset EBICS user'")
} else {
- ask("Got to ${kind.settings} and click on 'Activate EBICS user'.\nPress Enter when done>")
+ msg("Got to ${kind.settings} and click on 'Activate EBICS user'")
}
} else {
- ask("Activate your keys at your bank.\nPress Enter when done>")
+ msg("Activate your keys at your bank")
}
}
}
-
val arg = ask("testbench> ")!!.trim()
if (arg == "exit") break
+ if (arg == "") continue
val cmd = cmds[arg]
if (cmd != null) {
cmd()