From 75925fb2f7bfff249ff4274c4e7894a23b5f2d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Trefn=C3=BD?= Date: Sun, 23 Feb 2020 20:00:00 +0100 Subject: [PATCH] bitlk: Strip extra newline from potential recovery keys There might be a trailing newline added by the text editor when the recovery passphrase was passed using the '--key-file' option so we'll remove it before trying to use the passphrase. --- lib/bitlk/bitlk.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/bitlk/bitlk.c b/lib/bitlk/bitlk.c index dd524f2e..4af61e6d 100644 --- a/lib/bitlk/bitlk.c +++ b/lib/bitlk/bitlk.c @@ -788,8 +788,14 @@ static int get_recovery_key(struct crypt_device *cd, - 8 groups of 6 divided by '-' - each part is a number dividable by 11 */ - if (passwordLen != BITLK_RECOVERY_KEY_LEN) - return 0; + if (passwordLen != BITLK_RECOVERY_KEY_LEN) { + if (passwordLen == BITLK_RECOVERY_KEY_LEN + 1 && password[passwordLen - 1] == '\n') { + /* looks like a recovery key with an extra newline, possibly from a key file */ + passwordLen--; + log_dbg(cd, "Possible extra EOL stripped from the recovery key."); + } else + return 0; + } for (i = BITLK_RECOVERY_PART_LEN; i < passwordLen; i += BITLK_RECOVERY_PART_LEN + 1) { if (password[i] != '-')