gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated (f2ace12 -> 106c02f)


From: gnunet
Subject: [libeufin] branch master updated (f2ace12 -> 106c02f)
Date: Fri, 15 Nov 2019 20:42:04 +0100

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

marcello pushed a change to branch master
in repository libeufin.

    from f2ace12  typo
     new f6e7b7c  fix signature type
     new 106c02f  crafting TST upload order

The 2 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:
 nexus/src/main/kotlin/Main.kt                      | 110 +++++++++++++++++++++
 nexus/src/test/kotlin/SignatureDataTest.kt         |  77 +++++++++++++++
 .../tech/libeufin/sandbox/EbicsProtocolBackend.kt  |   2 +-
 .../libeufin/schema/ebics_h004/EbicsRequest.kt     |  18 +++-
 .../tech/libeufin/schema/ebics_h004/EbicsTypes.kt  |   1 -
 5 files changed, 204 insertions(+), 4 deletions(-)
 create mode 100644 nexus/src/test/kotlin/SignatureDataTest.kt

diff --git a/nexus/src/main/kotlin/Main.kt b/nexus/src/main/kotlin/Main.kt
index 9a88495..58b5461 100644
--- a/nexus/src/main/kotlin/Main.kt
+++ b/nexus/src/main/kotlin/Main.kt
@@ -52,6 +52,8 @@ import javax.sql.rowset.serial.SerialBlob
 import javax.xml.bind.JAXBElement
 import org.w3c.dom.Document
 import tech.libeufin.schema.ebics_s001.SignatureTypes
+import tech.libeufin.schema.ebics_s001.UserSignatureData
+import java.math.BigInteger
 import java.security.SecureRandom
 import java.text.SimpleDateFormat
 import java.time.Instant.now
@@ -665,6 +667,114 @@ fun main() {
                 return@post
             }
 
