libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit 537e5d6a77664d3968f68106e105855f692ff0f8
parent 60b65886f825057a74e208de9a345c61115c128d
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Thu, 17 Oct 2019 17:41:21 +0200

fix integer instantiation

Diffstat:
Msandbox/src/main/kotlin/DB.kt | 51++++++++++++++++++++++++++++++---------------------
Msandbox/src/main/kotlin/Main.kt | 11+++++------
Msandbox/src/test/kotlin/DbTest.kt | 1-
Asandbox/src/test/kotlin/InnerIniLoadTest.kt | 31+++++++++++++++++++++++++++++++
Msandbox/src/test/kotlin/RsaTest.kt | 14+++++++++++++-
5 files changed, 79 insertions(+), 29 deletions(-)

diff --git a/sandbox/src/main/kotlin/DB.kt b/sandbox/src/main/kotlin/DB.kt @@ -148,6 +148,28 @@ class EbicsSystem(id: EntityID<Int>) : IntEntity(id) { } /** + * This table stores RSA public keys. + */ +object EbicsPublicKeys: IntIdTable() { + val pub = binary("pub", PUBLIC_KEY_MAX_LENGTH) + val state = customEnumeration( + "state", + "ENUM('MISSING', 'NEW', 'RELEASED')", + {KeyStates.values()[it as Int]}, + {it.name}) +} + + +/** + * Definition of a row in the keys table + */ +class EbicsPublicKey(id: EntityID<Int>) : IntEntity(id) { + companion object : IntEntityClass<EbicsPublicKey>(EbicsPublicKeys) + var pub by EbicsPublicKeys.pub + var state by EbicsPublicKeys.state +} + +/** * Subscribers table. This table associates users with partners * and systems. Each value can appear multiple times in the same column. */ @@ -156,9 +178,9 @@ object EbicsSubscribers: IntIdTable() { val partnerId = reference("PartnerId", EbicsPartners) val systemId = reference("SystemId", EbicsSystems) - val signatureKey = reference("signatureKey", EbicsPublicKey).nullable() - val encryptionKey = reference("encryptionKey", EbicsPublicKey).nullable() - val authorizationKey = reference("authorizationKey", EbicsPublicKey).nullable() + val signatureKey = reference("signatureKey", EbicsPublicKeys).nullable() + val encryptionKey = reference("encryptionKey", EbicsPublicKeys).nullable() + val authorizationKey = reference("authorizationKey", EbicsPublicKeys).nullable() val state = customEnumeration( "state", @@ -174,9 +196,9 @@ class EbicsSubscriber(id: EntityID<Int>) : IntEntity(id) { var partnerId by EbicsPartner referencedOn EbicsSubscribers.partnerId var systemId by EbicsSystem referencedOn EbicsSubscribers.systemId - var signatureKey by EbicsPublicKey.id - var encryptionKey by EbicsPublicKey.id - var authorizationKey by EbicsPublicKey.id + var signatureKey by EbicsPublicKey optionalReferencedOn EbicsSubscribers.signatureKey + var encryptionKey by EbicsPublicKey optionalReferencedOn EbicsSubscribers.encryptionKey + var authorizationKey by EbicsPublicKey optionalReferencedOn EbicsSubscribers.authorizationKey var state by EbicsSubscribers.state } @@ -196,21 +218,9 @@ fun createSubscriber() : EbicsSubscriber { /** - * This table stores RSA public keys. - */ -object EbicsPublicKey: IntIdTable() { - val pub = binary("pub", PUBLIC_KEY_MAX_LENGTH) - val state = customEnumeration( - "state", - "ENUM('MISSING', 'NEW', 'RELEASED')", - {KeyStates.values()[it as Int]}, - {it.name}) -} - -/** * This table stores RSA private keys. */ -object EbicsPrivateKEy: IntIdTable() { +object EbicsPrivateKey: IntIdTable() { val pub = binary("priv", PRIV_KEY_MAX_LENGTH) } @@ -228,4 +238,4 @@ fun dbCreateTables() { EbicsSubscribers ) } -} -\ No newline at end of file +} diff --git a/sandbox/src/main/kotlin/Main.kt b/sandbox/src/main/kotlin/Main.kt @@ -102,12 +102,13 @@ fun downcastXml(document: Document, node: String, type: String) : Document { * @param modulus * @return key */ -fun loadRsaPublicKey (exponent: ByteArray, modulus: ByteArray) : PublicKey { +fun loadRsaPublicKey (modulus: ByteArray, exponent: ByteArray) : PublicKey { + + val modulusBigInt = BigInteger(1, modulus) + val exponentBigInt = BigInteger(1, exponent) - val exponentBigInt = BigInteger(exponent) - val modulusBigInt = BigInteger(modulus) val keyFactory = KeyFactory.getInstance("RSA") - val tmp = RSAPublicKeySpec(exponentBigInt, modulusBigInt) + val tmp = RSAPublicKeySpec(modulusBigInt, exponentBigInt) return keyFactory.generatePublic(tmp) } @@ -315,8 +316,6 @@ private suspend fun ApplicationCall.ebicsweb() { return } - logger.debug(EbicsUsers.userId.name) - // store key in database diff --git a/sandbox/src/test/kotlin/DbTest.kt b/sandbox/src/test/kotlin/DbTest.kt @@ -28,7 +28,6 @@ class DbTest { pub = "BINARYVALUE".toByteArray() state = KeyStates.NEW } - subscriber.authorizationKey = key } } diff --git a/sandbox/src/test/kotlin/InnerIniLoadTest.kt b/sandbox/src/test/kotlin/InnerIniLoadTest.kt @@ -0,0 +1,30 @@ +package tech.libeufin.sandbox + +import org.junit.Test +import tech.libeufin.messages.ebics.keyrequest.SignaturePubKeyOrderDataType +import java.math.BigInteger + +class InnerIniLoadTest { + + val jaxbKey = { + val classLoader = ClassLoader.getSystemClassLoader() + val file = classLoader.getResource( + "ebics_ini_inner_key.xml" + ) + xmlProcess.convertStringToJaxb( + SignaturePubKeyOrderDataType::class.java, + file.readText() + ) + }() + + @Test + fun loadInnerKey() { + + val modulus = jaxbKey.value.signaturePubKeyInfo.pubKeyValue.rsaKeyValue.modulus + val exponent = jaxbKey.value.signaturePubKeyInfo.pubKeyValue.rsaKeyValue.exponent + + loadRsaPublicKey(modulus, exponent) + } + + +} +\ No newline at end of file diff --git a/sandbox/src/test/kotlin/RsaTest.kt b/sandbox/src/test/kotlin/RsaTest.kt @@ -11,9 +11,21 @@ class RsaTest { @Test fun loadFromModulusAndExponent() { - val key = loadRsaPublicKey(publicExponent.toByteArray(), publicModulus.toByteArray()) println(key.toString()) + } + + /** + * Values generating helper. + */ + @Test + fun getBase64Values() { + println( + "Modulus: ${Base64.getEncoder().encodeToString(publicModulus.toByteArray())}" + ) + println( + "Exponent: ${Base64.getEncoder().encodeToString(publicExponent.toByteArray())}" + ) } } \ No newline at end of file