Skip to content

authentication manager feature addition#270

Open
JacobBarthelmeh wants to merge 47 commits intowolfSSL:mainfrom
JacobBarthelmeh:auth_manager
Open

authentication manager feature addition#270
JacobBarthelmeh wants to merge 47 commits intowolfSSL:mainfrom
JacobBarthelmeh:auth_manager

Conversation

@JacobBarthelmeh
Copy link
Copy Markdown
Contributor

@JacobBarthelmeh JacobBarthelmeh commented Jan 16, 2026

The authentication manager feature adds support for a user login and checking a users permissions for performing a group+action. The API was designed with PKCS11 in mind.

Some things of note:

  • I added a callback function framework for checking authorization of key use based on key ID and user permissions but did not tie in that check yet. I would like to tie that in later when/if needed. This currently checks for authorization of user for a group/action that they can do. Which ties a user ID to crypto actions done.
  • The user list in port/posix/posix_auth.c is a simple list not yet in NVM. This initial simplicity is deliberate.
  • There is a TODO listed for logging of authentication events. Login failures, success, crypto actions should have logging additions in the future.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds a comprehensive authentication and authorization manager to wolfHSM, enabling user management, login/logout functionality, and permission-based access control for HSM operations.

Changes:

  • New authentication manager with PIN and certificate-based authentication support
  • Authorization system with group and action-level permission checks
  • User management APIs for adding, deleting, and modifying users and their credentials
  • Complete client and server implementation with message translation support

Reviewed changes

