commit af3bc2ab7fa1cc3bc01cc310047f7373f852c3ae
parent 5bc798158d8767290ec3a0414be4e8c3c464cc2a
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Thu, 23 Jan 2020 17:13:07 +0100
Nexus extracts CAMT out of C52 response.
Diffstat:
3 files changed, 38 insertions(+), 5 deletions(-)
diff --git a/nexus/src/main/kotlin/Helpers.kt b/nexus/src/main/kotlin/Helpers.kt
@@ -3,12 +3,11 @@ package tech.libeufin.nexus
import io.ktor.client.HttpClient
import io.ktor.client.request.post
import io.ktor.http.HttpStatusCode
-import tech.libeufin.util.getGregorianDate
-import tech.libeufin.util.CryptoUtil
-import tech.libeufin.util.XMLUtil
+import tech.libeufin.util.*
import tech.libeufin.util.ebics_h004.EbicsRequest
+import tech.libeufin.util.ebics_h004.EbicsResponse
+import tech.libeufin.util.ebics_h004.EbicsTypes
import tech.libeufin.util.ebics_s001.UserSignatureData
-import tech.libeufin.util.toByteArray
import java.math.BigInteger
import java.security.PrivateKey
import java.security.SecureRandom
@@ -19,6 +18,29 @@ import javax.xml.bind.JAXBElement
import javax.xml.datatype.DatatypeFactory
import javax.xml.datatype.XMLGregorianCalendar
+
+/**
+ * Wrapper around the lower decryption routine, that takes a EBICS response
+ * object containing a encrypted payload, and return the plain version of it
+ * (including decompression).
+ */
+fun decryptAndDecompressResponse(response: EbicsResponse, privateKey: RSAPrivateCrtKey): ByteArray {
+
+ val er = CryptoUtil.EncryptionResult(
+ response.body.dataTransfer!!.dataEncryptionInfo!!.transactionKey,
+ (response.body.dataTransfer!!.dataEncryptionInfo as EbicsTypes.DataEncryptionInfo)
+ .encryptionPubKeyDigest.value,
+ Base64.getDecoder().decode(response.body.dataTransfer!!.orderData.value)
+ )
+
+ val dataCompr = CryptoUtil.decryptEbicsE002(
+ er,
+ privateKey
+ )
+
+ return EbicsOrderUtil.decodeOrderData(dataCompr)
+}
+
fun createDownloadInitializationPhase(
subscriberData: EbicsContainer,
orderType: String,
diff --git a/nexus/src/main/kotlin/Main.kt b/nexus/src/main/kotlin/Main.kt
@@ -219,10 +219,13 @@ fun main() {
subscriberData.customerAuthPriv
)
+ val payload: ByteArray = decryptAndDecompressResponse(response.value, subscriberData.customerEncPriv)
+
call.respondText(
- "Nothing crashed!",
+ payload.toString(Charsets.UTF_8),
ContentType.Text.Plain,
HttpStatusCode.OK)
+
return@post
}
diff --git a/util/src/main/kotlin/EbicsOrderUtil.kt b/util/src/main/kotlin/EbicsOrderUtil.kt
@@ -28,6 +28,14 @@ import java.util.zip.InflaterInputStream
* Helpers for dealing with order compression, encryption, decryption, chunking and re-assembly.
*/
object EbicsOrderUtil {
+
+ // Decompression only, no XML involved.
+ fun decodeOrderData(encodedOrderData: ByteArray): ByteArray {
+ return InflaterInputStream(encodedOrderData.inputStream()).use {
+ it.readAllBytes()
+ }
+ }
+
inline fun <reified T> decodeOrderDataXml(encodedOrderData: ByteArray): T {
return InflaterInputStream(encodedOrderData.inputStream()).use {
val bytes = it.readAllBytes()