@@ -443,6 +443,7 @@ int desfire_print_signature(uint8_t *uid, uint8_t uidlen, uint8_t *signature, si
443
443
PrintAndLogEx (DEBUG , "UID is NULL" );
444
444
return PM3_EINVARG ;
445
445
}
446
+
446
447
if (signature == NULL ) {
447
448
PrintAndLogEx (DEBUG , "SIGNATURE is NULL" );
448
449
return PM3_EINVARG ;
@@ -497,8 +498,9 @@ static int CmdDesGetSessionParameters(CLIParserContext *ctx, DesfireContext_t *d
497
498
memcpy (kdfInput , defaultKdfInput , defaultKdfInputLen );
498
499
499
500
int commmode = defaultCommMode ;
500
- if (defcommmode != DCMNone )
501
+ if (defcommmode != DCMNone ) {
501
502
commmode = defcommmode ;
503
+ }
502
504
503
505
int commset = defaultCommSet ;
504
506
int secchann = defaultSecureChannel ;
@@ -560,7 +562,6 @@ static int CmdDesGetSessionParameters(CLIParserContext *ctx, DesfireContext_t *d
560
562
}
561
563
562
564
if (schannid ) {
563
-
564
565
if (CLIGetOptionList (arg_get_str (ctx , schannid ), DesfireSecureChannelOpts , & secchann ))
565
566
return PM3_ESOFT ;
566
567
}
@@ -570,10 +571,14 @@ static int CmdDesGetSessionParameters(CLIParserContext *ctx, DesfireContext_t *d
570
571
uint8_t dfname_data [16 ] = {0 };
571
572
int dfname_len = 0 ;
572
573
if (CLIParamHexToBuf (arg_get_str (ctx , dfnameid ), dfname_data , sizeof (dfname_data ), & dfname_len ) == 0 && dfname_len > 0 ) {
574
+
573
575
if (dfname_len <= 16 ) {
576
+
574
577
DesfireSetDFName (dctx , dfname_data , dfname_len );
575
- if (selectway )
578
+ if (selectway ) {
576
579
* selectway = ISWDFName ;
580
+ }
581
+
577
582
} else {
578
583
PrintAndLogEx (ERR , "DF name length must be between 1-16 bytes, got %d" , dfname_len );
579
584
return PM3_EINVARG ;
@@ -583,31 +588,37 @@ static int CmdDesGetSessionParameters(CLIParserContext *ctx, DesfireContext_t *d
583
588
584
589
if (appid && id ) {
585
590
* id = 0x000000 ;
586
- if (CLIGetUint32Hex (ctx , appid , 0x000000 , id , NULL , 3 , "AID must have 3 bytes length" ))
591
+ if (CLIGetUint32Hex (ctx , appid , 0x000000 , id , NULL , 3 , "AID must have 3 bytes length" )) {
587
592
return PM3_EINVARG ;
588
- if (selectway )
593
+ }
594
+
595
+ if (selectway ) {
589
596
* selectway = ISW6bAID ;
590
597
}
598
+ }
591
599
592
600
if (appisoid && id ) {
593
601
uint32_t xisoid = 0x0000 ;
594
602
bool isoidpresent = false;
595
- if (CLIGetUint32Hex (ctx , appisoid , 0x0000 , & xisoid , & isoidpresent , 2 , "Application ISO ID (for EF) must have 2 bytes length" ))
603
+ if (CLIGetUint32Hex (ctx , appisoid , 0x0000 , & xisoid , & isoidpresent , 2 , "Application ISO ID (for EF) must have 2 bytes length" )) {
596
604
return PM3_EINVARG ;
605
+ }
597
606
598
607
if (isoidpresent ) {
599
608
* id = xisoid & 0xffff ;
600
- if (selectway )
609
+ if (selectway ) {
601
610
* selectway = ISWIsoID ;
602
611
}
603
612
}
613
+ }
604
614
605
615
DesfireSetKey (dctx , keynum , algores , key );
606
616
DesfireSetKdf (dctx , kdfAlgo , kdfInput , kdfInputLen );
607
617
DesfireSetCommandSet (dctx , commset );
608
618
DesfireSetCommMode (dctx , commmode );
609
- if (securechannel )
619
+ if (securechannel ) {
610
620
* securechannel = secchann ;
621
+ }
611
622
612
623
return PM3_SUCCESS ;
613
624
}
@@ -642,6 +653,10 @@ static int CmdHF14ADesDefault(const char *Cmd) {
642
653
643
654
CLIParserFree (ctx );
644
655
656
+ // clear out select DF Name length and array when resetting to default the desfire context
657
+ dctx .selectedDFNameLen = 0 ;
658
+ memset (dctx .selectedDFName , 0 , sizeof (dctx .selectedDFName ));
659
+
645
660
defaultKeyNum = dctx .keyNum ;
646
661
defaultAlgoId = dctx .keyType ;
647
662
memcpy (defaultKey , dctx .key , DESFIRE_MAX_KEY_SIZE );
@@ -2299,10 +2314,11 @@ static int CmdHF14ADesAuth(const char *Cmd) {
2299
2314
2300
2315
if (dctx .selectedDFNameLen > 0 ) {
2301
2316
PrintAndLogEx (SUCCESS , "DF selected and authenticated " _GREEN_ ("successfully" ));
2302
- } else if (DesfireMFSelected (selectway , id ))
2317
+ } else if (DesfireMFSelected (selectway , id )) {
2303
2318
PrintAndLogEx (SUCCESS , "PICC selected and authenticated " _GREEN_ ("succesfully" ));
2304
- else
2319
+ } else {
2305
2320
PrintAndLogEx (SUCCESS , "Application " _CYAN_ ("%s" ) " selected and authenticated " _GREEN_ ("succesfully" ), DesfireWayIDStr (selectway , id ));
2321
+ }
2306
2322
2307
2323
PrintAndLogEx (SUCCESS , _CYAN_ ("Context: " ));
2308
2324
DesfirePrintContext (& dctx );
0 commit comments