diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ad258b..4cc95bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,17 @@ Rules: `Unreleased`. - Add the date and the compare link once the version tag exists. +## Unreleased + +### Added + +- Locked Word, Excel, PowerPoint, Pages, Numbers and Keynote files open with + their password. + +### Changed + +- The engine is odrcore 7.7.0, up from 7.6.1. + ## [1.50] ### Added diff --git a/OpenDocumentReader.xcodeproj/project.pbxproj b/OpenDocumentReader.xcodeproj/project.pbxproj index 7fe4031..6ae808d 100644 --- a/OpenDocumentReader.xcodeproj/project.pbxproj +++ b/OpenDocumentReader.xcodeproj/project.pbxproj @@ -830,7 +830,7 @@ repositoryURL = "https://github.com/opendocument-app/OpenDocument.core.git"; requirement = { kind = upToNextMajorVersion; - minimumVersion = 7.6.1; + minimumVersion = 7.7.0; }; }; AD584FCD41577C8CDEE974AA /* XCRemoteSwiftPackageReference "swift-package-manager-google-mobile-ads" */ = { diff --git a/OpenDocumentReader.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/OpenDocumentReader.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index ae89404..eb41764 100644 --- a/OpenDocumentReader.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/OpenDocumentReader.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -6,8 +6,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/opendocument-app/OpenDocument.core.git", "state" : { - "revision" : "4a1ce6e505a325147f6d3360d29625aa432a669a", - "version" : "7.6.1" + "revision" : "fae77ff7232cc79eecaebeb9e6839acf568d09c2", + "version" : "7.7.0" } }, { diff --git a/OpenDocumentReader/CoreWrapper.swift b/OpenDocumentReader/CoreWrapper.swift index 6d8ebca..f7770d3 100644 --- a/OpenDocumentReader/CoreWrapper.swift +++ b/OpenDocumentReader/CoreWrapper.swift @@ -9,8 +9,8 @@ let CoreWrapperErrorDomain = "app.opendocument.CoreWrapperErrorDomain" case wrongPassword = 2 /// Not something odrcore renders for us — see the guard in `translate`. case unsupportedFileType = 3 - /// Locked, and odrcore has no way in whatever the password — a legacy Word, - /// Excel or PowerPoint file. + /// Locked with a cipher odrcore cannot decrypt, whatever the password, for + /// example a legacy Word file with XOR obfuscation. case undecryptable = 4 } @@ -143,6 +143,7 @@ private func selectViews(_ views: [HtmlView], _ documentType: DocumentType) -> [ throw coreWrapperError(.wrongPassword, "wrong password") } catch let error as NSError where error.code == ODRError.unsupportedOperation.rawValue + || error.code == ODRError.unsupportedCryptoAlgorithm.rawValue { throw coreWrapperError(.undecryptable, "odrcore cannot decrypt this format") } diff --git a/OpenDocumentReader/DocumentViewController.swift b/OpenDocumentReader/DocumentViewController.swift index 2722142..d936a94 100644 --- a/OpenDocumentReader/DocumentViewController.swift +++ b/OpenDocumentReader/DocumentViewController.swift @@ -1646,7 +1646,7 @@ class DocumentViewController: UIViewController, DocumentDelegate, UISearchBarDel enum FailedToOpen { /// odrcore does not read this format at all. case unsupported - /// A legacy Word, Excel or PowerPoint file no password opens. + /// A locked file that no password opens. case locked /// odrcore took it and it still did not appear. case broken diff --git a/OpenDocumentReaderTests/LockedDocumentTests.swift b/OpenDocumentReaderTests/LockedDocumentTests.swift index 86fbfde..5241155 100644 --- a/OpenDocumentReaderTests/LockedDocumentTests.swift +++ b/OpenDocumentReaderTests/LockedDocumentTests.swift @@ -37,9 +37,12 @@ class LockedDocumentTests: XCTestCase { return url } - /// Its own code, not `wrongPassword`: that one puts the prompt up, and the - /// prompt would only come back. - func testALockedLegacyFileReportsItsOwnError() throws { + /// The password of `test-encrypted.doc`, from `OpenDocument.test/index.csv`. + private let fixturePassword = "password" + + /// odrcore 7.7.0 decrypts RC4, so a locked legacy Word file asks for its + /// password like any other locked file. + func testALockedLegacyFileAsksForItsPassword() throws { let wrapper = CoreWrapper() for password in [nil, "secret"] { @@ -48,38 +51,37 @@ class LockedDocumentTests: XCTestCase { documentURL.path, into: temporaryDirectory, with: password, editable: false, scope: .document) ) { error in - XCTAssertEqual((error as NSError).code, CoreWrapperError.undecryptable.rawValue) + XCTAssertEqual((error as NSError).code, CoreWrapperError.wrongPassword.rawValue) } } } - /// Its own message rather than the broken-file one: no password opens it. - func testALockedLegacyFileSaysWhyItDidNotOpen() throws { - try present(documentURL) - - let opened = expectation(description: "opened") - document.open { _ in opened.fulfill() } - wait(for: [opened], timeout: 60) + func testALockedLegacyFileOpensWithItsPassword() throws { + let wrapper = CoreWrapper() - let alert = try XCTUnwrap(waitForAlert()) + try wrapper.translate( + documentURL.path, into: temporaryDirectory, with: fixturePassword, + editable: false, scope: .document) - XCTAssertEqual(alert.message, NSLocalizedString("toast_error_password_protected", comment: "")) - XCTAssertEqual( - alert.actions.map(\.title), [NSLocalizedString("ok", comment: "")], - "a locked file is not ours to hear about") + XCTAssertFalse(wrapper.pageURLs.isEmpty) } - /// The reader is taken off the screen before the message. - func testTheReaderIsClosedBeforeTheMessage() throws { + /// The reader keeps the document and puts the password prompt up. + func testALockedLegacyFileShowsThePasswordPrompt() throws { try present(documentURL) let opened = expectation(description: "opened") document.open { _ in opened.fulfill() } wait(for: [opened], timeout: 60) - _ = waitForAlert() + let alert = try XCTUnwrap(waitForAlert()) - XCTAssertNil(controller.document, "the reader is still holding the document") + XCTAssertEqual(alert.title, NSLocalizedString("toast_error_password_protected", comment: "")) + XCTAssertEqual(alert.textFields?.count, 1) + XCTAssertEqual( + alert.actions.map(\.title), + [NSLocalizedString("cancel", comment: ""), NSLocalizedString("ok", comment: "")]) + XCTAssertNotNil(controller.document, "the reader let go of the document") } private func waitForAlert() -> UIAlertController? {