SDKLauncher-Android icon indicating copy to clipboard operation
SDKLauncher-Android copied to clipboard

Opening encrypted epubs on android devices.

Open rahulk11 opened this issue 6 years ago • 19 comments

General Instructions

  • Please use a short, but meaningful title.
  • Delete everything in italics before submitting issue
  • Make sure to fill in as much information as possible

Question

(choose ONE from the above list and delete the others)

Product

Choose one of the following (and delete the others)

  • Native application (Readium SDK C++)
    • official "launcher" sample OR propietary app
    • Android

Additional information

Please list any additional information that might help us

rahulk11 avatar Feb 26 '18 09:02 rahulk11

Hi @rahulk11, You question is too vague. Encrypted epubs may mean anything. If it's about epubs protected by a DRM, which DRM? They are old DRM's (Adobe) and modern DRM's (e.g. Readium LCP).

Also, could you please rename your issue with a shorter title (e.g. Opening Readium LCP encrypted epubs), use a Github tag, not "Question" in the title, and provide a first comment with sufficient details?

llemeurfr avatar Feb 26 '18 09:02 llemeurfr

@llemeurfr I am sorry for the mistake. Any way, i have some epubs encrypted by an algorithm, not protected by DRM. I need to implement the decryption and reading of the books in my app, without storing decrypted files anywhere. How can i achieve it using Readium SDK?

rahulk11 avatar Feb 26 '18 10:02 rahulk11

Firstly, you need to follow the EPUB specification to make sure that your publications "declare" which resources (i.e. files within the zip container) are encrypted, and with what algorithm / DRM scheme: http://www.idpf.org/epub/301/spec/epub-ocf.html#sec-container-metainf-encryption.xml

Then, you should explore the notion of "Content Module" and "Content Filter" in the ReadiumSDK architecture, https://github.com/readium/readium-sdk/tree/develop/ePub3/ePub ...and use the concrete open-source LCP implementation as your guide: https://github.com/readium/readium-lcp-client/tree/develop/src/lcp-content-filter

Daniel

danielweck avatar Feb 26 '18 19:02 danielweck

@danielweck thanks. i'll look into these

rahulk11 avatar Feb 27 '18 10:02 rahulk11

Hi @danielweck , i've checked with the publication and they dont have any plan to include DRM. They just giving me an encrypted epub. Encryption is not done to individual files inside epub, instead, the epub file as a whole has been encrypted using conceal library from facebook.

rahulk11 avatar Mar 02 '18 11:03 rahulk11

ReadiumSDK does not support decrypting the publication as a whole (i.e. the EPUB zip archive as a single cypher stream).

The recommended ; and widely implemented ; practice in the electronic publishing industry is to encrypt individual resource within the EPUB package so that some resources remain available as plain text (e.g. essential metadata that reading systems can access prior to loading the full EPUB / prior to reading encrypted resources).

Furthermore, depending on the cypher algorithm, encrypting the zip container as a whole makes it hard ; if not impossible ; to efficiently "stream" data out of the EPUB package (e.g. video/audio files).

So I am afraid you use-case sits outside of the ReadiumSDK's scope.

You can of course decrypt the entire zip file in a separate process, place the output somewhere in a hidden folder on the filesystem, and pass the new file location to ReadiumSDK (in which case we fallback to loading a regular plain-text publication). The problem with that approach is that unless the hidden filesystem location is well protected, this is a weak solution because malicious users could potentially have access to the fully-decrypted version.

danielweck avatar Mar 02 '18 11:03 danielweck

@danielweck thank you for your input. However i was thinking if it is possible to provide stream of epub to ReadiumSDK instead of giving it a file path. I've seen something similar in this library I've not tried it yet because it seems very old and abandoned library. Thanks again.

rahulk11 avatar Mar 02 '18 13:03 rahulk11

ReadiumSDK (the C++ lib) only support s loading EPUB files from filesystem locations. Behind the scenes, the zip library accesses a low-level system file handle.

