gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: Nexus extracts CAMT out of C52 respons


From: gnunet
Subject: [libeufin] branch master updated: Nexus extracts CAMT out of C52 response.
Date: Thu, 23 Jan 2020 17:13:37 +0100

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new af3bc2a  Nexus extracts CAMT out of C52 response.
af3bc2a is described below

commit af3bc2ab7fa1cc3bc01cc310047f7373f852c3ae
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Jan 23 17:13:07 2020 +0100

    Nexus extracts CAMT out of C52 response.
---
 nexus/src/main/kotlin/Helpers.kt       | 30 ++++++++++++++++++++++++++----
 nexus/src/main/kotlin/Main.kt          |  5 ++++-
 util/src/main/kotlin/EbicsOrderUtil.kt |  8 ++++++++
 3 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/nexus/src/main/kotlin/Helpers.kt b/nexus/src/main/kotlin/Helpers.kt
index 7a7b68b..ca738eb 100644
--- 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
index 57d116f..43c59db 100644
--- 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
index a271c85..b9c2d20 100644
--- 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()

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]