Fix parsing of otpauth-migration Uri.

This solves the issue regarding duplicate accounts not being
recognized.
This commit is contained in:
Elias Bonnici 2024-01-10 17:02:41 +01:00
parent 73a5e4aa6b
commit 87b463f4e8
No known key found for this signature in database
GPG Key ID: 5EAC28EA3F980CCF

View File

@ -188,22 +188,30 @@ class CredentialData with _$CredentialData {
// Convert parsed credential values into CredentialData objects // Convert parsed credential values into CredentialData objects
return splitCreds(base64.decode(uri.queryParameters['data']!)) return splitCreds(base64.decode(uri.queryParameters['data']!))
.map((values) => CredentialData( .map((values) {
secret: base32.encode(values[1]), String? issuer;
name: utf8.decode(values[2], allowMalformed: true), String name = utf8.decode(values[2], allowMalformed: true);
issuer: values[3] != null final nameIndex = name.indexOf(':');
? utf8.decode(values[3], allowMalformed: true) if (nameIndex >= 0) {
: null, issuer = name.substring(0, nameIndex);
hashAlgorithm: switch (values[4]) { name = name.substring(nameIndex + 1);
2 => HashAlgorithm.sha256, }
3 => HashAlgorithm.sha512, return CredentialData(
_ => HashAlgorithm.sha1, secret: base32.encode(values[1]),
}, name: name,
digits: values[5] == 2 ? 8 : defaultDigits, issuer: values[3] != null
oathType: values[6] == 1 ? OathType.hotp : OathType.totp, ? utf8.decode(values[3], allowMalformed: true)
counter: values[7] ?? defaultCounter, : issuer,
)) hashAlgorithm: switch (values[4]) {
.toList(); 2 => HashAlgorithm.sha256,
3 => HashAlgorithm.sha512,
_ => HashAlgorithm.sha1,
},
digits: values[5] == 2 ? 8 : defaultDigits,
oathType: values[6] == 1 ? OathType.hotp : OathType.totp,
counter: values[7] ?? defaultCounter,
);
}).toList();
} }
factory CredentialData.fromOtpauth(Uri uri) { factory CredentialData.fromOtpauth(Uri uri) {