@@ -45,8 +45,10 @@ typedef struct whAuthBase_User {
4545} whAuthBase_User ;
4646static whAuthBase_User users [WH_AUTH_BASE_MAX_USERS ];
4747
48+ #if defined(WOLFHSM_CFG_CERTIFICATE_MANAGER ) && !defined(WOLFHSM_CFG_NO_CRYPTO )
4849#include <wolfssl/ssl.h>
4950#include <wolfssl/wolfcrypt/asn.h>
51+ #endif
5052
5153int posixAuth_Init (void * context , const void * config )
5254{
@@ -85,7 +87,7 @@ static whAuthBase_User* posixAuth_CheckPin(const char* username, const void* aut
8587 return NULL ;
8688}
8789
88-
90+ #if defined( WOLFHSM_CFG_CERTIFICATE_MANAGER ) && !defined( WOLFHSM_CFG_NO_CRYPTO )
8991static int posixAuth_VerifyCertificate (whAuthBase_User * found_user ,
9092 const uint8_t * certificate ,
9193 uint16_t certificate_len )
@@ -128,6 +130,7 @@ static whAuthBase_User* posixAuth_CheckCertificate(const char* username,
128130 }
129131 return NULL ;
130132}
133+ #endif /* WOLFHSM_CFG_CERTIFICATE_MANAGER && !WOLFHSM_CFG_NO_CRYPTO */
131134
132135int posixAuth_Login (void * context , uint8_t client_id , whAuthMethod method ,
133136 const char * username , const void * auth_data ,
@@ -148,9 +151,11 @@ int posixAuth_Login(void* context, uint8_t client_id, whAuthMethod method,
148151 case WH_AUTH_METHOD_PIN :
149152 current_user = posixAuth_CheckPin (username , auth_data , auth_data_len );
150153 break ;
154+ #if defined(WOLFHSM_CFG_CERTIFICATE_MANAGER ) && !defined(WOLFHSM_CFG_NO_CRYPTO )
151155 case WH_AUTH_METHOD_CERTIFICATE :
152156 current_user = posixAuth_CheckCertificate (username , auth_data , auth_data_len );
153157 break ;
158+ #endif /* WOLFHSM_CFG_CERTIFICATE_MANAGER && !WOLFHSM_CFG_NO_CRYPTO */
154159 default :
155160 return WH_ERROR_BADARGS ;
156161 }
@@ -300,8 +305,11 @@ int posixAuth_UserAdd(void* context, const char* username,
300305
301306 /* Validate method is supported if credentials are provided */
302307 if (credentials != NULL && credentials_len > 0 ) {
303- if (method != WH_AUTH_METHOD_PIN &&
304- method != WH_AUTH_METHOD_CERTIFICATE ) {
308+ if (method != WH_AUTH_METHOD_PIN
309+ #if defined(WOLFHSM_CFG_CERTIFICATE_MANAGER ) && !defined(WOLFHSM_CFG_NO_CRYPTO )
310+ & & method != WH_AUTH_METHOD_CERTIFICATE
311+ #endif /* WOLFHSM_CFG_CERTIFICATE_MANAGER && !WOLFHSM_CFG_NO_CRYPTO */
312+ ) {
305313 return WH_ERROR_BADARGS ;
306314 }
307315 }
@@ -315,7 +323,7 @@ int posixAuth_UserAdd(void* context, const char* username,
315323 if (i >= WH_AUTH_BASE_MAX_USERS ) {
316324 return WH_ERROR_BUFFER_SIZE ;
317325 }
318- userId = i + 1 ; /* save 0 fron WH_USER_ID_INVALID */
326+ userId = i + 1 ; /* save 0 for WH_USER_ID_INVALID */
319327 new_user = & users [i ];
320328
321329 memset (new_user , 0 , sizeof (whAuthBase_User ));
@@ -358,7 +366,7 @@ int posixAuth_UserDelete(void* context, uint16_t current_user_id,
358366{
359367 whAuthBase_User * user ;
360368
361- if (user_id == WH_USER_ID_INVALID || user_id >= WH_AUTH_BASE_MAX_USERS ) {
369+ if (user_id == WH_USER_ID_INVALID || user_id > WH_AUTH_BASE_MAX_USERS ) {
362370 return WH_ERROR_NOTFOUND ;
363371 }
364372
@@ -379,7 +387,7 @@ int posixAuth_UserSetPermissions(void* context, uint16_t current_user_id,
379387{
380388 whAuthBase_User * user ;
381389
382- if (user_id == WH_USER_ID_INVALID || user_id >= WH_AUTH_BASE_MAX_USERS ) {
390+ if (user_id == WH_USER_ID_INVALID || user_id > WH_AUTH_BASE_MAX_USERS ) {
383391 return WH_ERROR_NOTFOUND ;
384392 }
385393
@@ -432,12 +440,16 @@ int posixAuth_UserSetCredentials(void* context, uint16_t user_id,
432440 whAuthBase_User * user ;
433441 int rc = WH_ERROR_OK ;
434442
435- if (user_id == WH_USER_ID_INVALID || user_id >= WH_AUTH_BASE_MAX_USERS ) {
443+ if (user_id == WH_USER_ID_INVALID || user_id > WH_AUTH_BASE_MAX_USERS ) {
436444 return WH_ERROR_BADARGS ;
437445 }
438446
439447 /* Validate method is supported */
440- if (method != WH_AUTH_METHOD_PIN && method != WH_AUTH_METHOD_CERTIFICATE ) {
448+ if (method != WH_AUTH_METHOD_PIN
449+ #if defined(WOLFHSM_CFG_CERTIFICATE_MANAGER ) && !defined(WOLFHSM_CFG_NO_CRYPTO )
450+ & & method != WH_AUTH_METHOD_CERTIFICATE
451+ #endif /* WOLFHSM_CFG_CERTIFICATE_MANAGER && !WOLFHSM_CFG_NO_CRYPTO */
452+ ) {
441453 return WH_ERROR_BADARGS ;
442454 }
443455
0 commit comments