danielweck avatar Mar 02 '18 16:03 danielweck

How does SDKLauncher-Android project integrate lcp? I did not understand how to integrate the lcp project written in C++ into the readium sdk project. Is there any specific integration document or steps for reference? I want to test https://www.edrlab.org/readium/readium-lcp/testing-readium-lcp-compliant-devices/ on an android device. Is there any trouble to give specific instructions and help? Thank you very much!

xiaoxiaomuou avatar May 31 '18 02:05 xiaoxiaomuou

@xiaoxiaomuou have you tried compiling + running the feature/lcp branch? https://github.com/readium/SDKLauncher-Android/tree/feature/lcp

The Git submodules should be:

  • the develop branch of readium-lcp-client: https://github.com/readium/readium-lcp-client/tree/develop
  • the develop branch of readium-sdk: https://github.com/readium/readium-sdk/tree/develop
  • the develop branch of readium-shared-js: https://github.com/readium/readium-shared-js/tree/develop

danielweck avatar Jun 11 '18 20:06 danielweck

@danielweck I have completely cloned https://github.com/readium/SDKLauncher-Android/tree/feature/lcp, but I encountered an error that I didn't know how to modify during compilation: <Error:error: 'E: /LcpSdkTest/SDKLauncher-Android/readium-sdk/Platform/Android/epub3/libs/DEBUG/armeabi-v7a/libepub3.so', needed by '../../../../build/intermediates/cmake /arm7/debug/obj/armeabi-v7a/liblcp.so', missing and no known rule to make it> Please advise me how to modify the project? Thank you again!

xiaoxiaomuou avatar Jun 12 '18 11:06 xiaoxiaomuou

@xiaoxiaomuou yes, sorry the AndroidStudio/Gradle/CMake build system is currently imperfect, you need to make sure that the build output from readium-sdk (i.e. libepub3.so and libgnustl_shared.so) is located in SDKLauncher-Android/readium-sdk/Platform/Android/epub3/libs/DEBUG/armeabi-v7a/ (or x86 instead of armeabi-v7a, if you are building for the emulator instead of a physical device).

Try the following command line steps and let us know how it goes, please.

The hierarchy of filesystem folders / git repositories should look like:

  • SDKLauncher-Android (branch feature/lcp)
    • readium-sdk (branch develop)
    • readium-lcp-client (branch develop)
    • readium-shared-js (branch develop)
  1. cd PathToMyCode/
  2. git clone --recursive -b develop https://github.com/readium/SDKLauncher-Android.git SDKLauncher-Android
  3. cd SDKLauncher-Android
  4. git submodule update --init --recursive
  5. git checkout feature/lcp && git submodule foreach --recursive "git checkout develop"
  6. cd readium-sdk/Platform/Android
  7. make sure that the file local.properties exists with the contents shown below at appendix "A1"
  8. ./gradlew build
  9. make sure that the generated readium-sdk lib (libepub3.so) is copied into the SDKLauncher-Android/readium-sdk/Platform/Android/epub3/libs folder, using the following file hierarchy: ./DEBUG/armeabi-v7a/libepub3.so, ./DEBUG/armeabi-v7a/libgnustl_shared.so (same for RELEASE if you are building for production rather than tests, and also for x86 if you did not disable it in local.properties, as shown in "A1" appendix)
  10. cd readium-lcp-client/platform/android
  11. make sure that the file local.properties exists with the contents shown below at appendix "A2"
  12. ./gradlew build
  13. if these command line steps are successful, you should now be able to use AndroidStudio as normal.

Steps 6 to 9 are essential, because building liblcp.so requires the readium-sdk (i.e. libepub3.so) to be precompiled and located in a specific directory structure.

Note that steps 10, 11, 12 are actually optional, next time you can just use AndroidStudio directly. Make sure that the file SDKLauncher-Android/SDKLauncher-Android/local.properties exists with the contents shown below at appendix "A3".

