summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRHeniz <heniganr1@gmail.com>2021-11-15 11:38:57 -0500
committerRHeniz <heniganr1@gmail.com>2021-11-15 11:38:57 -0500
commit7024b2afbebb2ff939a325b8dd2ad6bedb6832da (patch)
tree2b6b379db68e8b4b2b48f6f6c19962886a01f0be
parentb92965544ddaf2a1e7a5c04a74c64abcbcd9e03e (diff)
downloadsdl_android-7024b2afbebb2ff939a325b8dd2ad6bedb6832da.tar.gz
Align to iOS
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/protocol/SecurityQueryPayloadTests.java6
-rw-r--r--base/src/main/java/com/smartdevicelink/protocol/SecurityQueryPayload.java70
-rw-r--r--base/src/main/java/com/smartdevicelink/session/BaseSdlSession.java12
3 files changed, 39 insertions, 49 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/protocol/SecurityQueryPayloadTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/protocol/SecurityQueryPayloadTests.java
index 68c64fedf..3a1cd50a1 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/protocol/SecurityQueryPayloadTests.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/protocol/SecurityQueryPayloadTests.java
@@ -68,7 +68,7 @@ public class SecurityQueryPayloadTests {
dummyBqh.setCorrelationID(3);
dummyBqh.setJsonData(new byte[0]);
- byte[] assembledHeader = dummyBqh.assembleSecurityQueryPayload(0);
+ byte[] assembledHeader = dummyBqh.assembleBinaryData();
assertEquals(dummyBqh.getQueryType(), SecurityQueryType.valueOf(assembledHeader[0]));
byte[] queryIDFromHeader = new byte[3];
System.arraycopy(assembledHeader, 1, queryIDFromHeader, 0, 3);
@@ -81,7 +81,7 @@ public class SecurityQueryPayloadTests {
public void testAssemblyAndParse() {
SecurityQueryPayload bqh = createDummyBqh();
- byte[] bqhBytes = bqh.assembleSecurityQueryPayload(0);
+ byte[] bqhBytes = bqh.assembleBinaryData();
assertNotNull(bqhBytes);
SecurityQueryPayload parsedBqh = SecurityQueryPayload.parseBinaryQueryHeader(bqhBytes);
@@ -99,7 +99,7 @@ public class SecurityQueryPayloadTests {
public void testCorruptHeader() {
SecurityQueryPayload bqh = createDummyBqh();
- byte[] bqhBytes = bqh.assembleSecurityQueryPayload(0);
+ byte[] bqhBytes = bqh.assembleBinaryData();
assertNotNull(safeParse(bqhBytes));
diff --git a/base/src/main/java/com/smartdevicelink/protocol/SecurityQueryPayload.java b/base/src/main/java/com/smartdevicelink/protocol/SecurityQueryPayload.java
index af82b004a..a41052c0d 100644
--- a/base/src/main/java/com/smartdevicelink/protocol/SecurityQueryPayload.java
+++ b/base/src/main/java/com/smartdevicelink/protocol/SecurityQueryPayload.java
@@ -16,7 +16,7 @@ public class SecurityQueryPayload {
private SecurityQueryID _securityQueryID;
private int _correlationID;
private int _jsonSize;
- private SecurityQueryErrorCode _errorCode;
+ private int _bulkDataSize;
private byte[] _jsonData = null;
private byte[] _bulkData = null;
@@ -51,11 +51,6 @@ public class SecurityQueryPayload {
int _jsonSize = BitConverter.intFromByteArray(binHeader, 8);
msg.setJsonSize(_jsonSize);
- //If we get an error message we want the error code from the last 8 bits
- if (msg.getQueryType() == SecurityQueryType.NOTIFICATION && msg.getQueryID() == SecurityQueryID.SEND_INTERNAL_ERROR) {
- msg.setErrorCode(SecurityQueryErrorCode.valueOf(binHeader[binHeader.length - 1]));
- }
-
try {
//Get the JsonData after the header (after 96 bits) based on the jsonData size
if (_jsonSize > 0 && _jsonSize <= (binHeader.length - SECURITY_QUERY_HEADER_SIZE)) {
@@ -84,40 +79,28 @@ public class SecurityQueryPayload {
return msg;
}
- public byte[] assembleSecurityQueryPayload(int payloadSize) {
- byte[] payLoad = new byte[SECURITY_QUERY_HEADER_SIZE];
- if (_securityQueryID == SecurityQueryID.SEND_INTERNAL_ERROR && _securityQueryType == SecurityQueryType.NOTIFICATION) {
- payLoad = new byte[SECURITY_QUERY_HEADER_SIZE + payloadSize + 1];
- System.arraycopy(_jsonData, 0, payLoad, SECURITY_QUERY_HEADER_SIZE, _jsonSize);
- byte[] errorCode = new byte[1];
- if (this._errorCode != null) {
- errorCode[0] = _errorCode.getValue();
- } else {
- errorCode[0] = SecurityQueryErrorCode.ERROR_UNKNOWN_INTERNAL_ERROR.getValue();
- }
- System.arraycopy(errorCode, 0, payLoad, payLoad.length - 1, 1);
- } else if (_securityQueryID == SecurityQueryID.SEND_HANDSHAKE_DATA && _securityQueryType == SecurityQueryType.RESPONSE) {
- payLoad = new byte[SECURITY_QUERY_HEADER_SIZE + payloadSize];
- System.arraycopy(_bulkData, 0, payLoad, SECURITY_QUERY_HEADER_SIZE, payloadSize);
- }
-
- System.arraycopy(assembleHeaderBytes(), 0, payLoad, 0, SECURITY_QUERY_HEADER_SIZE);
-
- return payLoad;
- }
-
- private byte[] assembleHeaderBytes() {
+ public byte[] assembleBinaryData() {
// From the properties, create a data buffer
// Query Type - first 8 bits
// Query ID - next 24 bits
// Sequence Number - next 32 bits
// JSON size - next 32 bits
- byte[] ret = new byte[SECURITY_QUERY_HEADER_SIZE];
- ret[0] = _securityQueryType.getValue();
- System.arraycopy(_securityQueryID.getValue(), 0, ret, 1, 3);
- System.arraycopy(BitConverter.intToByteArray(_correlationID), 0, ret, 4, 4);
- System.arraycopy(BitConverter.intToByteArray(_jsonSize), 0, ret, 8, 4);
- return ret;
+ byte[] header = new byte[SECURITY_QUERY_HEADER_SIZE];
+ header[0] = _securityQueryType.getValue();
+ System.arraycopy(_securityQueryID.getValue(), 0, header, 1, 3);
+ System.arraycopy(BitConverter.intToByteArray(_correlationID), 0, header, 4, 4);
+ System.arraycopy(BitConverter.intToByteArray(_jsonSize), 0, header, 8, 4);
+
+ int size = _jsonSize + _bulkDataSize + SECURITY_QUERY_HEADER_SIZE;
+ byte[] dataOut = new byte[size];
+ System.arraycopy(header, 0, dataOut, 0, SECURITY_QUERY_HEADER_SIZE);
+ if (_jsonData != null) {
+ System.arraycopy(_jsonData, 0, dataOut, SECURITY_QUERY_HEADER_SIZE, _jsonSize);
+ }
+ if (_bulkData != null) {
+ System.arraycopy(_bulkData, 0, dataOut, SECURITY_QUERY_HEADER_SIZE + _jsonSize, _bulkDataSize);
+ }
+ return dataOut;
}
public SecurityQueryType getQueryType() {
@@ -152,12 +135,12 @@ public class SecurityQueryPayload {
this._jsonSize = _jsonSize;
}
- public SecurityQueryErrorCode getErrorCode() {
- return _errorCode;
+ public int getBulkDataSize() {
+ return _bulkDataSize;
}
- public void setErrorCode(SecurityQueryErrorCode _errorCode) {
- this._errorCode = _errorCode;
+ private void setBulkDataSize(int _bulkDataSize) {
+ this._bulkDataSize = _bulkDataSize;
}
public byte[] getJsonData() {
@@ -180,6 +163,13 @@ public class SecurityQueryPayload {
}
public void setBulkData(byte[] _bulkData) {
- this._bulkData = _bulkData;
+ if(_bulkData == null) {
+ this._bulkDataSize = 0;
+ this._bulkData = null;
+ return;
+ }
+ this._bulkDataSize = _bulkData.length;
+ this._bulkData = new byte[this._bulkDataSize];
+ System.arraycopy(_bulkData, 0, this._bulkData, 0, _bulkDataSize);
}
}
diff --git a/base/src/main/java/com/smartdevicelink/session/BaseSdlSession.java b/base/src/main/java/com/smartdevicelink/session/BaseSdlSession.java
index 26627a879..2620f60fc 100644
--- a/base/src/main/java/com/smartdevicelink/session/BaseSdlSession.java
+++ b/base/src/main/java/com/smartdevicelink/session/BaseSdlSession.java
@@ -221,8 +221,8 @@ public abstract class BaseSdlSession implements ISdlProtocol, ISecurityInitializ
// If the query is of type `Notification` and the id represents a client internal error, we abort the response message and the encryptionManager will not be in state ready.
if (receivedHeader.getQueryID() == SecurityQueryID.SEND_INTERNAL_ERROR
&& receivedHeader.getQueryType() == SecurityQueryType.NOTIFICATION) {
- if (receivedHeader.getErrorCode() != null) {
- DebugTool.logError(TAG, "Security Query module internal error: " + receivedHeader.getErrorCode().getName());
+ if (receivedHeader.getBulkData() != null && receivedHeader.getBulkDataSize() == 1) {
+ DebugTool.logError(TAG, "Security Query module internal error: " + SecurityQueryErrorCode.valueOf(receivedHeader.getBulkData()[0]).getName());
} else {
DebugTool.logError(TAG, "Security Query module error: No information provided");
}
@@ -263,17 +263,17 @@ public abstract class BaseSdlSession implements ISdlProtocol, ISecurityInitializ
jsonData = new byte[0];
}
responseHeader.setJsonData(jsonData);
- responseHeader.setBulkData(null);
- responseHeader.setErrorCode(SecurityQueryErrorCode.ERROR_UNKNOWN_INTERNAL_ERROR);
- returnBytes = responseHeader.assembleSecurityQueryPayload(responseHeader.getJsonSize());
+ byte[] errorCode = new byte[1];
+ errorCode[0] = SecurityQueryErrorCode.ERROR_UNKNOWN_INTERNAL_ERROR.getValue();
+ responseHeader.setBulkData(errorCode);
} else {
responseHeader.setQueryID(SecurityQueryID.SEND_HANDSHAKE_DATA);
responseHeader.setQueryType(SecurityQueryType.RESPONSE);
responseHeader.setCorrelationID(msg.getCorrID());
responseHeader.setBulkData(dataToRead);
responseHeader.setJsonData(null);
- returnBytes = responseHeader.assembleSecurityQueryPayload(iNumBytes);
}
+ returnBytes = responseHeader.assembleBinaryData();
ProtocolMessage protocolMessage = new ProtocolMessage();
protocolMessage.setSessionType(SessionType.CONTROL);