gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] 02/02: crafting TST upload order


From: gnunet
Subject: [libeufin] 02/02: crafting TST upload order
Date: Fri, 15 Nov 2019 20:42:06 +0100

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

marcello pushed a commit to branch master
in repository libeufin.

commit 106c02fbf8c55376ac94575854de8c0134c387cb
Author: Marcello Stanisci <address@hidden>
AuthorDate: Fri Nov 15 20:41:53 2019 +0100

    crafting TST upload order
---
 nexus/src/main/kotlin/Main.kt                      | 110 +++++++++++++++++++++
 nexus/src/test/kotlin/SignatureDataTest.kt         |  77 +++++++++++++++
 .../libeufin/schema/ebics_h004/EbicsRequest.kt     |   4 +-
 .../tech/libeufin/schema/ebics_h004/EbicsTypes.kt  |   1 -
 4 files changed, 189 insertions(+), 3 deletions(-)

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/schema/ebics_h004/EbicsRequest.kt 
b/sandbox/src/main/kotlin/tech/libeufin/schema/ebics_h004/EbicsRequest.kt
index e5b2051..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,7 +200,7 @@ class EbicsRequest {
     }
 
     @XmlAccessorType(XmlAccessType.NONE)
-    class SignatureDataType {
+    class SignatureData {
         @get:XmlAttribute(name = "authenticate", required = true)
         var authenticate: Boolean = false
 
@@ -217,7 +217,7 @@ class EbicsRequest {
         var dataEncryptionInfo: EbicsTypes.DataEncryptionInfo? = null
 
         @get:XmlElement(name = "SignatureData")
-        var signatureData: SignatureDataType? = null
+        var signatureData: SignatureData? = null
 
         @get:XmlElement(name = "OrderData")
         var orderData: ByteArray? = null
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]