Skip to content

Commit 2178eaf

Browse files
authored
Merge pull request #143 from LinuxJedi/fips-fixes
Fix empty PIN handling for FIPS
2 parents 6b76537 + bd11e2d commit 2178eaf

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

.github/workflows/nss-pk12util-debian-test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ jobs:
179179
if [ -f "/tmp/nss-packages/libnss3_"*.deb ]; then
180180
echo "Using cached NSS packages:"
181181
ls -la /tmp/nss-packages/
182+
183+
# Install build dependencies when using cached packages
184+
echo "Installing NSS build dependencies for cached packages..."
185+
apt-get build-dep -y libnss3
186+
182187
cd /tmp/nss-packages
183188
else
184189
echo "Using freshly built NSS packages:"

src/internal.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5757,8 +5757,21 @@ static int HashPIN(char* pin, int pinLen, byte* seed, int seedLen, byte* hash,
57575757
int hashLen, WP11_Slot* slot)
57585758
{
57595759
#ifdef WOLFPKCS11_PBKDF2
5760-
return wc_PBKDF2_ex(hash, (byte*)pin, pinLen, seed, seedLen,
5760+
#if defined(HAVE_FIPS) && defined(WOLFPKCS11_NSS)
5761+
if (pinLen == 0) {
5762+
/* For FIPS, use empty pin of HMAC_FIPS_MIN_KEY bytes when pinLen is 0.
5763+
* Otherwise we hit HMAC_MIN_KEYLEN_E.
5764+
* Certain NSS tools will try to login a blank token with an empty pin
5765+
* and this needs to succeed, or the tool will fail.
5766+
*/
5767+
byte emptyPin[HMAC_FIPS_MIN_KEY];
5768+
XMEMSET(emptyPin, 0, sizeof(emptyPin));
5769+
return wc_PBKDF2_ex(hash, emptyPin, sizeof(emptyPin), seed, seedLen,
57615770
PBKDF2_ITERATIONS, hashLen, WC_SHA256, NULL, slot->devId);
5771+
}
5772+
#endif
5773+
return wc_PBKDF2_ex(hash, (byte*)pin, pinLen, seed, seedLen,
5774+
PBKDF2_ITERATIONS, hashLen, WC_SHA256, NULL, slot->devId);
57625775
#elif defined(HAVE_SCRYPT)
57635776
/* Convert PIN into secret using scrypt algorithm. */
57645777
(void)slot;

src/slot.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,9 @@ CK_RV C_Login(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType,
18391839
case PIN_NOT_SET_E:
18401840
rv = CKR_USER_PIN_NOT_INITIALIZED;
18411841
break;
1842+
/* No better error matches for pin too short for PBKDF2 HMAC */
1843+
case BAD_LENGTH_E:
1844+
case HMAC_MIN_KEYLEN_E:
18421845
case PIN_INVALID_E:
18431846
rv = CKR_PIN_INCORRECT;
18441847
break;

0 commit comments

Comments
 (0)