commit 6cb403f8e8caa481c475f42006e9bbd115f88e30
parent b7a3a024d388d4cc7b368f9d15a0289097a815a1
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Thu, 7 Nov 2019 20:59:48 +0100
decrypt result from bank
Diffstat:
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/nexus/src/main/kotlin/Main.kt b/nexus/src/main/kotlin/Main.kt
@@ -322,7 +322,7 @@ fun main() {
// _parse_ response!
// respond to client
val id = expectId(call.parameters["id"])
- val (url, body) = transaction {
+ val (url, body, encPriv) = transaction {
val subscriber = EbicsSubscriberEntity.findById(id) ?: throw SubscriberNotFoundError(HttpStatusCode.NotFound)
val hpbRequest = EbicsNpkdRequest().apply {
version = "H004"
@@ -351,10 +351,26 @@ fun main() {
hpbDoc,
CryptoUtil.loadRsaPrivateKey(subscriber.signaturePrivateKey.toByteArray())
)
- Pair(subscriber.ebicsURL, hpbDoc)
+ Triple(subscriber.ebicsURL, hpbDoc, subscriber.encryptionPrivateKey)
}
- val response = client.postToBank<EbicsKeyManagementResponse>(url, body)
+ val response = client.postToBank<EbicsKeyManagementResponse>(url, body) ?: throw UnreachableBankError(
+ HttpStatusCode.InternalServerError
+ )
+
+ if (response.value.body.returnCode.value != "000000") {
+ throw EbicsError(response.value.body.returnCode.value)
+ }
+
+ val er = CryptoUtil.EncryptionResult(
+ response.value.body.dataTransfer!!.dataEncryptionInfo!!.transactionKey,
+ (response.value.body.dataTransfer!!.dataEncryptionInfo as EbicsTypes.DataEncryptionInfo)
+ .encryptionPubKeyDigest.value,
+ (response.value.body.dataTransfer as EbicsKeyManagementResponse.OrderData).value
+ )
+
+ var dataCompr = CryptoUtil.decryptEbicsE002(er, CryptoUtil.loadRsaPrivateKey(encPriv.toByteArray()))
+ var data = EbicsOrderUtil.decodeOrderDataXml<HPBResponseOrderData>(dataCompr)
call.respond(HttpStatusCode.NotImplemented, NexusError("work in progress"))
return@post
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CryptoUtil.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CryptoUtil.kt
@@ -43,7 +43,7 @@ import javax.crypto.spec.SecretKeySpec
data class RsaCrtKeyPair(val private: RSAPrivateCrtKey, val public: RSAPublicKey)
/**
- * Helpers for dealing with crypographic operations in EBICS / LibEuFin.
+ * Helpers for dealing with cryptographic operations in EBICS / LibEuFin.
*/
class CryptoUtil {