NetBurner 3.5.0
PDF Version
 
UserAuthManager.h
Go to the documentation of this file.
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
16#ifndef _USER_AUTH_MANAGER_H_
17#define _USER_AUTH_MANAGER_H_
18
19#include <predef.h>
20
21#ifdef NB_SSH_SUPPORTED
22
23#ifndef WOLFSSL_USER_SETTINGS
24#define WOLFSSL_USER_SETTINGS // This wasn't getting defined in the project source files in NBEclipse
25#endif
26
27#include <basictypes.h>
28#include <nbstring.h>
29
30#include <crypto/wolfssl/wolfcrypt/sha256.h>
31
32#define MAX_AUTH_RECORDS 25
33#define WC_SHA256_DIGEST_SIZE 32
34
78{
80 uint8_t m_authHash[WC_SHA256_DIGEST_SIZE];
82 uint32_t m_authLevel;
84};
85
86// Callbacks used to load and save user authentication information
96typedef int (*SaveAuthRecordsFn)(const UserAuthRecord *authRec);
97
107typedef int (*LoadAuthRecordsFn)(UserAuthRecord *authRec);
108
116{
117 public:
122
127
138
147 bool UserExists(const NBString &userName);
148
159 AuthResponse AddUserAuth(const NBString &userName, const NBString &auth, AuthType authType);
160
172 AuthResponse CheckUserAuth(const NBString &userName, const NBString &auth, AuthType authType);
173
185 AuthResponse CheckUserAuth(const NBString &userName, byte *auth, AuthType authType);
186
198 AuthResponse UpdateUserAuth(const NBString &userName, const NBString &newAuth, AuthType authType);
199
209
222 AuthResponse CheckUserAuthLevel(const NBString &userName, uint32_t authLevel, bool hasAll = true);
223
235 AuthResponse SetUserAuthLevel(const NBString &userName, uint32_t authLevel);
236
247 AuthResponse ClrUserAuthLevel(const NBString &userName, uint32_t authLevel);
248
252 void ListUsers();
253
257 int GetMaxAuthRecords() { return MAX_AUTH_RECORDS; }
258
259 private:
266 int16_t GetNextEmptyRecord();
267
274 int16_t FindUser(const NBString &userName);
275
285 bool CreateHash(const NBString &auth, uint8_t *outHash);
286
287 // User defined functions for loading and saving auth data.
296 int (*m_SaveAuthRecords)(const UserAuthRecord *authRec) = nullptr;
297
306 int (*m_LoadAuthRecords)(UserAuthRecord *authRec) = nullptr;
307
308 UserAuthRecord m_authRecords[MAX_AUTH_RECORDS];
309};
310
311#endif /* NB_SSH_SUPPORTED */
312#endif // _USER_AUTH_MANAGER_H_
313
Lightweight alternative to C++ CString class.
Definition nbstring.h:118
The user authorization manager class allows application developers the ability to manage user authori...
Definition UserAuthManager.h:116
bool UserExists(const NBString &userName)
Determines if a user record exists.
AuthResponse RemoveUserAuth(const NBString &userName)
Remove a user authorization record. This function will automatically save all user records if the rem...
void ListUsers()
Lists the users currently in the User Authorization Record system, along with their saved authorizati...
AuthResponse SetUserAuthLevel(const NBString &userName, uint32_t authLevel)
This adds the authorization levels passed in to the user's current authorization level.
AuthResponse AddUserAuth(const NBString &userName, const NBString &auth, AuthType authType)
Attempts to add a user authorization record. This will automatically call the save record function if...
AuthResponse UpdateUserAuth(const NBString &userName, const NBString &newAuth, AuthType authType)
Updates a user authorization record with the information provided. This function will automatically s...
~UserAuthManager()
Default destructor.
Definition UserAuthManager.h:126
bool Init(SaveAuthRecordsFn svRcFn, LoadAuthRecordsFn ldRcFn)
Initialization function. Must be called before use.
UserAuthManager()
Default constructor.
Definition UserAuthManager.h:121
AuthResponse CheckUserAuth(const NBString &userName, const NBString &auth, AuthType authType)
Checks the for a user and compares the authorization value to what is stored.
AuthResponse ClrUserAuthLevel(const NBString &userName, uint32_t authLevel)
Clears the authorization for the specified user.
int GetMaxAuthRecords()
Gets the maximum number of authorization records available to the system. This can be changed with th...
Definition UserAuthManager.h:257
AuthResponse CheckUserAuth(const NBString &userName, byte *auth, AuthType authType)
Checks the for a user and compares the authorization value to what is stored.
AuthResponse CheckUserAuthLevel(const NBString &userName, uint32_t authLevel, bool hasAll=true)
Checks the user against the specific authLevel.
int(* LoadAuthRecordsFn)(UserAuthRecord *authRec)
User provided function for loading user authorization records. This allows the users to dictate where...
Definition UserAuthManager.h:107
int(* SaveAuthRecordsFn)(const UserAuthRecord *authRec)
User provided function for saving user authorization records. This allows the users to dictate where ...
Definition UserAuthManager.h:96
AuthResponse
Response return codes when checking for the authorization status of a user.
Definition UserAuthManager.h:59
@ eAuthErrorUnableToCreateHash
There was an error hashing the authorization value.
Definition UserAuthManager.h:64
@ eAuthErrorUnableToAddUser
The user was not added successfully.
Definition UserAuthManager.h:68
@ eAuthErrorFailedRecordUpdate
The record update failed.
Definition UserAuthManager.h:67
@ eAuthErrorAuthTypeMismatch
The authorization type didn't match the request.
Definition UserAuthManager.h:66
@ eAuthErrorNoEmptyUserAuthRecords
The authorization records are full.
Definition UserAuthManager.h:63
@ eAuthErrorSaveFailed
Unable to save user authorization records.
Definition UserAuthManager.h:69
@ eAuthSuccess
The authorization request or function was successful.
Definition UserAuthManager.h:60
@ eAuthErrorUserExists
The user already exists.
Definition UserAuthManager.h:61
@ eAuthErrorUserDoesNotExist
The user does not exist.
Definition UserAuthManager.h:62
@ eAuthErrorAuthCheckFailed
The authorization check failed.
Definition UserAuthManager.h:65
AuthType
The types of authorization requests that are managed. These just indicate what the has value is,...
Definition UserAuthManager.h:44
@ eAuthTypePassword
Password.
Definition UserAuthManager.h:46
@ eAuthTypeDefault
Default value, should be considered an invalid type.
Definition UserAuthManager.h:45
@ eAuthTypeKey
Key.
Definition UserAuthManager.h:47
NetBurner String Class.
A stored record of a user's authorization credentials. The value is hashed when saved so it can't be ...
Definition UserAuthManager.h:78
uint8_t m_authHash[WC_SHA256_DIGEST_SIZE]
The hashed representation of the authentication value.
Definition UserAuthManager.h:80
uint32_t m_authLevel
Definition UserAuthManager.h:82
NBString m_userName
The username for the record. This value must be unique across all records.
Definition UserAuthManager.h:79
AuthType m_authType
The type of authentication hashes. Currently supported are keys and passwords.
Definition UserAuthManager.h:81