3232
3333static int wh_DemoClient_AuthPin (whClientContext * clientContext )
3434{
35- int rc = 0 ;
36- int32_t serverRc = 0 ;
37- const uint8_t pin [] = "1234" ; /* demo PIN */
38- const uint8_t newPin [] = "5678" ; /* new PIN */
39- whUserId userId = WH_USER_ID_INVALID ;
40- whUserId adminUserId = WH_USER_ID_INVALID ;
35+ int rc = 0 ;
36+ int32_t serverRc = 0 ;
37+ const uint8_t pin [] = "1234" ; /* demo PIN */
38+ const uint8_t newPin [] = "5678" ; /* new PIN */
39+ whUserId userId = WH_USER_ID_INVALID ;
40+ whUserId adminUserId = WH_USER_ID_INVALID ;
4141 whAuthPermissions out_permissions ;
4242
4343 /* give permissions for everything */
@@ -48,11 +48,11 @@ static int wh_DemoClient_AuthPin(whClientContext* clientContext)
4848 }
4949
5050 /* login as the admin and add a new user */
51- rc = wh_Client_AuthLogin (clientContext ,
52- WH_AUTH_METHOD_PIN , "admin" , "1234" , 4 , & serverRc , & adminUserId );
51+ rc = wh_Client_AuthLogin (clientContext , WH_AUTH_METHOD_PIN , "admin" , "1234" ,
52+ 4 , & serverRc , & adminUserId );
5353 if (serverRc == WH_AUTH_NOT_ENABLED ) {
5454 printf ("[AUTH-DEMO] Authentication not enabled on server, "
55- "skipping PIN demo.\n" );
55+ "skipping PIN demo.\n" );
5656 return WH_ERROR_OK ;
5757 }
5858
@@ -63,17 +63,17 @@ static int wh_DemoClient_AuthPin(whClientContext* clientContext)
6363
6464 if (serverRc != 0 ) {
6565 printf ("[AUTH-DEMO] Server-side error logging in as admin: %d\n" ,
66- (int )serverRc );
66+ (int )serverRc );
6767 return (int )serverRc ;
6868 }
6969
7070 memset (& out_permissions , 0 , sizeof (whAuthPermissions ));
7171 rc = wh_Client_AuthUserAdd (clientContext , "demo" , out_permissions ,
72- WH_AUTH_METHOD_PIN , pin , ( uint16_t )( sizeof ( pin ) - 1 ) ,
73- & serverRc , & userId );
72+ WH_AUTH_METHOD_PIN , pin ,
73+ ( uint16_t )( sizeof ( pin ) - 1 ), & serverRc , & userId );
7474 if (rc != 0 || serverRc != 0 ) {
7575 printf ("[AUTH-DEMO] Failed to add user: %d, server error %d\n" , rc ,
76- serverRc );
76+ serverRc );
7777 return rc ;
7878 }
7979
@@ -84,10 +84,8 @@ static int wh_DemoClient_AuthPin(whClientContext* clientContext)
8484 }
8585
8686 /* Log in as the newly created 'demo' user */
87- rc = wh_Client_AuthLogin (clientContext ,
88- WH_AUTH_METHOD_PIN , "demo" , pin ,
89- (uint16_t )(sizeof (pin ) - 1 ), & serverRc ,
90- & userId );
87+ rc = wh_Client_AuthLogin (clientContext , WH_AUTH_METHOD_PIN , "demo" , pin ,
88+ (uint16_t )(sizeof (pin ) - 1 ), & serverRc , & userId );
9189 if (rc != 0 ) {
9290 printf ("[AUTH-DEMO] Login message failure, rc=%d\n" , rc );
9391 return rc ;
@@ -99,11 +97,11 @@ static int wh_DemoClient_AuthPin(whClientContext* clientContext)
9997 }
10098
10199 /* Update user credentials */
102- rc = wh_Client_AuthUserSetCredentials (clientContext , userId ,
103- WH_AUTH_METHOD_PIN ,
104- pin , (uint16_t )(sizeof (pin ) - 1 ), /* current credentials */
105- newPin , (uint16_t )(sizeof (newPin ) - 1 ), /* new credentials */
106- & serverRc );
100+ rc = wh_Client_AuthUserSetCredentials (
101+ clientContext , userId , WH_AUTH_METHOD_PIN , pin ,
102+ (uint16_t )(sizeof (pin ) - 1 ), /* current credentials */
103+ newPin , (uint16_t )(sizeof (newPin ) - 1 ), /* new credentials */
104+ & serverRc );
107105
108106 if (rc != 0 ) {
109107 printf ("[AUTH-DEMO] Failed to update credentials: %d\n" , rc );
@@ -112,7 +110,7 @@ static int wh_DemoClient_AuthPin(whClientContext* clientContext)
112110
113111 if (serverRc != 0 ) {
114112 printf ("[AUTH-DEMO] Server-side error updating credentials: %d\n" ,
115- (int )serverRc );
113+ (int )serverRc );
116114 return (int )serverRc ;
117115 }
118116
@@ -125,39 +123,31 @@ static int wh_DemoClient_AuthPin(whClientContext* clientContext)
125123
126124 if (serverRc != 0 ) {
127125 printf ("[AUTH-DEMO] Server-side error logging out user: %d\n" ,
128- (int )serverRc );
126+ (int )serverRc );
129127 return (int )serverRc ;
130128 }
131129
132130 /* Verify old PIN no longer works */
133- rc = wh_Client_AuthLogin (clientContext ,
134- WH_AUTH_METHOD_PIN ,
135- "demo" ,
136- pin ,
137- (uint16_t )(sizeof (pin ) - 1 ),
138- & serverRc ,
139- & userId );
131+ rc = wh_Client_AuthLogin (clientContext , WH_AUTH_METHOD_PIN , "demo" , pin ,
132+ (uint16_t )(sizeof (pin ) - 1 ), & serverRc , & userId );
140133
141134 if (rc == 0 && serverRc == 0 ) {
142135 printf ("[AUTH-DEMO] Old PIN still works (unexpected)\n" );
143136 }
144137
145138 /* Verify new PIN works */
146- rc = wh_Client_AuthLogin (clientContext ,
147- WH_AUTH_METHOD_PIN ,
148- "demo" ,
149- newPin ,
150- (uint16_t )(sizeof (newPin ) - 1 ),
151- & serverRc ,
152- & userId );
139+ rc =
140+ wh_Client_AuthLogin (clientContext , WH_AUTH_METHOD_PIN , "demo" , newPin ,
141+ (uint16_t )(sizeof (newPin ) - 1 ), & serverRc , & userId );
153142
154143 if (rc != 0 ) {
155144 printf ("[AUTH-DEMO] Client-side error with new PIN: %d\n" , rc );
156145 return rc ;
157146 }
158147
159148 if (serverRc != 0 ) {
160- printf ("[AUTH-DEMO] Server-side error with new PIN: %d\n" , (int )serverRc );
149+ printf ("[AUTH-DEMO] Server-side error with new PIN: %d\n" ,
150+ (int )serverRc );
161151 return (int )serverRc ;
162152 }
163153
@@ -172,24 +162,24 @@ static int wh_DemoClient_AuthPin(whClientContext* clientContext)
172162#include "../../test/wh_test_cert_data.h"
173163static int wh_DemoClient_AuthCertificate (whClientContext * clientContext )
174164{
175- int rc = 0 ;
176- int32_t serverRc = 0 ;
177- whUserId userId = WH_USER_ID_INVALID ;
178- whUserId adminUserId = WH_USER_ID_INVALID ;
165+ int rc = 0 ;
166+ int32_t serverRc = 0 ;
167+ whUserId userId = WH_USER_ID_INVALID ;
168+ whUserId adminUserId = WH_USER_ID_INVALID ;
179169 whAuthPermissions out_permissions ;
180170
181171 /* Include test certificates - prefer wolfssl/certs_test.h if available,
182172 * otherwise use test certificates from wh_test_cert_data.h */
183173 const unsigned char * ca_cert ;
184- uint16_t ca_cert_len ;
174+ uint16_t ca_cert_len ;
185175 const unsigned char * server_cert ;
186- uint16_t server_cert_len ;
176+ uint16_t server_cert_len ;
187177
188178 /* Use INTERMEDIATE_A_CERT as the CA since it directly signs LEAF_A_CERT
189179 * The chain is: ROOT_A_CERT -> INTERMEDIATE_A_CERT -> LEAF_A_CERT */
190- ca_cert = INTERMEDIATE_A_CERT ;
191- ca_cert_len = (uint16_t )INTERMEDIATE_A_CERT_len ;
192- server_cert = LEAF_A_CERT ;
180+ ca_cert = INTERMEDIATE_A_CERT ;
181+ ca_cert_len = (uint16_t )INTERMEDIATE_A_CERT_len ;
182+ server_cert = LEAF_A_CERT ;
193183 server_cert_len = (uint16_t )LEAF_A_CERT_len ;
194184
195185 memset (& out_permissions , 0 , sizeof (whAuthPermissions ));
@@ -199,15 +189,11 @@ static int wh_DemoClient_AuthCertificate(whClientContext* clientContext)
199189 }
200190
201191 /* login as the admin and add a new user with CA certificate */
202- rc = wh_Client_AuthLogin (clientContext ,
203- WH_AUTH_METHOD_PIN ,
204- "admin" ,
205- "1234" , 4 ,
206- & serverRc ,
207- & adminUserId );
192+ rc = wh_Client_AuthLogin (clientContext , WH_AUTH_METHOD_PIN , "admin" , "1234" ,
193+ 4 , & serverRc , & adminUserId );
208194 if (serverRc == WH_AUTH_NOT_ENABLED ) {
209195 printf ("[AUTH-DEMO] Authentication not enabled on server, "
210- "skipping certificate demo.\n" );
196+ "skipping certificate demo.\n" );
211197 return WH_ERROR_OK ;
212198 }
213199
@@ -217,21 +203,21 @@ static int wh_DemoClient_AuthCertificate(whClientContext* clientContext)
217203 }
218204 if (serverRc != 0 ) {
219205 printf ("[AUTH-DEMO] Server-side error logging in as admin: %d\n" ,
220- (int )serverRc );
206+ (int )serverRc );
221207 return (int )serverRc ;
222208 }
223209
224210 rc = wh_Client_AuthUserAdd (clientContext , "certuser" , out_permissions ,
225- WH_AUTH_METHOD_CERTIFICATE , ca_cert , ca_cert_len ,
226- & serverRc , & userId );
211+ WH_AUTH_METHOD_CERTIFICATE , ca_cert , ca_cert_len ,
212+ & serverRc , & userId );
227213 if (rc != 0 ) {
228214 printf ("[AUTH-DEMO] Failed to add user: %d\n" , rc );
229215 return rc ;
230216 }
231217
232218 if (serverRc != 0 ) {
233219 printf ("[AUTH-DEMO] Server-side error adding user: %d\n" ,
234- (int )serverRc );
220+ (int )serverRc );
235221 return (int )serverRc ;
236222 }
237223
@@ -242,16 +228,12 @@ static int wh_DemoClient_AuthCertificate(whClientContext* clientContext)
242228 }
243229
244230 /* Authenticate user with server certificate */
245- rc = wh_Client_AuthLogin (clientContext ,
246- WH_AUTH_METHOD_CERTIFICATE ,
247- "certuser" ,
248- server_cert ,
249- server_cert_len ,
250- & serverRc ,
251- & userId );
231+ rc = wh_Client_AuthLogin (clientContext , WH_AUTH_METHOD_CERTIFICATE ,
232+ "certuser" , server_cert , server_cert_len ,
233+ & serverRc , & userId );
252234 if (rc != 0 || serverRc != 0 ) {
253235 printf ("[AUTH-DEMO] Error logging in rc=%d server rc = %d.\n" , rc ,
254- serverRc );
236+ serverRc );
255237 return rc ;
256238 }
257239
@@ -274,21 +256,17 @@ static int wh_DemoClient_AuthCertificate(whClientContext* clientContext)
274256
275257static int wh_DemoClient_AuthUserDelete (whClientContext * clientContext )
276258{
277- int rc = 0 ;
278- int32_t serverRc = 0 ;
279- whUserId userId = WH_USER_ID_INVALID ;
280- whUserId adminUserId = WH_USER_ID_INVALID ;
259+ int rc = 0 ;
260+ int32_t serverRc = 0 ;
261+ whUserId userId = WH_USER_ID_INVALID ;
262+ whUserId adminUserId = WH_USER_ID_INVALID ;
281263 whAuthPermissions permissions ;
282264
283- rc = wh_Client_AuthLogin (clientContext ,
284- WH_AUTH_METHOD_PIN ,
285- "admin" ,
286- "1234" , 4 ,
287- & serverRc ,
288- & adminUserId );
265+ rc = wh_Client_AuthLogin (clientContext , WH_AUTH_METHOD_PIN , "admin" , "1234" ,
266+ 4 , & serverRc , & adminUserId );
289267 if (serverRc == WH_AUTH_NOT_ENABLED ) {
290268 printf ("[AUTH-DEMO] Authentication not enabled on server, "
291- "skipping user delete demo.\n" );
269+ "skipping user delete demo.\n" );
292270 return WH_ERROR_OK ;
293271 }
294272
@@ -301,13 +279,13 @@ static int wh_DemoClient_AuthUserDelete(whClientContext* clientContext)
301279 }
302280
303281 rc = wh_Client_AuthUserGet (clientContext , "certuser" , & serverRc , & userId ,
304- & permissions );
282+ & permissions );
305283 if (rc != 0 ) {
306284 return rc ;
307285 }
308286 if (serverRc != 0 ) {
309287 printf ("[AUTH-DEMO] Server-side error %d while getting user: %d\n" ,
310- (int )serverRc , userId );
288+ (int )serverRc , userId );
311289 return (int )serverRc ;
312290 }
313291
@@ -318,7 +296,7 @@ static int wh_DemoClient_AuthUserDelete(whClientContext* clientContext)
318296 }
319297 if (serverRc != 0 ) {
320298 printf ("[AUTH-DEMO] Server-side error deleting user: %d\n" ,
321- (int )serverRc );
299+ (int )serverRc );
322300 return (int )serverRc ;
323301 }
324302
@@ -336,21 +314,17 @@ static int wh_DemoClient_AuthUserDelete(whClientContext* clientContext)
336314
337315static int wh_DemoClient_AuthUserSetPermissions (whClientContext * clientContext )
338316{
339- int rc = 0 ;
340- int32_t serverRc = 0 ;
341- whUserId userId = WH_USER_ID_INVALID ;
342- whUserId adminUserId = WH_USER_ID_INVALID ;
317+ int rc = 0 ;
318+ int32_t serverRc = 0 ;
319+ whUserId userId = WH_USER_ID_INVALID ;
320+ whUserId adminUserId = WH_USER_ID_INVALID ;
343321 whAuthPermissions permissions ;
344322
345- rc = wh_Client_AuthLogin (clientContext ,
346- WH_AUTH_METHOD_PIN ,
347- "admin" ,
348- "1234" , 4 ,
349- & serverRc ,
350- & adminUserId );
323+ rc = wh_Client_AuthLogin (clientContext , WH_AUTH_METHOD_PIN , "admin" , "1234" ,
324+ 4 , & serverRc , & adminUserId );
351325 if (serverRc == WH_AUTH_NOT_ENABLED ) {
352326 printf ("[AUTH-DEMO] Authentication not enabled on server, "
353- "skipping user set permissions demo.\n" );
327+ "skipping user set permissions demo.\n" );
354328 return WH_ERROR_OK ;
355329 }
356330
@@ -359,19 +333,19 @@ static int wh_DemoClient_AuthUserSetPermissions(whClientContext* clientContext)
359333 }
360334 if (serverRc != 0 ) {
361335 printf ("[AUTH-DEMO] Error %d while logging in as admin: %d\n" ,
362- (int )serverRc , adminUserId );
336+ (int )serverRc , adminUserId );
363337 return (int )serverRc ;
364338 }
365339
366340 rc = wh_Client_AuthUserGet (clientContext , "demo" , & serverRc , & userId ,
367- & permissions );
341+ & permissions );
368342 if (rc != 0 ) {
369343 printf ("[AUTH-DEMO] Failed to get user: %d\n" , rc );
370344 return rc ;
371345 }
372346 if (serverRc != 0 ) {
373347 printf ("[AUTH-DEMO] Server-side error %d while getting user: %d\n" ,
374- (int )serverRc , userId );
348+ (int )serverRc , userId );
375349 return (int )serverRc ;
376350 }
377351
@@ -392,17 +366,18 @@ static int wh_DemoClient_AuthUserSetPermissions(whClientContext* clientContext)
392366 }
393367
394368 rc = wh_Client_AuthUserSetPermissions (clientContext , userId , permissions ,
395- & serverRc );
369+ & serverRc );
396370 if (rc != 0 || serverRc != 0 ) {
397371 printf ("[AUTH-DEMO] Failed to set permissions: %d, server error %d\n" ,
398- rc , serverRc );
372+ rc , serverRc );
399373 return rc != 0 ? rc : (int )serverRc ;
400374 }
401375
402- rc = wh_Client_AuthUserGet (clientContext , "demo" , & serverRc , & userId , & permissions );
376+ rc = wh_Client_AuthUserGet (clientContext , "demo" , & serverRc , & userId ,
377+ & permissions );
403378 if (rc != 0 || serverRc != 0 ) {
404379 printf ("[AUTH-DEMO] Failed to get user: %d, server error %d\n" , rc ,
405- serverRc );
380+ serverRc );
406381 return (rc != 0 ) ? rc : (int )serverRc ;
407382 }
408383
@@ -417,7 +392,7 @@ static int wh_DemoClient_AuthUserSetPermissions(whClientContext* clientContext)
417392
418393int wh_DemoClient_Auth (whClientContext * clientContext )
419394{
420- int rc = 0 ;
395+ int rc = 0 ;
421396
422397 printf ("[AUTH-DEMO] Starting authentication demo...\n" );
423398 rc = wh_DemoClient_AuthCertificate (clientContext );
0 commit comments