-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OP-TEE: Add option for PKCS11 TA (CFG_PKCS11_TA_LOCK_PIN_AFTER_FAILED…
…_LOGIN_ATTEMPTS) Note: Commit includes a custom patch for OP-TEE. Signed-off-by: Tanel Dettenborn <[email protected]>
- Loading branch information
1 parent
bf81393
commit 3f3766d
Showing
5 changed files
with
221 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Copyright <YEAR> <COPYRIGHT HOLDER> | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
186 changes: 186 additions & 0 deletions
186
targets/nvidia-jetson-orin/0001-ta-pkcs11-Build-time-option-for-controlling-pin-lock.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
From 18c1ea534dba4a75848fdeea3c55de00ca11c397 Mon Sep 17 00:00:00 2001 | ||
From: Tanel Dettenborn <[email protected]> | ||
Date: Sat, 14 Sep 2024 16:45:46 +0300 | ||
Subject: [PATCH] ta: pkcs11: Build time option for controlling pin locking | ||
Adding a build time option for disabling or enabling pin locking after failed | ||
authentication attempts. Option controls both, User and SO, pins. Default is | ||
'y'. | ||
|
||
Option is called: | ||
CFG_PKCS11_TA_LOCK_PIN_AFTER_FAILED_LOGIN_ATTEMPTS | ||
|
||
NOTE: Patch is backported! | ||
|
||
Signed-off-by: Tanel Dettenborn <[email protected]> | ||
--- | ||
optee/optee_os/ta/pkcs11/src/pkcs11_token.c | 102 +++++++++++--------- | ||
optee/optee_os/ta/pkcs11/sub.mk | 4 + | ||
2 files changed, 60 insertions(+), 46 deletions(-) | ||
|
||
diff --git a/optee/optee_os/ta/pkcs11/src/pkcs11_token.c b/optee/optee_os/ta/pkcs11/src/pkcs11_token.c | ||
index 25ba77827..9882d1cf2 100644 | ||
--- a/optee/optee_os/ta/pkcs11/src/pkcs11_token.c | ||
+++ b/optee/optee_os/ta/pkcs11/src/pkcs11_token.c | ||
@@ -884,16 +884,18 @@ enum pkcs11_rc entry_ck_token_initialize(uint32_t ptypes, TEE_Param *params) | ||
if (rc != PKCS11_CKR_PIN_INCORRECT) | ||
return rc; | ||
|
||
- token->db_main->flags |= PKCS11_CKFT_SO_PIN_COUNT_LOW; | ||
- token->db_main->so_pin_count++; | ||
+ if (IS_ENABLED(CFG_PKCS11_TA_LOCK_PIN_AFTER_FAILED_LOGIN_ATTEMPTS)) { | ||
+ token->db_main->flags |= PKCS11_CKFT_SO_PIN_COUNT_LOW; | ||
+ token->db_main->so_pin_count++; | ||
|
||
- pin_count = token->db_main->so_pin_count; | ||
- if (pin_count == PKCS11_TOKEN_SO_PIN_COUNT_MAX - 1) | ||
- token->db_main->flags |= PKCS11_CKFT_SO_PIN_FINAL_TRY; | ||
- if (pin_count == PKCS11_TOKEN_SO_PIN_COUNT_MAX) | ||
- token->db_main->flags |= PKCS11_CKFT_SO_PIN_LOCKED; | ||
+ pin_count = token->db_main->so_pin_count; | ||
+ if (pin_count == PKCS11_TOKEN_SO_PIN_COUNT_MAX - 1) | ||
+ token->db_main->flags |= PKCS11_CKFT_SO_PIN_FINAL_TRY; | ||
+ if (pin_count == PKCS11_TOKEN_SO_PIN_COUNT_MAX) | ||
+ token->db_main->flags |= PKCS11_CKFT_SO_PIN_LOCKED; | ||
|
||
- update_persistent_db(token); | ||
+ update_persistent_db(token); | ||
+ } | ||
|
||
return PKCS11_CKR_PIN_INCORRECT; | ||
} | ||
@@ -1140,35 +1142,39 @@ static enum pkcs11_rc check_so_pin(struct pkcs11_session *session, | ||
if (rc != PKCS11_CKR_PIN_INCORRECT) | ||
return rc; | ||
|
||
- token->db_main->flags |= PKCS11_CKFT_SO_PIN_COUNT_LOW; | ||
- token->db_main->so_pin_count++; | ||
+ if (IS_ENABLED(CFG_PKCS11_TA_LOCK_PIN_AFTER_FAILED_LOGIN_ATTEMPTS)) { | ||
+ token->db_main->flags |= PKCS11_CKFT_SO_PIN_COUNT_LOW; | ||
+ token->db_main->so_pin_count++; | ||
|
||
- pin_count = token->db_main->so_pin_count; | ||
- if (pin_count == PKCS11_TOKEN_SO_PIN_COUNT_MAX - 1) | ||
- token->db_main->flags |= PKCS11_CKFT_SO_PIN_FINAL_TRY; | ||
- if (pin_count == PKCS11_TOKEN_SO_PIN_COUNT_MAX) | ||
- token->db_main->flags |= PKCS11_CKFT_SO_PIN_LOCKED; | ||
+ pin_count = token->db_main->so_pin_count; | ||
+ if (pin_count == PKCS11_TOKEN_SO_PIN_COUNT_MAX - 1) | ||
+ token->db_main->flags |= PKCS11_CKFT_SO_PIN_FINAL_TRY; | ||
+ if (pin_count == PKCS11_TOKEN_SO_PIN_COUNT_MAX) | ||
+ token->db_main->flags |= PKCS11_CKFT_SO_PIN_LOCKED; | ||
|
||
- update_persistent_db(token); | ||
+ update_persistent_db(token); | ||
|
||
- if (token->db_main->flags & PKCS11_CKFT_SO_PIN_LOCKED) | ||
- return PKCS11_CKR_PIN_LOCKED; | ||
+ if (token->db_main->flags & PKCS11_CKFT_SO_PIN_LOCKED) | ||
+ return PKCS11_CKR_PIN_LOCKED; | ||
+ } | ||
|
||
return PKCS11_CKR_PIN_INCORRECT; | ||
} | ||
|
||
- if (token->db_main->so_pin_count) { | ||
- token->db_main->so_pin_count = 0; | ||
+ if (IS_ENABLED(CFG_PKCS11_TA_LOCK_PIN_AFTER_FAILED_LOGIN_ATTEMPTS)) { | ||
+ if (token->db_main->so_pin_count) { | ||
+ token->db_main->so_pin_count = 0; | ||
|
||
- update_persistent_db(token); | ||
- } | ||
+ update_persistent_db(token); | ||
+ } | ||
|
||
- if (token->db_main->flags & (PKCS11_CKFT_SO_PIN_COUNT_LOW | | ||
- PKCS11_CKFT_SO_PIN_FINAL_TRY)) { | ||
- token->db_main->flags &= ~(PKCS11_CKFT_SO_PIN_COUNT_LOW | | ||
- PKCS11_CKFT_SO_PIN_FINAL_TRY); | ||
+ if (token->db_main->flags & (PKCS11_CKFT_SO_PIN_COUNT_LOW | | ||
+ PKCS11_CKFT_SO_PIN_FINAL_TRY)) { | ||
+ token->db_main->flags &= ~(PKCS11_CKFT_SO_PIN_COUNT_LOW | | ||
+ PKCS11_CKFT_SO_PIN_FINAL_TRY); | ||
|
||
- update_persistent_db(token); | ||
+ update_persistent_db(token); | ||
+ } | ||
} | ||
|
||
return PKCS11_CKR_OK; | ||
@@ -1199,35 +1205,39 @@ static enum pkcs11_rc check_user_pin(struct pkcs11_session *session, | ||
if (rc != PKCS11_CKR_PIN_INCORRECT) | ||
return rc; | ||
|
||
- token->db_main->flags |= PKCS11_CKFT_USER_PIN_COUNT_LOW; | ||
- token->db_main->user_pin_count++; | ||
+ if (IS_ENABLED(CFG_PKCS11_TA_LOCK_PIN_AFTER_FAILED_LOGIN_ATTEMPTS)) { | ||
+ token->db_main->flags |= PKCS11_CKFT_USER_PIN_COUNT_LOW; | ||
+ token->db_main->user_pin_count++; | ||
|
||
- pin_count = token->db_main->user_pin_count; | ||
- if (pin_count == PKCS11_TOKEN_USER_PIN_COUNT_MAX - 1) | ||
- token->db_main->flags |= PKCS11_CKFT_USER_PIN_FINAL_TRY; | ||
- if (pin_count == PKCS11_TOKEN_USER_PIN_COUNT_MAX) | ||
- token->db_main->flags |= PKCS11_CKFT_USER_PIN_LOCKED; | ||
+ pin_count = token->db_main->user_pin_count; | ||
+ if (pin_count == PKCS11_TOKEN_USER_PIN_COUNT_MAX - 1) | ||
+ token->db_main->flags |= PKCS11_CKFT_USER_PIN_FINAL_TRY; | ||
+ if (pin_count == PKCS11_TOKEN_USER_PIN_COUNT_MAX) | ||
+ token->db_main->flags |= PKCS11_CKFT_USER_PIN_LOCKED; | ||
|
||
- update_persistent_db(token); | ||
+ update_persistent_db(token); | ||
|
||
- if (token->db_main->flags & PKCS11_CKFT_USER_PIN_LOCKED) | ||
- return PKCS11_CKR_PIN_LOCKED; | ||
+ if (token->db_main->flags & PKCS11_CKFT_USER_PIN_LOCKED) | ||
+ return PKCS11_CKR_PIN_LOCKED; | ||
+ } | ||
|
||
return PKCS11_CKR_PIN_INCORRECT; | ||
} | ||
|
||
- if (token->db_main->user_pin_count) { | ||
- token->db_main->user_pin_count = 0; | ||
+ if (IS_ENABLED(CFG_PKCS11_TA_LOCK_PIN_AFTER_FAILED_LOGIN_ATTEMPTS)) { | ||
+ if (token->db_main->user_pin_count) { | ||
+ token->db_main->user_pin_count = 0; | ||
|
||
- update_persistent_db(token); | ||
- } | ||
+ update_persistent_db(token); | ||
+ } | ||
|
||
- if (token->db_main->flags & (PKCS11_CKFT_USER_PIN_COUNT_LOW | | ||
- PKCS11_CKFT_USER_PIN_FINAL_TRY)) { | ||
- token->db_main->flags &= ~(PKCS11_CKFT_USER_PIN_COUNT_LOW | | ||
- PKCS11_CKFT_USER_PIN_FINAL_TRY); | ||
+ if (token->db_main->flags & (PKCS11_CKFT_USER_PIN_COUNT_LOW | | ||
+ PKCS11_CKFT_USER_PIN_FINAL_TRY)) { | ||
+ token->db_main->flags &= ~(PKCS11_CKFT_USER_PIN_COUNT_LOW | | ||
+ PKCS11_CKFT_USER_PIN_FINAL_TRY); | ||
|
||
- update_persistent_db(token); | ||
+ update_persistent_db(token); | ||
+ } | ||
} | ||
|
||
return PKCS11_CKR_OK; | ||
diff --git a/optee/optee_os/ta/pkcs11/sub.mk b/optee/optee_os/ta/pkcs11/sub.mk | ||
index 30dd13cb5..c9c401879 100644 | ||
--- a/optee/optee_os/ta/pkcs11/sub.mk | ||
+++ b/optee/optee_os/ta/pkcs11/sub.mk | ||
@@ -10,6 +10,10 @@ CFG_PKCS11_TA_HEAP_SIZE ?= (32 * 1024) | ||
# Defines the number of PKCS11 token implemented by the PKCS11 TA | ||
CFG_PKCS11_TA_TOKEN_COUNT ?= 3 | ||
|
||
+# Locks correspondingly User or SO PIN when reaching maximum | ||
+# failed authentication attemps (continous) limit | ||
+CFG_PKCS11_TA_LOCK_PIN_AFTER_FAILED_LOGIN_ATTEMPTS ?= y | ||
+ | ||
global-incdirs-y += include | ||
global-incdirs-y += src | ||
subdirs-y += src | ||
-- | ||
2.42.2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters