Skip to content

Commit

Permalink
fix(LCP): edge-case, there are broken publications that are encrypted…
Browse files Browse the repository at this point in the history
… but do not contain a license to unlock them ( PR #2637 Fixes #2114 )
  • Loading branch information
danielweck authored Nov 5, 2024
1 parent fc74d55 commit 9d2e3e8
Show file tree
Hide file tree
Showing 30 changed files with 107 additions and 153 deletions.
32 changes: 32 additions & 0 deletions src/main/redux/sagas/publication/openPublication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,33 @@ const filename_ = "readium-desktop:main:redux:sagas:publication:open";
const debug = debug_(filename_);

export const ERROR_MESSAGE_ON_USERKEYCHECKREQUEST = "ERROR_MESSAGE_ON_USERKEYCHECKREQUEST";
export const ERROR_MESSAGE_ENCRYPTED_NO_LICENSE = "ERROR_MESSAGE_ENCRYPTED_NO_LICENSE";

export const r2PublicationIsEncryptedAndHasNoLicense = (pub: R2Publication) => {
if (pub.LCP) {
return false;
}
let atLeastOneResourceIsEncrypted = false;
if (pub.Spine) {
for (const link of pub.Spine) {
// link.Properties?.Encrypted?.Scheme === "http://readium.org/2014/01/lcp"
if (link.Properties?.Encrypted?.Algorithm && link.Properties.Encrypted.Algorithm !== "http://www.idpf.org/2008/embedding" && link.Properties.Encrypted.Algorithm !== "http://ns.adobe.com/pdf/enc#RC") {
atLeastOneResourceIsEncrypted = true;
break;
}
}
}
if (!atLeastOneResourceIsEncrypted && pub.Resources) {
for (const link of pub.Resources) {
// link.Properties?.Encrypted?.Scheme === "http://readium.org/2014/01/lcp"
if (link.Properties?.Encrypted?.Algorithm && link.Properties.Encrypted.Algorithm !== "http://www.idpf.org/2008/embedding" && link.Properties.Encrypted.Algorithm !== "http://ns.adobe.com/pdf/enc#RC") {
atLeastOneResourceIsEncrypted = true;
break;
}
}
}
return atLeastOneResourceIsEncrypted;
};

const convertDoc = async (doc: PublicationDocument, publicationViewConverter: PublicationViewConverter) => {
return await publicationViewConverter.convertDocumentToView(doc);
Expand Down Expand Up @@ -225,6 +252,11 @@ export function* streamerOpenPublicationAndReturnManifestUrl(pubId: string) {

throw error;
}
} else {
const isEncrypted = r2PublicationIsEncryptedAndHasNoLicense(r2Publication);
if (isEncrypted) {
throw ERROR_MESSAGE_ENCRYPTED_NO_LICENSE;
}
}

// const manifestUrl = _USE_HTTP_STREAMER ?
Expand Down
14 changes: 11 additions & 3 deletions src/main/redux/sagas/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { call as callTyped, select as selectTyped, put as putTyped } from "typed
import { types } from "util";

import {
ERROR_MESSAGE_ON_USERKEYCHECKREQUEST, streamerOpenPublicationAndReturnManifestUrl,
ERROR_MESSAGE_ON_USERKEYCHECKREQUEST, ERROR_MESSAGE_ENCRYPTED_NO_LICENSE, streamerOpenPublicationAndReturnManifestUrl,
} from "./publication/openPublication";
import { PublicationDocument } from "readium-desktop/main/db/document/publication";
import { getTranslator } from "readium-desktop/common/services/translator";
Expand Down Expand Up @@ -177,7 +177,15 @@ function* readerOpenRequest(action: readerActions.openRequest.TAction) {

} catch (e) {

if (e.toString() !== ERROR_MESSAGE_ON_USERKEYCHECKREQUEST) {
const errMsg = e.toString();
if (errMsg === ERROR_MESSAGE_ENCRYPTED_NO_LICENSE) {
yield put(
toastActions.openRequest.build(
ToastType.Error,
getTranslator().translate("message.open.error", { err: getTranslator().translate("publication.encryptedNoLicense") }),
),
);
} else if (errMsg !== ERROR_MESSAGE_ON_USERKEYCHECKREQUEST) {

if (types.isNativeError(e)) {
// disable "Error: "
Expand All @@ -187,7 +195,7 @@ function* readerOpenRequest(action: readerActions.openRequest.TAction) {
yield put(
toastActions.openRequest.build(
ToastType.Error,
getTranslator().translate("message.open.error", { err: e.toString() }),
getTranslator().translate("message.open.error", { err: errMsg }),
),
);
}
Expand Down
7 changes: 2 additions & 5 deletions src/resources/locales/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"leftSlideButton": "سحب إلى اليسار",
"mainContent": "المحتوى الرئيسي",
"rightSlideButton": "سحب إلى اليمين",
"searchBook": "بحث حسب العنوان",
"skipLink": "تخطى الى المحتوى",
"toolbar": "شريط الأدوات"
},
Expand Down Expand Up @@ -119,7 +118,6 @@
"released": "تم نشره بتاريخ",
"sort": "الفرز حسب",
"tag": "الوسم",
"tagCount": "عدد الوسوم",
"tags": "الوسوم",
"update": "تحرير"
},
Expand Down Expand Up @@ -293,6 +291,7 @@
"duration": {
"title": "المدة"
},
"encryptedNoLicense": "",
"expired": "انتهت مدة الاستعارة",
"expiredLcp": "انتهت صلاحية ترخيص LCP الخاص بهذا المنشور.",
"incorrectPassphrase": "",
Expand Down Expand Up @@ -557,9 +556,7 @@
"title": ""
},
"session": {
"no": "تعطيل",
"title": "حفظ الجلسة",
"yes": "تمكين"
"title": "حفظ الجلسة"
},
"tabs": {
"appearance": "المظهر",
Expand Down
7 changes: 2 additions & 5 deletions src/resources/locales/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"leftSlideButton": "Плъзни списъка наляво",
"mainContent": "главно съдържание",
"rightSlideButton": "Плъзни списъка надясно",
"searchBook": "Търси по заглавие",
"skipLink": "Преминете към съдържанието",
"toolbar": "лента с инструменти"
},
Expand Down Expand Up @@ -119,7 +118,6 @@
"released": "Публикувано на",
"sort": "Сортирай по",
"tag": "",
"tagCount": "Брой маркери",
"tags": "Маркери",
"update": "Редактирай"
},
Expand Down Expand Up @@ -293,6 +291,7 @@
"duration": {
"title": "Продължителност"
},
"encryptedNoLicense": "",
"expired": "",
"expiredLcp": "Тази книга не може да бъде прочетена, защото лицензът за LCP е изтекъл.",
"incorrectPassphrase": "",
Expand Down Expand Up @@ -557,9 +556,7 @@
"title": ""
},
"session": {
"no": "Деактивирай",
"title": "Запиши сесията",
"yes": "Активирай"
"title": "Запиши сесията"
},
"tabs": {
"appearance": "",
Expand Down
7 changes: 2 additions & 5 deletions src/resources/locales/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"leftSlideButton": "Lliscar llista a l'esquerra",
"mainContent": "Contingut principal",
"rightSlideButton": "Lliscar llista a la dreta",
"searchBook": "Cercar per títol",
"skipLink": "Passar el contingut",
"toolbar": "Barra d'eines"
},
Expand Down Expand Up @@ -119,7 +118,6 @@
"released": "Publicat en",
"sort": "Ordenar per",
"tag": "Etiqueta",
"tagCount": "Número d'etiquetes",
"tags": "Etiquetes",
"update": "Editar"
},
Expand Down Expand Up @@ -293,6 +291,7 @@
"duration": {
"title": "Duració"
},
"encryptedNoLicense": "",
"expired": "Préstec expirat",
"expiredLcp": "Aquest llibre no es pot llegir perquè la llicència LCP ha expirat.",
"incorrectPassphrase": "",
Expand Down Expand Up @@ -557,9 +556,7 @@
"title": ""
},
"session": {
"no": "Deshabilitar",
"title": "Guardar sessió",
"yes": "Habilitar"
"title": "Guardar sessió"
},
"tabs": {
"appearance": "Aparença",
Expand Down
7 changes: 2 additions & 5 deletions src/resources/locales/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"leftSlideButton": "Flyt listen til venstre",
"mainContent": "hovedindhold",
"rightSlideButton": "Flyt listen til højre",
"searchBook": "Søg efter titel",
"skipLink": "Hop til indhold",
"toolbar": "værktøjslinje"
},
Expand Down Expand Up @@ -119,7 +118,6 @@
"released": "Udgivelsesdato",
"sort": "Sortér efter",
"tag": "Tag",
"tagCount": "Antal tags",
"tags": "Tags",
"update": "Rediger"
},
Expand Down Expand Up @@ -293,6 +291,7 @@
"duration": {
"title": "Spilletid"
},
"encryptedNoLicense": "",
"expired": "Lånet er udløbet",
"expiredLcp": "Denne bog kan ikke læses, da LCP-licensen er udløbet.",
"incorrectPassphrase": "",
Expand Down Expand Up @@ -557,9 +556,7 @@
"title": "Tilføj en bibliotekskonto"
},
"session": {
"no": "Fra",
"title": "Gem session",
"yes": "Til"
"title": "Gem session"
},
"tabs": {
"appearance": "Udseende",
Expand Down
7 changes: 2 additions & 5 deletions src/resources/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"leftSlideButton": "Scrolle nach links",
"mainContent": "Hauptinhalt",
"rightSlideButton": "Scrolle nach rechts",
"searchBook": "Suche nach einem Buch",
"skipLink": "Gehe zum Inhalt",
"toolbar": "Symbolleiste"
},
Expand Down Expand Up @@ -119,7 +118,6 @@
"released": "Veröffentlicht am",
"sort": "Sortieren nach",
"tag": "Tag",
"tagCount": "Anzahl der Tags",
"tags": "Tags",
"update": "Bearbeiten"
},
Expand Down Expand Up @@ -293,6 +291,7 @@
"duration": {
"title": "Dauer"
},
"encryptedNoLicense": "",
"expired": "Ausleihe abgelaufen",
"expiredLcp": "Die LCP-Lizenz dieser Veröffentlichung ist abgelaufen.",
"incorrectPassphrase": "",
Expand Down Expand Up @@ -557,9 +556,7 @@
"title": ""
},
"session": {
"no": "Deaktivieren",
"title": "Sitzung speichern",
"yes": "Aktivieren"
"title": "Sitzung speichern"
},
"tabs": {
"appearance": "Erscheinungsbild",
Expand Down
7 changes: 2 additions & 5 deletions src/resources/locales/el.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"leftSlideButton": "Μετακίνηση προς τα αριστερά",
"mainContent": "Κυρίως περιεχόμενο",
"rightSlideButton": "Μετακίνηση προς τα δεξιά",
"searchBook": "Αναζήτηση με τίτλο",
"skipLink": "Μετάβαση στο περιεχόμενο",
"toolbar": "Γραμμή εργαλείων"
},
Expand Down Expand Up @@ -119,7 +118,6 @@
"released": "Δημοσιεύθηκε στις",
"sort": "Ταξινόμηση με",
"tag": "Ετικέτα",
"tagCount": "Πλήθος ετικετών",
"tags": "Ετικέτες",
"update": "Επεξεργασία"
},
Expand Down Expand Up @@ -293,6 +291,7 @@
"duration": {
"title": "Διάρκεια"
},
"encryptedNoLicense": "",
"expired": "Ο δανεισμός έχει λήξει",
"expiredLcp": "Αυτό το βιβλίο δεν μπορεί να διαβαστεί επειδή η άδεια χρήσης LCP έχει λήξει.",
"incorrectPassphrase": "",
Expand Down Expand Up @@ -557,9 +556,7 @@
"title": ""
},
"session": {
"no": "Ανενεργή",
"title": "Αποθήκευση συνεδρίας",
"yes": "Ενεργή"
"title": "Αποθήκευση συνεδρίας"
},
"tabs": {
"appearance": "Εμφάνιση",
Expand Down
7 changes: 2 additions & 5 deletions src/resources/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"leftSlideButton": "Slide to the left",
"mainContent": "main content",
"rightSlideButton": "Slide to the right",
"searchBook": "Search by title",
"skipLink": "Skip to content",
"toolbar": "toolbar"
},
Expand Down Expand Up @@ -119,7 +118,6 @@
"released": "Published on",
"sort": "Sort by",
"tag": "Tag",
"tagCount": "Tag count",
"tags": "Tags",
"update": "Edit"
},
Expand Down Expand Up @@ -293,6 +291,7 @@
"duration": {
"title": "Duration"
},
"encryptedNoLicense": "Publication is encrypted but lacks an LCP license!",
"expired": "Loan expired",
"expiredLcp": "This publication's LCP license is expired.",
"incorrectPassphrase": "No stored passphrase fits the publication, or the entered passphrase is wrong.",
Expand Down Expand Up @@ -557,9 +556,7 @@
"title": "Add a library account"
},
"session": {
"no": "Disable",
"title": "Save session",
"yes": "Enable"
"title": "Save session"
},
"tabs": {
"appearance": "Appearance",
Expand Down
7 changes: 2 additions & 5 deletions src/resources/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"leftSlideButton": "Desplazar lista a la izquierda",
"mainContent": "Contenido principal",
"rightSlideButton": "Desplazar lista a la derecha",
"searchBook": "Buscar por título",
"skipLink": "Pasar al contenido",
"toolbar": "Barra de herramientas"
},
Expand Down Expand Up @@ -119,7 +118,6 @@
"released": "Publicado en",
"sort": "Ordenar por",
"tag": "Etiqueta",
"tagCount": "Número de etiquetas",
"tags": "Etiquetas",
"update": "Editar"
},
Expand Down Expand Up @@ -293,6 +291,7 @@
"duration": {
"title": "Duración"
},
"encryptedNoLicense": "",
"expired": "Préstamo vencido",
"expiredLcp": "Este libro no se puede leer porque la licencia LCP ha expirado.",
"incorrectPassphrase": "",
Expand Down Expand Up @@ -557,9 +556,7 @@
"title": ""
},
"session": {
"no": "Deshabilitar",
"title": "Guardar sesión",
"yes": "Habilitar"
"title": "Guardar sesión"
},
"tabs": {
"appearance": "Aspecto visual",
Expand Down
7 changes: 2 additions & 5 deletions src/resources/locales/eu.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"leftSlideButton": "Mugitu zerrenda ezkerrera",
"mainContent": "Eduki nagusia",
"rightSlideButton": "Mugitu zerrenda eskuinera",
"searchBook": "Bilatu izenburuaren arabera",
"skipLink": "Pasatu edukira",
"toolbar": "Tresna-barra"
},
Expand Down Expand Up @@ -119,7 +118,6 @@
"released": "Hemen argitaratua",
"sort": "Ordenatu honen arabera",
"tag": "Etiketa",
"tagCount": "Etiketa kopurua",
"tags": "Etiketak",
"update": "Editatu"
},
Expand Down Expand Up @@ -293,6 +291,7 @@
"duration": {
"title": "Iraupena"
},
"encryptedNoLicense": "",
"expired": "Mailegua iraungi",
"expiredLcp": "Liburu hau ezin da irakurri LCP lizentzia iraungi delako.",
"incorrectPassphrase": "",
Expand Down Expand Up @@ -557,9 +556,7 @@
"title": ""
},
"session": {
"no": "Desgaitu",
"title": "Gorde saioa",
"yes": "Gaitu"
"title": "Gorde saioa"
},
"tabs": {
"appearance": "Itxura",
Expand Down
Loading

0 comments on commit 9d2e3e8

Please sign in to comment.