Fix OPVault import when there are multiple OTP fields

* Fix #8371 - store multiple OTP fields as `otp_#` instead of silently discarding them.
This commit is contained in:
Jonathan White 2022-09-01 06:54:34 -04:00
parent 28328a7080
commit f3d448485a
2 changed files with 20 additions and 1 deletions

View file

@ -84,7 +84,16 @@ void OpVaultReader::fillFromSectionField(Entry* entry, const QString& sectionNam
auto kind = field["k"].toString();
if (attrName.startsWith("TOTP_")) {
if (attrValue.startsWith("otpauth://")) {
if (entry->hasTotp()) {
// Store multiple TOTP definitions as additional otp attributes
int i = 0;
QString name("otp");
auto attributes = entry->attributes()->keys();
while (attributes.contains(name)) {
name = QString("otp_%1").arg(++i);
}
entry->attributes()->set(name, attrValue);
} else if (attrValue.startsWith("otpauth://")) {
QUrlQuery query(attrValue);
// at least as of 1Password 7, they don't append the digits= and period= which totp.cpp requires
if (!query.hasQueryItem("digits")) {