libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit 4bcafa4eb29eceec465edeaa2f4ec80681c529fd
parent d0973f02ba3f2d7f87582439e9b90dfe84eecaa6
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Mon, 11 Nov 2019 21:13:26 +0100

Ack of HTD download order.

Extraction of actual data still missing.

Diffstat:
Mnexus/src/main/kotlin/Main.kt | 51++++++++++++++++++++++++++++++++++++++++++++++++---
Msandbox/src/main/kotlin/tech/libeufin/schema/ebics_h004/EbicsRequest.kt | 2+-
2 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/nexus/src/main/kotlin/Main.kt b/nexus/src/main/kotlin/Main.kt @@ -263,7 +263,7 @@ fun main() { get("/ebics/subscribers/{id}/sendHtd") { val id = expectId(call.parameters["id"]) - val (url, body, encPrivBlob) = transaction { + val (url, requestDoc, encPrivBlob) = transaction { val subscriber = EbicsSubscriberEntity.findById(id) ?: throw SubscriberNotFoundError(HttpStatusCode.NotFound) val request = EbicsRequest().apply { version = "H004" @@ -323,8 +323,53 @@ fun main() { Triple(subscriber.ebicsURL, hpbDoc, subscriber.encryptionPrivateKey.toByteArray()) } - val response = client.postToBank<EbicsResponse>(url, body) - print("HTD response: " + XMLUtil.convertJaxbToString<EbicsResponse>(response.value)) + val response = client.postToBank<EbicsResponse>(url, requestDoc) + logger.debug("HTD response: " + XMLUtil.convertJaxbToString<EbicsResponse>(response.value)) + + if (response.value.body.returnCode.value != "000000") { + throw EbicsError(response.value.body.returnCode.value) + } + + val ackRequestDoc = transaction { + val subscriber = EbicsSubscriberEntity.findById(id) ?: throw SubscriberNotFoundError(HttpStatusCode.NotFound) + + val ackRequest = EbicsRequest().apply { + header = EbicsRequest.Header().apply { + version = "H004" + revision = 1 + authenticate = true + static = EbicsRequest.StaticHeaderType().apply { + hostID = subscriber.hostID + transactionID = response.value.header._static.transactionID + } + mutable = EbicsRequest.MutableHeader().apply { + transactionPhase = EbicsTypes.TransactionPhaseType.RECEIPT + } + authSignature = SignatureType() + } + body = EbicsRequest.Body().apply { + transferReceipt = EbicsRequest.TransferReceipt().apply { + authenticate = true + receiptCode = 0 // always true at this point. + } + } + } + + val ackRequestDoc = XMLUtil.convertJaxbToDocument(ackRequest) + XMLUtil.signEbicsDocument( + ackRequestDoc, + CryptoUtil.loadRsaPrivateKey(subscriber.authenticationPrivateKey.toByteArray()) + ) + + ackRequestDoc + } + + val ackResponse = client.postToBank<EbicsResponse>(url, ackRequestDoc) + logger.debug("HTD final response: " + XMLUtil.convertJaxbToString<EbicsResponse>(response.value)) + + if (ackResponse.value.body.returnCode.value != "000000") { + throw EbicsError(response.value.body.returnCode.value) + } call.respond( HttpStatusCode.NotImplemented, diff --git a/sandbox/src/main/kotlin/tech/libeufin/schema/ebics_h004/EbicsRequest.kt b/sandbox/src/main/kotlin/tech/libeufin/schema/ebics_h004/EbicsRequest.kt @@ -61,7 +61,7 @@ class EbicsRequest { @get:XmlElement(name = "Nonce", type = String::class) @get:XmlJavaTypeAdapter(HexBinaryAdapter::class) @get:XmlSchemaType(name = "hexBinary") - lateinit var nonce: ByteArray + var nonce: ByteArray? = null /** * Present only in the initialization phase.