gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated (3a53d88 -> ba998ad)


From: gnunet
Subject: [libeufin] branch master updated (3a53d88 -> ba998ad)
Date: Mon, 28 Oct 2019 22:46:40 +0100

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

dold pushed a change to branch master
in repository libeufin.

    from 3a53d88  share less build settings between gradle modules
     new a9c4bb1  implement XML signing, minor refactoring
     new 264d6c4  signing / verification WIP
     new ba998ad  file permission for schema

The 3 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:
 .idea/dictionaries/dold.xml                        |   7 +
 .idea/gradle.xml                                   |   2 +-
 .idea/misc.xml                                     |   2 +-
 sandbox/build.gradle                               |   3 +
 .../libeufin/messages/ebics/hev/ObjectFactory.java |   2 +-
 sandbox/src/main/kotlin/Main.kt                    |  16 +-
 sandbox/src/main/kotlin/{XML.kt => XMLUtil.kt}     | 233 ++++++++++++++-------
 sandbox/src/main/resources/ebics_hev.xsd           |   0
 sandbox/src/test/kotlin/GeneratePrivateKeyTest.kt  |   2 +-
 sandbox/src/test/kotlin/HiaLoadTest.kt             |  15 +-
 sandbox/src/test/kotlin/JaxbTest.kt                |   8 +-
 sandbox/src/test/kotlin/MarshalNonJaxbTest.kt      |   2 +-
 sandbox/src/test/kotlin/ResponseTest.kt            |   2 +-
 sandbox/src/test/kotlin/XmlSigTest.kt              |  33 +++
 sandbox/src/test/kotlin/XmlTest.kt                 |   5 +-
 sandbox/src/test/kotlin/XsiTypeAttributeTest.kt    |   8 +-
 16 files changed, 233 insertions(+), 107 deletions(-)
 create mode 100644 .idea/dictionaries/dold.xml
 rename sandbox/src/main/kotlin/{XML.kt => XMLUtil.kt} (55%)
 mode change 100755 => 100644 sandbox/src/main/resources/ebics_hev.xsd
 create mode 100644 sandbox/src/test/kotlin/XmlSigTest.kt

diff --git a/.idea/dictionaries/dold.xml b/.idea/dictionaries/dold.xml
new file mode 100644
index 0000000..bef9337
--- /dev/null
+++ b/.idea/dictionaries/dold.xml
@@ -0,0 +1,7 @@
+<component name="ProjectDictionaryState">
+  <dictionary name="dold">
+    <words>
+      <w>ebics</w>
+    </words>
+  </dictionary>
+</component>
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 49f0342..b8ed810 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -9,7 +9,7 @@
         <option name="distributionType" value="DEFAULT_WRAPPED" />
         <option name="externalProjectPath" value="$PROJECT_DIR$" />
         <option name="gradleHome" value="/usr/share/java/gradle" />
-        <option name="gradleJvm" value="11" />
+        <option name="gradleJvm" value="#JAVA_INTERNAL" />
         <option name="modules">
           <set>
             <option value="$PROJECT_DIR$" />
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 25d34a4..c1d4bf5 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="ExternalStorageConfigurationManager" enabled="true" />
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_11" 
project-jdk-name="11" project-jdk-type="JavaSDK" />
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_11" 
default="false" project-jdk-name="12" project-jdk-type="JavaSDK" />
 </project>
\ No newline at end of file
diff --git a/sandbox/build.gradle b/sandbox/build.gradle
index 876e554..912ec8c 100644
--- a/sandbox/build.gradle
+++ b/sandbox/build.gradle
@@ -33,6 +33,9 @@ dependencies {
     compile "javax.activation:activation:1.1"
     compile "org.glassfish.jaxb:jaxb-runtime:2.3.1"
     testCompile group: 'junit', name: 'junit', version: '4.12'
+    testImplementation 'org.jetbrains.kotlin:kotlin-test-junit:1.3.50'
+    testImplementation 'org.jetbrains.kotlin:kotlin-test:1.3.50'
+    compile 'org.apache.santuario:xmlsec:2.1.4'
     runtime rootProject.files("resources")
 }
 
