From 5f7761b5622665ed22e48a5fb7a0b54e88205586 Mon Sep 17 00:00:00 2001 From: Frank Elias Date: Fri, 22 Oct 2021 15:17:30 -0400 Subject: returning serverHandshake error in payload --- SmartDeviceLink/private/SDLProtocol.m | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/SmartDeviceLink/private/SDLProtocol.m b/SmartDeviceLink/private/SDLProtocol.m index f2ef868c5..5841296a9 100644 --- a/SmartDeviceLink/private/SDLProtocol.m +++ b/SmartDeviceLink/private/SDLProtocol.m @@ -828,7 +828,7 @@ NS_ASSUME_NONNULL_BEGIN if (serverHandshakeData == nil) { SDLLogE(@"Error running TLS handshake procedure. Sending error to module. Error: %@", handshakeError); - serverSecurityMessage = [self.class sdl_serverSecurityFailedMessageWithClientMessageHeader:clientHandshakeMessage.header messageId:++_messageID]; + serverSecurityMessage = [self.class sdl_serverSecurityFailedMessageWithClientMessageHeader:clientHandshakeMessage.header messageId:++_messageID handshakeError:handshakeError]; } else { // The handshake went fine, send the module the remaining handshake data serverSecurityMessage = [self.class sdl_serverSecurityHandshakeMessageWithData:serverHandshakeData clientMessageHeader:clientHandshakeMessage.header messageId:++_messageID]; @@ -857,7 +857,7 @@ NS_ASSUME_NONNULL_BEGIN return [SDLProtocolMessage messageWithHeader:serverMessageHeader andPayload:binaryData]; } -+ (SDLProtocolMessage *)sdl_serverSecurityFailedMessageWithClientMessageHeader:(SDLProtocolHeader *)clientHeader messageId:(UInt32)messageId { ++ (SDLProtocolMessage *)sdl_serverSecurityFailedMessageWithClientMessageHeader:(SDLProtocolHeader *)clientHeader messageId:(UInt32)messageId handshakeError:(NSError *)handshakeError { // This can't possibly be a v1 header because v1 does not have control protocol messages SDLV2ProtocolHeader *serverMessageHeader = [SDLProtocolHeader headerForVersion:clientHeader.version]; serverMessageHeader.encrypted = NO; @@ -868,7 +868,13 @@ NS_ASSUME_NONNULL_BEGIN serverMessageHeader.messageID = messageId; // For a control service packet, we need a binary header with a function ID corresponding to what type of packet we're sending. - SDLSecurityQueryPayload *serverTLSPayload = [[SDLSecurityQueryPayload alloc] initWithQueryType:SDLSecurityQueryTypeNotification queryID:SDLSecurityQueryIdSendInternalError sequenceNumber:0x00 jsonData:nil binaryData:nil]; + UInt8 codeError = (UInt8)handshakeError.code; + + NSDictionary *jsonDictionary = @{@"id" : @(codeError), @"text" : [SDLSecurityQueryError convertErrorIdToStringEnum:@(codeError)]}; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDictionary options:NSJSONWritingPrettyPrinted error:nil]; + + NSData *binaryDataPayload = [NSData dataWithBytes:&index length:sizeof(codeError)]; + SDLSecurityQueryPayload *serverTLSPayload = [[SDLSecurityQueryPayload alloc] initWithQueryType:SDLSecurityQueryTypeNotification queryID:SDLSecurityQueryIdSendInternalError sequenceNumber:0x00 jsonData:jsonData binaryData:binaryDataPayload]; NSData *binaryData = [serverTLSPayload convertToData]; -- cgit v1.2.1 From 7704c96d452ae4769b29da639eb6cf1a5278c713 Mon Sep 17 00:00:00 2001 From: Frank Elias Date: Fri, 22 Oct 2021 15:33:04 -0400 Subject: implementing default internal error --- SmartDeviceLink/private/SDLProtocol.m | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/SmartDeviceLink/private/SDLProtocol.m b/SmartDeviceLink/private/SDLProtocol.m index 5841296a9..88b9615e4 100644 --- a/SmartDeviceLink/private/SDLProtocol.m +++ b/SmartDeviceLink/private/SDLProtocol.m @@ -828,7 +828,7 @@ NS_ASSUME_NONNULL_BEGIN if (serverHandshakeData == nil) { SDLLogE(@"Error running TLS handshake procedure. Sending error to module. Error: %@", handshakeError); - serverSecurityMessage = [self.class sdl_serverSecurityFailedMessageWithClientMessageHeader:clientHandshakeMessage.header messageId:++_messageID handshakeError:handshakeError]; + serverSecurityMessage = [self.class sdl_serverSecurityFailedMessageWithClientMessageHeader:clientHandshakeMessage.header messageId:++_messageID]; } else { // The handshake went fine, send the module the remaining handshake data serverSecurityMessage = [self.class sdl_serverSecurityHandshakeMessageWithData:serverHandshakeData clientMessageHeader:clientHandshakeMessage.header messageId:++_messageID]; @@ -857,7 +857,7 @@ NS_ASSUME_NONNULL_BEGIN return [SDLProtocolMessage messageWithHeader:serverMessageHeader andPayload:binaryData]; } -+ (SDLProtocolMessage *)sdl_serverSecurityFailedMessageWithClientMessageHeader:(SDLProtocolHeader *)clientHeader messageId:(UInt32)messageId handshakeError:(NSError *)handshakeError { ++ (SDLProtocolMessage *)sdl_serverSecurityFailedMessageWithClientMessageHeader:(SDLProtocolHeader *)clientHeader messageId:(UInt32)messageId { // This can't possibly be a v1 header because v1 does not have control protocol messages SDLV2ProtocolHeader *serverMessageHeader = [SDLProtocolHeader headerForVersion:clientHeader.version]; serverMessageHeader.encrypted = NO; @@ -868,12 +868,11 @@ NS_ASSUME_NONNULL_BEGIN serverMessageHeader.messageID = messageId; // For a control service packet, we need a binary header with a function ID corresponding to what type of packet we're sending. - UInt8 codeError = (UInt8)handshakeError.code; - - NSDictionary *jsonDictionary = @{@"id" : @(codeError), @"text" : [SDLSecurityQueryError convertErrorIdToStringEnum:@(codeError)]}; + UInt8 errorCode = 0xFF; + NSDictionary *jsonDictionary = @{@"id" : @0xFF, @"text" : [SDLSecurityQueryError convertErrorIdToStringEnum:@(errorCode)]}; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDictionary options:NSJSONWritingPrettyPrinted error:nil]; - NSData *binaryDataPayload = [NSData dataWithBytes:&index length:sizeof(codeError)]; + NSData *binaryDataPayload = [NSData dataWithBytes:&errorCode length:sizeof(errorCode)]; SDLSecurityQueryPayload *serverTLSPayload = [[SDLSecurityQueryPayload alloc] initWithQueryType:SDLSecurityQueryTypeNotification queryID:SDLSecurityQueryIdSendInternalError sequenceNumber:0x00 jsonData:jsonData binaryData:binaryDataPayload]; NSData *binaryData = [serverTLSPayload convertToData]; -- cgit v1.2.1 From b2185eade15e045ad042a0d1742516155cd7d4ac Mon Sep 17 00:00:00 2001 From: Frank Elias Date: Mon, 25 Oct 2021 15:51:51 -0400 Subject: comments review --- SmartDeviceLink/private/SDLProtocol.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SmartDeviceLink/private/SDLProtocol.m b/SmartDeviceLink/private/SDLProtocol.m index 88b9615e4..e189df839 100644 --- a/SmartDeviceLink/private/SDLProtocol.m +++ b/SmartDeviceLink/private/SDLProtocol.m @@ -869,8 +869,8 @@ NS_ASSUME_NONNULL_BEGIN // For a control service packet, we need a binary header with a function ID corresponding to what type of packet we're sending. UInt8 errorCode = 0xFF; - NSDictionary *jsonDictionary = @{@"id" : @0xFF, @"text" : [SDLSecurityQueryError convertErrorIdToStringEnum:@(errorCode)]}; - NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDictionary options:NSJSONWritingPrettyPrinted error:nil]; + NSDictionary *jsonDictionary = @{@"id" : @(errorCode), @"text" : [SDLSecurityQueryError convertErrorIdToStringEnum:@(errorCode)]}; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDictionary options:kNilOptions error:nil]; NSData *binaryDataPayload = [NSData dataWithBytes:&errorCode length:sizeof(errorCode)]; SDLSecurityQueryPayload *serverTLSPayload = [[SDLSecurityQueryPayload alloc] initWithQueryType:SDLSecurityQueryTypeNotification queryID:SDLSecurityQueryIdSendInternalError sequenceNumber:0x00 jsonData:jsonData binaryData:binaryDataPayload]; -- cgit v1.2.1