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

Opening encrypted epubs on android devices. #135

Open
rahulk11 opened this issue Feb 26, 2018 · 19 comments
Open

Opening encrypted epubs on android devices. #135

rahulk11 opened this issue Feb 26, 2018 · 19 comments

Comments

@rahulk11
Copy link

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 rahulk11 changed the title I want to open encrypted epubs on android devices. Is there any documentation for implementing this? type:Question I want to open encrypted epubs on android devices. Is there any documentation for implementing this? Feb 26, 2018
@llemeurfr
Copy link

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?

@rahulk11 rahulk11 changed the title type:Question I want to open encrypted epubs on android devices. Is there any documentation for implementing this? Opening encrypted epubs on android devices. Feb 26, 2018
@rahulk11
Copy link
Author

@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?

@danielweck
Copy link
Member

danielweck commented Feb 26, 2018

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

@rahulk11
Copy link
Author

rahulk11 commented Feb 27, 2018

@danielweck thanks. i'll look into these

@rahulk11
Copy link
Author

rahulk11 commented Mar 2, 2018

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.

@danielweck
Copy link
Member

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.

@rahulk11
Copy link
Author

rahulk11 commented Mar 2, 2018

@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.

@danielweck
Copy link
Member

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.

@xiaoxiaomuou
Copy link

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!

@danielweck
Copy link
Member

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

The Git submodules should be:

@xiaoxiaomuou
Copy link

@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!

@danielweck
Copy link
Member

@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

@ashishtyagi056
Copy link

@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.

@danielweck
Copy link
Member

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

@ashishtyagi056
Copy link

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.

@danielweck
Copy link
Member

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
Copy link
Member

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

@ashishtyagi056
Copy link

ashishtyagi056 commented Jun 13, 2019

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"

@danielweck
Copy link
Member

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

readium-sdk:
readium/readium-sdk#317

readium-lcp-client:
readium/readium-lcp-client#49

SDKLauncher-Android:
#147

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

#152

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants