Skip to content

Commit 3be9048

Browse files
fix for load token with empty pin
1 parent 52be358 commit 3be9048

File tree

4 files changed

+569
-0
lines changed

4 files changed

+569
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Empty PIN Token Store Test
2+
3+
# This test verifies that encrypted objects can be stored and loaded correctly
4+
# when using an empty user PIN. It tests whether HashPIN needs to be called
5+
# before decoding objects in the empty PIN case.
6+
7+
on:
8+
push:
9+
branches: [ 'master', 'main', 'release/**' ]
10+
pull_request:
11+
branches: [ '*' ]
12+
13+
env:
14+
WOLFSSL_VERSION: master
15+
16+
jobs:
17+
empty-pin-store-test:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout wolfPKCS11
22+
uses: actions/checkout@v4
23+
with:
24+
submodules: true
25+
26+
- name: Cache wolfSSL
27+
id: cache-wolfssl
28+
uses: actions/cache@v4
29+
with:
30+
path: wolfssl
31+
key: wolfssl-${{ env.WOLFSSL_VERSION }}-empty-pin-test
32+
33+
- name: Checkout wolfSSL
34+
if: steps.cache-wolfssl.outputs.cache-hit != 'true'
35+
uses: actions/checkout@v4
36+
with:
37+
repository: wolfssl/wolfssl
38+
path: wolfssl
39+
ref: ${{ env.WOLFSSL_VERSION }}
40+
41+
- name: Build wolfSSL
42+
if: steps.cache-wolfssl.outputs.cache-hit != 'true'
43+
working-directory: ./wolfssl
44+
run: |
45+
./autogen.sh
46+
./configure --enable-cryptocb --enable-aescfb --enable-rsapss \
47+
--enable-keygen --enable-pwdbased --enable-scrypt \
48+
C_EXTRA_FLAGS="-DWOLFSSL_PUBLIC_MP -DWC_RSA_DIRECT"
49+
make
50+
51+
- name: Install wolfSSL
52+
working-directory: ./wolfssl
53+
run: |
54+
sudo make install
55+
sudo ldconfig
56+
57+
- name: Build wolfPKCS11
58+
run: |
59+
./autogen.sh
60+
# Enable empty PIN by setting WP11_MIN_PIN_LEN=0
61+
./configure --enable-debug C_EXTRA_FLAGS="-DWP11_MIN_PIN_LEN=0"
62+
make
63+
64+
- name: Create test store directory
65+
run: mkdir -p store/empty_pin_test
66+
67+
- name: Run empty PIN store test
68+
run: |
69+
echo "=== Running Empty PIN Token Store Test ==="
70+
echo "This test verifies that encrypted objects can be stored and"
71+
echo "loaded correctly when using an empty user PIN."
72+
echo ""
73+
./tests/empty_pin_store_test
74+
echo ""
75+
echo "=== Test completed ==="
76+
77+
- name: Show store directory contents on failure
78+
if: failure()
79+
run: |
80+
echo "=== Store directory contents ==="
81+
ls -la store/empty_pin_test/ 2>/dev/null || echo "Directory not found or empty"
82+
echo ""
83+
echo "=== Hexdump of token file (if exists) ==="
84+
hexdump -C store/empty_pin_test/wp11_token_0000000000000001 2>/dev/null | head -100 || echo "Token file not found"
85+
86+
- name: Upload failure logs
87+
if: failure() || cancelled()
88+
uses: actions/upload-artifact@v4
89+
with:
90+
name: empty-pin-store-test-logs
91+
path: |
92+
test-suite.log
93+
config.log
94+
store/
95+
retention-days: 5

src/internal.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5146,6 +5146,10 @@ static void wp11_Token_Final(WP11_Token* token)
51465146
}
51475147

51485148
#ifndef WOLFPKCS11_NO_STORE
5149+
/* Forward declaration for HashPIN - needed for empty PIN decode path */
5150+
static int HashPIN(char* pin, int pinLen, byte* seed, int seedLen, byte* hash,
5151+
int hashLen, WP11_Slot* slot);
5152+
51495153
/**
51505154
* Load a token from storage.
51515155
*
@@ -5291,6 +5295,9 @@ static int wp11_Token_Load(WP11_Slot* slot, int tokenId, WP11_Token* token)
52915295
/* If there is no pin, there is no login, so decode now */
52925296
if (WP11_Slot_Has_Empty_Pin(slot) && (ret == 0)) {
52935297
#ifndef WOLFPKCS11_NO_STORE
5298+
/* Derive token->key from empty PIN + seed before decoding */
5299+
ret = HashPIN((char*)"", 0, token->seed, sizeof(token->seed),
5300+
token->key, sizeof(token->key), slot);
52945301
object = token->object;
52955302
while (ret == 0 && object != NULL) {
52965303
ret = wp11_Object_Decode(object);

0 commit comments

Comments
 (0)