diff --git 
a/sandbox/src/main/java/tech/libeufin/messages/ebics/hev/ObjectFactory.java 
b/sandbox/src/main/java/tech/libeufin/messages/ebics/hev/ObjectFactory.java
index 9eb2b69..8674e2d 100644
--- a/sandbox/src/main/java/tech/libeufin/messages/ebics/hev/ObjectFactory.java
+++ b/sandbox/src/main/java/tech/libeufin/messages/ebics/hev/ObjectFactory.java
@@ -11,7 +11,7 @@ import javax.xml.namespace.QName;
  * This object contains factory methods for each 
  * Java content interface and Java element interface 
  * generated in the tech.libeufin package. 
- * <p>An ObjectFactory allows you to programatically 
+ * <p>An ObjectFactory allows you to programmatically
  * construct new instances of the Java representation 
  * for XML content. The Java representation of XML 
  * content can consist of schema derived interfaces 
diff --git a/sandbox/src/main/kotlin/Main.kt b/sandbox/src/main/kotlin/Main.kt
index 7122e03..9e64892 100644
--- a/sandbox/src/main/kotlin/Main.kt
+++ b/sandbox/src/main/kotlin/Main.kt
@@ -36,6 +36,7 @@ import io.ktor.routing.post
 import io.ktor.routing.routing
 import io.ktor.server.engine.embeddedServer
 import io.ktor.server.netty.Netty
+import io.ktor.util.pipeline.PipelineContext
 import org.jetbrains.exposed.dao.EntityID
 import org.jetbrains.exposed.sql.transactions.transaction
 import org.slf4j.LoggerFactory
@@ -48,17 +49,15 @@ import java.math.BigInteger
 import java.nio.charset.StandardCharsets.US_ASCII
 import java.text.DateFormat
 import java.security.KeyFactory
-import java.security.KeyPairGenerator
 import java.security.PrivateKey
 import java.security.PublicKey
-import java.security.interfaces.RSAPrivateKey
 import java.security.spec.RSAPrivateKeySpec
 import java.security.spec.RSAPublicKeySpec
 import java.util.*
 import java.util.zip.InflaterInputStream
 
 val logger = LoggerFactory.getLogger("tech.libeufin.sandbox")
-val xmlProcess = XML()
+val xmlProcess = XMLUtil()
 val getEbicsHostId = {"LIBEUFIN-SANDBOX"}
 val getEbicsVersion = {"H004"}
 val getEbicsRevision = {1}
