[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: reduce newlines
From: |
gnunet |
Subject: |
[libeufin] branch master updated: reduce newlines |
Date: |
Wed, 29 Jan 2020 16:54:10 +0100 |
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 7db84ba reduce newlines
7db84ba is described below
commit 7db84ba88dd17c557273046ce9269f4fe79f6cb1
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed Jan 29 16:54:05 2020 +0100
reduce newlines
---
.../main/kotlin/tech/libeufin/nexus/Containers.kt | 5 ----
nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 3 ---
util/src/main/kotlin/CryptoUtil.kt | 30 ---------------------
util/src/main/kotlin/XMLUtil.kt | 31 ----------------------
util/src/main/kotlin/XmlCombinators.kt | 9 -------
5 files changed, 78 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Containers.kt
b/nexus/src/main/kotlin/tech/libeufin/nexus/Containers.kt
index 32526ab..a19be7d 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Containers.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Containers.kt
@@ -1,12 +1,7 @@
package tech.libeufin.nexus
-import javax.crypto.SecretKey
-import org.w3c.dom.Document
-import java.security.PrivateKey
import java.security.interfaces.RSAPrivateCrtKey
import java.security.interfaces.RSAPublicKey
-import javax.xml.bind.JAXBElement
-
/**
* This class is a mere container that keeps data found
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
index 625ea57..79ed455 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
@@ -9,7 +9,6 @@ import java.sql.Connection
const val ID_MAX_LENGTH = 50
object EbicsSubscribersTable : IdTable<String>() {
-
override val id = varchar("id", ID_MAX_LENGTH).entityId().primaryKey()
val ebicsURL = text("ebicsURL")
val hostID = text("hostID")
@@ -24,7 +23,6 @@ object EbicsSubscribersTable : IdTable<String>() {
}
class EbicsSubscriberEntity(id: EntityID<String>) : Entity<String>(id) {
-
companion object : EntityClass<String,
EbicsSubscriberEntity>(EbicsSubscribersTable)
var ebicsURL by EbicsSubscribersTable.ebicsURL
var hostID by EbicsSubscribersTable.hostID
@@ -41,7 +39,6 @@ class EbicsSubscriberEntity(id: EntityID<String>) :
Entity<String>(id) {
fun dbCreateTables() {
Database.connect("jdbc:sqlite:libeufin-nexus.sqlite3", "org.sqlite.JDBC")
TransactionManager.manager.defaultIsolationLevel =
Connection.TRANSACTION_SERIALIZABLE
-
transaction {
addLogger(StdOutSqlLogger)
SchemaUtils.create(
diff --git a/util/src/main/kotlin/CryptoUtil.kt
b/util/src/main/kotlin/CryptoUtil.kt
index f15784b..9867f02 100644
--- a/util/src/main/kotlin/CryptoUtil.kt
+++ b/util/src/main/kotlin/CryptoUtil.kt
@@ -43,20 +43,16 @@ object CryptoUtil {
* RSA key pair.
*/
data class RsaCrtKeyPair(val private: RSAPrivateCrtKey, val public:
RSAPublicKey)
-
class EncryptionResult(
val encryptedTransactionKey: ByteArray,
val pubKeyDigest: ByteArray,
val encryptedData: ByteArray,
-
/**
* This key needs to be reused between different upload phases.
*/
val plainTransactionKey: SecretKey? = null
)
-
private val bouncyCastleProvider = BouncyCastleProvider()
-
/**
* Load an RSA private key from its binary PKCS#8 encoding.
*/
@@ -67,7 +63,6 @@ object CryptoUtil {
throw Exception("wrong encoding")
return priv
}
-
/**
* Load an RSA public key from its binary X509 encoding.
*/
@@ -78,7 +73,6 @@ object CryptoUtil {
throw Exception("wrong encoding")
return pub
}
-
/**
* Load an RSA public key from its binary X509 encoding.
*/
@@ -89,7 +83,6 @@ object CryptoUtil {
throw Exception("wrong encoding")
return pub
}
-
/**
* Generate a fresh RSA key pair.
*
@@ -107,7 +100,6 @@ object CryptoUtil {
throw Exception("key generation failed")
return RsaCrtKeyPair(priv, pub)
}
-
/**
* Load an RSA public key from its components.
*
@@ -123,7 +115,6 @@ object CryptoUtil {
val tmp = RSAPublicKeySpec(modulusBigInt, exponentBigInt)
return keyFactory.generatePublic(tmp) as RSAPublicKey
}
-
/**
* Hash an RSA public key according to the EBICS standard (EBICS 2.5:
4.4.1.2.3).
*/
@@ -135,7 +126,6 @@ object CryptoUtil {
val digest = MessageDigest.getInstance("SHA-256")
return digest.digest(keyBytes.toByteArray())
}
-
fun encryptEbicsE002(data: ByteArray, encryptionPublicKey: RSAPublicKey):
EncryptionResult {
val keygen = KeyGenerator.getInstance("AES", bouncyCastleProvider)
keygen.init(128)
@@ -146,7 +136,6 @@ object CryptoUtil {
transactionKey
)
}
-
/**
* Encrypt data according to the EBICS E002 encryption process.
*/
@@ -155,7 +144,6 @@ object CryptoUtil {
encryptionPublicKey: RSAPublicKey,
transactionKey: SecretKey
): EncryptionResult {
-
val symmetricCipher = Cipher.getInstance("AES/CBC/X9.23Padding",
bouncyCastleProvider
)
@@ -175,7 +163,6 @@ object CryptoUtil {
transactionKey
)
}
-
fun decryptEbicsE002(enc: EncryptionResult, privateKey: RSAPrivateCrtKey):
ByteArray {
return decryptEbicsE002(
enc.encryptedTransactionKey,
@@ -183,7 +170,6 @@ object CryptoUtil {
privateKey
)
}
-
fun decryptEbicsE002(encryptedTransactionKey: ByteArray, encryptedData:
ByteArray, privateKey: RSAPrivateCrtKey): ByteArray {
val asymmetricCipher = Cipher.getInstance("RSA/None/PKCS1Padding",
bouncyCastleProvider
@@ -200,7 +186,6 @@ object CryptoUtil {
val data = symmetricCipher.doFinal(encryptedData)
return data
}
-
/**
* Signing algorithm corresponding to the EBICS A006 signing process.
*
@@ -215,7 +200,6 @@ object CryptoUtil {
signature.update(data)
return signature.sign()
}
-
fun verifyEbicsA006(sig: ByteArray, data: ByteArray, publicKey:
RSAPublicKey): Boolean {
val signature = Signature.getInstance("SHA256withRSA/PSS",
bouncyCastleProvider)
signature.setParameter(PSSParameterSpec("SHA-256", "MGF1",
MGF1ParameterSpec.SHA256, 32, 1))
@@ -223,7 +207,6 @@ object CryptoUtil {
signature.update(data)
return signature.verify(sig)
}
-
fun digestEbicsOrderA006(orderData: ByteArray): ByteArray {
val digest = MessageDigest.getInstance("SHA-256")
for (b in orderData) {
@@ -234,14 +217,11 @@ object CryptoUtil {
}
return digest.digest()
}
-
-
fun decryptKey(data: EncryptedPrivateKeyInfo, passphrase: String):
RSAPrivateCrtKey {
/* make key out of passphrase */
val pbeKeySpec = PBEKeySpec(passphrase.toCharArray())
val keyFactory = SecretKeyFactory.getInstance(data.algName)
val secretKey = keyFactory.generateSecret(pbeKeySpec)
-
/* Make a cipher */
val cipher = Cipher.getInstance(data.algName)
cipher.init(
@@ -249,7 +229,6 @@ object CryptoUtil {
secretKey,
data.algParameters // has hash count and salt
)
-
/* Ready to decrypt */
val decryptedKeySpec: PKCS8EncodedKeySpec = data.getKeySpec(cipher)
val priv =
KeyFactory.getInstance("RSA").generatePrivate(decryptedKeySpec)
@@ -257,36 +236,27 @@ object CryptoUtil {
throw Exception("wrong encoding")
return priv
}
-
fun encryptKey(data: ByteArray, passphrase: String): ByteArray {
-
/* Cipher parameters: salt and hash count */
val hashIterations = 30
val salt = ByteArray(8)
SecureRandom().nextBytes(salt)
val pbeParameterSpec = PBEParameterSpec(salt, hashIterations)
-
/* *Other* cipher parameters: symmetric key (from password) */
val pbeAlgorithm = "PBEWithSHA1AndDESede"
val pbeKeySpec = PBEKeySpec(passphrase.toCharArray())
val keyFactory = SecretKeyFactory.getInstance(pbeAlgorithm)
val secretKey = keyFactory.generateSecret(pbeKeySpec)
-
/* Make a cipher */
val cipher = Cipher.getInstance(pbeAlgorithm)
cipher.init(Cipher.ENCRYPT_MODE, secretKey, pbeParameterSpec)
-
/* ready to encrypt now */
val cipherText = cipher.doFinal(data)
-
/* Must now bundle a PKCS#8-compatible object, that contains
* algorithm, salt and hash count information */
-
val bundleAlgorithmParams =
AlgorithmParameters.getInstance(pbeAlgorithm)
bundleAlgorithmParams.init(pbeParameterSpec)
-
val bundle = EncryptedPrivateKeyInfo(bundleAlgorithmParams, cipherText)
-
return bundle.encoded
}
}
diff --git a/util/src/main/kotlin/XMLUtil.kt b/util/src/main/kotlin/XMLUtil.kt
index e7fef95..eeeba86 100644
--- a/util/src/main/kotlin/XMLUtil.kt
+++ b/util/src/main/kotlin/XMLUtil.kt
@@ -104,16 +104,12 @@ class XMLUtil private constructor() {
* Validator for EBICS messages.
*/
private val validator = try {
-
} catch (e: SAXException) {
e.printStackTrace()
throw e
}
-
companion object {
-
private var cachedEbicsValidator: Validator? = null
-
private fun getEbicsValidator(): Validator {
val currentValidator = cachedEbicsValidator
if (currentValidator != null)
@@ -160,7 +156,6 @@ class XMLUtil private constructor() {
cachedEbicsValidator = newValidator
return newValidator
}
-
/**
*
* @param xmlDoc the XML document to validate
@@ -175,7 +170,6 @@ class XMLUtil private constructor() {
}
return true;
}
-
/**
* Validates the DOM against the Schema(s) of this object.
* @param domDocument DOM to validate
@@ -190,7 +184,6 @@ class XMLUtil private constructor() {
}
return true
}
-
/**
* Craft object to be passed to the XML validator.
* @param xmlString XML body, as read from the POST body.
@@ -201,8 +194,6 @@ class XMLUtil private constructor() {
val xmlSource = StreamSource(xmlInputStream)
return validate(xmlSource)
}
-
-
inline fun <reified T> convertJaxbToString(obj: T): String {
val sw = StringWriter()
val jc = JAXBContext.newInstance(T::class.java)
@@ -212,7 +203,6 @@ class XMLUtil private constructor() {
m.marshal(obj, sw)
return sw.toString()
}
-
inline fun <reified T> convertJaxbToDocument(obj: T): Document {
val dbf: DocumentBuilderFactory =
DocumentBuilderFactory.newInstance()
dbf.isNamespaceAware = true
@@ -224,7 +214,6 @@ class XMLUtil private constructor() {
m.marshal(obj, doc)
return doc
}
-
/**
* Convert a XML string to the JAXB representation.
*
@@ -239,7 +228,6 @@ class XMLUtil private constructor() {
T::class.java
)
}
-
/**
* Extract String from DOM.
*
@@ -260,7 +248,6 @@ class XMLUtil private constructor() {
t.transform(DOMSource(document), StreamResult(sw))
return sw.toString()
}
-
/**
* Convert a node to a string without the XML declaration or
* indentation.
@@ -269,17 +256,13 @@ class XMLUtil private constructor() {
/* Make Transformer. */
val tf = TransformerFactory.newInstance()
val t = tf.newTransformer()
-
t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
-
/* Make string writer. */
val sw = StringWriter()
-
/* Extract string. */
t.transform(DOMSource(node), StreamResult(sw))
return sw.toString()
}
-
/**
* Convert a DOM document to the JAXB representation.
*
@@ -288,14 +271,11 @@ class XMLUtil private constructor() {
* @return the JAXB object reflecting the original XML document.
*/
fun <T> convertDomToJaxb(finalType: Class<T>, document: Document):
JAXBElement<T> {
-
val jc = JAXBContext.newInstance(finalType)
-
/* Marshalling the object into the document. */
val m = jc.createUnmarshaller()
return m.unmarshal(document, finalType) // document "went" into
Jaxb
}
-
/**
* Parse string into XML DOM.
* @param xmlString the string to parse.
@@ -309,7 +289,6 @@ class XMLUtil private constructor() {
val builder = factory.newDocumentBuilder()
return builder.parse(InputSource(xmlInputStream))
}
-
fun signEbicsResponse(ebicsResponse: EbicsResponse, privateKey:
RSAPrivateCrtKey): String {
val doc = convertJaxbToDocument(ebicsResponse)
signEbicsDocument(doc, privateKey)
@@ -317,7 +296,6 @@ class XMLUtil private constructor() {
println("response: $signedDoc")
return signedDoc
}
-
/**
* Sign an EBICS document with the authentication and identity
signature.
*/
@@ -330,11 +308,9 @@ class XMLUtil private constructor() {
else -> throw IllegalArgumentException()
}
}
-
override fun getPrefix(p0: String?): String {
throw UnsupportedOperationException()
}
-
override fun getPrefixes(p0: String?): MutableIterator<String>
{
throw UnsupportedOperationException()
}
@@ -360,20 +336,15 @@ class XMLUtil private constructor() {
val dsc = DOMSignContext(signingPriv, authSigNode)
dsc.defaultNamespacePrefix = "ds"
dsc.uriDereferencer = EbicsSigUriDereferencer()
-
dsc.setProperty("javax.xml.crypto.dsig.cacheReference", true)
-
sig.sign(dsc)
-
println("canon data: " +
sig.signedInfo.canonicalizedData.readAllBytes().toString(Charsets.UTF_8))
-
val innerSig = authSigNode.firstChild
while (innerSig.hasChildNodes()) {
authSigNode.appendChild(innerSig.firstChild)
}
authSigNode.removeChild(innerSig)
}
-
fun verifyEbicsDocument(doc: Document, signingPub: PublicKey): Boolean
{
val xpath = XPathFactory.newInstance().newXPath()
xpath.namespaceContext = object : NamespaceContext {
@@ -383,11 +354,9 @@ class XMLUtil private constructor() {
else -> throw IllegalArgumentException()
}
}
-
override fun getPrefix(p0: String?): String {
throw UnsupportedOperationException()
}
-
override fun getPrefixes(p0: String?): MutableIterator<String>
{
throw UnsupportedOperationException()
}
diff --git a/util/src/main/kotlin/XmlCombinators.kt
b/util/src/main/kotlin/XmlCombinators.kt
index 71ed68d..332d07a 100644
--- a/util/src/main/kotlin/XmlCombinators.kt
+++ b/util/src/main/kotlin/XmlCombinators.kt
@@ -6,7 +6,6 @@ import javax.xml.stream.XMLOutputFactory
import javax.xml.stream.XMLStreamWriter
class XmlElementBuilder(val w: XMLStreamWriter) {
-
/**
* First consumes all the path's components, and _then_ starts applying f.
*/
@@ -20,16 +19,13 @@ class XmlElementBuilder(val w: XMLStreamWriter) {
this.element(path, f)
w.writeEndElement()
}
-
fun element(path: String, f: XmlElementBuilder.() -> Unit = {}) {
val splitPath = path.trim('/').split("/").toMutableList()
this.element(splitPath, f)
}
-
fun attribute(name: String, value: String) {
w.writeAttribute(name, value)
}
-
fun text(content: String) {
w.writeCharacters(content)
}
@@ -38,7 +34,6 @@ class XmlElementBuilder(val w: XMLStreamWriter) {
class XmlDocumentBuilder {
private var maybeWriter: XMLStreamWriter? = null
-
internal var writer: XMLStreamWriter
get() {
val w = maybeWriter
@@ -47,16 +42,12 @@ class XmlDocumentBuilder {
set(w: XMLStreamWriter) {
maybeWriter = w
}
-
-
fun namespace(prefix: String, uri: String) {
writer.setPrefix(prefix, uri)
}
-
fun defaultNamespace(uri: String) {
writer.setDefaultNamespace(uri)
}
-
fun root(name: String, f: XmlElementBuilder.() -> Unit) {
val elementBuilder = XmlElementBuilder(writer)
writer.writeStartElement(name)
--
To stop receiving notification emails like this one, please contact
address@hidden.