gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libeufin] branch master updated: load RSA public key


From: gnunet
Subject: [GNUnet-SVN] [libeufin] branch master updated: load RSA public key
Date: Thu, 17 Oct 2019 10:46:08 +0200

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

marcello pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new 0953e0b  load RSA public key
0953e0b is described below

commit 0953e0bf43e5a260af13e3fd0d5580d690697358
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Oct 17 10:46:01 2019 +0200

    load RSA public key
---
 sandbox/src/main/kotlin/Main.kt    | 48 ++++++++++++++++++++++++++++++++++----
 sandbox/src/test/kotlin/RsaTest.kt | 19 +++++++++++++++
 2 files changed, 63 insertions(+), 4 deletions(-)

diff --git a/sandbox/src/main/kotlin/Main.kt b/sandbox/src/main/kotlin/Main.kt
index 4a11650..21b0520 100644
--- a/sandbox/src/main/kotlin/Main.kt
+++ b/sandbox/src/main/kotlin/Main.kt
@@ -45,18 +45,24 @@ import tech.libeufin.messages.ebics.hev.HEVResponseDataType
 import tech.libeufin.messages.ebics.keyrequest.EbicsUnsecuredRequest
 import tech.libeufin.messages.ebics.keyrequest.SignaturePubKeyOrderDataType
 import tech.libeufin.messages.ebics.keyrequest.UnsecuredReqOrderDetailsType
+import java.math.BigInteger
 import java.nio.charset.StandardCharsets.US_ASCII
 import java.text.DateFormat
 import java.util.*
 import java.util.zip.GZIPInputStream
 import javax.xml.bind.JAXBElement
 import java.nio.charset.StandardCharsets.UTF_8
+import java.security.KeyFactory
+import java.security.PublicKey
+import java.security.interfaces.RSAPublicKey
+import java.security.spec.RSAPublicKeySpec
 import java.util.zip.Inflater
 import java.util.zip.InflaterInputStream
 
 
 val logger = LoggerFactory.getLogger("tech.libeufin.sandbox")
 val xmlProcess = XML()
+val getEbicsHostId = {"LIBEUFIN-SANDBOX"}
 
 /**
  * Sometimes, JAXB is not able to figure out to which type
@@ -88,6 +94,23 @@ fun downcastXml(document: Document, node: String, type: 
String) : Document {
     return document
 }
 
+/**
+ * Instantiate a new RSA public key.
+ *
+ * @param exponent
+ * @param modulus
+ * @return key
+ */
+fun loadRsaPublicKey (exponent: ByteArray, modulus: ByteArray) : PublicKey {
+
+    val exponentBigInt = BigInteger(exponent)
+    val modulusBigInt = BigInteger(modulus)
+    val keyFactory = KeyFactory.getInstance("RSA")
+    val tmp = RSAPublicKeySpec(exponentBigInt, modulusBigInt)
+    return keyFactory.generatePublic(tmp)
+}
+
+
 private suspend fun ApplicationCall.adminCustomers() {
     val body = try {
         receive<CustomerRequest>()
@@ -207,11 +230,17 @@ private suspend fun ApplicationCall.ebicsweb() {
 
     logger.info("Processing ${bodyDocument.documentElement.localName}")
 
+    val hostId = bodyDocument.getElementsByTagName("HostID").item(0)
+    if (hostId.nodeValue != getEbicsHostId()) {
+        respond(
+            HttpStatusCode.NotFound,
+            SandboxError("Unknown HostID specified")
+        )
+    }
+
     when (bodyDocument.documentElement.localName) {
         "ebicsUnsecuredRequest" -> {
 
-            /* Manage request.  */
-
             val bodyJaxb = xmlProcess.convertDomToJaxb(
                 EbicsUnsecuredRequest::class.java,
                 downcastXml(
@@ -242,7 +271,7 @@ private suspend fun ApplicationCall.ebicsweb() {
                     if (zkey.isEmpty()) {
                         logger.error("0-length key element given, invalid 
request")
                         respondText(
-                            contentType = ContentType.Application.Xml,
+                            contentType = ContentType.Text.Plain,
                             status = HttpStatusCode.BadRequest
                         ) { "Bad request / invalid document" }
 
@@ -269,7 +298,18 @@ private suspend fun ApplicationCall.ebicsweb() {
                         result.toString(US_ASCII)
                     )
 
-                    
println(keyObject.value.signaturePubKeyInfo.signatureVersion)
+                    // get the customer id
+                    val ebicsUserId = bodyJaxb.value.header.static.userID
+
+                    // get key modulus and exponent
+                    // (do sanity check on the key - see if it loads)
+
+                    val publicKeyy = loadRsaPublicKey(
+                        
keyObject.value.signaturePubKeyInfo.pubKeyValue.rsaKeyValue.modulus,
+                        
keyObject.value.signaturePubKeyInfo.pubKeyValue.rsaKeyValue.exponent
+                    )
+                    // store key in database
+
 
                 }
             }
diff --git a/sandbox/src/test/kotlin/RsaTest.kt 
b/sandbox/src/test/kotlin/RsaTest.kt
new file mode 100644
index 0000000..c4637e8
--- /dev/null
+++ b/sandbox/src/test/kotlin/RsaTest.kt
@@ -0,0 +1,19 @@
+package tech.libeufin.sandbox
+
+import org.junit.Test
+import java.math.BigInteger
+import java.util.*
+
+class RsaTest {
+
+    val publicModulus = BigInteger("65537")
+    val publicExponent = BigInteger(512, Random())
+
+    @Test
+    fun loadFromModulusAndExponent() {
+
+        val key = loadRsaPublicKey(publicExponent.toByteArray(), 
publicModulus.toByteArray())
+        println(key.toString())
+
+    }
+}
\ No newline at end of file

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



reply via email to

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