FIxing bugs from76181dfb8and377d7cd61breaking secure channel operations
This commit is contained in:
1 parent
77a9f45db6
commit
f5dc8ab42f
3 files changed
+34
-8
No files matched your search
@@ -17,6 +17,7 @@
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
#include "sam_picopass.h"
|
#include "sam_picopass.h"
|
||||||
#include "sam_common.h"
|
#include "sam_common.h"
|
||||||
|
#include "sam_sc.h"
|
||||||
#include "iclass.h"
|
#include "iclass.h"
|
||||||
#include "crc16.h"
|
#include "crc16.h"
|
||||||
#include "proxmark3_arm.h"
|
#include "proxmark3_arm.h"
|
||||||
@@ -636,6 +637,10 @@ int sam_picopass_get_pacs(PacketCommandNG *c) {
|
|||||||
uint8_t sam_response_len = 0;
|
uint8_t sam_response_len = 0;
|
||||||
|
|
||||||
clear_trace();
|
clear_trace();
|
||||||
|
// This path resets the SAM, invalidating any secure-channel state held by
|
||||||
|
// CMD_HF_SAM_SC. Ensure the next SC request reopens instead of sending
|
||||||
|
// into a reset SAM with a stale routing/session flag.
|
||||||
|
sam_sc_session_invalidate();
|
||||||
I2C_Reset_EnterMainProgram();
|
I2C_Reset_EnterMainProgram();
|
||||||
|
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
|||||||
+24
-8
@@ -492,30 +492,46 @@ void sam_sc_handler(const PacketCommandNG *c) {
|
|||||||
LED_D_ON();
|
LED_D_ON();
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
|
||||||
|
int res = PM3_SUCCESS;
|
||||||
|
|
||||||
// Reset the SAM only if the caller asked for it OR this is the first SC
|
// Reset the SAM only if the caller asked for it OR this is the first SC
|
||||||
// op since boot / since the previous session was released. Crucially
|
// op since boot / since the previous session was released. Crucially
|
||||||
// this dispatcher does NOT reset on every call the way sam_picopass_get_pacs
|
// this dispatcher does NOT reset on every call the way sam_picopass_get_pacs
|
||||||
// does, so the SAM-side session-flag binding established by ContinueAuth
|
// does, so the SAM-side session-flag binding established by ContinueAuth
|
||||||
// survives across multiple CMD_HF_SAM_SC invocations.
|
// survives across multiple CMD_HF_SAM_SC invocations.
|
||||||
//
|
//
|
||||||
// After every reset we issue a sam_get_version() warmup ping. This
|
// A module reset can leave an ATR pending and returns the module UART to
|
||||||
// mirrors what sam_picopass_get_pacs does (which is what `hf iclass sam
|
// its default rate. Consume the ATR first: besides preventing it from
|
||||||
// --info` runs through). Without this warmup, the FIRST sam_send_payload_ex
|
// colliding with the warmup APDU, GetATR() restores the cached PPS rate so
|
||||||
// after I2C_Reset can time out - the 8051<->SAM UART link needs a
|
// the module and SAM are synchronized again. This mirrors the direct
|
||||||
// sacrificial round-trip to settle. The version response is discarded.
|
// PICOPASS SAM path.
|
||||||
|
//
|
||||||
|
// Then issue a sam_get_version() warmup ping. Without it, the first real
|
||||||
|
// sam_send_payload_ex() after I2C_Reset can time out while the 8051<->SAM
|
||||||
|
// UART link settles. Do not enter a session when either stage fails.
|
||||||
//
|
//
|
||||||
// NOTE: HF_SELECT / HF_OFF must NOT trigger a reset - they run inside an
|
// NOTE: HF_SELECT / HF_OFF must NOT trigger a reset - they run inside an
|
||||||
// already-open SC session and a reset would wipe the SAM-side session-flag
|
// already-open SC session and a reset would wipe the SAM-side session-flag
|
||||||
// binding. They pass neither force_reset nor a cleared session flag.
|
// binding. They pass neither force_reset nor a cleared session flag.
|
||||||
if (force_reset || s_sam_sc_session_active == false) {
|
if (force_reset || s_sam_sc_session_active == false) {
|
||||||
|
// A forced reset may replace an otherwise valid active session. Do not
|
||||||
|
// leave it marked live if ATR recovery or the warmup subsequently
|
||||||
|
// fails.
|
||||||
|
s_sam_sc_session_active = false;
|
||||||
I2C_Reset_EnterMainProgram();
|
I2C_Reset_EnterMainProgram();
|
||||||
StartTicks();
|
StartTicks();
|
||||||
sam_get_version(false);
|
smart_card_atr_t card;
|
||||||
|
if (GetATR(&card, false) == false) {
|
||||||
|
res = PM3_ECARDEXCHANGE;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
res = sam_get_version(false);
|
||||||
|
if (res != PM3_SUCCESS) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
s_sam_sc_session_active = true;
|
s_sam_sc_session_active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int res = PM3_SUCCESS;
|
|
||||||
|
|
||||||
// ---- HF_OFF: disarm the field (no SAM traffic) ----
|
// ---- HF_OFF: disarm the field (no SAM traffic) ----
|
||||||
if (hf_off) {
|
if (hf_off) {
|
||||||
switch_off();
|
switch_off();
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
#include "sam_seos.h"
|
#include "sam_seos.h"
|
||||||
#include "sam_common.h"
|
#include "sam_common.h"
|
||||||
|
#include "sam_sc.h"
|
||||||
#include "iclass.h"
|
#include "iclass.h"
|
||||||
|
|
||||||
#include "proxmark3_arm.h"
|
#include "proxmark3_arm.h"
|
||||||
@@ -291,6 +292,10 @@ int sam_seos_get_pacs(PacketCommandNG *c) {
|
|||||||
int res = PM3_EFAILED;
|
int res = PM3_EFAILED;
|
||||||
|
|
||||||
clear_trace();
|
clear_trace();
|
||||||
|
// Like the PICOPASS dispatcher, this reset destroys a live SC session.
|
||||||
|
// Mark it stale so the next CMD_HF_SAM_SC call performs its reset/ATR
|
||||||
|
// synchronization path before sending a secured APDU.
|
||||||
|
sam_sc_session_invalidate();
|
||||||
I2C_Reset_EnterMainProgram();
|
I2C_Reset_EnterMainProgram();
|
||||||
|
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
|||||||
Reference in new issue
Block a user