commit bd6f0b03f2df6aa048aedf339673d2abf4105cd4
parent 896255878f365bcbf05647c9ab0be795282e9dd7
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Wed, 22 Jan 2020 23:41:50 +0100
5973.
Report more appropriate error when subscriber
state is not suitable for the request.
Diffstat:
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -53,12 +53,28 @@ import javax.sql.rowset.serial.SerialBlob
open class EbicsRequestError(val errorText: String, val errorCode: String) :
Exception("EBICS request management error: $errorText ($errorCode)")
-class EbicsInvalidRequestError : EbicsRequestError("[EBICS_INVALID_REQUEST] Invalid request", "060102")
+class EbicsInvalidRequestError : EbicsRequestError(
+ "[EBICS_INVALID_REQUEST] Invalid request",
+ "060102"
+)
+
+/**
+ * This error is thrown whenever the Subscriber's state is not suitable
+ * for the requested action. For example, the subscriber sends a EbicsRequest
+ * message without having first uploaded their keys (#5973).
+ */
+class EbicsSubscriberStateError : EbicsRequestError(
+ "[EBICS_INVALID_USER_OR_USER_STATE] Subscriber unknown or subscriber state inadmissible",
+ "091002"
+)
open class EbicsKeyManagementError(val errorText: String, val errorCode: String) :
Exception("EBICS key management error: $errorText ($errorCode)")
-private class EbicsInvalidXmlError : EbicsKeyManagementError("[EBICS_INVALID_XML]", "091010")
+private class EbicsInvalidXmlError : EbicsKeyManagementError(
+ "[EBICS_INVALID_XML]",
+ "091010"
+)
private class EbicsInvalidOrderType : EbicsRequestError(
"[EBICS_UNSUPPORTED_ORDER_TYPE] Order type not supported",
@@ -356,7 +372,7 @@ private suspend fun ApplicationCall.handleEbicsHpb(
throw EbicsInvalidRequestError()
}
if (ebicsSubscriber.state != SubscriberState.INITIALIZED) {
- throw EbicsInvalidRequestError()
+ throw EbicsSubscriberStateError()
}
val authPubBlob = ebicsSubscriber.authenticationKey!!.rsaPublicKey
val encPubBlob = ebicsSubscriber.encryptionKey!!.rsaPublicKey
@@ -694,7 +710,8 @@ suspend fun ApplicationCall.ebicsweb() {
}
if (ebicsHost == null) throw EbicsInvalidRequestError()
- if (subscriber == null) throw EbicsInvalidRequestError()
+ if (subscriber == null || subscriber.state != SubscriberState.INITIALIZED)
+ throw EbicsSubscriberStateError()
val hostAuthPriv = CryptoUtil.loadRsaPrivateKey(
ebicsHost.authenticationPrivateKey