summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine A <>2024-03-09 15:18:25 +0100
committerAntoine A <>2024-03-09 15:18:25 +0100
commit30eefb68a131b44edc78d3dbf346be840f999b0a (patch)
treeee56a06eaa85b6f85edff48c609ae176856bc495
parent16b5d74cad21d533353b0412b78302dcd37304f8 (diff)
downloadlibeufin-30eefb68a131b44edc78d3dbf346be840f999b0a.tar.gz
libeufin-30eefb68a131b44edc78d3dbf346be840f999b0a.tar.bz2
libeufin-30eefb68a131b44edc78d3dbf346be840f999b0a.zip
Eager base64 decoding for EBICS order data
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics2.kt13
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics3.kt6
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsCommon.kt11
3 files changed, 15 insertions, 15 deletions
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics2.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics2.kt
index bee41525..a7c2ba50 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics2.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics2.kt
@@ -160,11 +160,11 @@ class Ebics3KeyMng(
}
companion object {
- fun parseResponse(doc: Document, clientEncryptionKey: RSAPrivateCrtKey): EbicsResponse<ByteArray?> {
+ fun parseResponse(doc: Document, clientEncryptionKey: RSAPrivateCrtKey): EbicsResponse<InputStream?> {
return XmlDestructor.fromDoc(doc, "ebicsKeyManagementResponse") {
lateinit var technicalCode: EbicsReturnCode
lateinit var bankCode: EbicsReturnCode
- var payload: ByteArray? = null
+ var payload: InputStream? = null
one("header") {
one("mutable") {
technicalCode = EbicsReturnCode.lookup(one("ReturnCode").text())
@@ -179,11 +179,12 @@ class Ebics3KeyMng(
one("EncryptionPubKeyDigest").text().decodeBase64()
)
}
+ val chunk = one("OrderData").text().decodeBase64()
decryptAndDecompressPayload(
clientEncryptionKey,
descriptionInfo,
- listOf(one("OrderData").text())
- ).readBytes()
+ listOf(chunk)
+ )
}
}
EbicsResponse(
@@ -194,8 +195,8 @@ class Ebics3KeyMng(
}
}
- fun parseHpbOrder(data: ByteArray): Pair<RSAPublicKey, RSAPublicKey> {
- return XmlDestructor.fromStream(data.inputStream(), "HPBResponseOrderData") {
+ fun parseHpbOrder(data: InputStream): Pair<RSAPublicKey, RSAPublicKey> {
+ return XmlDestructor.fromStream(data, "HPBResponseOrderData") {
val authPub = one("AuthenticationPubKeyInfo").one("PubKeyValue").one("RSAKeyValue") {
CryptoUtil.loadRsaPublicKeyFromComponents(
one("Modulus").text().decodeBase64(),
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics3.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics3.kt
index e4306ada..11ccf30d 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics3.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics3.kt
@@ -339,7 +339,7 @@ class Ebics3BTS(
lateinit var bankCode: EbicsReturnCode
var orderID: String? = null
var segmentNumber: Int? = null
- var payloadChunk: String? = null
+ var payloadChunk: ByteArray? = null
var dataEncryptionInfo: DataEncryptionInfo? = null
one("header") {
one("static") {
@@ -354,7 +354,7 @@ class Ebics3BTS(
}
one("body") {
opt("DataTransfer") {
- payloadChunk = one("OrderData").text()
+ payloadChunk = one("OrderData").text().decodeBase64()
dataEncryptionInfo = opt("DataEncryptionInfo") {
DataEncryptionInfo(
one("TransactionKey").text().decodeBase64(),
@@ -385,7 +385,7 @@ data class BTSResponse(
val transactionID: String?,
val orderID: String?,
val dataEncryptionInfo: DataEncryptionInfo?,
- val payloadChunk: String?,
+ val payloadChunk: ByteArray?,
val segmentNumber: Int?,
val numSegments: Int?
) \ No newline at end of file
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsCommon.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsCommon.kt
index 8fd7e07b..fd969340 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsCommon.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsCommon.kt
@@ -78,15 +78,14 @@ enum class SupportedDocument {
* one actually used to encrypt the payload.
* @param encryptionInfo details related to the encrypted payload.
* @param chunks the several chunks that constitute the whole encrypted payload.
- * @return the plain payload. Errors throw, so the caller must handle those.
+ * @return the plain payload.
*/
fun decryptAndDecompressPayload(
clientEncryptionKey: RSAPrivateCrtKey,
encryptionInfo: DataEncryptionInfo,
- chunks: List<String>
+ chunks: List<ByteArray>
): InputStream =
- SequenceInputStream(Collections.enumeration(chunks.map { it.toByteArray().inputStream() })) // Aggregate
- .decodeBase64()
+ SequenceInputStream(Collections.enumeration(chunks.map { it.inputStream() })) // Aggregate
.run {
CryptoUtil.decryptEbicsE002(
encryptionInfo.transactionKey,
@@ -233,7 +232,7 @@ suspend fun ebicsDownload(
checkCancellation()
// Decompress encrypted chunks
- val payloadBytes = try {
+ val payloadStream = try {
decryptAndDecompressPayload(
clientKeys.encryption_private_key,
dataEncryptionInfo,
@@ -247,7 +246,7 @@ suspend fun ebicsDownload(
// Run business logic
val res = runCatching {
- processing(payloadBytes)
+ processing(payloadStream)
}
// First send a proper EBICS transaction receipt