From 6889b42933b8487c25871615e12a67c21fe7f660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Menu?= Date: Tue, 21 Jan 2025 11:28:23 +0100 Subject: [PATCH] Fix regression with LCP passphrases --- CHANGELOG.md | 9 ++++++++- .../SQLiteLCPPassphraseRepository.swift | 17 +++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e4d42dc1..abb25d1fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,14 @@ All notable changes to this project will be documented in this file. Take a look **Warning:** Features marked as *alpha* may change or be removed in a future release without notice. Use with caution. - +## [Unreleased] + +### Fixed + +#### LCP + +* Fixed a regression that caused some LCP passphrases to no longer match the protected publication. + ## [3.0.0-beta.2] diff --git a/Sources/Adapters/LCPSQLite/SQLiteLCPPassphraseRepository.swift b/Sources/Adapters/LCPSQLite/SQLiteLCPPassphraseRepository.swift index 7728bd20e..43292afe0 100644 --- a/Sources/Adapters/LCPSQLite/SQLiteLCPPassphraseRepository.swift +++ b/Sources/Adapters/LCPSQLite/SQLiteLCPPassphraseRepository.swift @@ -41,10 +41,19 @@ public class LCPSQLitePassphraseRepository: LCPPassphraseRepository, Loggable { public func passphrasesMatching(userID: User.ID?, provider: LicenseDocument.Provider) async throws -> [LCPPassphraseHash] { try logAndRethrow { - try db.prepare(transactions.select(passphrase) - .filter(self.userId == userID && self.provider == provider) - ) - .compactMap { try $0.get(passphrase) } + var passphrases = + try db.prepare(transactions.select(passphrase) + .filter(self.userId == userID && self.provider == provider) + ) + .compactMap { try $0.get(passphrase) } + + // The legacy SQLite database did not save all the new + // (passphrase, userID, provider) tuples. So we need to fall back + // on checking all the saved passphrases for a match. + passphrases += try db.prepare(transactions.select(passphrase)) + .compactMap { try $0.get(passphrase) } + + return passphrases } }