Skip to content

Commit fa9301e

Browse files
committed
Add PSM fix for already released Core versions
This is added to deal with the case where Core would incorrectly encrypt the first frame which would make the payload length greater than 8 which is a protocol spec violation.
1 parent e21d198 commit fa9301e

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

  • base/src/main/java/com/smartdevicelink/transport

base/src/main/java/com/smartdevicelink/transport/SdlPsm.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ public class SdlPsm {
6161
private static final byte FIRST_FRAME_DATA_SIZE = 0x08;
6262

6363
private static final int VERSION_MASK = 0xF0; //4 highest bits
64-
private static final int COMPRESSION_MASK = 0x08; //4th lowest bit
64+
private static final int ENCRYPTION_MASK = 0x08; //4th lowest bit
6565
private static final int FRAME_TYPE_MASK = 0x07; //3 lowest bits
6666

6767

6868
int state;
6969

7070
int version;
71-
boolean compression;
71+
boolean encrypted;
7272
int frameType;
7373
int serviceType;
7474
int controlFrameInfo;
@@ -97,7 +97,7 @@ private int transitionOnInput(byte rawByte, int state) {
9797
if (version == 0) { //It should never be 0
9898
return ERROR_STATE;
9999
}
100-
compression = (1 == ((rawByte & (byte) COMPRESSION_MASK) >> 3));
100+
encrypted = (1 == ((rawByte & (byte) ENCRYPTION_MASK) >> 3));
101101

102102

103103
frameType = rawByte & (byte) FRAME_TYPE_MASK;
@@ -194,7 +194,10 @@ private int transitionOnInput(byte rawByte, int state) {
194194
break;
195195

196196
case SdlPacket.FRAME_TYPE_FIRST:
197-
if (dataLength == FIRST_FRAME_DATA_SIZE) {
197+
if (dataLength == FIRST_FRAME_DATA_SIZE || this.encrypted) {
198+
//In a few production releases of core the first frame could be
199+
//encrypted. Therefore it is not an error state if the first frame data
200+
//length is greater than 8 in that case alone.
198201
break;
199202
}
200203
default:
@@ -263,7 +266,7 @@ private int transitionOnInput(byte rawByte, int state) {
263266
public SdlPacket getFormedPacket() {
264267
if (state == FINISHED_STATE) {
265268
//Log.trace(TAG, "Finished packet.");
266-
return new SdlPacket(version, compression, frameType,
269+
return new SdlPacket(version, encrypted, frameType,
267270
serviceType, controlFrameInfo, sessionId,
268271
dataLength, messageId, payload);
269272
} else {

0 commit comments

Comments
 (0)