Skip to content

Commit e421ae4

Browse files
add debug message on authorization call and function signatures in wh_client.h
1 parent 88626ad commit e421ae4

File tree

4 files changed

+82
-10
lines changed

4 files changed

+82
-10
lines changed

src/wh_auth.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ int wh_Auth_SessionGet(whAuthContext* context, whSessionId session_id,
114114
return WH_ERROR_NOTIMPL;
115115
}
116116

117-
int wh_Auth_CheckAuthorization(whAuthContext* context, whSessionId session_id,
118-
whAuthAction action, uint32_t object_id)
117+
int wh_Auth_CheckAuthorization(whAuthContext* context, uint8_t client_id,
118+
uint16_t group, uint16_t action)
119119
{
120-
/* TODO: Check if action is authorized for session */
120+
/* TODO: Check if action is authorized for client */
121+
122+
printf("In authorization check: Client ID: %d, Group: %d, Action: %d\n",
123+
client_id, group, action);
121124
(void)context;
122-
(void)session_id;
123-
(void)action;
124-
(void)object_id;
125-
return WH_ERROR_NOTIMPL;
125+
return WH_ERROR_OK;
126126
}
127127

128128
int wh_Auth_UserAdd(whAuthContext* context, const char* username,

src/wh_server.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,17 @@ int wh_Server_HandleRequestMessage(whServerContext* server)
321321
if (rc == 0) {
322322
group = WH_MESSAGE_GROUP(kind);
323323
action = WH_MESSAGE_ACTION(kind);
324+
325+
/* If the authentication context is set then check if the action is
326+
* allowed */
327+
if (server->auth != NULL) {
328+
rc = wh_Auth_CheckAuthorization(server->auth,
329+
server->comm->client_id, group, action);
330+
if (rc != WH_ERROR_OK) {
331+
return rc;
332+
}
333+
}
334+
324335
switch (group) {
325336

326337
case WH_MESSAGE_GROUP_COMM:

wolfhsm/wh_auth.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include <stdbool.h>
4141

4242
#include "wolfhsm/wh_common.h"
43-
#include "wolfhsm/wh_comm.h" /* For whClientId */
4443

4544
/** Auth Manager Types */
4645

@@ -219,8 +218,8 @@ int wh_Auth_SessionGet(whAuthContext* context, whSessionId session_id,
219218
whAuthSession* out_session);
220219

221220
/* Check authorization for an action */
222-
int wh_Auth_CheckAuthorization(whAuthContext* context, whSessionId session_id,
223-
whAuthAction action, uint32_t object_id);
221+
int wh_Auth_CheckAuthorization(whAuthContext* context, uint8_t client_id,
222+
uint16_t group, uint16_t action);
224223

225224
/* Add a new user */
226225
int wh_Auth_UserAdd(whAuthContext* context, const char* username,

wolfhsm/wh_client.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "wolfhsm/wh_dma.h"
5454
#endif /* WOLFHSM_CFG_DMA */
5555
#include "wolfhsm/wh_keyid.h"
56+
#include "wolfhsm/wh_auth.h"
5657

5758

5859
/* Forward declaration of the client structure so its elements can reference
@@ -1866,6 +1867,67 @@ int wh_Client_CustomCbCheckRegisteredResponse(whClientContext* c,
18661867
int wh_Client_CustomCbCheckRegistered(whClientContext* c, uint16_t id,
18671868
int* responseError);
18681869

1870+
/* Auth Manager functions */
1871+
1872+
/**
1873+
* @brief Sends an authentication request to the server.
1874+
*
1875+
* This function prepares and sends an authentication request message to the server.
1876+
* The request includes the authentication method and authentication data (e.g., PIN).
1877+
* This function does not block; it returns immediately after sending the request.
1878+
*
1879+
* @param[in] c Pointer to the client context.
1880+
* @param[in] method The authentication method to use (e.g., WH_AUTH_METHOD_PIN).
1881+
* @param[in] auth_data Pointer to the authentication data.
1882+
* @param[in] auth_data_len Length of the authentication data.
1883+
* @return int Returns 0 on success, or a negative error code on failure.
1884+
*/
1885+
int wh_Client_AuthAuthenticateRequest(whClientContext* c,
1886+
whAuthMethod method, const void* auth_data, uint16_t auth_data_len);
1887+
1888+
/**
1889+
* @brief Receives an authentication response from the server.
1890+
*
1891+
* This function attempts to process an authentication response message from the server.
1892+
* It validates the response and extracts the return code, user ID, session ID, and
1893+
* permissions. This function does not block; it returns WH_ERROR_NOTREADY if a
1894+
* response has not been received.
1895+
*
1896+
* @param[in] c Pointer to the client context.
1897+
* @param[out] out_rc Pointer to store the return code from the server.
1898+
* @param[out] out_user_id Pointer to store the authenticated user ID.
1899+
* @param[out] out_session_id Pointer to store the session ID.
1900+
* @param[out] out_permissions Pointer to store the user permissions.
1901+
* @return int Returns 0 on success, WH_ERROR_NOTREADY if no response is
1902+
* available, or a negative error code on failure.
1903+
*/
1904+
int wh_Client_AuthAuthenticateResponse(whClientContext* c, int32_t *out_rc,
1905+
whUserId* out_user_id, whSessionId* out_session_id,
1906+
whAuthPermissions* out_permissions);
1907+
1908+
/**
1909+
* @brief Authenticates a user with the server (blocking convenience wrapper).
1910+
*
1911+
* This function handles the complete process of sending an authentication request
1912+
* to the server and receiving the response. It sends the request and repeatedly
1913+
* attempts to receive a valid response. This function blocks until the entire
1914+
* operation is complete or an error occurs.
1915+
*
1916+
* @param[in] c Pointer to the client context.
1917+
* @param[in] method The authentication method to use (e.g., WH_AUTH_METHOD_PIN).
1918+
* @param[in] auth_data Pointer to the authentication data.
1919+
* @param[in] auth_data_len Length of the authentication data.
1920+
* @param[out] out_rc Pointer to store the return code from the server.
1921+
* @param[out] out_user_id Pointer to store the authenticated user ID.
1922+
* @param[out] out_session_id Pointer to store the session ID.
1923+
* @param[out] out_permissions Pointer to store the user permissions.
1924+
* @return int Returns 0 on success, or a negative error code on failure.
1925+
*/
1926+
int wh_Client_AuthAuthenticate(whClientContext* c, whAuthMethod method,
1927+
const void* auth_data, uint16_t auth_data_len,
1928+
int32_t* out_rc, whUserId* out_user_id, whSessionId* out_session_id,
1929+
whAuthPermissions* out_permissions);
1930+
18691931
/* Certificate functions */
18701932

18711933
/**

0 commit comments

Comments
 (0)