Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix opening LCP-protected publication in restricted mode #494

Merged
merged 4 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ internal class LcpContentProtection(
asset: ContainerAsset,
license: Try<LcpLicense, LcpError>
): Try<ContentProtection.OpenResult, ContentProtection.OpenError> {
// ContentProtectionService should not expose errors due to user cancellation
val error = license.failureOrNull()
.takeUnless { it is LcpError.MissingPassphrase }

val serviceFactory = LcpContentProtectionService
.createFactory(license.getOrNull(), license.failureOrNull())
.createFactory(license.getOrNull(), error)

val encryptionData =
when {
Expand Down
3 changes: 3 additions & 0 deletions readium/lcp/src/main/java/org/readium/r2/lcp/LcpError.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public sealed class LcpError(
override val cause: Error? = null
) : Error {

public object MissingPassphrase :
LcpError("Passphrase is not available.")

/** The interaction is not available with this License. */
public object LicenseInteractionNotAvailable :
LcpError("This interaction is not available.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ internal class LicenseValidation(
transitionTo(State.failure(it.error))
}
on<Event.cancelled> {
if (DEBUG) Timber.d("State.cancelled)")
if (DEBUG) Timber.d("State.cancelled")
transitionTo(State.cancelled)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ internal class LicensesService(
val licenseDocument = LicenseDocument(lcpl)
Timber.d("license ${licenseDocument.json}")
fetchPublication(licenseDocument, destination, onProgress).let { Try.success(it) }
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
tryOrLog { destination.delete() }
Try.failure(LcpError.wrap(e))
Expand Down Expand Up @@ -338,7 +340,7 @@ internal class LicensesService(

// Both error and documents can be null if the user cancelled the passphrase prompt.
if (documents == null) {
throw CancellationException("License validation was interrupted.")
throw LcpException(LcpError.MissingPassphrase)
}
}
}
Expand Down
Loading