Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib/common/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const struct config Configuration::valid_config[] = {
{ "slots.removable", CONFIG_TYPE_BOOL },
{ "slots.mechanisms", CONFIG_TYPE_STRING },
{ "library.reset_on_fork", CONFIG_TYPE_BOOL },
{ "login.fail_delay", CONFIG_TYPE_INT },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend to add a default in softhsm2.conf.in and softhsm2.conf.5.in to document this new feature as well, e.g. somewhere here:

library.reset_on_fork = false

.SH LIBRARY.RESET_ON_FORK

Also to indicate which units (e.g. seconds or milliseconds) these are supposed to be set to.

{ "", CONFIG_TYPE_UNSUPPORTED }
};

Expand Down
10 changes: 10 additions & 0 deletions src/lib/data_mgr/SecureDataManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,19 @@
*****************************************************************************/

#include "config.h"
#include "Configuration.h"
#include "SecureDataManager.h"
#include "CryptoFactory.h"
#include "AESKey.h"
#include "SymmetricAlgorithm.h"
#include "RFC4880.h"

#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif

// Constructors

// Initialise the object; called by all constructors
Expand Down Expand Up @@ -263,6 +270,7 @@ bool SecureDataManager::login(const ByteString& passphrase, const ByteString& en

if (!RFC4880::PBEDeriveKey(passphrase, salt, &pbeKey))
{
sleep(Configuration::i()->getInt("login.fail_delay", 0));
Copy link
Contributor

@ijsf ijsf Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows I would expect this to be a capitalized Sleep (https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-sleep) which takes in milliseconds, instead of the POSIX sleep which takes seconds, so I'm not sure how this could work for both platforms.

(I guess a utility function elsewhere would help.)

return false;
}

Expand All @@ -275,6 +283,7 @@ bool SecureDataManager::login(const ByteString& passphrase, const ByteString& en
!aes->decryptUpdate(encryptedKeyData, decryptedKeyData) ||
!aes->decryptFinal(finalBlock))
{
sleep(Configuration::i()->getInt("login.fail_delay", 0));
delete pbeKey;

return false;
Expand All @@ -288,6 +297,7 @@ bool SecureDataManager::login(const ByteString& passphrase, const ByteString& en
if (decryptedKeyData.substr(0, 3) != magic)
{
// The passphrase was incorrect
sleep(Configuration::i()->getInt("login.fail_delay", 0));
DEBUG_MSG("Incorrect passphrase supplied");

return false;
Expand Down