gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated (e71407e -> 2d656c1)


From: gnunet
Subject: [libeufin] branch master updated (e71407e -> 2d656c1)
Date: Tue, 12 May 2020 16:16:04 +0200

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

ms pushed a change to branch master
in repository libeufin.

    from e71407e  Adjust transport retrieval.
     new 8dbbb33  implement /send{MSG}
     new 85ffd41  add HEV to available messages to send
     new 2d656c1  implement /sync{MSG}

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../src/main/kotlin/tech/libeufin/nexus/Helpers.kt |  26 ++++--
 nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt  | 103 ++++++++++++++++++++-
 .../kotlin/tech/libeufin/nexus/MainDeprecated.kt   |  26 +++---
 nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt |   2 +-
 4 files changed, 128 insertions(+), 29 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
index 1826ae3..4258b84 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
@@ -1,6 +1,5 @@
 package tech.libeufin.nexus
 
-import io.ktor.application.ApplicationCall
 import io.ktor.client.HttpClient
 import io.ktor.http.HttpStatusCode
 import org.jetbrains.exposed.sql.and
@@ -101,7 +100,7 @@ fun getBankAccountsFromNexusUserId(id: String): 
MutableList<BankAccountEntity> {
     return ret
 }
 
-fun getSubscriberDetails(subscriber: EbicsSubscriberEntity): 
EbicsClientSubscriberDetails {
+fun getEbicsSubscriberDetailsInternal(subscriber: EbicsSubscriberEntity): 
EbicsClientSubscriberDetails {
     var bankAuthPubValue: RSAPublicKey? = null
     if (subscriber.bankAuthenticationPublicKey != null) {
         bankAuthPubValue = CryptoUtil.loadRsaPublicKey(
@@ -129,11 +128,7 @@ fun getSubscriberDetails(subscriber: 
EbicsSubscriberEntity): EbicsClientSubscrib
     )
 }
 
-/**
- * Retrieve Ebics subscriber details given a Transport
- * object and handling the default case.
- */
-fun getEbicsSubscriberDetails(userId: String, transportId: String?): 
EbicsClientSubscriberDetails {
+fun getEbicsTransport(userId: String, transportId: String?): 
EbicsSubscriberEntity {
     val transport = transaction {
         if (transportId == null) {
             return@transaction EbicsSubscriberEntity.all().first()
@@ -150,8 +145,17 @@ fun getEbicsSubscriberDetails(userId: String, transportId: 
String?): EbicsClient
             "No rights over transport $transportId"
         )
     }
+    return transport
+}
+
+/**
+ * Retrieve Ebics subscriber details given a Transport
+ * object and handling the default case.
+ */
+fun getEbicsSubscriberDetails(userId: String, transportId: String?): 
EbicsClientSubscriberDetails {
+    val transport = getEbicsTransport(userId, transportId)
     // transport exists and belongs to caller.
-    return getSubscriberDetails(transport)
+    return getEbicsSubscriberDetailsInternal(transport)
 }
 
 suspend fun downloadAndPersistC5xEbics(
@@ -394,8 +398,10 @@ fun addPreparedPayment(paymentData: Pain001Data, 
nexusUser: NexusUserEntity): Pr
     }
 }
 
-fun expectId(param: String?): String {
-    return param ?: throw NexusError(HttpStatusCode.BadRequest, "Bad ID given")
+fun ensureNonNull(param: String?): String {
+    return param ?: throw NexusError(
+        HttpStatusCode.BadRequest, "Bad ID given"
+    )
 }
 
 /* Needs a transaction{} block to be called */
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
index d67dc75..793ba53 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -58,6 +58,63 @@ import javax.sql.rowset.serial.SerialBlob
 data class NexusError(val statusCode: HttpStatusCode, val reason: String) : 
Exception()
 val logger: Logger = LoggerFactory.getLogger("tech.libeufin.nexus")
 
+suspend fun handleEbicsSendMSG(
+    httpClient: HttpClient,
+    userId: String,
+    transportId: String?,
+    msg: String,
+    sync: Boolean
+): String {
+    val subscriber = getEbicsSubscriberDetails(userId, transportId)
+    val response = when (msg.toUpperCase()) {
+        "HIA" -> {
+            val request = makeEbicsHiaRequest(subscriber)
+            httpClient.postToBank(
+                subscriber.ebicsUrl,
+                request
+            )
+        }
+        "INI" -> {
+            val request = makeEbicsIniRequest(subscriber)
+            httpClient.postToBank(
+                subscriber.ebicsUrl,
+                request
+            )
+        }
+        "HPB" -> {
+            /** should NOT put bank's keys into any table.  */
+            val request = makeEbicsHpbRequest(subscriber)
+            val response = httpClient.postToBank(
+                subscriber.ebicsUrl,
+                request
+            )
+            if (sync) {
+                val parsedResponse = 
parseAndDecryptEbicsKeyManagementResponse(subscriber, response)
+                val orderData = parsedResponse.orderData ?: throw NexusError(
+                    HttpStatusCode.InternalServerError,
+                    "Cannot find data in a HPB response"
+                )
+                val hpbData = parseEbicsHpbOrder(orderData)
+                transaction {
+                    val transport = getEbicsTransport(userId, transportId)
+                    transport.bankAuthenticationPublicKey = 
SerialBlob(hpbData.authenticationPubKey.encoded)
+                    transport.bankEncryptionPublicKey = 
SerialBlob(hpbData.encryptionPubKey.encoded)
+                }
+            }
+            return response
+        }
+        "HEV" -> {
+            val request = makeEbicsHEVRequest(subscriber)
+            httpClient.postToBank(subscriber.ebicsUrl, request)
+        }
+        else -> throw NexusError(
+            HttpStatusCode.NotFound,
+            "Message $msg not found"
+        )
+    }
+    return response
+}
+
 @ExperimentalIoApi
 @KtorExperimentalAPI
 fun main() {
@@ -224,7 +281,7 @@ fun main() {
              */
             get("/bank-accounts/{accountid}/prepared-payments/{uuid}") {
                 val userId = 
authenticateRequest(call.request.headers["Authorization"])
-                val preparedPayment = 
getPreparedPayment(expectId(call.parameters["uuid"]))
+                val preparedPayment = 
getPreparedPayment(ensureNonNull(call.parameters["uuid"]))
                 if (preparedPayment.nexusUser.id.value != userId) throw 
NexusError(
                     HttpStatusCode.Forbidden,
                     "No rights over such payment"
@@ -249,7 +306,7 @@ fun main() {
              */
             post("/bank-accounts/{accountid}/prepared-payments") {
                 val userId = 
authenticateRequest(call.request.headers["Authorization"])
-                val bankAccount = getBankAccount(userId, 
expectId(call.parameters["accountid"]))
+                val bankAccount = getBankAccount(userId, 
ensureNonNull(call.parameters["accountid"]))
                 val body = call.receive<PreparedPaymentRequest>()
                 val amount = parseAmount(body.amount)
                 val paymentEntity = addPreparedPayment(
@@ -337,7 +394,6 @@ fun main() {
                                 amount = "${it.currency}:${it.amount}"
                             )
                         )
-
                     }
                 }
                 return@get
@@ -431,9 +487,27 @@ fun main() {
             }
             /**
              * Sends to the bank a message "MSG" according to the transport
-             * "transportName".  Does not alterate any DB table.
+             * "transportName".  Does not modify any DB table.
              */
-            post("/bank-transports/{transportName}/send{MSG}") {
+            post("/bank-transports/send{MSG}") {
+                val userId = 
authenticateRequest(call.request.headers["Authorization"])
+                val body = call.receive<Transport>()
+                when (body.type) {
+                    "ebics" -> {
+                        val response = handleEbicsSendMSG(
+                            httpClient = client,
+                            userId = userId,
+                            transportId = body.name,
+                            msg = ensureNonNull(call.parameters["MSG"]),
+                            sync = true
+                        )
+                        call.respondText(response)
+                    }
+                    else -> throw NexusError(
+                        HttpStatusCode.NotImplemented,
+                        "Transport '${body.type}' not implemented.  Use 
'ebics'"
+                    )
+                }
                 return@post
             }
             /**
@@ -441,6 +515,25 @@ fun main() {
              * "transportName".  DOES alterate DB tables.
              */
             post("/bank-transports/{transportName}/sync{MSG}") {
+                val userId = 
authenticateRequest(call.request.headers["Authorization"])
+                val body = call.receive<Transport>()
+                when (body.type) {
+                    "ebics" -> {
+                        val response = handleEbicsSendMSG(
+                            httpClient = client,
+                            userId = userId,
+                            transportId = body.name,
+                            msg = ensureNonNull(call.parameters["MSG"]),
+                            sync = true
+                            )
+                        call.respondText(response)
+                    }
+                    else -> throw NexusError(
+                        HttpStatusCode.NotImplemented,
+                        "Transport '${body.type}' not implemented.  Use 
'ebics'"
+                    )
+                }
+
                 return@post
             }
 
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/MainDeprecated.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/MainDeprecated.kt
index df00d65..d730001 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/MainDeprecated.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/MainDeprecated.kt
@@ -202,7 +202,7 @@ fun main() {
             }
             /** Make a new NEXUS user in the system */
             post("/users/{id}") {
-                val newUserId = expectId(call.parameters["id"])
+                val newUserId = ensureNonNull(call.parameters["id"])
                 val body = call.receive<NexusUserRequest>()
                 transaction {
                     NexusUserEntity.new(id = newUserId) {
@@ -224,7 +224,7 @@ fun main() {
             /** Show bank accounts associated with a given NEXUS user */
             get("/users/{id}/accounts") {
                 // this information is only avaiable *after* HTD or HKD has 
been called
-                val id = expectId(call.parameters["id"])
+                val id = ensureNonNull(call.parameters["id"])
                 val ret = BankAccountsInfoResponse()
                 transaction {
                     BankAccountMapEntity.find {
@@ -248,7 +248,7 @@ fun main() {
             }
             /** Show PREPARED payments */
             get("/users/{id}/payments") {
-                val nexusUserId = expectId(call.parameters["id"])
+                val nexusUserId = ensureNonNull(call.parameters["id"])
                 val ret = RawPayments()
                 transaction {
                     val nexusUser = extractNexusUser(nexusUserId)
@@ -345,7 +345,7 @@ fun main() {
             }
             post("/ebics/subscribers/{id}/restoreBackup") {
                 val body = call.receive<EbicsKeysBackupJson>()
-                val nexusId = expectId(call.parameters["id"])
+                val nexusId = ensureNonNull(call.parameters["id"])
                 val subscriber = transaction {
                     NexusUserEntity.findById(nexusId)
                 }
@@ -425,7 +425,7 @@ fun main() {
                 )
             }
             get("/ebics/subscribers/{id}/keyletter") {
-                val nexusUserId = expectId(call.parameters["id"])
+                val nexusUserId = ensureNonNull(call.parameters["id"])
                 var usernameLine = "TODO"
                 var recipientLine = "TODO"
                 val customerIdLine = "TODO"
@@ -572,7 +572,7 @@ fun main() {
                 logger.debug("Uploading PAIN.001: ${painDoc}")
                 doEbicsUploadTransaction(
                     client,
-                    getSubscriberDetails(subscriber),
+                    getEbicsSubscriberDetailsInternal(subscriber),
                     "CCT",
                     painDoc.toByteArray(Charsets.UTF_8),
                     EbicsStandardOrderParams()
@@ -651,7 +651,7 @@ fun main() {
                 return@post
             }
             post("/ebics/subscribers/{id}/fetch-payment-status") {
-                val id = expectId(call.parameters["id"])
+                val id = ensureNonNull(call.parameters["id"])
                 val paramsJson = call.receive<EbicsStandardOrderParamsJson>()
                 val orderParams = paramsJson.toOrderParams()
                 val subscriberData = getSubscriberDetailsFromNexusUserId(id)
@@ -677,7 +677,7 @@ fun main() {
                 return@post
             }
             post("/ebics/subscribers/{id}/collect-transactions-c53") {
-                val id = expectId(call.parameters["id"])
+                val id = ensureNonNull(call.parameters["id"])
                 val paramsJson = call.receive<EbicsStandardOrderParamsJson>()
                 val orderParams = paramsJson.toOrderParams()
                 val subscriberData = getSubscriberDetailsFromNexusUserId(id)
@@ -778,8 +778,8 @@ fun main() {
 
             // FIXME: some messages include a ZIPped payload.
             post("/ebics/subscribers/{id}/send{MSG}") {
-                val id = expectId(call.parameters["id"])
-                val MSG = expectId(call.parameters["MSG"])
+                val id = ensureNonNull(call.parameters["id"])
+                val MSG = ensureNonNull(call.parameters["MSG"])
                 val paramsJson = call.receive<EbicsStandardOrderParamsJson>()
                 val orderParams = paramsJson.toOrderParams()
                 println("$MSG order params: $orderParams")
@@ -808,7 +808,7 @@ fun main() {
                 return@post
             }
             get("/ebics/{id}/sendHEV") {
-                val id = expectId(call.parameters["id"])
+                val id = ensureNonNull(call.parameters["id"])
                 val subscriberData = getSubscriberDetailsFromNexusUserId(id)
                 val request = makeEbicsHEVRequest(subscriberData)
                 val response = client.postToBank(subscriberData.ebicsUrl, 
request)
@@ -825,7 +825,7 @@ fun main() {
                 return@get
             }
             post("/ebics/subscribers/{id}/sendINI") {
-                val id = expectId(call.parameters["id"])
+                val id = ensureNonNull(call.parameters["id"])
                 val subscriberData = getSubscriberDetailsFromNexusUserId(id)
                 val iniRequest = makeEbicsIniRequest(subscriberData)
                 val responseStr = client.postToBank(
@@ -844,7 +844,7 @@ fun main() {
             }
 
             post("/ebics/subscribers/{id}/sendHIA") {
-                val id = expectId(call.parameters["id"])
+                val id = ensureNonNull(call.parameters["id"])
                 val subscriberData = getSubscriberDetailsFromNexusUserId(id)
                 val hiaRequest = makeEbicsHiaRequest(subscriberData)
                 val responseStr = client.postToBank(
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt
index 8a97107..b259bb5 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt
@@ -395,7 +395,7 @@ class Taler(app: Route) {
          * payment was added as well.
          */
         app.post("/ebics/taler/{id}/crunch-raw-transactions") {
-            val id = expectId(call.parameters["id"])
+            val id = ensureNonNull(call.parameters["id"])
             // first find highest ID value of already processed rows.
             transaction {
                 val subscriberAccount = getBankAccountFromNexusUserId(id)

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



reply via email to

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