This confusing situation is an unfortunate consequence of the evolving build system: originally Eclipse shell scripts, then AndroidStudio + Gradle and NDK Makefile invoked externally, then Gradle-experimental internal DSL for NDK/JNI, now Gradle and pure CMake which allows hybrid Java/C++ debugging without the need for Gradle-experimental ... ! Within the next couple of months there will be a refactoring of the build system to only use the latest recommended practice, instead of a combination of techniques. In the meantime, thank you for your understanding, and good luck with building! Let us know if this works for you. Thanks.

Appendix "A1" SDKLauncher-Android/readium-sdk/Platform/Android/local.properties:

ndk.dir=/PATH/TO/Android/sdk/ndk-bundle
sdk.dir=/PATH/TO/Android/sdk

readium.ndk_experimental=true
readium.ndk_clang=false
readium.ndk_skipARM=false
readium.ndk_skipX86=true

Appendix "A2" SDKLauncher-Android/readium-lcp-client/platform/android/local.properties:

ndk.dir=/PATH/TO/Android/sdk/ndk-bundle
sdk.dir=/PATH/TO/Android/sdk

readium.ndk_experimental=true
readium.ndk_clang=false
readium.ndk_skipARM=false
readium.ndk_skipX86=true

readium.sdk_lib_dir=/PATH/TO/SDKLauncher-Android/readium-sdk/Platform/Android/epub3/libs/
readium.sdk_include_dir=/PATH/TO/SDKLauncher-Android/readium-sdk/Platform/Android/epub3/include/

Appendix "A3" SDKLauncher-Android/SDKLauncher-Android/local.properties:

ndk.dir=/PATH/TO/Android/sdk/ndk-bundle
sdk.dir=/PATH/TO/Android/sdk

readium.ndk_experimental=true
readium.ndk_clang=false
readium.ndk_skipARM=false
readium.ndk_skipX86=true

danielweck avatar Jun 13 '18 14:06 danielweck

@danielweck my project works fine with "com.android.tools.build:gradle:2.2.3" but now because of playstore restriction i have upgraded project gradle to 'com.android.tools.build:gradle:3.2.1' it compiles fine but after this upgrade licence is not getting decrypted , if (mLicense.isDecrypted()) returns false. can you suggest something.

ashishtyagi056 avatar Jun 12 '19 13:06 ashishtyagi056

Do you compile readium-sdk yourself, and if so with what NDK version?

danielweck avatar Jun 12 '19 14:06 danielweck

Do you compile readium-sdk yourself, and if so with what NDK version?

Pkg.Revision = 15.2.4203891 is this what you are asking? same ndk was working previously.

ashishtyagi056 avatar Jun 12 '19 15:06 ashishtyagi056

Thanks. Would you mind trying with NDK 16.1.4479499 please? This is still an older version compared with the latest available NDK (installed by default by Android Studio), but to my knowledge this is the last compatible version with the readium-sdk (pre-Clang GCC compiler for the Readium C++ code).

danielweck avatar Jun 12 '19 15:06 danielweck

PS: what other changes did you make to the Gradle config? You had to add build "flavors", right? Anything else?

danielweck avatar Jun 12 '19 15:06 danielweck

I tried with ndk 16b still same issue. yes i added flavorDimensions "default" in LCP gradle and removed following code from LCP manifest. uses-sdk android:minSdkVersion="19" android:targetSdkVersion="26"

ashishtyagi056 avatar Jun 13 '19 08:06 ashishtyagi056

The latest working Gradle (etc) configuration is available in these Pull Requests:

readium-sdk: https://github.com/readium/readium-sdk/pull/317

readium-lcp-client: https://github.com/readium/readium-lcp-client/pull/49

SDKLauncher-Android: https://github.com/readium/SDKLauncher-Android/pull/147

...or if not using readium-sdk and readium-lcp-client Git submodules inside SDKLauncher-Android, but pre-compiled AARs instead:

https://github.com/readium/SDKLauncher-Android/pull/152

danielweck avatar Jun 17 '19 22:06 danielweck