diff --git a/lib/src/internal/extension_utils.dart b/lib/src/internal/extension_utils.dart index 9bc20e9..c6ae88f 100644 --- a/lib/src/internal/extension_utils.dart +++ b/lib/src/internal/extension_utils.dart @@ -21,6 +21,14 @@ extension XmlElementExt on xml.XmlElement { return findElements(nodeName).single.text; } + Iterable breadcrumbs() { + final ret = parentElement?.let((p) => p.breadcrumbs()) ?? []; + return [this].followedBy(ret); + } + + String breadcrumbsNames() => + breadcrumbs().map((e) => e.name.local).join(' / '); + /// If an element child with the given name already exists, /// it will be removed and the given element will be added. /// otherwise it will be only added. diff --git a/lib/src/kdbx_format.dart b/lib/src/kdbx_format.dart index 040b053..aa6c6ea 100644 --- a/lib/src/kdbx_format.dart +++ b/lib/src/kdbx_format.dart @@ -773,11 +773,27 @@ class KdbxFormat { for (final el in document .findAllElements(KdbxXml.NODE_VALUE) .where((el) => el.getAttributeBool(KdbxXml.ATTR_PROTECTED))) { - final pw = gen.decryptBase64(el.text.trim()); - if (pw == null) { - continue; + try { + final pw = gen.decryptBase64(el.text.trim()); + if (pw == null) { + continue; + } + KdbxFile.protectedValues[el] = ProtectedValue.fromString(pw); + } catch (e, stackTrace) { + final stringKey = + el.parentElement.singleElement(KdbxXml.NODE_KEY)?.text; + final uuid = el.parentElement?.parentElement + ?.singleElement(KdbxXml.NODE_UUID) + ?.text; + _logger.severe( + 'Error while decoding protected value in ' + '{${el.breadcrumbsNames()}} of key' + ' {$stringKey} of entry {$uuid}.', + e, + stackTrace); + + rethrow; } - KdbxFile.protectedValues[el] = ProtectedValue.fromString(pw); } final keePassFile = document.findElements('KeePassFile').single;