@@ -149,7 +148,7 @@ object OkHelper {
  * @return the modified document
  */
 fun downcastXml(document: Document, node: String, type: String) : Document {
-    logger.debug("Downcasting: ${xmlProcess.convertDomToString(document)}")
+    logger.debug("Downcasting: ${XMLUtil.convertDomToString(document)}")
     val x: Element = document.getElementsByTagNameNS(
         "urn:org:ebics:H004",
         "OrderDetails"
@@ -234,7 +233,7 @@ private suspend fun ApplicationCall.adminCustomers() {
     logger.info(body.toString())
 
     val returnId = transaction {
-        var myUserId = EbicsUser.new { }
+        val myUserId = EbicsUser.new { }
         val myPartnerId = EbicsPartner.new { }
         val mySystemId = EbicsSystem.new { }
         val subscriber = EbicsSubscriber.new {
@@ -395,10 +394,10 @@ private suspend fun ApplicationCall.ebicsweb() {
     val body: String = receiveText()
     logger.debug("Data received: $body")
 
-    val bodyDocument: Document? = xmlProcess.parseStringIntoDom(body)
+    val bodyDocument: Document? = XMLUtil.parseStringIntoDom(body)
 
     if (bodyDocument == null || (!xmlProcess.validateFromDom(bodyDocument))) {
-        var response = EbicsResponse(
+        val response = EbicsResponse(
             returnCode = InvalidXmlHelper.getCode(),
             reportText = InvalidXmlHelper.getMessage()
         )
@@ -493,7 +492,7 @@ private suspend fun ApplicationCall.ebicsweb() {
              */
             if (zkey.isEmpty()) {
                 logger.info("0-length key element given, invalid request")
-                var response = KeyManagementResponse(
+                val response = KeyManagementResponse(
                     returnCode = InvalidXmlHelper.getCode(),
                     reportText = InvalidXmlHelper.getMessage("Key field was 
empty")
                 )
@@ -678,6 +677,7 @@ private suspend fun ApplicationCall.ebicsweb() {
     }
 }
 
+
 fun main() {
     dbCreateTables()
     val server = embeddedServer(Netty, port = 5000) {
diff --git a/sandbox/src/main/kotlin/XML.kt b/sandbox/src/main/kotlin/XMLUtil.kt
similarity index 55%
rename from sandbox/src/main/kotlin/XML.kt
rename to sandbox/src/main/kotlin/XMLUtil.kt
index c9b96e4..5f16bf9 100644
--- a/sandbox/src/main/kotlin/XML.kt
+++ b/sandbox/src/main/kotlin/XMLUtil.kt
@@ -21,6 +21,8 @@ package tech.libeufin.sandbox
 
 import com.sun.org.apache.xerces.internal.dom.DOMInputImpl
 import org.w3c.dom.Document
+import org.w3c.dom.Node
+import org.w3c.dom.NodeList
 import org.w3c.dom.ls.LSInput
 import org.w3c.dom.ls.LSResourceResolver
 import org.xml.sax.ErrorHandler
@@ -28,25 +30,64 @@ import org.xml.sax.InputSource
 import org.xml.sax.SAXException
 import org.xml.sax.SAXParseException
 import java.io.*
+import java.security.PrivateKey
+import java.security.PublicKey
+import java.util.*
 import javax.xml.XMLConstants
 import javax.xml.bind.JAXBContext
 import javax.xml.bind.JAXBElement
 import javax.xml.bind.JAXBException
 import javax.xml.bind.Marshaller
+import javax.xml.crypto.*
+import javax.xml.crypto.dom.DOMURIReference
+import javax.xml.crypto.dsig.*
+import javax.xml.crypto.dsig.dom.DOMSignContext
+import javax.xml.crypto.dsig.dom.DOMValidateContext
+import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec
+import javax.xml.crypto.dsig.spec.TransformParameterSpec
 import javax.xml.parsers.DocumentBuilderFactory
 import javax.xml.parsers.ParserConfigurationException
-import javax.xml.transform.*
+import javax.xml.transform.OutputKeys
+import javax.xml.transform.Source
+import javax.xml.transform.TransformerFactory
 import javax.xml.transform.dom.DOMSource
 import javax.xml.transform.stream.StreamResult
 import javax.xml.transform.stream.StreamSource
 import javax.xml.validation.SchemaFactory
-
+import javax.xml.xpath.XPath
+import javax.xml.xpath.XPathConstants
+import javax.xml.xpath.XPathFactory
 
 /**
- * This class takes care of importing XSDs and validate
- * XMLs against those.
+ * Helpers for dealing with XML in EBICS.
  */
-class XML {
+class XMLUtil {
+    /**
+     * This URI dereferencer allows handling the resource reference used for
+     * XML signatures in EBICS.
+     */
+    private class EbicsSigUriDereferencer : URIDereferencer {
+        override fun dereference(myRef: URIReference?, myCtx: 
XMLCryptoContext?): Data {
+            val ebicsXpathExpr = "//*[@authenticate='true']"
+            if (myRef !is DOMURIReference)
+                throw Exception("invalid type")
+            if (myRef.uri != "#xpointer($ebicsXpathExpr)")
+                throw Exception("invalid EBICS XML signature URI: 
'${myRef.uri}'")
+            val xp: XPath = XPathFactory.newInstance().newXPath()
+            val nodeSet = 
xp.compile(ebicsXpathExpr).evaluate(myRef.here.ownerDocument, 
XPathConstants.NODESET)
+            if (nodeSet !is NodeList)
+                throw Exception("invalid type")
+            if (nodeSet.length <= 0) {
+                throw Exception("no nodes to sign")
+            }
+            val nodeList = LinkedList<Node>()
+            for (i in 0 until nodeSet.length) {
+                nodeList.add(nodeSet.item(i))
+            }
+            return NodeSetData { nodeList.iterator() }
+        }
+    }
+
     /**
      * Validator for EBICS messages.
      */
@@ -96,33 +137,6 @@ class XML {
     }
 
 
-    /**
-     * Parse string into XML DOM.
-     * @param xmlString the string to parse.
-     * @return the DOM representing @a xmlString
-     */
-    fun parseStringIntoDom(xmlString: String): Document? {
-
-        val factory = DocumentBuilderFactory.newInstance()
-        factory.isNamespaceAware = true
-
-        try {
-            val xmlInputStream = ByteArrayInputStream(xmlString.toByteArray())
-            val builder = factory.newDocumentBuilder()
-            val document = builder.parse(InputSource(xmlInputStream))
-
-            return document
-
-        } catch (e: ParserConfigurationException) {
-            e.printStackTrace()
-        } catch (e: SAXException) {
-            e.printStackTrace()
-        } catch (e: IOException) {
-            e.printStackTrace()
-        }
-        return null
-    }
-
     /**
      *
      * @param xmlDoc the XML document to validate
@@ -131,15 +145,11 @@ class XML {
     fun validate(xmlDoc: StreamSource): Boolean {
         try {
             validator?.validate(xmlDoc)
-        } catch (e: SAXException) {
-            println(e.message)
-            return false
-        } catch (e: IOException) {
-            e.printStackTrace()
+        } catch (e: Exception) {
+            logger.warn("Validation failed: {}", e)
             return false
         }
-
-        return true
+        return true;
     }
 
     /**
@@ -175,7 +185,7 @@ class XML {
      * @param document the document to convert into JAXB.
      * @return the JAXB object reflecting the original XML document.
      */
-    fun <T>convertDomToJaxb(finalType: Class<T>, document: Document) : 
JAXBElement<T> {
+    fun <T> convertDomToJaxb(finalType: Class<T>, document: Document): 
JAXBElement<T> {
 
         val jc = JAXBContext.newInstance(finalType)
 
@@ -191,7 +201,7 @@ class XML {
      * @param documentString the string to convert into JAXB.
      * @return the JAXB object reflecting the original XML document.
      */
-    fun <T>convertStringToJaxb(finalType: Class<T>, documentString: String) : 
JAXBElement<T> {
+    fun <T> convertStringToJaxb(finalType: Class<T>, documentString: String): 
JAXBElement<T> {
 
         val jc = JAXBContext.newInstance(finalType.packageName)
 
@@ -204,7 +214,6 @@ class XML {
     }
 
 
-
     /**
      * Return the DOM representation of the Java object, using the JAXB
      * interface.  FIXME: narrow input type to JAXB type!
@@ -213,7 +222,7 @@ class XML {
      *               has already got its setters called.
      * @return the DOM Document, or null (if errors occur).
      */
-    fun <T>convertJaxbToDom(obj: JAXBElement<T>): Document? {
+    fun <T> convertJaxbToDom(obj: JAXBElement<T>): Document? {
 
         try {
             val jc = JAXBContext.newInstance(obj.declaredType)
@@ -237,19 +246,42 @@ class XML {
     }
 
     /**
-     * Extract String from DOM.
+     * Extract String from JAXB.
      *
-     * @param document the DOM to extract the string from.
-     * @return the final String, or null if errors occur.
+     * @param obj the JAXB instance
+     * @return String representation of @a object, or null if errors occur
      */
-    fun convertDomToString(document: Document): String? {
+    fun <T> convertJaxbToString(obj: JAXBElement<T>): String? {
+        val sw = StringWriter()
 
         try {
+            val jc = JAXBContext.newInstance(obj.declaredType)
+            /* Getting the string.  */
+            val m = jc.createMarshaller()
+            m.marshal(obj, sw)
+            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true)
+
+        } catch (e: JAXBException) {
+            e.printStackTrace()
+            return "Bank fatal error."
+        }
+
+        return sw.toString()
+    }
+
+    companion object {
+        /**
+         * Extract String from DOM.
+         *
+         * @param document the DOM to extract the string from.
+         * @return the final String, or null if errors occur.
+         */
+        fun convertDomToString(document: Document): String? {
             /* Make Transformer.  */
             val tf = TransformerFactory.newInstance()
             val t = tf.newTransformer()
 
-            t.setOutputProperty(OutputKeys.INDENT, "no")
+            t.setOutputProperty(OutputKeys.INDENT, "yes")
 
             /* Make string writer.  */
             val sw = StringWriter()
@@ -257,36 +289,93 @@ class XML {
             /* Extract string.  */
             t.transform(DOMSource(document), StreamResult(sw))
             return sw.toString()
+        }
 
-        } catch (e: TransformerConfigurationException) {
-            e.printStackTrace()
-        } catch (e: TransformerException) {
-            e.printStackTrace()
+        fun convertNodeToString(node: Node): String? {
+            /* Make Transformer.  */
+            val tf = TransformerFactory.newInstance()
+            val t = tf.newTransformer()
+
+            t.setOutputProperty(OutputKeys.INDENT, "yes")
+
+            /* Make string writer.  */
+            val sw = StringWriter()
+
+            /* Extract string.  */
+            t.transform(DOMSource(node), StreamResult(sw))
+            return sw.toString()
         }
-        return null
-    }
 
-    /**
-     * Extract String from JAXB.
-     *
-     * @param obj the JAXB instance
-     * @return String representation of @a object, or null if errors occur
-     */
-    fun <T> convertJaxbToString(obj: JAXBElement<T>): String? {
-        val sw = StringWriter()
+        /**
+         * Parse string into XML DOM.
+         * @param xmlString the string to parse.
+         * @return the DOM representing @a xmlString
+         */
+        fun parseStringIntoDom(xmlString: String): Document {
+            val factory = DocumentBuilderFactory.newInstance().apply {
+                isNamespaceAware = true
+            }
+            val xmlInputStream = ByteArrayInputStream(xmlString.toByteArray())
+            val builder = factory.newDocumentBuilder()
+            return builder.parse(InputSource(xmlInputStream))
+        }
 
-        try {
-            val jc = JAXBContext.newInstance(obj.declaredType)
-            /* Getting the string.  */
-            val m = jc.createMarshaller()
-            m.marshal(obj, sw)
-            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true)
 
-        } catch (e: JAXBException) {
-            e.printStackTrace()
-            return "Bank fatal error."
+        /**
+         * Sign an EBICS document with the authentication and identity 
signature.
+         */
+        fun signEbicsDocument(doc: Document, signingPriv: PrivateKey): Unit {
+            val xpath = XPathFactory.newInstance().newXPath()
+            val authSigNode = 
xpath.compile("/*[1]/AuthSignature").evaluate(doc, XPathConstants.NODE)
+            if (authSigNode !is Node)
+                throw java.lang.Exception("no AuthSignature")
+            val fac = XMLSignatureFactory.getInstance("DOM")
+            val c14n = fac.newTransform(CanonicalizationMethod.INCLUSIVE, null 
as TransformParameterSpec?)
+            val ref: Reference =
+                fac.newReference(
+                    "#xpointer(//*[@authenticate='true'])",
+                    fac.newDigestMethod(DigestMethod.SHA256, null),
+                    listOf(c14n),
+                    null,
+                    null
+                )
+            val canon: CanonicalizationMethod =
+                
fac.newCanonicalizationMethod(CanonicalizationMethod.INCLUSIVE, null as 
C14NMethodParameterSpec?)
+            val signatureMethod = 
fac.newSignatureMethod(SignatureMethod.RSA_SHA256, null)
+            val si: SignedInfo = fac.newSignedInfo(canon, signatureMethod, 
listOf(ref))
+            val sig: XMLSignature = fac.newXMLSignature(si, null)
+            val dsc = DOMSignContext(signingPriv, authSigNode)
+            dsc.defaultNamespacePrefix = "ds"
+            dsc.uriDereferencer = EbicsSigUriDereferencer()
+
+            sig.sign(dsc)
+
+            val innerSig = authSigNode.firstChild
+            while (innerSig.hasChildNodes()) {
+                authSigNode.appendChild(innerSig.firstChild)
+            }
+            authSigNode.removeChild(innerSig)
         }
 
-        return sw.toString()
+        fun verifyEbicsDocument(doc: Document, signingPub: PublicKey): Boolean 
{
+            val xpath = XPathFactory.newInstance().newXPath()
+            val doc2: Document = doc.cloneNode(true) as Document
+            val authSigNode = 
xpath.compile("/*[1]/AuthSignature").evaluate(doc2, XPathConstants.NODE)
+            if (authSigNode !is Node)
+                throw java.lang.Exception("no AuthSignature")
+            val sigEl = 
doc2.createElementNS("http://www.w3.org/2000/09/xmldsig#";, "ds:Signature")
+            authSigNode.parentNode.insertBefore(sigEl, authSigNode)
+            while (authSigNode.hasChildNodes()) {
+                sigEl.appendChild(authSigNode.firstChild)
+            }
+            authSigNode.parentNode.removeChild(authSigNode)
+            val fac = XMLSignatureFactory.getInstance("DOM")
+            println(convertDomToString(doc2))
+            val dvc = DOMValidateContext(signingPub, sigEl)
+            dvc.uriDereferencer = EbicsSigUriDereferencer()
+            val sig = fac.unmarshalXMLSignature(dvc)
+            // FIXME: check that parameters are okay!
+            return sig.validate(dvc)
+        }
     }
 }
\ No newline at end of file
diff --git a/sandbox/src/main/resources/ebics_hev.xsd 
b/sandbox/src/main/resources/ebics_hev.xsd
old mode 100755
new mode 100644
diff --git a/sandbox/src/test/kotlin/GeneratePrivateKeyTest.kt 
b/sandbox/src/test/kotlin/GeneratePrivateKeyTest.kt
index d5f6496..cddd900 100644
--- a/sandbox/src/test/kotlin/GeneratePrivateKeyTest.kt
+++ b/sandbox/src/test/kotlin/GeneratePrivateKeyTest.kt
@@ -15,7 +15,7 @@ class GeneratePrivateKeyTest {
     @Test
     fun loadOrGeneratePrivateKey() {
 
-        val x = getOrMakePrivateKey()
+        getOrMakePrivateKey()
 
         assertTrue(
             transaction {
diff --git a/sandbox/src/test/kotlin/HiaLoadTest.kt 
b/sandbox/src/test/kotlin/HiaLoadTest.kt
index 349b180..bf34ccb 100644
--- a/sandbox/src/test/kotlin/HiaLoadTest.kt
+++ b/sandbox/src/test/kotlin/HiaLoadTest.kt
@@ -9,13 +9,14 @@ class HiaLoadTest {
     @Test
     fun hiaLoad() {
 
-        val processor = XML()
+        val processor = XMLUtil()
         val classLoader = ClassLoader.getSystemClassLoader()
         val hia = classLoader.getResource("HIA.xml")
-        val hiaDom = processor.parseStringIntoDom(hia.readText())
-        val x: Element = hiaDom?.getElementsByTagNameNS(
+        val hiaDom = XMLUtil.parseStringIntoDom(hia.readText())
+        val x: Element = hiaDom.getElementsByTagNameNS(
             "urn:org:ebics:H004",
-            "OrderDetails")?.item(0) as Element
+            "OrderDetails"
+        )?.item(0) as Element
 
         x.setAttributeNS(
             "http://www.w3.org/2001/XMLSchema-instance";,
@@ -25,9 +26,7 @@ class HiaLoadTest {
 
         processor.convertDomToJaxb<EbicsUnsecuredRequest>(
             EbicsUnsecuredRequest::class.java,
-            hiaDom!!)
+            hiaDom
+        )
     }
-
-
-
 }
\ No newline at end of file
diff --git a/sandbox/src/test/kotlin/JaxbTest.kt 
b/sandbox/src/test/kotlin/JaxbTest.kt
index 5de2cec..a5a788f 100644
--- a/sandbox/src/test/kotlin/JaxbTest.kt
+++ b/sandbox/src/test/kotlin/JaxbTest.kt
@@ -7,7 +7,7 @@ import 
tech.libeufin.messages.ebics.keyrequest.SignaturePubKeyOrderDataType
 
 class JaxbTest {
 
-    val processor = XML()
+    val processor = XMLUtil()
     val classLoader = ClassLoader.getSystemClassLoader()
     val hevResponseJaxb = HEVResponse(
         "000000",
@@ -80,11 +80,11 @@ class JaxbTest {
      */
     @Test
     fun domToJaxb() {
-
         val ini = 
classLoader.getResource("ebics_ini_request_sample_patched.xml")
-        val iniDom = processor.parseStringIntoDom(ini.readText())
+        val iniDom = XMLUtil.parseStringIntoDom(ini.readText())
         processor.convertDomToJaxb<EbicsUnsecuredRequest>(
             EbicsUnsecuredRequest::class.java,
-            iniDom!!)
+            iniDom
+        )
     }
 }
\ No newline at end of file
diff --git a/sandbox/src/test/kotlin/MarshalNonJaxbTest.kt 
b/sandbox/src/test/kotlin/MarshalNonJaxbTest.kt
index cc4759b..ce88953 100644
--- a/sandbox/src/test/kotlin/MarshalNonJaxbTest.kt
+++ b/sandbox/src/test/kotlin/MarshalNonJaxbTest.kt
@@ -34,7 +34,7 @@ class MarshalNonJaxbTest {
             "EBICS_NON_OK"
         )
 
-        val proc = XML()
+        val proc = XMLUtil()
         println(proc.convertJaxbToString(obj.get()))
     }
 }
\ No newline at end of file
diff --git a/sandbox/src/test/kotlin/ResponseTest.kt 
b/sandbox/src/test/kotlin/ResponseTest.kt
index 8a5d942..d13c1c3 100644
--- a/sandbox/src/test/kotlin/ResponseTest.kt
+++ b/sandbox/src/test/kotlin/ResponseTest.kt
@@ -4,7 +4,7 @@ import org.junit.Test
 
 class ResponseTest {
 
-    val xmlprocess = XML()
+    val xmlprocess = XMLUtil()
 
     @Test
     fun loadResponse() {
diff --git a/sandbox/src/test/kotlin/XmlSigTest.kt 
b/sandbox/src/test/kotlin/XmlSigTest.kt
new file mode 100644
index 0000000..febd0b2
--- /dev/null
+++ b/sandbox/src/test/kotlin/XmlSigTest.kt
@@ -0,0 +1,33 @@
+package tech.libeufin.sandbox
+
+import org.junit.Test
+import java.security.KeyPairGenerator
+import kotlin.test.*
+
+
+
+class XmlSigTest {
+
+    @Test
+    fun basicSigningTest() {
+        val doc = XMLUtil.parseStringIntoDom("""
+            <foo xmlns:ds="http://www.w3.org/2000/09/xmldsig#";>
+                <AuthSignature />
+                <bar authenticate='true'>bla</bar>Hello World
+                <spam>
+                eggs
+                
+                ham
+                </spam>
+            </foo>
+        """.trimIndent())
+        val kpg = KeyPairGenerator.getInstance("RSA")
+        kpg.initialize(2048)
+        val pair = kpg.genKeyPair()
+        val otherPair = kpg.genKeyPair()
+        XMLUtil.signEbicsDocument(doc, pair.private)
+        println(XMLUtil.convertDomToString(doc))
+        assertTrue(XMLUtil.verifyEbicsDocument(doc, pair.public))
+        assertFalse(XMLUtil.verifyEbicsDocument(doc, otherPair.public))
+    }
+}
\ No newline at end of file
diff --git a/sandbox/src/test/kotlin/XmlTest.kt 
b/sandbox/src/test/kotlin/XmlTest.kt
index ca3176b..121e198 100644
--- a/sandbox/src/test/kotlin/XmlTest.kt
+++ b/sandbox/src/test/kotlin/XmlTest.kt
@@ -1,15 +1,12 @@
 package tech.libeufin.sandbox
 
-import org.junit.Assert
 import org.junit.Test
 import org.junit.Assert.*
-import java.io.File
-import javax.xml.transform.Source
 import javax.xml.transform.stream.StreamSource
 
 class XmlTest {
 
-    val processor = tech.libeufin.sandbox.XML()
+    val processor = tech.libeufin.sandbox.XMLUtil()
 
     @Test
     fun hevValidation(){
diff --git a/sandbox/src/test/kotlin/XsiTypeAttributeTest.kt 
b/sandbox/src/test/kotlin/XsiTypeAttributeTest.kt
index 73c4811..84eb1eb 100644
--- a/sandbox/src/test/kotlin/XsiTypeAttributeTest.kt
+++ b/sandbox/src/test/kotlin/XsiTypeAttributeTest.kt
@@ -3,19 +3,17 @@ package tech.libeufin.sandbox
 import org.junit.Test
 import org.w3c.dom.Element
 import tech.libeufin.messages.ebics.keyrequest.EbicsUnsecuredRequest
-import tech.libeufin.messages.ebics.keyrequest.OrderDetailsType
-import tech.libeufin.messages.ebics.keyrequest.UnsecuredReqOrderDetailsType
 
 class XsiTypeAttributeTest {
 
     @Test
     fun domToJaxb() {
 
-        val processor = XML()
+        val processor = XMLUtil()
         val classLoader = ClassLoader.getSystemClassLoader()
         val ini = classLoader.getResource("ebics_ini_request_sample.xml")
-        val iniDom = processor.parseStringIntoDom(ini.readText())
-        val x: Element = iniDom?.getElementsByTagName("OrderDetails")?.item(0) 
as Element
+        val iniDom = XMLUtil.parseStringIntoDom(ini.readText())
+        val x: Element = iniDom.getElementsByTagName("OrderDetails")?.item(0) 
as Element
 
         x.setAttributeNS(
             "http://www.w3.org/2001/XMLSchema-instance";,

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



reply via email to

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