Copilot reviewed 22 out of 23 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
wolfhsm/wh_auth.h Core auth manager types, structures, and API definitions
wolfhsm/wh_message_auth.h Message structures and translation functions for auth operations
wolfhsm/wh_server_auth.h Server-side auth request handler declaration
wolfhsm/wh_client.h Client-side auth API function declarations
wolfhsm/wh_server.h Server context updated with auth context pointer
wolfhsm/wh_message.h New auth message group and action enums
wolfhsm/wh_error.h New auth-specific error codes
src/wh_auth.c Core auth manager implementation with callback wrappers
src/wh_message_auth.c Message translation implementations for auth messages
src/wh_server_auth.c Server-side request handler for auth operations
src/wh_client_auth.c Client-side auth API implementations
src/wh_server.c Server integration with authorization checks
src/wh_client.c Minor formatting fixes
port/posix/posix_auth.h POSIX auth backend declarations
port/posix/posix_auth.c POSIX auth backend implementation with in-memory user storage
test/wh_test_auth.h Auth test suite declarations
test/wh_test_auth.c Comprehensive auth test suite implementation
test/wh_test.c Test integration for auth tests
examples/posix/wh_posix_server/* Server configuration with auth context setup
examples/demo/client/wh_demo_client_all.c Demo integration for auth

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 24 out of 25 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 29 out of 30 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 29 out of 30 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bigbrett
Copy link
Copy Markdown
Contributor

@JacobBarthelmeh merge conflicts

@JacobBarthelmeh
Copy link
Copy Markdown
Contributor Author

Force pushed to resolve merge conflict.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 28 out of 29 changed files in this pull request and generated 17 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…d test that authorization callback override is being called when set
…ique max credentials, add force zero to utils
… to auth translation layer, admin user add restriction, duplicate user name restriction
Copilot AI review requested due to automatic review settings April 13, 2026 16:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 41 out of 43 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 40 to 166
@@ -138,6 +139,7 @@ typedef struct {
typedef struct whServerConfig_t {
whCommServerConfig* comm_config;
whNvmContext* nvm;
whAuthContext* auth;

#ifndef WOLFHSM_CFG_NO_CRYPTO
whServerCryptoContext* crypto;
@@ -160,6 +162,7 @@ typedef struct whServerConfig_t {
/* Context structure to maintain the state of an HSM server */
struct whServerContext_t {
whNvmContext* nvm;
whAuthContext* auth;
whCommServer comm[1];
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

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

whServerConfig / whServerContext now unconditionally include whAuthContext* auth and #include "wolfhsm/wh_auth.h", which changes the public struct layout/ABI even when authentication is not enabled. If auth is meant to be optional (as other features are), consider wrapping the include and these struct members in #ifdef WOLFHSM_CFG_ENABLE_AUTHENTICATION (or adding an opaque extension pointer) to avoid forcing an ABI break and extra footprint in non-auth builds.

Copilot uses AI. Check for mistakes.
Comment on lines +49 to +56
size_t len;

if (username == NULL) {
return 0;
}

len = strnlen(username, WH_MESSAGE_AUTH_MAX_USERNAME_LEN);
return (len < WH_MESSAGE_AUTH_MAX_USERNAME_LEN);
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

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

_UserNameIsValid() relies on strnlen(), which is not ISO C90/C99 and may not exist on some embedded/libc configurations. Also, it currently accepts the empty string as a valid username. Consider switching to a small bounded loop (or memchr) for portability and require username[0] != '\0' to prevent empty-user edge cases.

Suggested change
size_t len;
if (username == NULL) {
return 0;
}
len = strnlen(username, WH_MESSAGE_AUTH_MAX_USERNAME_LEN);
return (len < WH_MESSAGE_AUTH_MAX_USERNAME_LEN);
size_t i;
if (username == NULL || username[0] == '\0') {
return 0;
}
for (i = 0; i < WH_MESSAGE_AUTH_MAX_USERNAME_LEN; i++) {
if (username[i] == '\0') {
return 1;
}
}
return 0;

Copilot uses AI. Check for mistakes.
Comment on lines +94 to +104
/* Secure zeroization that resists compiler optimization.
* Uses volatile to prevent the compiler from optimizing away the writes. */
void wh_Utils_ForceZero(void* mem, uint32_t size)
{
volatile uint8_t* p = (volatile uint8_t*)mem;
while (size > 0) {
*p = 0;
p++;
size--;
}
}
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

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

wh_Utils_ForceZero() will dereference mem when size > 0 even if mem == NULL, which can crash callers. Consider guarding if (mem == NULL || size == 0) return; (and optionally using memset_s/explicit_bzero where available) so it’s safe as a general-purpose utility.

Copilot uses AI. Check for mistakes.
Comment on lines +110 to +137
static whAuthBase_User* wh_Auth_BaseCheckPin(const char* username,
const void* auth_data,
uint16_t auth_data_len)
{
whAuthBase_User* found_user;
unsigned char authCheck[WH_AUTH_BASE_MAX_CREDENTIALS_LEN];
uint16_t authCheck_len;
int rc;

/* Process auth_data: hash if crypto enabled, copy if disabled */
rc = wh_Auth_BaseHashPin(auth_data, auth_data_len, authCheck);
if (rc != WH_ERROR_OK) {
return NULL;
}
#ifndef WOLFHSM_CFG_NO_CRYPTO
authCheck_len = WC_SHA256_DIGEST_SIZE;
#else
authCheck_len = auth_data_len;
#endif /* WOLFHSM_CFG_NO_CRYPTO */

found_user = wh_Auth_BaseFindUser(username);
if (found_user != NULL && found_user->method == WH_AUTH_METHOD_PIN &&
found_user->credentials_len == authCheck_len &&
wh_Utils_ConstantCompare(found_user->credentials, authCheck,
authCheck_len) == 0) {
return found_user;
}
return NULL;
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

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

wh_Auth_BaseCheckPin() leaves the derived credential material (authCheck) on the stack after returning. Since this buffer contains a PIN hash / PIN copy (when NO_CRYPTO), consider zeroizing authCheck (and any temporary hashes) with wh_Utils_ForceZero() before returning to reduce credential lifetime in memory.

Copilot uses AI. Check for mistakes.
Comment on lines +39 to +51
/* Pick up compile-time configuration */
#include "wolfhsm/wh_settings.h"

#include <stdint.h>
#include <stddef.h>
#include <string.h>

#include "wolfhsm/wh_common.h"
#include "wolfhsm/wh_error.h"

#include "wolfhsm/wh_auth.h"
#include "wolfhsm/wh_message_auth.h"

Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

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

Auth sources (e.g., this file) are compiled unconditionally, while other optional subsystems (e.g., certificate manager: src/wh_message_cert.c) are fully gated by feature macros. If WOLFHSM_CFG_ENABLE_AUTHENTICATION is intended to exclude auth code from non-auth builds (as docs state), consider wrapping these implementations in #ifdef WOLFHSM_CFG_ENABLE_AUTHENTICATION and providing minimal stubs (returning WH_AUTH_NOT_ENABLED) when disabled.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants