gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] 01/03: New package: tech.libeufin.nexus


From: gnunet
Subject: [libeufin] 01/03: New package: tech.libeufin.nexus
Date: Tue, 28 Jan 2020 17:43: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 785563f75054cf97a366dab740a8cfd42f68e542
Author: Marcello Stanisci <address@hidden>
AuthorDate: Tue Jan 28 15:57:53 2020 +0100

    New package: tech.libeufin.nexus
---
 .../kotlin/{ => tech/libeufin/nexus}/Containers.kt |  2 +-
 .../main/kotlin/{ => tech/libeufin/nexus}/DB.kt    |  9 +--
 .../kotlin/{ => tech/libeufin/nexus}/Helpers.kt    | 39 +++++++++---
 .../main/kotlin/{ => tech/libeufin/nexus}/JSON.kt  |  4 +-
 .../main/kotlin/{ => tech/libeufin/nexus}/Main.kt  | 74 +++++++++++++++++-----
 nexus/src/test/kotlin/LetterFormatTest.kt          |  2 +
 nexus/src/test/kotlin/SignatureDataTest.kt         |  1 +
 sandbox/build.gradle                               |  2 -
 .../src/main/kotlin/tech/libeufin/sandbox/DB.kt    |  1 -
 9 files changed, 97 insertions(+), 37 deletions(-)

diff --git a/nexus/src/main/kotlin/Containers.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Containers.kt
similarity index 94%
rename from nexus/src/main/kotlin/Containers.kt
rename to nexus/src/main/kotlin/tech/libeufin/nexus/Containers.kt
index 8c69ee1..286ee18 100644
--- a/nexus/src/main/kotlin/Containers.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Containers.kt
@@ -1,4 +1,4 @@
-package tech.libeufin.nexus
+package tech.libeufin.nexus.tech.libeufin.nexus
 
 import javax.crypto.SecretKey
 import org.w3c.dom.Document
diff --git a/nexus/src/main/kotlin/DB.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
similarity index 85%
rename from nexus/src/main/kotlin/DB.kt
rename to nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
index aba2e5c..0a4ec89 100644
--- a/nexus/src/main/kotlin/DB.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
@@ -1,8 +1,7 @@
-package tech.libeufin.nexus
+package tech.libeufin.nexus.tech.libeufin.nexus
 
 import org.jetbrains.exposed.dao.*
 import org.jetbrains.exposed.sql.*
-import org.jetbrains.exposed.sql.transactions.TransactionManager
 import org.jetbrains.exposed.sql.transactions.transaction
 
 