+            post("/ebics/subscribers/{id}/sync") {
+                val id = expectId(call.parameters["id"])
+
+                val (url, doc) = transaction {
+                    val subscriber = EbicsSubscriberEntity.findById(id) ?: 
throw SubscriberNotFoundError(HttpStatusCode.NotFound)
+
+                    // first prepare ES content
+                    val ES_signature = CryptoUtil.signEbicsA006(
+                        CryptoUtil.digestEbicsA006("ES-PAYLOAD".toByteArray()),
+                        
CryptoUtil.loadRsaPrivateKey(subscriber.signaturePrivateKey.toByteArray())
+                    )
+
+                    val userSignatureData = UserSignatureData().apply {
+                        orderSignatureList = listOf(
+                            UserSignatureData.OrderSignatureData().apply {
+                                signatureVersion = "A006"
+                                signatureValue = ES_signature
+                                partnerID = subscriber.partnerID
+                                userID = subscriber.userID
+                            }
+                        )
+                    }
+
+                    println("inner ES is: 
${XMLUtil.convertJaxbToString(userSignatureData)}")
+
+                    val usd_compressed = 
EbicsOrderUtil.encodeOrderDataXml(userSignatureData)
+                    val usd_encrypted = CryptoUtil.encryptEbicsE002(
+                        usd_compressed,
+                        
CryptoUtil.loadRsaPublicKey(subscriber.bankEncryptionPublicKey!!.toByteArray()
+                        )
+                    )
+
+                    val tmp = EbicsRequest().apply {
+                        header = EbicsRequest.Header().apply {
+                            version = "H004"
+                            revision = 1
+                            authenticate = true
+                            static = EbicsRequest.StaticHeaderType().apply {
+                                hostID = subscriber.hostID
+                                nonce = getNonce(128)
+                                timestamp = getGregorianDate()
+                                partnerID = subscriber.partnerID
+                                userID = subscriber.userID
+                                orderDetails = 
EbicsRequest.OrderDetails().apply {
+                                    orderType = "TST"
+                                    orderAttribute = "OZHNN"
+                                }
+                                bankPubKeyDigests = 
EbicsRequest.BankPubKeyDigests().apply {
+                                    authentication = 
EbicsTypes.PubKeyDigest().apply {
+                                        algorithm = 
"http://www.w3.org/2001/04/xmlenc#sha256";
+                                        version = "X002"
+                                        value = 
CryptoUtil.getEbicsPublicKeyHash(
+                                            
CryptoUtil.loadRsaPublicKey(subscriber.bankAuthenticationPublicKey!!.toByteArray())
+                                        )
+                                    }
+                                    encryption = 
EbicsTypes.PubKeyDigest().apply {
+                                        algorithm = 
"http://www.w3.org/2001/04/xmlenc#sha256";
+                                        version = "E002"
+                                        value = 
CryptoUtil.getEbicsPublicKeyHash(
+                                            
CryptoUtil.loadRsaPublicKey(subscriber.bankEncryptionPublicKey!!.toByteArray())
+
+                                        )
+                                    }
+                                }
+                                securityMedium = "0000"
+                                numSegments = BigInteger.ONE
+
+                                authSignature = SignatureType()
+                            }
+                            mutable = EbicsRequest.MutableHeader().apply {
+                                transactionPhase = 
EbicsTypes.TransactionPhaseType.INITIALISATION
+                            }
+                            body = EbicsRequest.Body().apply {
+                                dataTransfer = 
EbicsRequest.DataTransfer().apply {
+                                    signatureData = 
EbicsRequest.SignatureData().apply {
+                                        authenticate = true
+                                        value = usd_encrypted.encryptedData
+                                    }
+                                    dataEncryptionInfo = 
EbicsTypes.DataEncryptionInfo().apply {
+                                        transactionKey = 
usd_encrypted.encryptedTransactionKey
+                                        authenticate = true
+                                        encryptionPubKeyDigest = 
EbicsTypes.PubKeyDigest().apply {
+                                            algorithm = 
"http://www.w3.org/2001/04/xmlenc#sha256";
+                                            version = "E002"
+                                            value = 
CryptoUtil.getEbicsPublicKeyHash(
+                                                CryptoUtil.loadRsaPublicKey(
+                                                    
subscriber.bankEncryptionPublicKey!!.toByteArray()
+                                                )
+                                            )
+                                        }
+                                    }
+                                    hostId = subscriber.hostID
+                                }
+                            }
+                        }
+                    }
+
+                    val doc = XMLUtil.convertJaxbToDocument(tmp)
+                    XMLUtil.signEbicsDocument(
+                        doc,
+                        
CryptoUtil.loadRsaPrivateKey(subscriber.authenticationPrivateKey.toByteArray())
+                    )
+                    Pair(subscriber.ebicsURL, doc)
+                }
+
+                // send document here
+            }
+
             post("/ebics/subscribers/{id}/sync") {
                 val id = expectId(call.parameters["id"])
                 val (url, body, encPrivBlob) = transaction {
diff --git a/nexus/src/test/kotlin/SignatureDataTest.kt 
b/nexus/src/test/kotlin/SignatureDataTest.kt
new file mode 100644
index 0000000..8cd133a
--- /dev/null
+++ b/nexus/src/test/kotlin/SignatureDataTest.kt
@@ -0,0 +1,77 @@
+package tech.libeufin.nexus
+
+import okio.internal.commonAsUtf8ToByteArray
+import tech.libeufin.sandbox.XMLUtil
+import org.apache.xml.security.binding.xmldsig.SignatureType
+import org.junit.Test
+import tech.libeufin.sandbox.CryptoUtil
+import tech.libeufin.schema.ebics_h004.EbicsRequest
+import tech.libeufin.schema.ebics_h004.EbicsTypes
+import java.math.BigInteger
+
+class SignatureDataTest {
+
+    @Test
+    fun makeSignatureData() {
+
+        val pair = CryptoUtil.generateRsaKeyPair(1024)
+
+        val tmp = EbicsRequest().apply {
+            header = EbicsRequest.Header().apply {
+                version = "H004"
+                revision = 1
+                authenticate = true
+                static = EbicsRequest.StaticHeaderType().apply {
+                    hostID = "some host ID"
+                    nonce = getNonce(128)
+                    timestamp = getGregorianDate()
+                    partnerID = "some partner ID"
+                    userID = "some user ID"
+                    orderDetails = EbicsRequest.OrderDetails().apply {
+                        orderType = "TST"
+                        orderAttribute = "OZHNN"
+                    }
+                    bankPubKeyDigests = EbicsRequest.BankPubKeyDigests().apply 
{
+                        authentication = EbicsTypes.PubKeyDigest().apply {
+                            algorithm = 
"http://www.w3.org/2001/04/xmlenc#sha256";
+                            version = "X002"
+                            value = 
CryptoUtil.getEbicsPublicKeyHash(pair.public)
+                        }
+                        encryption = EbicsTypes.PubKeyDigest().apply {
+                            algorithm = 
"http://www.w3.org/2001/04/xmlenc#sha256";
+                            version = "E002"
+                            value = 
CryptoUtil.getEbicsPublicKeyHash(pair.public)
+                        }
+                    }
+                    securityMedium = "0000"
+                    numSegments = BigInteger.ONE
+
+                    authSignature = SignatureType()
+                }
+                mutable = EbicsRequest.MutableHeader().apply {
+                    transactionPhase = 
EbicsTypes.TransactionPhaseType.INITIALISATION
+                }
+                body = EbicsRequest.Body().apply {
+                    dataTransfer = EbicsRequest.DataTransfer().apply {
+                        signatureData = EbicsRequest.SignatureData().apply {
+                            authenticate = true
+                            value = "to byte array".toByteArray()
+                        }
+                        dataEncryptionInfo = 
EbicsTypes.DataEncryptionInfo().apply {
+                            transactionKey = "mock".toByteArray()
+                            authenticate = true
+                            encryptionPubKeyDigest = 
EbicsTypes.PubKeyDigest().apply {
+                                algorithm = 
"http://www.w3.org/2001/04/xmlenc#sha256";
+                                version = "E002"
+                                value = 
CryptoUtil.getEbicsPublicKeyHash(pair.public)
+                            }
+                        }
+                        hostId = "a host ID"
+                    }
+                }
+            }
+        }
+
+        println(XMLUtil.convertJaxbToString(tmp))
+    }
+}
\ No newline at end of file
diff --git 
a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
index 69fbfb7..f17f1ec 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -594,7 +594,7 @@ suspend fun ApplicationCall.ebicsweb() {
                                 
requestObject.body.dataTransfer?.dataEncryptionInfo?.encryptionPubKeyDigest?.value
                             if (encPubKeyDigest == null)
                                 throw EbicsInvalidRequestError()
-                            val encSigData = 
requestObject.body.dataTransfer?.signatureData
+                            val encSigData = 
requestObject.body.dataTransfer?.signatureData?.value
                             if (encSigData == null)
                                 throw EbicsInvalidRequestError()
                             val decryptedSignatureData = 
CryptoUtil.decryptEbicsE002(
diff --git 
a/sandbox/src/main/kotlin/tech/libeufin/schema/ebics_h004/EbicsRequest.kt 
b/sandbox/src/main/kotlin/tech/libeufin/schema/ebics_h004/EbicsRequest.kt
index 786fa98..0f5567f 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/schema/ebics_h004/EbicsRequest.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/schema/ebics_h004/EbicsRequest.kt
@@ -200,16 +200,30 @@ class EbicsRequest {
     }
 
     @XmlAccessorType(XmlAccessType.NONE)
-    @XmlType(propOrder = ["dataEncryptionInfo", "signatureData", "orderData"])
+    class SignatureData {
+        @get:XmlAttribute(name = "authenticate", required = true)
+        var authenticate: Boolean = false
+
+        @get:XmlValue
+        var value: ByteArray? = null
+    }
+
+
+    @XmlAccessorType(XmlAccessType.NONE)
+    @XmlType(propOrder = ["dataEncryptionInfo", "signatureData", "orderData", 
"hostId"])
     class DataTransfer {
+
         @get:XmlElement(name = "DataEncryptionInfo")
         var dataEncryptionInfo: EbicsTypes.DataEncryptionInfo? = null
 
         @get:XmlElement(name = "SignatureData")
-        var signatureData: ByteArray? = null
+        var signatureData: SignatureData? = null
 
         @get:XmlElement(name = "OrderData")
         var orderData: ByteArray? = null
+
+        @get:XmlElement(name = "HostID")
+        var hostId: String? = null
     }
 
     @XmlAccessorType(XmlAccessType.NONE)
diff --git 
a/sandbox/src/main/kotlin/tech/libeufin/schema/ebics_h004/EbicsTypes.kt 
b/sandbox/src/main/kotlin/tech/libeufin/schema/ebics_h004/EbicsTypes.kt
index 3f9c605..8c9ff3f 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/schema/ebics_h004/EbicsTypes.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/schema/ebics_h004/EbicsTypes.kt
@@ -243,7 +243,6 @@ object EbicsTypes {
 
         @get:XmlElement(name = "NumSigRequired")
         var numSigRequired: Int? = null
-
     }
 
     @XmlAccessorType(XmlAccessType.NONE)

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



reply via email to

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