GUACAMOLE-641: Manually extract password value from KeeperRecord.

Simply calling getPassword() does not currently work correctly, as the
implementation of getPassword() assumes there will be at least one
value if the field is present. This results in an
ArrayIndexOutOfBoundsException for records with empty passwords:

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
 at java.util.ArrayList.rangeCheck(ArrayList.java:659)
 at java.util.ArrayList.get(ArrayList.java:435)
 at com.keepersecurity.secretsManager.core.KeeperRecord.getPassword(SecretsManager.kt:134)
 ...
This commit is contained in:
Michael Jumper
2022-01-21 15:23:41 -08:00
parent b6e6800c0d
commit f8f0779d7a

View File

@@ -25,6 +25,7 @@ import com.keepersecurity.secretsManager.core.KeeperRecordData;
import com.keepersecurity.secretsManager.core.KeyPair;
import com.keepersecurity.secretsManager.core.KeyPairs;
import com.keepersecurity.secretsManager.core.Login;
import com.keepersecurity.secretsManager.core.Password;
import java.util.List;
/**
@@ -73,7 +74,19 @@ public class KsmRecordService {
* has no associated password.
*/
public String getPassword(KeeperRecord record) {
return record.getPassword();
KeeperRecordData data = record.getData();
Password passwordField = (Password) data.getField(Password.class);
if (passwordField == null)
return null;
List<String> values = passwordField.getValue();
if (values.size() != 1)
return null;
return values.get(0);
}
/**