@@ -20,7 +19,9 @@ object EbicsSubscribersTable : IntIdTable() {
 }
 
 class EbicsSubscriberEntity(id: EntityID<Int>) : IntEntity(id) {
-    companion object : 
IntEntityClass<EbicsSubscriberEntity>(EbicsSubscribersTable)
+    companion object : IntEntityClass<EbicsSubscriberEntity>(
+        EbicsSubscribersTable
+    )
 
     var ebicsURL by EbicsSubscribersTable.ebicsURL
     var hostID by EbicsSubscribersTable.hostID
@@ -35,7 +36,7 @@ class EbicsSubscriberEntity(id: EntityID<Int>) : 
IntEntity(id) {
 }
 
 fun dbCreateTables() {
-    Database.connect("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", driver = 
"org.h2.Driver")
+    Database.connect("jdbc:sqlite:libeufin-nexus.sqlite3", "org.sqlite.JDBC")
 
     transaction {
         addLogger(StdOutSqlLogger)
diff --git a/nexus/src/main/kotlin/Helpers.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
similarity index 89%
rename from nexus/src/main/kotlin/Helpers.kt
rename to nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
index f0edd18..4995a20 100644
--- a/nexus/src/main/kotlin/Helpers.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
@@ -1,4 +1,4 @@
-package tech.libeufin.nexus
+package tech.libeufin.nexus.tech.libeufin.nexus
 
 import io.ktor.client.HttpClient
 import io.ktor.client.request.post
@@ -15,7 +15,6 @@ import java.security.interfaces.RSAPrivateCrtKey
 import java.security.interfaces.RSAPublicKey
 import java.util.*
 import javax.xml.bind.JAXBElement
-import javax.xml.datatype.DatatypeFactory
 import javax.xml.datatype.XMLGregorianCalendar
 
 
@@ -54,8 +53,12 @@ fun createDownloadInitializationPhase(
         subscriberData.hostId,
         nonce,
         date,
-        subscriberData.bankEncPub ?: throw 
BankKeyMissing(HttpStatusCode.PreconditionFailed),
-        subscriberData.bankAuthPub ?: throw 
BankKeyMissing(HttpStatusCode.PreconditionFailed),
+        subscriberData.bankEncPub ?: throw BankKeyMissing(
+            HttpStatusCode.PreconditionFailed
+        ),
+        subscriberData.bankAuthPub ?: throw BankKeyMissing(
+            HttpStatusCode.PreconditionFailed
+        ),
         orderType
     )
 }
@@ -75,8 +78,12 @@ fun createDownloadInitializationPhase(
         subscriberData.hostId,
         nonce,
         date,
-        subscriberData.bankEncPub ?: throw 
BankKeyMissing(HttpStatusCode.PreconditionFailed),
-        subscriberData.bankAuthPub ?: throw 
BankKeyMissing(HttpStatusCode.PreconditionFailed),
+        subscriberData.bankEncPub ?: throw BankKeyMissing(
+            HttpStatusCode.PreconditionFailed
+        ),
+        subscriberData.bankAuthPub ?: throw BankKeyMissing(
+            HttpStatusCode.PreconditionFailed
+        ),
         orderType,
         dateStart,
         dateEnd
@@ -241,7 +248,10 @@ suspend inline fun <reified T, reified S> 
HttpClient.postToBankSignedAndVerify(
         XMLUtil.parseStringIntoDom(response)
     } catch (e: Exception) {
 
-        throw UnparsableResponse(HttpStatusCode.BadRequest, response)
+        throw UnparsableResponse(
+            HttpStatusCode.BadRequest,
+            response
+        )
     }
 
     if (!XMLUtil.verifyEbicsDocument(responseDocument, pub)) {
@@ -254,7 +264,10 @@ suspend inline fun <reified T, reified S> 
HttpClient.postToBankSignedAndVerify(
         return XMLUtil.convertStringToJaxb(response)
     } catch (e: Exception) {
 
-        throw UnparsableResponse(HttpStatusCode.BadRequest, response)
+        throw UnparsableResponse(
+            HttpStatusCode.BadRequest,
+            response
+        )
     }
 }
 
@@ -272,7 +285,10 @@ suspend inline fun <reified T, reified S> 
HttpClient.postToBankSigned(
     try {
         return XMLUtil.convertStringToJaxb(response)
     } catch (e: Exception) {
-        throw UnparsableResponse(HttpStatusCode.BadRequest, response)
+        throw UnparsableResponse(
+            HttpStatusCode.BadRequest,
+            response
+        )
     }
 }
 
@@ -289,7 +305,10 @@ suspend inline fun <reified T, reified S> 
HttpClient.postToBankUnsigned(
     try {
         return XMLUtil.convertStringToJaxb(response)
     } catch (e: Exception) {
-        throw UnparsableResponse(HttpStatusCode.BadRequest, response)
+        throw UnparsableResponse(
+            HttpStatusCode.BadRequest,
+            response
+        )
     }
 }
 
diff --git a/nexus/src/main/kotlin/JSON.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt
similarity index 92%
rename from nexus/src/main/kotlin/JSON.kt
rename to nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt
index f2dba5c..b6dea54 100644
--- a/nexus/src/main/kotlin/JSON.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt
@@ -1,8 +1,6 @@
-package tech.libeufin.nexus
+package tech.libeufin.nexus.tech.libeufin.nexus
 
-import com.google.gson.annotations.JsonAdapter
 import com.squareup.moshi.JsonClass
-import org.joda.time.DateTime
 
 
 data class EbicsBackupRequest(
diff --git a/nexus/src/main/kotlin/Main.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
similarity index 92%
rename from nexus/src/main/kotlin/Main.kt
rename to nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
index 6ec477b..8326055 100644
--- a/nexus/src/main/kotlin/Main.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -17,7 +17,7 @@
  * <http://www.gnu.org/licenses/>
  */
 
-package tech.libeufin.nexus
+package tech.libeufin.nexus.tech.libeufin.nexus
 
 import com.ryanharter.ktor.moshi.moshi
 import com.squareup.moshi.JsonDataException
@@ -201,7 +201,13 @@ fun main() {
                 // will throw DateTimeParseException if strings are malformed.
 
                 val subscriberData = transaction {
-                    containerInit(EbicsSubscriberEntity.findById(id) ?: throw 
SubscriberNotFoundError(HttpStatusCode.NotFound))
+                    containerInit(
+                        EbicsSubscriberEntity.findById(
+                            id
+                        ) ?: throw SubscriberNotFoundError(
+                            HttpStatusCode.NotFound
+                        )
+                    )
                 }
 
                 val response = client.postToBankSigned<EbicsRequest, 
EbicsResponse>(
@@ -217,7 +223,11 @@ fun main() {
                     subscriberData.customerAuthPriv
                 )
 
-                val payload: ByteArray = 
decryptAndDecompressResponse(response.value, subscriberData.customerEncPriv)
+                val payload: ByteArray =
+                    decryptAndDecompressResponse(
+                        response.value,
+                        subscriberData.customerEncPriv
+                    )
 
                 call.respondText(
                     payload.toString(Charsets.UTF_8),
@@ -237,7 +247,13 @@ fun main() {
             get("/ebics/subscribers/{id}/sendHtd") {
                 val id = expectId(call.parameters["id"])
                 val subscriberData = transaction {
-                    containerInit(EbicsSubscriberEntity.findById(id) ?: throw 
SubscriberNotFoundError(HttpStatusCode.NotFound))
+                    containerInit(
+                        EbicsSubscriberEntity.findById(
+                            id
+                        ) ?: throw SubscriberNotFoundError(
+                            HttpStatusCode.NotFound
+                        )
+                    )
                 }
 
                 val response = client.postToBankSigned<EbicsRequest, 
EbicsResponse>(
@@ -274,14 +290,18 @@ fun main() {
                 logger.debug("HTD payload is: 
${XMLUtil.convertJaxbToString(data)}")
 
                 val ackRequest = EbicsRequest.createForDownloadReceiptPhase(
-                    response.value.header._static.transactionID ?: throw 
BankInvalidResponse(HttpStatusCode.ExpectationFailed),
+                    response.value.header._static.transactionID ?: throw 
BankInvalidResponse(
+                        HttpStatusCode.ExpectationFailed
+                    ),
                     subscriberData.hostId
                 )
 
                 val ackResponse = 
client.postToBankSignedAndVerify<EbicsRequest, EbicsResponse>(
                     subscriberData.ebicsUrl,
                     ackRequest,
-                    subscriberData.bankAuthPub ?: throw 
BankKeyMissing(HttpStatusCode.PreconditionFailed),
+                    subscriberData.bankAuthPub ?: throw BankKeyMissing(
+                        HttpStatusCode.PreconditionFailed
+                    ),
                     subscriberData.customerAuthPriv
                 )
 
@@ -332,7 +352,9 @@ fun main() {
 
 
                 transaction {
-                    val subscriber = EbicsSubscriberEntity.findById(id) ?: 
throw SubscriberNotFoundError(HttpStatusCode.NotFound)
+                    val subscriber = EbicsSubscriberEntity.findById(id) ?: 
throw SubscriberNotFoundError(
+                        HttpStatusCode.NotFound
+                    )
 
                     val signPubTmp = CryptoUtil.getRsaPublicFromPrivate(
                         
CryptoUtil.loadRsaPrivateKey(subscriber.signaturePrivateKey.toByteArray())
@@ -463,7 +485,9 @@ fun main() {
             get("/ebics/subscribers/{id}") {
                 val id = expectId(call.parameters["id"])
                 val response = transaction {
-                    val tmp = EbicsSubscriberEntity.findById(id) ?: throw 
SubscriberNotFoundError(HttpStatusCode.NotFound)
+                    val tmp = EbicsSubscriberEntity.findById(id) ?: throw 
SubscriberNotFoundError(
+                        HttpStatusCode.NotFound
+                    )
                     EbicsSubscriberInfoResponse(
                         accountID = tmp.id.value,
                         hostID = tmp.hostID,
@@ -511,10 +535,14 @@ fun main() {
 
             post("/ebics/subscribers/{id}/sendIni") {
 
-                val id = expectId(call.parameters["id"]) // caught above
+                val id =
+                    expectId(call.parameters["id"]) // caught above
                 val subscriberData = transaction {
                     containerInit(
-                        EbicsSubscriberEntity.findById(id) ?: throw 
SubscriberNotFoundError(HttpStatusCode.NotFound)
+                        EbicsSubscriberEntity.findById(id)
+                            ?: throw SubscriberNotFoundError(
+                                HttpStatusCode.NotFound
+                            )
                     )
                 }
 
@@ -566,7 +594,9 @@ fun main() {
                 }
 
                 transaction {
-                    val subscriber = EbicsSubscriberEntity.findById(id) ?: 
throw SubscriberNotFoundError(HttpStatusCode.NotFound)
+                    val subscriber = EbicsSubscriberEntity.findById(id) ?: 
throw SubscriberNotFoundError(
+                        HttpStatusCode.NotFound
+                    )
 
                     subscriber.encryptionPrivateKey = 
SerialBlob(encKey.encoded)
                     subscriber.authenticationPrivateKey = 
SerialBlob(authKey.encoded)
@@ -587,7 +617,9 @@ fun main() {
                 val body = call.receive<EbicsBackupRequest>()
 
                 val content = transaction {
-                    val subscriber = EbicsSubscriberEntity.findById(id) ?: 
throw SubscriberNotFoundError(HttpStatusCode.NotFound)
+                    val subscriber = EbicsSubscriberEntity.findById(id) ?: 
throw SubscriberNotFoundError(
+                        HttpStatusCode.NotFound
+                    )
 
 
                     EbicsKeysBackup(
@@ -599,7 +631,8 @@ fun main() {
 
                         encBlob = CryptoUtil.encryptKey(
                             subscriber.encryptionPrivateKey.toByteArray(),
-                            body.passphrase),
+                            body.passphrase
+                        ),
 
                         sigBlob = CryptoUtil.encryptKey(
                             subscriber.signaturePrivateKey.toByteArray(),
@@ -621,7 +654,10 @@ fun main() {
 
                 val subscriberData = transaction {
                     containerInit(
-                        EbicsSubscriberEntity.findById(id) ?: throw 
SubscriberNotFoundError(HttpStatusCode.NotFound)
+                        EbicsSubscriberEntity.findById(id)
+                            ?: throw SubscriberNotFoundError(
+                                HttpStatusCode.NotFound
+                            )
                     )
                 }
                 val payload = "PAYLOAD"
@@ -707,7 +743,10 @@ fun main() {
                 val id = expectId(call.parameters["id"])
                 val bundle = transaction {
                     containerInit(
-                        EbicsSubscriberEntity.findById(id) ?: throw 
SubscriberNotFoundError(HttpStatusCode.NotFound)
+                        EbicsSubscriberEntity.findById(id)
+                            ?: throw SubscriberNotFoundError(
+                                HttpStatusCode.NotFound
+                            )
                     )
                 }
                 val response = client.postToBankSigned<EbicsNpkdRequest, 
EbicsKeyManagementResponse>(
@@ -769,7 +808,10 @@ fun main() {
 
                 val subscriberData = transaction {
                     containerInit(
-                        EbicsSubscriberEntity.findById(id) ?: throw 
SubscriberNotFoundError(HttpStatusCode.NotFound)
+                        EbicsSubscriberEntity.findById(id)
+                            ?: throw SubscriberNotFoundError(
+                                HttpStatusCode.NotFound
+                            )
                     )
                 }
 
diff --git a/nexus/src/test/kotlin/LetterFormatTest.kt 
b/nexus/src/test/kotlin/LetterFormatTest.kt
index f5a455e..7d9d26a 100644
--- a/nexus/src/test/kotlin/LetterFormatTest.kt
+++ b/nexus/src/test/kotlin/LetterFormatTest.kt
@@ -1,6 +1,8 @@
 package tech.libeufin.nexus
 
 import org.junit.Test
+import tech.libeufin.nexus.tech.libeufin.nexus.chunkString
+import tech.libeufin.nexus.tech.libeufin.nexus.getNonce
 import tech.libeufin.util.toHexString
 
 class LetterFormatTest {
diff --git a/nexus/src/test/kotlin/SignatureDataTest.kt 
b/nexus/src/test/kotlin/SignatureDataTest.kt
index cb0c1d5..899706f 100644
--- a/nexus/src/test/kotlin/SignatureDataTest.kt
+++ b/nexus/src/test/kotlin/SignatureDataTest.kt
@@ -3,6 +3,7 @@ package tech.libeufin.nexus
 import tech.libeufin.util.XMLUtil
 import org.apache.xml.security.binding.xmldsig.SignatureType
 import org.junit.Test
+import tech.libeufin.nexus.tech.libeufin.nexus.getNonce
 import tech.libeufin.util.CryptoUtil
 import tech.libeufin.util.ebics_h004.EbicsRequest
 import tech.libeufin.util.ebics_h004.EbicsTypes
diff --git a/sandbox/build.gradle b/sandbox/build.gradle
index 573671d..b1fdee3 100644
--- a/sandbox/build.gradle
+++ b/sandbox/build.gradle
@@ -4,12 +4,10 @@ plugins {
     id 'application'
 }
 
-
 sourceCompatibility = "11"
 targetCompatibility = "11"
 version '1.0-snapshot'
 
-
 compileKotlin {
 
     kotlinOptions {
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
index e8853d5..f825491 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
@@ -365,7 +365,6 @@ class EbicsUploadTransactionChunkEntity(id : 
EntityID<String>): Entity<String>(i
 
 fun dbCreateTables() {
     Database.connect("jdbc:sqlite:libeufin-sandbox.sqlite3", "org.sqlite.JDBC")
-    // Database.connect("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", driver = 
"org.h2.Driver")
     TransactionManager.manager.defaultIsolationLevel = 
Connection.TRANSACTION_SERIALIZABLE
 
     transaction {

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



reply via email to

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