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

Issues decrypting LCP resources (CBCDRMInputStream) #154

Closed
mickael-menu-mantano opened this issue Dec 5, 2019 · 8 comments
Closed

Issues decrypting LCP resources (CBCDRMInputStream) #154

mickael-menu-mantano opened this issue Dec 5, 2019 · 8 comments
Assignees

Comments

@mickael-menu-mantano
Copy link
Contributor

CBCDRMInputStream needs to be reviewed because there are a number of issues:

A few clues:

@mickael-menu-mantano mickael-menu-mantano self-assigned this Dec 5, 2019
@aferditamuriqi
Copy link
Member

@mickael-menu can this issue be closed? can I assume it is fixed by this PR readium/r2-streamer-swift#140

@mickael-menu-mantano
Copy link
Contributor Author

@aferditamuriqi No I didn't do anything to fix this issue so far

@danielweck
Copy link
Member

danielweck commented Dec 28, 2019 via email

@aferditamuriqi
Copy link
Member

@mickael-menu ok, great, just wanted to make sure, since it was connected to a PR

@danielweck
Copy link
Member

* [`CBCDRMInputStream` was directly translated from this C++ implementation](https://github.com/readium/readium-lcp-client/blob/764b28f5f4d879f771be7e727cf4a79ac0d62d9f/src/lcp-client-lib/AesCbcSymmetricAlgorithm.cpp#L125). The only difference I can see is that [the C++ version provides the type of padding](https://github.com/readium/readium-lcp-client/blob/764b28f5f4d879f771be7e727cf4a79ac0d62d9f/src/lcp-client-lib/AesCbcSymmetricAlgorithm.cpp#L122). The private LCP framework doesn't take any padding scheme as a parameter though, so I'm not sure we're getting the proper `outSize`, which might explain why the padding could not be removed properly. Any thoughts on the padding scheme @danielweck?

See this recent bugfix:

readium/readium-lcp-client@25d2e37

@mickael-menu
Copy link
Member

@danielweck Thanks, this looks promising!

Do we need to provide the padding scheme as well? There's no way to do that with the R2 LCP lib.

// Figure out what padding scheme to use
BlockPaddingSchemeDef::BlockPaddingScheme padding = BlockPaddingSchemeDef::NO_PADDING;
if (total > (ssize - CryptoPP::AES::BLOCKSIZE))
{
    padding = BlockPaddingSchemeDef::W3C_PADDING; // Note that handling of W3C padding scheme during decryption also handles PKCS#7 (which is BlockPaddingSchemeDef::PKCS_PADDING in CryptoPP, with AES CBC Block Size > 8 (not PKCS#5))
}

@danielweck
Copy link
Member

danielweck commented Jan 31, 2020

This is a CryptoPP implementation detail, strictly-speaking we do not need to ask the underlying crypto lib to automatically remove padding, instead we can just trim the padding suffix "manually".

@mickael-menu mickael-menu transferred this issue from readium/r2-streamer-swift Aug 14, 2020
@mickael-menu
Copy link
Member

Equivalent issue on r2-lcp-kotlin: readium/kotlin-toolkit#207

And a Kotlin PR fixing it: readium/r2-lcp-kotlin#84

@mickael-menu mickael-menu transferred this issue from readium/r2-lcp-swift Aug 12, 2022
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

4 participants