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

Add support for non-ASCII passwords #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add support for non-ASCII passwords #66

wants to merge 1 commit into from

Conversation

kholia
Copy link

@kholia kholia commented May 30, 2018

I have tested this with Android 4.4.4, Android 6.0, and Android 8.0 ADB backups.

This patch is somewhat hacky but hopefully the general idea is reusable.

@kholia
Copy link
Author

kholia commented May 30, 2018

I got this idea, of only checking the PCKS5 padding to verify the password, while working on openwall/john#3261 (OpenCL support for cracking Android Backups) and related issues.

@nelenkov
Copy link
Owner

nelenkov commented Jun 6, 2018

Hacky indeed :) The proper way to handle non-ascii password is to fix the key derivation, why do you think that checking the padding is enough? Also, why if (pad_byte < 8)? Technically, you could have 1,2, etc. bytes of padding.

@kholia
Copy link
Author

kholia commented Jun 7, 2018

I have answered this question at openwall/john#3261 (comment).

In short,

// The structure of masteykey_blob is fixed:
//   + masteykey_blob -> length_1 (byte) + IV (16 bytes) + length_2 + masteykey (32 bytes) + length_3 + checksum (32 bytes) => total of 83 bytes
//   + padding -> this data blob of 83 bytes gets 13 bytes of padding making the masteykey_blob_length = 96 bytes always

This implies that padding is always 13 bytes in practice.

Good question!

@nelenkov
Copy link
Owner

Hi,

I get the fixed padding part. However, this format has checksum that allows you to verify if derived key is correct. Why not just use that (aside from the slight performance optimization)? If buildPasswordKey() is called with utf8=true, non-ASCII passwords should work fine.

@kholia
Copy link
Author

kholia commented Jun 18, 2018

Yep, the format does have a checksum. However, the process of calculating a checksum is problematic.

The program does calculatedCk = makeKeyChecksum(mk, ckSalt, rounds, useUtf) followed by calculatedCk = makeKeyChecksum(mk, ckSalt, rounds, !useUtf). This is hacky and doesn't look robust. Wouldn't it be nice if we can avoid this hack entirely? :)

Also, I could not find a way to port PBEParametersGenerator.PKCS5PasswordToBytes (when useUtf is True) to C easily (due to wide-chars vs unsigned chars conversion).

@nelenkov
Copy link
Owner

Hm, checking the checksum is still better than only checking padding. Is the current code broken for non-ASCII passwords? AFAIK, that code was added to handle both v1 and v2 backups (with UTF-8 support)

As for porting to C, you'd need to use iconv or similar to get proper unicode support.

@kholia
Copy link
Author

kholia commented Jun 18, 2018

Is the current code broken for non-ASCII passwords?

Yes! This is the reason behind this PR.

Hm, checking the checksum is still better than only checking padding.

Checking proper padding of length 8 is quite safe. To make it even safer, I can check for proper padding of length 13. In JtR project, we rely on these padding checks for cracking passwords. We are able to do this without triggering false positives.

By removing the hacky checksum checking code, I think we will be able to decrypt a wider variety of encrypted backup files. I am not 100% sure about this last statement though.

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.

2 participants