From: Oleg Moiseenko <807634+merlokk@users.noreply.github.com>
Date: Mon, 4 Feb 2019 07:03:44 +0000 (+0200)
Subject: fido fix (#775)
X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/3962dce565fc63c0190d4570bfaf339ec32b7025?hp=97096af62bd25105acd3d56eda5cd9a3112aa876

fido fix (#775)
---

diff --git a/client/emv/emvcore.c b/client/emv/emvcore.c
index 53559e85..78a30206 100644
--- a/client/emv/emvcore.c
+++ b/client/emv/emvcore.c
@@ -308,11 +308,11 @@ static int EMVExchangeEx(EMVCommandChannel channel, bool ActivateField, bool Lea
 		return 200;
 	}
 
-	if (Result[*ResultLen-2] == 0x61) {
+/*	if (Result[*ResultLen-2] == 0x61) {
 		uint8_t La = Result[*ResultLen-1];
 		uint8_t get_response[5] = {apdu[0], ISO7816_GET_RESPONSE, 0x00, 0x00, La};
 		return EMVExchangeEx(channel, false, LeaveFieldON, get_response, sizeof(get_response), Result, MaxResultLen, ResultLen, sw, tlv);
-	}
+	}*/
 
 	*ResultLen -= 2;
 	isw = Result[*ResultLen] * 0x0100 + Result[*ResultLen + 1];
@@ -346,7 +346,8 @@ int EMVExchange(EMVCommandChannel channel, bool LeaveFieldON, uint8_t *apdu, int
 		} else if (apdu_len > 5 && apdu_len == 5 + apdu[4] + 1) {
 			// there is Lc, data and Le
 		} else {
-			apdu_len++; // no Le, add Le = 0x00 because some vendors require it for contactless
+			if (apdu[1] != 0xc0)
+				apdu_len++; // no Le, add Le = 0x00 because some vendors require it for contactless
 		}
 	}
 	return EMVExchangeEx(channel, false, LeaveFieldON, APDU, apdu_len, Result, MaxResultLen, ResultLen, sw, tlv);
diff --git a/client/fido/fidocore.c b/client/fido/fidocore.c
index 4d973737..5498c9d2 100644
--- a/client/fido/fidocore.c
+++ b/client/fido/fidocore.c
@@ -197,22 +197,22 @@ int FIDOExchange(uint8_t* apdu, int apdulen, uint8_t *Result, size_t MaxResultLe
 
 int FIDORegister(uint8_t *params, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw) 
 {
-	uint8_t APDU[4 + 64] = {0x00, 0x01, 0x03, 0x00, 64, 0x00};
-	memcpy(APDU, params, 64);
-	return FIDOExchange(APDU, 4 + 64, Result, MaxResultLen, ResultLen, sw);
+	uint8_t APDU[5 + 64] = {0x00, 0x01, 0x03, 0x00, 64, 0x00};
+	memcpy(APDU + 5, params, 64);
+	return FIDOExchange(APDU, 5 + 64, Result, MaxResultLen, ResultLen, sw);
 }
 
 int FIDOAuthentication(uint8_t *params, uint8_t paramslen, uint8_t controlb, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw) 
 {
 	uint8_t APDU[APDU_COMMAND_LEN] = {0x00, 0x02, controlb, 0x00, paramslen, 0x00};
-	memcpy(APDU+5, params, paramslen);
+	memcpy(APDU + 5, params, paramslen);
 	int apdu_len = 5 + paramslen;
 	return FIDOExchange(APDU, apdu_len, Result, MaxResultLen, ResultLen, sw);
 }
 
 int FIDO2GetInfo(uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw) 
 {
-	uint8_t APDU[5] = {0x80, 0x10, 0x00, 0x00, fido2CmdGetInfo};
+	uint8_t APDU[6] = {0x80, 0x10, 0x00, 0x00, 0x01, fido2CmdGetInfo};
 	return FIDOExchange(APDU, sizeof(APDU), Result, MaxResultLen, ResultLen, sw);
 }