Skip to content

Commit

Permalink
Fixed a security bug causing anonymous unlock
Browse files Browse the repository at this point in the history
Enhance the serial stability and fix a security bug in recognition_1vN
  • Loading branch information
Matrixchung committed Feb 22, 2023
1 parent fd5a145 commit b097737
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SFM-V1.7
version=1.0.1
version=1.0.2
author=Matrixchung <[email protected]>
maintainer=Matrixchung <[email protected]>
sentence=Interfacing to the SFM-V1.7 Fingerprint Sensor for ESP32 platform
Expand Down
18 changes: 15 additions & 3 deletions src/sfm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ uint8_t SFM_Module::recognition_1vN(uint16_t &returnUid){
q3 = sendCmd(0x0C, 0x00, 0x00, 0x00, ackType, q1, q2);
if(ackType == 0x0C){
returnUid = (q1 << 8) | q2;
return returnUid == 0 ? SFM_ACK_FAIL : SFM_ACK_SUCCESS;
return (returnUid == 0 && q3 != SFM_ACK_SUCCESS) ? SFM_ACK_FAIL : SFM_ACK_SUCCESS;
}
return SFM_ACK_FAIL;
}
Expand Down Expand Up @@ -176,7 +176,15 @@ uint8_t SFM_Module::sendCmd(uint8_t cmdType, uint8_t p1, uint8_t p2, uint8_t p3,
unsigned int timer = SFM_SERIAL_TIMEOUT;
while(timer--){
if(sfmSerial.available() >= 8){
while(sfmSerial.peek() != 0xF5) sfmSerial.read(); // trim the cache to find first 0xF5 (ack start)
unsigned int trimTimer = SFM_SERIAL_TIMEOUT;
while(sfmSerial.peek() != 0xF5 && trimTimer--){
sfmSerial.read(); // trim the cache to find first 0xF5 (ack start)
}
if(!trimTimer) {
while(sfmSerial.available()) sfmSerial.read(); // flush buffer
sfmSerial.flush();
return SFM_ACK_SERIALTIMEOUT;
}
if(sfmSerial.available() >= 8){ // more than 8 bytes since the first 0xF5
sfmSerial.readBytes(ackBuffer, 8);
if(ackBuffer[6] == _getCheckSum(ackBuffer)){ // checksum matched, exit without flush buffer
Expand All @@ -185,7 +193,11 @@ uint8_t SFM_Module::sendCmd(uint8_t cmdType, uint8_t p1, uint8_t p2, uint8_t p3,
q2 = ackBuffer[3];
return ackBuffer[4]; // return q3 as SFM_ACK
}
else return SFM_ACK_FAIL;
else {
while(sfmSerial.available()) sfmSerial.read(); // flush buffer
sfmSerial.flush();
return SFM_ACK_FAIL;
}
}
}
delay(1);
Expand Down

0 comments on commit b097737

Please sign in to comment.