commit 9f9c5878df52ad3c12d5743218685d896ee80294
parent 0953e0bf43e5a260af13e3fd0d5580d690697358
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Thu, 17 Oct 2019 11:07:56 +0200
catch bad key exception
Diffstat:
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/sandbox/src/main/kotlin/Main.kt b/sandbox/src/main/kotlin/Main.kt
@@ -52,6 +52,7 @@ import java.util.*
import java.util.zip.GZIPInputStream
import javax.xml.bind.JAXBElement
import java.nio.charset.StandardCharsets.UTF_8
+import java.security.InvalidKeyException
import java.security.KeyFactory
import java.security.PublicKey
import java.security.interfaces.RSAPublicKey
@@ -236,6 +237,7 @@ private suspend fun ApplicationCall.ebicsweb() {
HttpStatusCode.NotFound,
SandboxError("Unknown HostID specified")
)
+ return
}
when (bodyDocument.documentElement.localName) {
@@ -298,19 +300,27 @@ private suspend fun ApplicationCall.ebicsweb() {
result.toString(US_ASCII)
)
- // get the customer id
- val ebicsUserId = bodyJaxb.value.header.static.userID
+ try {
+ loadRsaPublicKey(
+ keyObject.value.signaturePubKeyInfo.pubKeyValue.rsaKeyValue.exponent,
+ keyObject.value.signaturePubKeyInfo.pubKeyValue.rsaKeyValue.modulus
+ )
+ } catch (e: Exception) {
+ logger.info("User gave bad key, not storing it")
+ e.printStackTrace()
+ respond(
+ HttpStatusCode.BadRequest,
+ SandboxError("Bad public key given")
+ )
+ return
+ }
- // get key modulus and exponent
- // (do sanity check on the key - see if it loads)
+ logger.debug(EbicsUsers.userId.name)
- val publicKeyy = loadRsaPublicKey(
- keyObject.value.signaturePubKeyInfo.pubKeyValue.rsaKeyValue.modulus,
- keyObject.value.signaturePubKeyInfo.pubKeyValue.rsaKeyValue.exponent
- )
// store key in database
+
}
}