26
26
#include "iscsi_target_nego.h"
27
27
#include "iscsi_target_auth.h"
28
28
29
- static int chap_string_to_hex (unsigned char * dst , unsigned char * src , int len )
30
- {
31
- int j = DIV_ROUND_UP (len , 2 ), rc ;
32
-
33
- rc = hex2bin (dst , src , j );
34
- if (rc < 0 )
35
- pr_debug ("CHAP string contains non hex digit symbols\n" );
36
-
37
- dst [j ] = '\0' ;
38
- return j ;
39
- }
40
-
41
29
static void chap_binaryhex_to_asciihex (char * dst , char * src , int src_len )
42
30
{
43
31
int i ;
@@ -248,9 +236,16 @@ static int chap_server_compute_md5(
248
236
pr_err ("Could not find CHAP_R.\n" );
249
237
goto out ;
250
238
}
239
+ if (strlen (chap_r ) != MD5_SIGNATURE_SIZE * 2 ) {
240
+ pr_err ("Malformed CHAP_R\n" );
241
+ goto out ;
242
+ }
243
+ if (hex2bin (client_digest , chap_r , MD5_SIGNATURE_SIZE ) < 0 ) {
244
+ pr_err ("Malformed CHAP_R\n" );
245
+ goto out ;
246
+ }
251
247
252
248
pr_debug ("[server] Got CHAP_R=%s\n" , chap_r );
253
- chap_string_to_hex (client_digest , chap_r , strlen (chap_r ));
254
249
255
250
tfm = crypto_alloc_shash ("md5" , 0 , 0 );
256
251
if (IS_ERR (tfm )) {
@@ -349,9 +344,7 @@ static int chap_server_compute_md5(
349
344
pr_err ("Could not find CHAP_C.\n" );
350
345
goto out ;
351
346
}
352
- pr_debug ("[server] Got CHAP_C=%s\n" , challenge );
353
- challenge_len = chap_string_to_hex (challenge_binhex , challenge ,
354
- strlen (challenge ));
347
+ challenge_len = DIV_ROUND_UP (strlen (challenge ), 2 );
355
348
if (!challenge_len ) {
356
349
pr_err ("Unable to convert incoming challenge\n" );
357
350
goto out ;
@@ -360,6 +353,11 @@ static int chap_server_compute_md5(
360
353
pr_err ("CHAP_C exceeds maximum binary size of 1024 bytes\n" );
361
354
goto out ;
362
355
}
356
+ if (hex2bin (challenge_binhex , challenge , challenge_len ) < 0 ) {
357
+ pr_err ("Malformed CHAP_C\n" );
358
+ goto out ;
359
+ }
360
+ pr_debug ("[server] Got CHAP_C=%s\n" , challenge );
363
361
/*
364
362
* During mutual authentication, the CHAP_C generated by the
365
363
* initiator must not match the original CHAP_C generated by
0 commit comments