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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/org/nick/abe/AndroidBackup.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ public static void extractAsTar(String backupFilename, String filename,

// decrypt the master key blob
Cipher c = Cipher.getInstance(ENCRYPTION_MECHANISM);
// XXX we don't support non-ASCII passwords
SecretKey userKey = buildPasswordKey(password, userSalt, rounds, false);
SecretKey userKey = buildPasswordKey(password, userSalt, rounds, true);
byte[] IV = hexToByteArray(userIvHex);
IvParameterSpec ivSpec = new IvParameterSpec(IV);
c.init(Cipher.DECRYPT_MODE,
Expand Down Expand Up @@ -153,6 +152,25 @@ public static void extractAsTar(String backupFilename, String filename,
System.err.println("MK checksum: " + toHex(mkChecksum));
}

// checking pkcs5 padding (of length 13 or even 8) is enough to determine a wrong password
c = Cipher.getInstance("AES/CBC/NoPadding");
userKey = buildPasswordKey(password, userSalt, rounds, true);
byte[] IVCheck = hexToByteArray(userIvHex);
ivSpec = new IvParameterSpec(IVCheck);
c.init(Cipher.DECRYPT_MODE,
new SecretKeySpec(userKey.getEncoded(), "AES"), ivSpec);
mkCipher = hexToByteArray(masterKeyBlobHex);
byte[] mkBlobCheck = c.doFinal(mkCipher);
int pad_byte = mkBlobCheck[mkBlobCheck.length - 1];
if (pad_byte < 8) {
System.err.println("PKCS5Padding is not correct, wrong password?");
} else {
c = Cipher.getInstance(ENCRYPTION_MECHANISM);
ivSpec = new IvParameterSpec(IV);
c.init(Cipher.DECRYPT_MODE, new SecretKeySpec(mk, "AES"), ivSpec);
cipherStream = new CipherInputStream(rawInStream, c);
}
/*
// now validate the decrypted master key against the checksum
// first try the algorithm matching the archive version
boolean useUtf = version >= BACKUP_FILE_V2;
Expand All @@ -172,7 +190,7 @@ public static void extractAsTar(String backupFilename, String filename,
// Only if all of the above worked properly will 'result' be
// assigned
cipherStream = new CipherInputStream(rawInStream, c);
}
} */
}

if (isEncrypted && cipherStream == null) {
Expand Down