report the card status when a satochip extended key request does not succeed instead of parsing the response
What changed, and why it matters
This commit fixes a bug in how Sparrow Wallet reads responses from Satochip hardware cards when fetching an extended Bitcoin public key. Previously, if the card reported an error, the app would blindly try to interpret the error response as a valid key. Now it first checks whether the card signaled success, and if not, throws a clear error containing the card's status code. The change is defensive and improves error handling, but it is not obviously exploitable as a security vulnerability on its own.
Treat as a hardening/defensive fix. Ensure the fix is included in the next release and consider auditing other Satochip parser methods for similar missing status checks. No urgent security advisory appears required based solely on this diff.
Security signals we found
Missing status-word validation before parsing cryptographic material
Potential parsing of error APDU as valid BIP32 extended key
Defensive fix with added unit test for error-status handling
Evidence from the diff
In SatochipParser.parseBip32GetExtendedKey(), the code now checks rapdu.getSw() against APDUResponse.SW_OK before attempting to parse the response bytes as a 33-byte public key plus chain code. If the status word indicates failure, a CardException is thrown with the hex status. Previously, error responses would have been parsed as key material, which could lead to incorrect extended keys or downstream failures. A unit test verifies that status 0x6F00 is reported rather than parsed.
Changed components
src/main/java/com/sparrowwallet/sparrow/io/satochip/SatochipParser.javaSatochip hardware wallet integrationBIP32 extended key import/derivation flowInspect captured patch +24 / −0
### src/main/java/com/sparrowwallet/sparrow/io/satochip/SatochipParser.java
@@ -56,6 +56,10 @@ public byte[] parseInitiateSecureChannel(APDUResponse rapdu) throws CardExceptio
}
public byte[][] parseBip32GetExtendedKey(APDUResponse rapdu) throws CardException {
+ if(rapdu.getSw() != APDUResponse.SW_OK) {
+ throw new CardException("Satochip returned status 0x" + Integer.toHexString(rapdu.getSw()) + " for extended key");
+ }
+
try {
byte[][] extendedkey = new byte[2][];
extendedkey[0] = new byte[33]; // pubkey
### src/test/java/com/sparrowwallet/sparrow/io/satochip/SatochipParserTest.java
@@ -0,0 +1,20 @@
+package com.sparrowwallet.sparrow.io.satochip;
+
+import org.junit.jupiter.api.Test;
+
+import javax.smartcardio.CardException;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class SatochipParserTest {
+ /**
+ * A response the card did not complete reports the card's status rather than being read as an extended key.
+ */
+ @Test
+ public void extendedKeyResponseWithAnErrorStatusReportsTheStatus() {
+ APDUResponse response = new APDUResponse(new byte[70], (byte)0x6f, (byte)0x00);
+ CardException e = assertThrows(CardException.class, () -> new SatochipParser().parseBip32GetExtendedKey(response));
+ assertTrue(e.getMessage().contains("0x6f00"), e.getMessage());
+ }
+}Why this scored 42/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.