Commit 982f118
committed
Fix Fenrir static analysis findings
Address Fenrir findings covering missing object attribute
enforcement, missing operation termination on error paths, and an
authentication fail-open on the SO PIN check.
Attribute enforcement:
- C_CopyObject rejects non-copyable objects (CKR_ACTION_PROHIBITED).
- C_DestroyObject rejects non-destroyable objects (CKR_ACTION_PROHIBITED).
- C_DeriveKey enforces CKA_DERIVE on the base key.
- C_EncapsulateKey/C_DecapsulateKey enforce CKA_ENCAPSULATE/DECAPSULATE
and return CKR_KEY_FUNCTION_NOT_PERMITTED.
- C_SetAttributeValue rejects flipping CKA_COPYABLE/CKA_DESTROYABLE
from CK_FALSE back to CK_TRUE per PKCS#11 v2.40 sec. 4.4.1.
- CKA_COPYABLE/CKA_DESTROYABLE are now stored via inverted opFlag bits
(WP11_FLAG_NOT_COPYABLE/NOT_DESTROYABLE) so the values survive
C_GetAttributeValue/C_SetAttributeValue round trips.
CKA_COPYABLE default flips from CK_FALSE to CK_TRUE to match the
PKCS#11 spec. The legacy read-back behavior is preserved behind
WOLFPKCS11_LEGACY_COPYABLE_FALSE_DEFAULT. The C_CopyObject gate reads
the stored flag bit directly via WP11_Object_IsCopyable so the legacy
macro never disables copy for objects that explicitly opted in.
Operation termination: C_Encrypt, C_Decrypt, C_EncryptUpdate,
C_DecryptUpdate, C_DigestUpdate, C_SignUpdate, C_VerifyUpdate, and
C_DigestKey now call WP11_Session_SetOpInitialized(session, 0) on
their early-return error paths so a follow-up *Init succeeds.
C_DigestKey preserves positive CK_RV returns (e.g.
CKR_FUNCTION_NOT_SUPPORTED on WOLFPKCS11_NO_STORE builds) instead of
collapsing them to CKR_FUNCTION_FAILED.
SO PIN check: WP11_Slot_CheckSOPin no longer accepts an empty PIN
when the SO PIN has not been set. Previously the empty-PIN
constant-compare against the zero-length unset PIN returned equal,
granting WP11_APP_STATE_RW_SO without authentication.
C_CopyObject and C_DestroyObject now run the COPYABLE/DESTROYABLE
gates after the R/W session check so the previously-returned
CKR_SESSION_READ_ONLY is preserved for read-only sessions.
Tests: new test_copy_object_not_copyable, test_destroy_object_not_-
destroyable, test_derive_key_not_allowed, test_mlkem_encap_decap_-
not_permitted, test_op_active_after_data_len_range, test_op_active_-
after_update_data_len_range, test_op_active_after_sign_verify_-
update_failure, test_op_active_after_digest_key_failure, and
WOLFPKCS11_NO_STORE-gated test_op_active_after_digest_key_no_store
in pkcs11test/pkcs11v3test, plus a new tests/so_login_uninit_test
binary that walks C_Login(CKU_SO, ...) on a fresh uninitialized
token. test_copy_object_not_copyable and test_destroy_object_not_-
destroyable also assert that the FALSE->TRUE flip is rejected.
Several existing helpers (get_generic_key, get_ecc_priv_key,
get_aes_128_key, gen_aes_key, the HKDF and ML-KEM templates) now
set CKA_DERIVE=CK_TRUE explicitly so they survive the new gate.
README.md documents the new WOLFPKCS11_LEGACY_COPYABLE_FALSE_DEFAULT
build define and the spec-compliance behavior changes that callers
upgrading from earlier versions need to be aware of.1 parent 47e1453 commit 982f118
9 files changed
Lines changed: 1024 additions & 41 deletions
File tree
- src
- tests
- wolfpkcs11
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
100 | 132 | | |
101 | 133 | | |
102 | 134 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7012 | 7012 | | |
7013 | 7013 | | |
7014 | 7014 | | |
7015 | | - | |
7016 | | - | |
| 7015 | + | |
| 7016 | + | |
| 7017 | + | |
| 7018 | + | |
7017 | 7019 | | |
7018 | | - | |
| 7020 | + | |
7019 | 7021 | | |
7020 | 7022 | | |
7021 | 7023 | | |
| |||
8941 | 8943 | | |
8942 | 8944 | | |
8943 | 8945 | | |
| 8946 | + | |
| 8947 | + | |
| 8948 | + | |
| 8949 | + | |
| 8950 | + | |
| 8951 | + | |
| 8952 | + | |
| 8953 | + | |
| 8954 | + | |
| 8955 | + | |
| 8956 | + | |
| 8957 | + | |
| 8958 | + | |
| 8959 | + | |
| 8960 | + | |
| 8961 | + | |
| 8962 | + | |
| 8963 | + | |
| 8964 | + | |
| 8965 | + | |
| 8966 | + | |
| 8967 | + | |
| 8968 | + | |
| 8969 | + | |
| 8970 | + | |
| 8971 | + | |
8944 | 8972 | | |
8945 | 8973 | | |
8946 | 8974 | | |
| |||
10866 | 10894 | | |
10867 | 10895 | | |
10868 | 10896 | | |
| 10897 | + | |
10869 | 10898 | | |
| 10899 | + | |
| 10900 | + | |
| 10901 | + | |
| 10902 | + | |
10870 | 10903 | | |
10871 | 10904 | | |
10872 | | - | |
| 10905 | + | |
| 10906 | + | |
10873 | 10907 | | |
10874 | 10908 | | |
10875 | 10909 | | |
| |||
11220 | 11254 | | |
11221 | 11255 | | |
11222 | 11256 | | |
| 11257 | + | |
| 11258 | + | |
| 11259 | + | |
| 11260 | + | |
| 11261 | + | |
| 11262 | + | |
| 11263 | + | |
| 11264 | + | |
| 11265 | + | |
11223 | 11266 | | |
11224 | 11267 | | |
11225 | 11268 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
44 | 49 | | |
45 | 50 | | |
46 | 51 | | |
| |||
90 | 95 | | |
91 | 96 | | |
92 | 97 | | |
| 98 | + | |
93 | 99 | | |
94 | 100 | | |
95 | 101 | | |
| |||
101 | 107 | | |
102 | 108 | | |
103 | 109 | | |
| 110 | + | |
104 | 111 | | |
105 | 112 | | |
106 | 113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
805 | 805 | | |
806 | 806 | | |
807 | 807 | | |
| 808 | + | |
808 | 809 | | |
809 | 810 | | |
810 | 811 | | |
| |||
3434 | 3435 | | |
3435 | 3436 | | |
3436 | 3437 | | |
| 3438 | + | |
3437 | 3439 | | |
3438 | 3440 | | |
3439 | 3441 | | |
| |||
0 commit comments