gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated: signing error responses


From: gnunet
Subject: [libeufin] branch master updated: signing error responses
Date: Thu, 23 Jul 2020 13:18:42 +0200

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

ms pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new 718da3b  signing error responses
718da3b is described below

commit 718da3b56d3784396bd5ccb5b86685b08e7bc794
Author: MS <ms@taler.net>
AuthorDate: Thu Jul 23 13:18:39 2020 +0200

    signing error responses
---
 .../tech/libeufin/sandbox/EbicsProtocolBackend.kt  | 27 ++++++++++++++--------
 .../src/main/kotlin/tech/libeufin/sandbox/Main.kt  |  7 +++++-
 2 files changed, 23 insertions(+), 11 deletions(-)

diff --git 
a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
index 0635ae7..889ff3e 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -72,8 +72,12 @@ data class PainParseResult(
     val msgId: String
 )
 
-open class EbicsRequestError(val errorText: String, val errorCode: String) :
-    Exception("EBICS request  error: $errorText ($errorCode)")
+open class EbicsRequestError(
+    val errorText: String,
+    val errorCode: String,
+    // needed to sign the (error) response.
+    val hostAuthPriv: RSAPrivateCrtKey? = null
+) : Exception("EBICS request  error: $errorText ($errorCode)")
 
 class EbicsInvalidRequestError : EbicsRequestError(
     "[EBICS_INVALID_REQUEST] Invalid request",
@@ -562,11 +566,10 @@ private fun parsePain001(paymentRequest: String, 
initiatorName: String): PainPar
 /**
  * Process a payment request in the pain.001 format.
  */
-private fun handleCct(paymentRequest: String, initiatorName: String) {
+private fun handleCct(paymentRequest: String, initiatorName: String, ctx: 
RequestContext) {
     val parseResult = parsePain001(paymentRequest, initiatorName)
-
-    try{
-        transaction {
+    transaction {
+        try {
             PaymentsTable.insert {
                 it[creditorIban] = parseResult.creditorIban
                 it[creditorName] = parseResult.creditorName
@@ -579,10 +582,14 @@ private fun handleCct(paymentRequest: String, 
initiatorName: String) {
                 it[pmtInfId] = parseResult.pmtInfId
                 it[msgId] = parseResult.msgId
             }
+        } catch (e: ExposedSQLException) {
+            logger.warn("Could not insert new payment into the database: ${e}")
+            throw EbicsRequestError(
+                "[EBICS_PROCESSING_ERROR] ${e.sqlState}",
+                "091116",
+                ctx.hostAuthPriv
+            )
         }
-    } catch (e: ExposedSQLException) {
-        logger.warn("Could not insert new payment into the database: ${e}")
-        throw EbicsRequestError("[EBICS_PROCESSING_ERROR] ${e.sqlState}", 
"091116")
     }
 }
 
@@ -1071,7 +1078,7 @@ private fun 
handleEbicsUploadTransactionTransmission(requestContext: RequestCont
         if (getOrderTypeFromTransactionId(requestTransactionID) == "CCT") {
             logger.debug("Attempting a payment.")
             val involvedBankAccout = 
getBankAccountFromSubscriber(requestContext.subscriber)
-            handleCct(unzippedData.toString(Charsets.UTF_8), 
involvedBankAccout.name)
+            handleCct(unzippedData.toString(Charsets.UTF_8), 
involvedBankAccout.name, requestContext)
         }
         return EbicsResponse.createForUploadTransferPhase(
             requestTransactionID,
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index 9140ddc..6c41db8 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -190,8 +190,13 @@ fun serverMain(dbName: String) {
                     // already been caught by the chunking logic.
                     EbicsTypes.TransactionPhaseType.TRANSFER
                 )
+                if (cause.hostAuthPriv == null)
+                    throw SandboxError(
+                        reason = "Cannot sign error response",
+                        statusCode = HttpStatusCode.InternalServerError
+                    )
                 call.respondText(
-                    XMLUtil.convertJaxbToString(resp),
+                    XMLUtil.signEbicsResponse(resp, cause.hostAuthPriv),
                     ContentType.Application.Xml,
                     HttpStatusCode.OK
                 )

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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