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

AES256 CBC W3C padding scheme (instead of PKCS#7) #26

Merged
merged 4 commits into from
Jan 25, 2017

Conversation

danielweck
Copy link
Member

@danielweck danielweck commented Jan 22, 2017

In reaction to:
readium/readium-lcp-server#18 (comment)

credits @drminside

Work In Progress

This contribution involves patching Crypto++

Fixed : 기본 패딩 모드 변경 DEFAULT_PADDING -> W3C_PADDING , AesCbcSymmetricAlgorithm.cpp
@danielweck
Copy link
Member Author

Server implementation: readium/readium-lcp-server#111

@llemeurfr
Copy link

I just see in the DRMInside commit that the inline comments (line 99 and others was not changed and seems to indicate PKCS#7 is used, which is not the case anymore. Shouldn' the comment be updated?

@danielweck
Copy link
Member Author

@llemeurfr agreed.

@danielweck
Copy link
Member Author

On the client side, personally I would like to be able to switch between PKCS#7 and W3C padding schemes based on some discoverable metadata, such as the URI http://www.w3.org/2001/04/xmlenc#aes256-cbc
(which impies W3C padding algorithm)
Unfortunately, I am not aware of a URI / metadata that indicates PKCS#7
Any ideas?

@llemeurfr
Copy link

What is the advantage, for the ecosystem, of offering such a flexibility?

@danielweck
Copy link
Member Author

No discernable advantage for the "ecosystem", I think, because the LCP profile strictly requires one padding scheme.
However, if PKCS#7 vs. W3C discovery is cheap (e.g. URI comparison), then this would make the code clearer, and less prone to errors in future evolutions.
We already have a well-defined switch for GCM vs. CBC for the AES256 encryption (based on a canonical URI), in both server and client implementations. Yet, right now the LCP ecosystem mandates the use of CBC (in other words, excludes the use of GCM).

At any rate, assuming DRM-Inside's code contribution passes peer-reviews and tests, do we revisit the decision to use PKCS#7?
readium/readium-lcp-server#18 (comment)

My personal opinion is that if the URI http://www.w3.org/2001/04/xmlenc#aes256-cbc indeed implies W3C padding instead of PKCS#7, then we clearly have an inconsistency and we should stop using PKCS#7. Or, we change the URI to mirror the fact that PKCS#7 is used.

@llemeurfr
Copy link

I agree that DRMInside's contrib makes us revisit the decision to use PKCS#17.
Note that the Readium LCP Encryption Profile 1.0 draft spec has proactively modified by Taehyun to reflect that :-)
Let's validate this contribution and update readium/readium-lcp-server#18 (comment).

The other question is: should we be able to activate the use of PKCS#7 using some discoverable metadata? My feeling is that there is no real interest in that, and that the code (which is kept in the history) can be removed from the "live" code.

@danielweck
Copy link
Member Author

okay.

@jpbougie
Copy link

The only difference between PKCS#7 and W3C padding is that the W3C variant does not specify which values to use to fill the padding bytes (except for the last one), while PKCS specifies that every padding byte must be equal to the padding length. Thus, while appending the padding bytes, PKCS#7 is a superset of the W3C padding.

As we can see in the client PR, the critical part is relaxing the requirement that the padding bytes be the same as the length of the pad. I would thus suggest that we keep the server as is and relax the requirement on the client, which is what DRMInside already proposed.

@thkim2015
Copy link

IMO, we need to consider why W3C suddenly added the padding restriction in 2002.

There was no padding details before 2002 in the W3C encryption standard. But after publishing the possibility of the Padding Oracle Attack on the block cipher algorithm in 2002, W3C had instantly updated the specification as size of the padding bytes should not be described in the padding block except last byte.

Key point of the padding oracle is that the last encrypted block before the PKCS#7 padding could be easily cracked, if the decryption program provides unnecessary error codes related padding.

So I think that not allowing using the vulnerable PCKS#7 on both server and client side is the clear way for not only consistency of the specification, but also the security perspective.

@danielweck
Copy link
Member Author

Now that Readium is effectively creating a fork of CryptoPP, I have submitted a Pull Request at Crypto++ to add support for the W3C padding scheme for AES-256-CBC, based on DRM-Inside's code: weidai11/cryptopp#368

@danielweck danielweck force-pushed the feature/cbc-w3c-padding branch from fd77cdf to a6843bb Compare January 24, 2017 17:17
@danielweck
Copy link
Member Author

I have successfully tested this code with EPUBs encrypted by the Go server with the existing PKCS#7 method (this works because W3C algorithm operates on the client side as a "superset" functionally-speaking)

@danielweck
Copy link
Member Author

Merging this CryptoPP patch directly into the Readium LCP client lib source tree.

Note that we now maintain a Crypto++ fork in "parallel" at https://github.com/edrlab/cryptopp
So, we can easily track upstream changes and manually merge them into the LCP client lib source tree.

@danielweck danielweck merged commit 3567779 into develop Jan 25, 2017
@danielweck danielweck deleted the feature/cbc-w3c-padding branch January 25, 2017 13:16
@danielweck
Copy link
Member Author

Follow-up: weidai11/cryptopp@8a177c5

@danielweck
Copy link
Member Author

The above follow-up is merged (cherry-picked) into the EDRLab fork of CryptoPP:
edrlab/cryptopp@CRYPTOPP_5_6_5...CRYPTOPP_5_6_5_CBC_W3C_PADDING

@danielweck
Copy link
Member Author

So, all-in, this is the CBC W3C_PADDING diff:
edrlab/cryptopp@CRYPTOPP_5_6_5_XCode_etc_projects...CRYPTOPP_5_6_5_CBC_W3C_PADDING

danielweck added a commit that referenced this pull request May 9, 2017
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

Successfully merging this pull request may close these issues.

5 participants