Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If raw data fails to encrypt, don't send the protocol message #2005

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions SmartDeviceLink/private/SDLProtocol.m
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ - (void)startServiceWithType:(SDLServiceType)serviceType payload:(nullable NSDat
- (void)startSecureServiceWithType:(SDLServiceType)serviceType payload:(nullable NSData *)payload tlsInitializationHandler:(void (^)(BOOL success, NSError *error))tlsInitializationHandler {
SDLLogD(@"Attempting to start TLS for service type: %hhu", serviceType);
[self sdl_initializeTLSEncryptionWithCompletionHandler:^(BOOL success, NSError *error) {
tlsInitializationHandler(success, error);
if (!success) {
// We can't start the service because we don't have encryption, return the error
tlsInitializationHandler(success, error);
BLOCK_RETURN;
}

// TLS initialization succeeded. Build and send the message.
SDLProtocolMessage *message = [self sdl_createStartServiceMessageWithType:serviceType encrypted:YES payload:nil];
SDLProtocolMessage *message = [self sdl_createStartServiceMessageWithType:serviceType encrypted:YES payload:payload];
SDLLogD(@"TLS initialized, sending start service with encryption for message: %@", message);
[self sdl_sendDataToTransport:message.data onService:serviceType];
}];
Expand Down Expand Up @@ -470,13 +470,14 @@ - (void)sdl_sendRawData:(NSData *)data onService:(SDLServiceType)service encrypt
NSError *encryptError = nil;
data = [self.securityManager encryptData:data withError:&encryptError];

if (encryptError) {
// If the data fails to encrypt, fail out of sending this chunk of data.
if ((data.length == 0) || (encryptError != nil)) {
SDLLogE(@"Error attempting to encrypt raw data for service: %@, error: %@", @(service), encryptError);
return;
}
}

SDLProtocolMessage *message = [SDLProtocolMessage messageWithHeader:header andPayload:data];

if (message.size < [[SDLGlobals sharedGlobals] mtuSizeForServiceType:service]) {
SDLLogV(@"Sending protocol message: %@", message);
[self sdl_sendDataToTransport:message.data onService:header.serviceType];
Expand Down Expand Up @@ -531,7 +532,7 @@ - (void)sdl_processMessages {
NSError *decryptError = nil;
payload = [self.securityManager decryptData:payload withError:&decryptError];

if (decryptError) {
if (decryptError != nil) {
SDLLogE(@"Error attempting to decrypt a payload with error: %@", decryptError);
return;
}
Expand Down
10 changes: 5 additions & 5 deletions SmartDeviceLinkTests/DevAPISpecs/SDLMenuCellSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,19 @@
});
});

describe(@"check cell eqality", ^{
describe(@"check cell equality", ^{
it(@"should compare cells and return true if cells equal", ^{
testCell = [[SDLMenuCell alloc] initWithTitle:someTitle secondaryText:someSecondaryTitle tertiaryText:someTertiaryTitle icon:nil secondaryArtwork:someSecondaryArtwork submenuLayout:testLayout subCells:@[]];
testCell2 = [[SDLMenuCell alloc] initWithTitle:someTitle secondaryText:someSecondaryTitle tertiaryText:someTertiaryTitle icon:nil secondaryArtwork:someSecondaryArtwork submenuLayout:testLayout subCells:@[]];

expect([testCell isEqual:testCell2]).to(equal(true));
expect([testCell isEqual:testCell2]).to(beTrue());
});

it(@"should compare cells and return false if not equal ", ^{
testCell = [[SDLMenuCell alloc] initWithTitle:@"True" secondaryText:someSecondaryTitle tertiaryText:someTertiaryTitle icon:nil secondaryArtwork:someSecondaryArtwork submenuLayout:testLayout subCells:@[]];
testCell2 = [[SDLMenuCell alloc] initWithTitle:@"False" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil submenuLayout:testLayout subCells:@[]];

expect([testCell isEqual:testCell2]).to(equal(false));
expect([testCell isEqual:testCell2]).to(beFalse());
});

it(@"should compare cells and return true if cells equal", ^{
Expand All @@ -115,7 +115,7 @@
testCell2 = [[SDLMenuCell alloc] initWithTitle:someTitle icon:nil submenuLayout:testLayout subCells:@[]];
#pragma clang diagnostic pop

expect([testCell isEqual:testCell2]).to(equal(true));
expect([testCell isEqual:testCell2]).to(beTrue());
});

it(@"should compare cells and return false if not equal ", ^{
Expand All @@ -125,7 +125,7 @@
testCell2 = [[SDLMenuCell alloc] initWithTitle:@"False" icon:nil submenuLayout:testLayout subCells:@[]];
#pragma clang diagnostic pop

expect([testCell isEqual:testCell2]).to(equal(false));
expect([testCell isEqual:testCell2]).to(beFalse());
});
});
});
Expand Down