Skip to content

Commit fb625ad

Browse files
committed
Clarify exception msg when using an invalid keyring password
1 parent e6504c3 commit fb625ad

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/io/calimero/secure/Keyring.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ public byte[] decryptKey(final byte[] input, final char[] keyringPassword) {
614614
* @param input encrypted password
615615
* @param keyringPassword the password of this keyring
616616
* @return decrypted password as char array
617-
* @throws KnxSecureException for cryptographic setup/algorithm problems
617+
* @throws KnxSecureException for cryptographic setup/algorithm problems or invalid keyring password
618618
*/
619619
public char[] decryptPassword(final byte[] input, final char[] keyringPassword) {
620620
final var keyringPwdHash = hashKeyringPwd(keyringPassword);
@@ -626,6 +626,7 @@ public char[] decryptPassword(final byte[] input, final char[] keyringPassword)
626626
Arrays.fill(pwdData, (byte) 0);
627627
return chars;
628628
}
629+
catch (KnxSecureException e) { throw e; }
629630
catch (GeneralSecurityException | RuntimeException e) {
630631
throw new KnxSecureException("decrypting password data", e);
631632
}
@@ -724,7 +725,11 @@ private static byte[] extractPassword(final byte[] data) {
724725
if (data.length == 0)
725726
return emptyPwd;
726727
final int b = data[data.length - 1] & 0xff;
727-
final byte[] range = Arrays.copyOfRange(data, 8, data.length - b);
728+
final int from = 8;
729+
final int to = data.length - b;
730+
if (from > to || to > data.length)
731+
throw new KnxSecureException("invalid password");
732+
final byte[] range = Arrays.copyOfRange(data, from, to);
728733
return range;
729734
}
730735

0 commit comments

Comments
 (0)