Show error for PIN exceeding max length on set and change
This commit is contained in:
@@ -273,6 +273,10 @@ class OutputFormatter(private val context: Context) {
|
||||
context.getString(R.string.pin_policy_violation_title),
|
||||
context.getString(R.string.pin_policy_violation_message)
|
||||
)
|
||||
is PinProtocol.PinChangeError.PinTooLong -> status(
|
||||
context.getString(R.string.pin_too_long_title),
|
||||
context.getString(R.string.pin_too_long_message)
|
||||
)
|
||||
is PinProtocol.PinChangeError.PinNotSet -> status(
|
||||
context.getString(R.string.pin_not_set_title),
|
||||
context.getString(R.string.pin_not_set_message)
|
||||
@@ -306,6 +310,10 @@ class OutputFormatter(private val context: Context) {
|
||||
context.getString(R.string.pin_policy_violation_title),
|
||||
context.getString(R.string.pin_policy_violation_message)
|
||||
)
|
||||
is PinProtocol.PinSetError.PinTooLong -> status(
|
||||
context.getString(R.string.pin_too_long_title),
|
||||
context.getString(R.string.pin_too_long_message)
|
||||
)
|
||||
is PinProtocol.PinSetError.PinBlocked -> status(
|
||||
context.getString(R.string.pin_blocked_title),
|
||||
context.getString(R.string.pin_blocked_message)
|
||||
|
||||
@@ -216,6 +216,7 @@ class PinProtocol(private val transport: FidoTransport) {
|
||||
sealed class PinSetError(message: String) : Exception(message) {
|
||||
class PinAlreadySet : PinSetError("A PIN is already set on this authenticator")
|
||||
class PinPolicyViolation : PinSetError("PIN does not meet authenticator requirements")
|
||||
class PinTooLong : PinSetError("PIN exceeds maximum allowed length")
|
||||
class PinBlocked : PinSetError("PIN is blocked")
|
||||
data class Other(val errorName: String) : PinSetError(errorName)
|
||||
}
|
||||
@@ -226,6 +227,9 @@ class PinProtocol(private val transport: FidoTransport) {
|
||||
|
||||
try {
|
||||
val newPinBytes = newPin.toByteArray(Charsets.UTF_8)
|
||||
if (newPinBytes.size > 63) {
|
||||
return Result.failure(PinSetError.PinTooLong())
|
||||
}
|
||||
val newPinPadded = ByteArray(64)
|
||||
newPinBytes.copyInto(newPinPadded, 0, 0, newPinBytes.size)
|
||||
|
||||
@@ -264,6 +268,7 @@ class PinProtocol(private val transport: FidoTransport) {
|
||||
class InvalidPin : PinChangeError("Current PIN is incorrect")
|
||||
class PinBlocked : PinChangeError("PIN is blocked due to too many incorrect attempts")
|
||||
class PinPolicyViolation : PinChangeError("New PIN does not meet authenticator requirements")
|
||||
class PinTooLong : PinChangeError("PIN exceeds maximum allowed length")
|
||||
class PinNotSet : PinChangeError("No PIN is set on this authenticator")
|
||||
data class Other(val errorName: String) : PinChangeError(errorName)
|
||||
}
|
||||
@@ -279,6 +284,9 @@ class PinProtocol(private val transport: FidoTransport) {
|
||||
val currentPinHashLeft16 = currentPinHash.copyOf(16)
|
||||
|
||||
val newPinBytes = newPin.toByteArray(Charsets.UTF_8)
|
||||
if (newPinBytes.size > 63) {
|
||||
return Result.failure(PinChangeError.PinTooLong())
|
||||
}
|
||||
val newPinPadded = ByteArray(64)
|
||||
newPinBytes.copyInto(newPinPadded, 0, 0, newPinBytes.size)
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@
|
||||
<string name="pin_hint_confirm">Confirm new PIN</string>
|
||||
<string name="pin_continue">Continue</string>
|
||||
<string name="pin_too_short">PIN must be at least %1$d characters</string>
|
||||
<string name="pin_too_long_title">PIN Too Long</string>
|
||||
<string name="pin_too_long_message">PIN exceeds maximum allowed length</string>
|
||||
<string name="pin_retries_remaining">Enter PIN (%1$d retries remaining)</string>
|
||||
<string name="pin_incorrect_retries">Incorrect PIN. %1$d retries remaining</string>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user