Skip to content

Commit 8fcd8a7

Browse files
onikombroz
authored andcommitted
Make changes in token unlock for further changes in reencrypt action.
The token preference condition is moved outside the try_token_unlock routine body.
1 parent 5f48657 commit 8fcd8a7

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

src/cryptsetup.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -875,10 +875,12 @@ static int action_resize(void)
875875
if (isLUKS2(crypt_get_type(cd))) {
876876
/* try load VK in kernel keyring using token */
877877
r = luks_try_token_unlock(cd, ARG_INT32(OPT_KEY_SLOT_ID),
878-
ARG_INT32(OPT_TOKEN_ID_ID), NULL,
879-
ARG_STR(OPT_TOKEN_TYPE_ID),
880-
CRYPT_ACTIVATE_KEYRING_KEY,1, true,
881-
ARG_SET(OPT_TOKEN_ONLY_ID));
878+
ARG_INT32(OPT_TOKEN_ID_ID),
879+
NULL, ARG_STR(OPT_TOKEN_TYPE_ID),
880+
CRYPT_ACTIVATE_KEYRING_KEY,
881+
1, true,
882+
ARG_SET(OPT_TOKEN_ONLY_ID) || ARG_SET(OPT_TOKEN_ID_ID) || ARG_SET(OPT_TOKEN_TYPE_ID),
883+
NULL);
882884

883885
if (r >= 0 || quit || ARG_SET(OPT_TOKEN_ONLY_ID))
884886
goto out;
@@ -1829,7 +1831,9 @@ static int action_open_luks(void)
18291831
r = luks_try_token_unlock(cd, ARG_INT32(OPT_KEY_SLOT_ID),
18301832
ARG_INT32(OPT_TOKEN_ID_ID), activated_name,
18311833
ARG_STR(OPT_TOKEN_TYPE_ID), activate_flags,
1832-
set_tries_tty(false), true, ARG_SET(OPT_TOKEN_ONLY_ID));
1834+
set_tries_tty(false), true,
1835+
ARG_SET(OPT_TOKEN_ONLY_ID) || ARG_SET(OPT_TOKEN_ID_ID) || ARG_SET(OPT_TOKEN_TYPE_ID),
1836+
NULL);
18331837

18341838
if (r >= 0 || r == -EEXIST || quit || ARG_SET(OPT_TOKEN_ONLY_ID))
18351839
goto out;
@@ -2707,7 +2711,9 @@ static int action_luksResume(void)
27072711
/* try to resume LUKS2 device by token first */
27082712
r = luks_try_token_unlock(cd, ARG_INT32(OPT_KEY_SLOT_ID), ARG_INT32(OPT_TOKEN_ID_ID),
27092713
action_argv[0], ARG_STR(OPT_TOKEN_TYPE_ID), 0,
2710-
set_tries_tty(false), false, ARG_SET(OPT_TOKEN_ONLY_ID));
2714+
set_tries_tty(false), false,
2715+
ARG_SET(OPT_TOKEN_ONLY_ID) || ARG_SET(OPT_TOKEN_ID_ID) || ARG_SET(OPT_TOKEN_TYPE_ID),
2716+
NULL);
27112717

27122718
if (r >= 0 || quit || ARG_SET(OPT_TOKEN_ONLY_ID))
27132719
goto out;

src/utils_luks.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ int luks_try_token_unlock(struct crypt_device *cd,
310310
uint32_t activate_flags,
311311
int tries,
312312
bool activation,
313-
bool token_only)
313+
bool retry_with_pin,
314+
struct crypt_keyslot_context **r_kc)
314315
{
315316
int r;
316317
struct crypt_keyslot_context *kc;
@@ -326,15 +327,15 @@ int luks_try_token_unlock(struct crypt_device *cd,
326327
return r;
327328

328329
if (activation)
329-
r = crypt_activate_by_keyslot_context(cd, activated_name, keyslot, kc, CRYPT_ANY_SLOT, NULL, activate_flags);
330+
r = crypt_activate_by_keyslot_context(cd, activated_name, keyslot, kc, CRYPT_ANY_SLOT, kc, activate_flags);
330331
else
331332
r = crypt_resume_by_keyslot_context(cd, activated_name, keyslot, kc);
332333

333334
tools_keyslot_msg(r, UNLOCKED);
334335
tools_token_error_msg(r, token_type, token_id, false);
335336

336-
/* Token requires PIN (-ENOANO). Ask for it if there is evident preference for tokens */
337-
if (r != -ENOANO || (!token_only && !token_type && token_id == CRYPT_ANY_TOKEN))
337+
/* Token requires PIN (-ENOANO). */
338+
if (r != -ENOANO || !retry_with_pin)
338339
goto out;
339340

340341
if (token_id == CRYPT_ANY_TOKEN)
@@ -368,6 +369,10 @@ int luks_try_token_unlock(struct crypt_device *cd,
368369
check_signal(&r);
369370
} while (r == -ENOANO && (--tries > 0));
370371
out:
371-
crypt_keyslot_context_free(kc);
372+
if (r >= 0 && r_kc)
373+
*r_kc = kc;
374+
else
375+
crypt_keyslot_context_free(kc);
376+
372377
return r;
373378
}

src/utils_luks.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ int luks_try_token_unlock(struct crypt_device *cd,
5151
uint32_t activate_flags,
5252
int tries,
5353
bool activation,
54-
bool token_only);
54+
bool retry_with_pin,
55+
struct crypt_keyslot_context **r_kc);
5556

5657
#endif /* UTILS_LUKS_H */

0 commit comments

Comments
 (0)