diff options
36 files changed, 148 insertions, 169 deletions
diff --git a/Example Apps/Example ObjC/AudioManager.m b/Example Apps/Example ObjC/AudioManager.m index 81ad666fd..cd6ec4ecf 100644 --- a/Example Apps/Example ObjC/AudioManager.m +++ b/Example Apps/Example ObjC/AudioManager.m @@ -100,7 +100,7 @@ NS_ASSUME_NONNULL_BEGIN UInt32 recordingDurationInMilliseconds = 10000; SDLPerformAudioPassThru *performAudioPassThru = [[SDLPerformAudioPassThru alloc] initWithInitialPrompt:@"Starting sound recording" audioPassThruDisplayText1:@"Say Something" audioPassThruDisplayText2:[NSString stringWithFormat:@"Recording for %d seconds", (recordingDurationInMilliseconds / 1000)] samplingRate:SDLSamplingRate16KHZ bitsPerSample:SDLBitsPerSample16Bit audioType:SDLAudioTypePCM maxDuration:recordingDurationInMilliseconds muteAudio:true audioDataHandler:self.audioDataReceivedHandler]; - [self.sdlManager sendRequest:performAudioPassThru withEncryption:NO withResponseHandler:self.audioPassThruEndedHandler]; + [self.sdlManager sendRequest:performAudioPassThru withResponseHandler:self.audioPassThruEndedHandler]; } /** diff --git a/Example Apps/Example ObjC/ButtonManager.m b/Example Apps/Example ObjC/ButtonManager.m index cd90fbf03..1809249db 100644 --- a/Example Apps/Example ObjC/ButtonManager.m +++ b/Example Apps/Example ObjC/ButtonManager.m @@ -81,7 +81,7 @@ NS_ASSUME_NONNULL_BEGIN if (buttonPress == nil) { return; } [weakself.sdlManager.fileManager uploadArtwork:[SDLArtwork artworkWithImage:[UIImage imageNamed:CarBWIconImageName] asImageFormat:SDLArtworkImageFormatPNG] completionHandler:^(BOOL success, NSString * _Nonnull artworkName, NSUInteger bytesAvailable, NSError * _Nullable error) { - [weakself.sdlManager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"You pushed the soft button!" textField2:nil iconName:artworkName] withEncryption:NO withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [weakself.sdlManager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"You pushed the soft button!" textField2:nil iconName:artworkName] withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { NSLog(@"ALERT req: %@, res: %@, err: %@", request, response, error); }]; }]; diff --git a/Example Apps/Example ObjC/MenuManager.m b/Example Apps/Example ObjC/MenuManager.m index 2f4b656b0..41458da3b 100644 --- a/Example Apps/Example ObjC/MenuManager.m +++ b/Example Apps/Example ObjC/MenuManager.m @@ -96,7 +96,7 @@ NS_ASSUME_NONNULL_BEGIN // Non - Media SDLMenuCell *cell = [[SDLMenuCell alloc] initWithTitle:@"Non - Media (Default)" icon:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) { SDLSetDisplayLayout* display = [[SDLSetDisplayLayout alloc] initWithPredefinedLayout:SDLPredefinedLayoutNonMedia]; - [manager sendRequest:display withEncryption:NO withResponseHandler:^(SDLRPCRequest *request, SDLRPCResponse *response, NSError *error) { + [manager sendRequest:display withResponseHandler:^(SDLRPCRequest *request, SDLRPCResponse *response, NSError *error) { if (![response.resultCode isEqualToEnum:SDLResultSuccess]) { [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:errorMessage textField2:nil iconName:nil]]; } @@ -107,7 +107,7 @@ NS_ASSUME_NONNULL_BEGIN // Graphic With Text SDLMenuCell *cell2 = [[SDLMenuCell alloc] initWithTitle:@"Graphic With Text" icon:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) { SDLSetDisplayLayout* display = [[SDLSetDisplayLayout alloc] initWithPredefinedLayout:SDLPredefinedLayoutGraphicWithText]; - [manager sendRequest:display withEncryption:NO withResponseHandler:^(SDLRPCRequest *request, SDLRPCResponse *response, NSError *error) { + [manager sendRequest:display withResponseHandler:^(SDLRPCRequest *request, SDLRPCResponse *response, NSError *error) { if (![response.resultCode isEqualToEnum:SDLResultSuccess]) { [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:errorMessage textField2:nil iconName:nil]]; } diff --git a/Example Apps/Example ObjC/VehicleDataManager.m b/Example Apps/Example ObjC/VehicleDataManager.m index 5e5f1f9e9..54ff9642f 100644 --- a/Example Apps/Example ObjC/VehicleDataManager.m +++ b/Example Apps/Example ObjC/VehicleDataManager.m @@ -53,7 +53,7 @@ NS_ASSUME_NONNULL_BEGIN SDLLogD(@"Subscribing to odometer vehicle data"); SDLSubscribeVehicleData *subscribeToVehicleOdometer = [[SDLSubscribeVehicleData alloc] init]; subscribeToVehicleOdometer.odometer = @YES; - [self.sdlManager sendRequest:subscribeToVehicleOdometer withEncryption:NO withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [self.sdlManager sendRequest:subscribeToVehicleOdometer withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { if (error || ![response isKindOfClass:SDLSubscribeVehicleDataResponse.class]) { SDLLogE(@"Error sending Get Vehicle Data RPC: %@", error); } @@ -95,7 +95,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)unsubscribeToVehicleOdometer { SDLUnsubscribeVehicleData *unsubscribeToVehicleOdometer = [[SDLUnsubscribeVehicleData alloc] init]; unsubscribeToVehicleOdometer.odometer = @YES; - [self.sdlManager sendRequest:unsubscribeToVehicleOdometer withEncryption:NO withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [self.sdlManager sendRequest:unsubscribeToVehicleOdometer withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { if (!response.success.boolValue) { return; } [self sdlex_resetOdometer]; }]; @@ -144,7 +144,7 @@ NS_ASSUME_NONNULL_BEGIN SDLLogD(@"App has permission to access vehicle data. Requesting vehicle data..."); SDLGetVehicleData *getAllVehicleData = [[SDLGetVehicleData alloc] initWithAccelerationPedalPosition:YES airbagStatus:YES beltStatus:YES bodyInformation:YES clusterModeStatus:YES deviceStatus:YES driverBraking:YES eCallInfo:YES electronicParkBrakeStatus:YES emergencyEvent:YES engineOilLife:YES engineTorque:YES externalTemperature:YES fuelLevel:YES fuelLevelState:YES fuelRange:YES gps:YES headLampStatus:YES instantFuelConsumption:YES myKey:YES odometer:YES prndl:YES rpm:YES speed:YES steeringWheelAngle:YES tirePressure:YES turnSignal:YES vin:YES wiperStatus:YES]; - [manager sendRequest:getAllVehicleData withEncryption:NO withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [manager sendRequest:getAllVehicleData withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { if (error || ![response isKindOfClass:SDLGetVehicleDataResponse.class]) { [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"Something went wrong while getting vehicle data" textField2:nil iconName:nil]]; return; @@ -279,7 +279,7 @@ NS_ASSUME_NONNULL_BEGIN */ + (void)sdlex_dialPhoneNumber:(NSString *)phoneNumber manager:(SDLManager *)manager { SDLDialNumber *dialNumber = [[SDLDialNumber alloc] initWithNumber:phoneNumber]; - [manager sendRequest:dialNumber withEncryption:NO withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [manager sendRequest:dialNumber withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { if (!response.resultCode) { return; } SDLLogD(@"Sent dial number request: %@", response.resultCode == SDLResultSuccess ? @"successfully" : @"unsuccessfully"); }]; diff --git a/SmartDeviceLink/SDLAsynchronousRPCRequestOperation.h b/SmartDeviceLink/SDLAsynchronousRPCRequestOperation.h index b46f3dc22..908d0d3e6 100644 --- a/SmartDeviceLink/SDLAsynchronousRPCRequestOperation.h +++ b/SmartDeviceLink/SDLAsynchronousRPCRequestOperation.h @@ -44,7 +44,7 @@ NS_ASSUME_NONNULL_BEGIN * @param responseHandler Called when the request has a response from Core * @return A SDLAsynchronousRPCRequestOperation object */ -- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager request:(SDLRPCRequest *)request withEncryption:(BOOL)encryption responseHandler:(nullable SDLResponseHandler)responseHandler; +- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager request:(SDLRPCRequest *)request responseHandler:(nullable SDLResponseHandler)responseHandler; @end diff --git a/SmartDeviceLink/SDLAsynchronousRPCRequestOperation.m b/SmartDeviceLink/SDLAsynchronousRPCRequestOperation.m index 1a252b2e7..c77c80d52 100644 --- a/SmartDeviceLink/SDLAsynchronousRPCRequestOperation.m +++ b/SmartDeviceLink/SDLAsynchronousRPCRequestOperation.m @@ -26,7 +26,6 @@ NS_ASSUME_NONNULL_BEGIN @property (assign, nonatomic) NSUInteger requestsStarted; @property (assign, nonatomic, readonly) float percentComplete; @property (assign, nonatomic) BOOL requestFailed; -@property (assign, nonatomic) BOOL encryption; @end @@ -46,7 +45,6 @@ NS_ASSUME_NONNULL_BEGIN _requestsComplete = 0; _requestsStarted = 0; _requestFailed = NO; - _encryption = NO; return self; } @@ -62,13 +60,12 @@ NS_ASSUME_NONNULL_BEGIN return self; } -- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager request:(SDLRPCRequest *)request withEncryption:(BOOL)encryption responseHandler:(nullable SDLResponseHandler)responseHandler { +- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager request:(SDLRPCRequest *)request responseHandler:(nullable SDLResponseHandler)responseHandler { self = [self init]; _connectionManager = connectionManager; _requests = @[request]; _responseHandler = responseHandler; - _encryption = encryption; return self; } @@ -93,7 +90,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)sdl_sendRequest:(SDLRPCRequest *)request { __weak typeof(self) weakSelf = self; - [self.connectionManager sendConnectionRequest:request withEncryption:self.encryption withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [self.connectionManager sendConnectionRequest:request withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { if (weakSelf == nil) { return; } if (weakSelf.isCancelled) { diff --git a/SmartDeviceLink/SDLConnectionManagerType.h b/SmartDeviceLink/SDLConnectionManagerType.h index da136e761..d0e7f7f84 100644 --- a/SmartDeviceLink/SDLConnectionManagerType.h +++ b/SmartDeviceLink/SDLConnectionManagerType.h @@ -30,10 +30,9 @@ NS_ASSUME_NONNULL_BEGIN * Sends an RPC of type `SDLRPCRequest` without bypassing the block on RPC sends before managers complete setup. * * @param request An RPC of type `SDLRPCRequest` be sent to Core. - * @param encryption Whether or not the RPC should be encrypted. * @param handler Called when the response is received by Core */ -- (void)sendConnectionRequest:(__kindof SDLRPCRequest *)request withEncryption:(BOOL)encryption withResponseHandler:(nullable SDLResponseHandler)handler; +- (void)sendConnectionRequest:(__kindof SDLRPCRequest *)request withResponseHandler:(nullable SDLResponseHandler)handler; /** * Sends an RPC of type `SDLRPCResponse` or `SDLRPCNotification` without bypassing the block on RPC sends before managers complete setup. Unlike requests, responses and notifications sent to Core do not get a response from Core, so no handler is needed. diff --git a/SmartDeviceLink/SDLEncryptionLifecycleManager.h b/SmartDeviceLink/SDLEncryptionLifecycleManager.h index 63eeb031b..ef2b70807 100644 --- a/SmartDeviceLink/SDLEncryptionLifecycleManager.h +++ b/SmartDeviceLink/SDLEncryptionLifecycleManager.h @@ -36,7 +36,7 @@ NS_ASSUME_NONNULL_BEGIN @param rpcOperationQueue The RPC operation queue that the encrypted RPC will be sent on @return A new encryption lifecycle manager */ -- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager configuration:(SDLEncryptionConfiguration *)configuration rpcOperationQueue:(NSOperationQueue *)rpcOperationQueue; +- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager configuration:(SDLEncryptionConfiguration *)configuration permissionManager:(SDLPermissionManager *)permissionManager rpcOperationQueue:(NSOperationQueue *)rpcOperationQueue; /** * Start the manager. This is used internally to get notified of the ACK message. diff --git a/SmartDeviceLink/SDLEncryptionLifecycleManager.m b/SmartDeviceLink/SDLEncryptionLifecycleManager.m index e42244093..8e98f2c99 100644 --- a/SmartDeviceLink/SDLEncryptionLifecycleManager.m +++ b/SmartDeviceLink/SDLEncryptionLifecycleManager.m @@ -16,12 +16,13 @@ #import "SDLOnHMIStatus.h" #import "SDLOnPermissionsChange.h" #import "SDLPermissionItem.h" +#import "SDLError.h" @interface SDLEncryptionLifecycleManager() <SDLProtocolListener> @property (strong, nonatomic, readonly) NSOperationQueue *rpcOperationQueue; @property (weak, nonatomic) id<SDLConnectionManagerType> connectionManager; -@property (strong, nonatomic) NSMutableDictionary<SDLPermissionRPCName, SDLPermissionItem *> *permissions; +@property (strong, nonatomic) SDLPermissionManager *permissionManager; @property (weak, nonatomic) SDLProtocol *protocol; @property (strong, nonatomic, readwrite) SDLStateMachine *encryptionStateMachine; @@ -31,7 +32,7 @@ @implementation SDLEncryptionLifecycleManager -- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager configuration:(SDLEncryptionConfiguration *)configuration rpcOperationQueue:(NSOperationQueue *)rpcOperationQueue { +- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager configuration:(SDLEncryptionConfiguration *)configuration permissionManager:(SDLPermissionManager *)permissionManager rpcOperationQueue:(NSOperationQueue *)rpcOperationQueue { self = [super init]; if (!self) { return nil; @@ -40,12 +41,11 @@ SDLLogV(@"Creating EncryptionLifecycleManager"); _hmiLevel = SDLHMILevelNone; _connectionManager = connectionManager; - _permissions = [NSMutableDictionary<SDLPermissionRPCName, SDLPermissionItem *> dictionary]; + _permissionManager = permissionManager; _rpcOperationQueue = rpcOperationQueue; _encryptionStateMachine = [[SDLStateMachine alloc] initWithTarget:self initialState:SDLEncryptionLifecycleManagerStateStopped states:[self.class sdl_encryptionStateTransitionDictionary]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_hmiStatusDidChange:) name:SDLDidChangeHMIStatusNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_permissionsDidChange:) name:SDLDidChangePermissionsNotification object:nil]; return self; } @@ -64,20 +64,23 @@ - (void)stop { _hmiLevel = SDLHMILevelNone; - _permissions = [NSMutableDictionary<SDLPermissionRPCName, SDLPermissionItem *> dictionary]; + _permissionManager = nil; _protocol = nil; SDLLogD(@"Stopping encryption manager"); - [self sdl_stopEncryptionService]; } - (void)sendEncryptedRequest:(SDLRPCRequest *)request withResponseHandler:(SDLResponseHandler)handler { if (!self.protocol || !self.isEncryptionReady) { - SDLLogW(@"Encryption manager is not yet ready, wait until after proxy is opened"); + SDLLogW(@"Encryption Manager not ready, request not sent (%@)", request); + if (handler) { + handler(request, nil, [NSError sdl_encryption_lifecycle_notReadyError]); + } + return; } - SDLAsynchronousRPCRequestOperation *op = [[SDLAsynchronousRPCRequestOperation alloc] initWithConnectionManager:self.connectionManager request:request withEncryption:YES responseHandler:handler]; + SDLAsynchronousRPCRequestOperation *op = [[SDLAsynchronousRPCRequestOperation alloc] initWithConnectionManager:self.connectionManager request:request responseHandler:handler]; [self.rpcOperationQueue addOperation:op]; } @@ -93,18 +96,18 @@ return; } - if (!self.hmiLevel || !self.permissions) { + if (!self.hmiLevel) { SDLLogV(@"Encryption Manager is not ready to encrypt."); return; } - if (![self.hmiLevel isEqualToEnum:SDLHMILevelNone]) { + if (![self.hmiLevel isEqualToEnum:SDLHMILevelNone] && self.permissionManager.containsAtLeastOneRPCThatRequiresEncryption) { [self.encryptionStateMachine transitionToState:SDLEncryptionLifecycleManagerStateStarting]; } else { SDLLogE(@"Unable to send encryption start service request\n" "permissions: %@\n" "HMI state must be LIMITED, FULL, BACKGROUND: %@\n", - self.permissions, self.hmiLevel); + self.permissionManager, self.hmiLevel); } } @@ -118,12 +121,6 @@ }]; } -- (void)sdl_stopEncryptionService { - _protocol = nil; - - [self.encryptionStateMachine transitionToState:SDLEncryptionLifecycleManagerStateStopped]; -} - #pragma mark Encryption + (NSDictionary<SDLState *, SDLAllowableStateTransitions *> *)sdl_encryptionStateTransitionDictionary { return @{ @@ -226,16 +223,4 @@ } } -- (void)sdl_permissionsDidChange:(SDLRPCNotificationNotification *)notification { - if (![notification isNotificationMemberOfClass:[SDLOnPermissionsChange class]]) { - return; - } - - SDLOnPermissionsChange *onPermissionChange = notification.notification; - - for (SDLPermissionItem *item in onPermissionChange.permissionItem) { - self.permissions[item.rpcName] = item; - } -} - @end diff --git a/SmartDeviceLink/SDLError.h b/SmartDeviceLink/SDLError.h index 715305a24..d58d5b320 100644 --- a/SmartDeviceLink/SDLError.h +++ b/SmartDeviceLink/SDLError.h @@ -28,6 +28,9 @@ extern SDLErrorDomain *const SDLErrorDomainRPCStore; @interface NSError (SDLErrors) +#pragma mark SDLEncryptionLifecycleManager ++ (NSError *)sdl_encryption_lifecycle_notReadyError; + #pragma mark SDLManager + (NSError *)sdl_lifecycle_rpcErrorWithDescription:(NSString *)description andReason:(NSString *)reason; diff --git a/SmartDeviceLink/SDLError.m b/SmartDeviceLink/SDLError.m index 8a716c5b0..b8feec93e 100644 --- a/SmartDeviceLink/SDLError.m +++ b/SmartDeviceLink/SDLError.m @@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark Error Domains SDLErrorDomain *const SDLErrorDomainLifecycleManager = @"com.sdl.lifecyclemanager.error"; +SDLErrorDomain *const SDLErrorDomainEncryptionLifecycleManager = @"com.sdl.encryptionlifecyclemanager.error"; SDLErrorDomain *const SDLErrorDomainFileManager = @"com.sdl.filemanager.error"; SDLErrorDomain *const SDLErrorDomainTextAndGraphicManager = @"com.sdl.textandgraphicmanager.error"; SDLErrorDomain *const SDLErrorDomainSoftButtonManager = @"com.sdl.softbuttonmanager.error"; @@ -25,6 +26,19 @@ SDLErrorDomain *const SDLErrorDomainRPCStore = @"com.sdl.rpcStore.error"; @implementation NSError (SDLErrors) +#pragma mark - SDLEncryptionLifecycleManager ++ (NSError *)sdl_encryption_lifecycle_notReadyError { + NSDictionary<NSString *, NSString *> *userInfo = @{ + NSLocalizedDescriptionKey: NSLocalizedString(@"Encryption Lifecycle manager not ready", nil), + NSLocalizedFailureReasonErrorKey: NSLocalizedString(@"The SDL library is not finished setting up the connection, please wait until the encryption lifecycleState is SDLEncryptionLifecycleStateReady", nil), + NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString(@"Make sure HMI is not NONE and at least one RPC requires encryption in permissions?", nil) + }; + + return [NSError errorWithDomain:SDLErrorDomainEncryptionLifecycleManager + code:SDLEncryptionLifecycleManagerErrorNotConnected + userInfo:userInfo]; +} + #pragma mark - SDLManager + (NSError *)sdl_lifecycle_rpcErrorWithDescription:(NSString *)description andReason:(NSString *)reason { diff --git a/SmartDeviceLink/SDLErrorConstants.h b/SmartDeviceLink/SDLErrorConstants.h index f7c7bcc2a..dfdeba026 100644 --- a/SmartDeviceLink/SDLErrorConstants.h +++ b/SmartDeviceLink/SDLErrorConstants.h @@ -11,6 +11,16 @@ /** * Errors associated with the SDLManager class. */ +typedef NS_ENUM(NSInteger, SDLEncryptionLifecycleManagerError) { + /** + * Some action was attempted that requires a connection to the remote head unit. + */ + SDLEncryptionLifecycleManagerErrorNotConnected = -1, +}; + +/** + * Errors associated with the SDLManager class. + */ typedef NS_ENUM(NSInteger, SDLManagerError) { /** * An RPC request failed to send. diff --git a/SmartDeviceLink/SDLLifecycleManager.h b/SmartDeviceLink/SDLLifecycleManager.h index 1e937b101..91fee121d 100644 --- a/SmartDeviceLink/SDLLifecycleManager.h +++ b/SmartDeviceLink/SDLLifecycleManager.h @@ -138,14 +138,6 @@ typedef void (^SDLManagerReadyBlock)(BOOL success, NSError *_Nullable error); - (void)sendRequest:(__kindof SDLRPCMessage *)request withResponseHandler:(nullable SDLResponseHandler)handler; /** - * Send RPC request that will be encrypted and set a completion handler that will be called with the response when the response returns. - * - * @param request The RPC request to send - * @param handler The handler that will be called when the response returns - */ -- (void)sendEncryptedRequest:(__kindof SDLRPCMessage *)request withResponseHandler:(nullable SDLResponseHandler)handler; - -/** Send all of the requests given as quickly as possible, but in order. Call the completionHandler after all requests have either failed or given a response. @param requests The requests to be sent diff --git a/SmartDeviceLink/SDLLifecycleManager.m b/SmartDeviceLink/SDLLifecycleManager.m index 48bc466f9..894dee227 100644 --- a/SmartDeviceLink/SDLLifecycleManager.m +++ b/SmartDeviceLink/SDLLifecycleManager.m @@ -141,7 +141,7 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask // Managers _fileManager = [[SDLFileManager alloc] initWithConnectionManager:self configuration:_configuration.fileManagerConfig]; - _permissionManager = [SDLPermissionManager sharedInstance]; + _permissionManager = [[SDLPermissionManager alloc] init]; _lockScreenManager = [[SDLLockScreenManager alloc] initWithConfiguration:_configuration.lockScreenConfig notificationDispatcher:_notificationDispatcher presenter:[[SDLLockScreenPresenter alloc] init]]; _screenManager = [[SDLScreenManager alloc] initWithConnectionManager:self fileManager:_fileManager]; _systemCapabilityManager = [[SDLSystemCapabilityManager alloc] initWithConnectionManager:self]; @@ -156,7 +156,7 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask } if (configuration.encryptionConfig != nil) { - _encryptionLifecycleManager = [[SDLEncryptionLifecycleManager alloc] initWithConnectionManager:self configuration:_configuration.encryptionConfig rpcOperationQueue:_rpcOperationQueue]; + _encryptionLifecycleManager = [[SDLEncryptionLifecycleManager alloc] initWithConnectionManager:self configuration:_configuration.encryptionConfig permissionManager:_permissionManager rpcOperationQueue:_rpcOperationQueue]; } // Notifications @@ -330,7 +330,6 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask // Send the request and depending on the response, post the notification __weak typeof(self) weakSelf = self; [self sdl_sendRequest:regRequest - requiresEncryption: [self.permissionManager requestRequiresEncryption:regRequest] withResponseHandler:^(__kindof SDLRPCRequest *_Nullable request, __kindof SDLRPCResponse *_Nullable response, NSError *_Nullable error) { // If the success BOOL is NO or we received an error at this point, we failed. Call the ready handler and transition to the DISCONNECTED state. if (error != nil || ![response.success boolValue]) { @@ -525,7 +524,6 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask __weak typeof(self) weakSelf = self; [self sdl_sendRequest:unregisterRequest - requiresEncryption:[self.permissionManager requestRequiresEncryption:unregisterRequest] withResponseHandler:^(__kindof SDLRPCRequest *_Nullable request, __kindof SDLRPCResponse *_Nullable response, NSError *_Nullable error) { if (error != nil || ![response.success boolValue]) { SDLLogE(@"SDL Error unregistering, we are going to hard disconnect: %@, response: %@", error, response); @@ -562,7 +560,6 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask setAppIcon.syncFileName = appIcon.name; [self sdl_sendRequest:setAppIcon - requiresEncryption:[self.permissionManager requestRequiresEncryption:setAppIcon] withResponseHandler:^(__kindof SDLRPCRequest *_Nullable request, __kindof SDLRPCResponse *_Nullable response, NSError *_Nullable error) { if (error != nil) { SDLLogW(@"Error setting up app icon: %@", error); @@ -594,13 +591,11 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask } - (void)sendRequest:(SDLRPCRequest *)request withResponseHandler:(nullable SDLResponseHandler)handler { - SDLAsynchronousRPCRequestOperation *op = [[SDLAsynchronousRPCRequestOperation alloc] initWithConnectionManager:self request:request withEncryption:NO responseHandler:handler]; - [self.rpcOperationQueue addOperation:op]; -} - -- (void)sendEncryptedRequest:(__kindof SDLRPCMessage *)request withResponseHandler:(nullable SDLResponseHandler)handler { - if (self.encryptionLifecycleManager != nil) { + if (request.isPayloadProtected) { [self.encryptionLifecycleManager sendEncryptedRequest:request withResponseHandler:handler]; + } else { + SDLAsynchronousRPCRequestOperation *op = [[SDLAsynchronousRPCRequestOperation alloc] initWithConnectionManager:self request:request responseHandler:handler]; + [self.rpcOperationQueue addOperation:op]; } } @@ -633,37 +628,33 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask } dispatch_async(_lifecycleQueue, ^{ - [self sdl_sendRequest:rpc requiresEncryption:[self.permissionManager requestRequiresEncryption:rpc] withResponseHandler:nil]; + [self sdl_sendRequest:rpc withResponseHandler:nil]; + }); +} + +// Managers need to avoid state checking. Part of <SDLConnectionManagerType>. +- (void)sendConnectionManagerRequest:(__kindof SDLRPCMessage *)request withResponseHandler:(nullable SDLResponseHandler)handler { + dispatch_async(_lifecycleQueue, ^{ + [self sdl_sendRequest:request withResponseHandler:handler]; }); } -- (void)sendConnectionRequest:(__kindof SDLRPCRequest *)request withEncryption:(BOOL)encryption withResponseHandler:(nullable SDLResponseHandler)handler { +- (void)sendConnectionRequest:(__kindof SDLRPCRequest *)request withResponseHandler:(nullable SDLResponseHandler)handler { if (![self.lifecycleStateMachine isCurrentState:SDLLifecycleStateReady]) { SDLLogW(@"Manager not ready, request not sent (%@)", request); if (handler) { handler(request, nil, [NSError sdl_lifecycle_notReadyError]); } - + return; } - - dispatch_async(_lifecycleQueue, ^{ - if ([self.permissionManager requestRequiresEncryption:request] || encryption) { - [self sdl_sendRequest:request requiresEncryption:YES withResponseHandler:handler]; - } else { - [self sdl_sendRequest:request requiresEncryption:NO withResponseHandler:handler]; - } - }); -} - -// Managers need to avoid state checking. Part of <SDLConnectionManagerType>. -- (void)sendConnectionManagerRequest:(__kindof SDLRPCMessage *)request withResponseHandler:(nullable SDLResponseHandler)handler { + dispatch_async(_lifecycleQueue, ^{ - [self sdl_sendRequest:request requiresEncryption:[self.permissionManager requestRequiresEncryption:request] withResponseHandler:handler]; + [self sdl_sendRequest:request withResponseHandler:handler]; }); } -- (void)sdl_sendRequest:(__kindof SDLRPCMessage *)request requiresEncryption:(BOOL)encryption withResponseHandler:(nullable SDLResponseHandler)handler { +- (void)sdl_sendRequest:(__kindof SDLRPCMessage *)request withResponseHandler:(nullable SDLResponseHandler)handler { // We will allow things to be sent in a "SDLLifecycleStateConnected" state in the private method, but block it in the public method sendRequest:withCompletionHandler: so that the lifecycle manager can complete its setup without being bothered by developer error NSParameterAssert(request != nil); @@ -683,9 +674,9 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask NSNumber *corrID = [self sdl_getNextCorrelationId]; requestRPC.correlationID = corrID; [self.responseDispatcher storeRequest:requestRPC handler:handler]; - [self.proxy sendRPC:requestRPC withEncryption: encryption]; + [self.proxy sendRPC:requestRPC]; } else if ([request isKindOfClass:SDLRPCResponse.class] || [request isKindOfClass:SDLRPCNotification.class]) { - [self.proxy sendRPC:request withEncryption: encryption]; + [self.proxy sendRPC:request]; } else { SDLLogE(@"Attempting to send an RPC with unknown type, %@. The request should be of type request, response or notification. Returning...", request.class); } diff --git a/SmartDeviceLink/SDLManager.h b/SmartDeviceLink/SDLManager.h index f25937a6e..9764f3f3a 100644 --- a/SmartDeviceLink/SDLManager.h +++ b/SmartDeviceLink/SDLManager.h @@ -156,10 +156,9 @@ typedef void (^SDLManagerReadyBlock)(BOOL success, NSError *_Nullable error); * Send an RPC request and set a completion handler that will be called with the response when the response returns. * * @param request The RPC request to send - * @param encryption Whether or not the RPC should be encrypted * @param handler The handler that will be called when the response returns */ -- (void)sendRequest:(SDLRPCRequest *)request withEncryption:(BOOL)encryption withResponseHandler:(nullable SDLResponseHandler)handler NS_SWIFT_NAME(send(request:withEncryption:responseHandler:)); +- (void)sendRequest:(SDLRPCRequest *)request withResponseHandler:(nullable SDLResponseHandler)handler NS_SWIFT_NAME(send(request:responseHandler:)); /** Send all of the requests given as quickly as possible, but in order. Call the completionHandler after all requests have either failed or given a response. diff --git a/SmartDeviceLink/SDLManager.m b/SmartDeviceLink/SDLManager.m index 02f36158d..b198f7e52 100644 --- a/SmartDeviceLink/SDLManager.m +++ b/SmartDeviceLink/SDLManager.m @@ -131,15 +131,11 @@ NS_ASSUME_NONNULL_BEGIN } - (void)sendRequest:(SDLRPCRequest *)request { - [self sendRequest:request withEncryption:NO withResponseHandler:nil]; + [self sendRequest:request withResponseHandler:nil]; } -- (void)sendRequest:(__kindof SDLRPCRequest *)request withEncryption:(BOOL)encryption withResponseHandler:(nullable SDLResponseHandler)handler { - if (encryption) { - [self.lifecycleManager sendEncryptedRequest:(__kindof SDLRPCMessage *)request withResponseHandler:handler]; - } else { - [self.lifecycleManager sendRequest:(__kindof SDLRPCMessage *)request withResponseHandler:handler]; - } +- (void)sendRequest:(__kindof SDLRPCRequest *)request withResponseHandler:(nullable SDLResponseHandler)handler { + [self.lifecycleManager sendRequest:(__kindof SDLRPCMessage *)request withResponseHandler:handler]; } - (void)sendRequests:(NSArray<SDLRPCRequest *> *)requests progressHandler:(nullable SDLMultipleAsyncRequestProgressHandler)progressHandler completionHandler:(nullable SDLMultipleRequestCompletionHandler)completionHandler { diff --git a/SmartDeviceLink/SDLMenuManager.m b/SmartDeviceLink/SDLMenuManager.m index 2ad396244..1ca796dcc 100644 --- a/SmartDeviceLink/SDLMenuManager.m +++ b/SmartDeviceLink/SDLMenuManager.m @@ -649,7 +649,7 @@ UInt32 const MenuCellIdMin = 1; SDLShowAppMenu *openMenu = [[SDLShowAppMenu alloc] init]; - [self.connectionManager sendConnectionRequest:openMenu withEncryption:NO withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [self.connectionManager sendConnectionRequest:openMenu withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { if (error != nil) { SDLLogE(@"Error opening application menu: %@", error); } @@ -672,7 +672,7 @@ UInt32 const MenuCellIdMin = 1; SDLShowAppMenu *subMenu = [[SDLShowAppMenu alloc] initWithMenuID:cell.cellId]; - [self.connectionManager sendConnectionRequest:subMenu withEncryption:NO withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [self.connectionManager sendConnectionRequest:subMenu withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { if (error != nil) { SDLLogE(@"Error opening application to submenu cell: %@, with error: %@", cell, error); } diff --git a/SmartDeviceLink/SDLPermissionItem.h b/SmartDeviceLink/SDLPermissionItem.h index c59461bed..1b363b068 100644 --- a/SmartDeviceLink/SDLPermissionItem.h +++ b/SmartDeviceLink/SDLPermissionItem.h @@ -34,7 +34,7 @@ NS_ASSUME_NONNULL_BEGIN /** Describes whether or not the RPC needs encryption - Optional Boolean + Optional, Boolean, since SDL 6.0 */ @property (strong, nonatomic, nullable) NSNumber<SDLBool> *requireEncryption; diff --git a/SmartDeviceLink/SDLPermissionManager.h b/SmartDeviceLink/SDLPermissionManager.h index ea3eae22d..f7d66ca96 100644 --- a/SmartDeviceLink/SDLPermissionManager.h +++ b/SmartDeviceLink/SDLPermissionManager.h @@ -20,11 +20,6 @@ NS_ASSUME_NONNULL_BEGIN @interface SDLPermissionManager : NSObject /** - * Shared instance of the manager. This method is used internally. - */ -+ (instancetype)sharedInstance; - -/** * Start the manager with a completion block that will be called when startup completes. This is used internally. To use an SDLPermissionManager, you should use the manager found on `SDLManager`. * * @param completionHandler The block to be called when the manager's setup is complete. @@ -98,7 +93,12 @@ NS_ASSUME_NONNULL_BEGIN /** * Check whether or not an RPC needs encryption */ -- (BOOL)requestRequiresEncryption:(__kindof SDLRPCMessage *)request; +- (BOOL)rpcRequiresEncryption:(__kindof SDLRPCMessage *)rpc; + +/** + * Check if at least one RPC needs protection + */ +- (BOOL)containsAtLeastOneRPCThatRequiresEncryption; @end diff --git a/SmartDeviceLink/SDLPermissionManager.m b/SmartDeviceLink/SDLPermissionManager.m index beca8aedb..7c7df112f 100644 --- a/SmartDeviceLink/SDLPermissionManager.m +++ b/SmartDeviceLink/SDLPermissionManager.m @@ -34,15 +34,6 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Lifecycle -+ (instancetype)sharedInstance { - static SDLPermissionManager *sharedInstace = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - sharedInstace = [[SDLPermissionManager alloc] init]; - }); - return sharedInstace; -} - - (instancetype)init { self = [super init]; if (!self) { @@ -193,7 +184,7 @@ NS_ASSUME_NONNULL_BEGIN } SDLOnPermissionsChange *onPermissionChange = notification.notification; - self.requiresEncryption = onPermissionChange.requireEncryption.boolValue ? YES : NO; + self.requiresEncryption = onPermissionChange.requireEncryption.boolValue; NSArray<SDLPermissionItem *> *newPermissionItems = [onPermissionChange.permissionItem copy]; NSArray<SDLPermissionFilter *> *currentFilters = [self.filters copy]; @@ -364,9 +355,19 @@ NS_ASSUME_NONNULL_BEGIN } -- (BOOL)requestRequiresEncryption:(__kindof SDLRPCMessage *)request { - if (self.permissions[request.name].requireEncryption != nil) { - return self.permissions[request.name].requireEncryption.boolValue; +- (BOOL)rpcRequiresEncryption:(__kindof SDLRPCMessage *)rpc { + if (self.permissions[rpc.name].requireEncryption != nil) { + return self.permissions[rpc.name].requireEncryption.boolValue; + } + return NO; +} + +- (BOOL)containsAtLeastOneRPCThatRequiresEncryption { + for (SDLPermissionItem *item in self.permissions) { + SDLPermissionItem *currentItem = self.permissions[item.rpcName]; + if(currentItem.requireEncryption.boolValue) { + return YES; + } } return NO; } diff --git a/SmartDeviceLink/SDLPresentChoiceSetOperation.m b/SmartDeviceLink/SDLPresentChoiceSetOperation.m index 26e1f0803..87caf9d0a 100644 --- a/SmartDeviceLink/SDLPresentChoiceSetOperation.m +++ b/SmartDeviceLink/SDLPresentChoiceSetOperation.m @@ -113,7 +113,7 @@ NS_ASSUME_NONNULL_BEGIN setProperties.keyboardProperties = self.keyboardProperties; __weak typeof(self) weakself = self; - [self.connectionManager sendConnectionRequest:setProperties withEncryption:NO withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [self.connectionManager sendConnectionRequest:setProperties withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { if (error != nil) { SDLLogE(@"Error setting keyboard properties to new value: %@, with error: %@", request, error); } @@ -128,7 +128,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)sdl_presentChoiceSet { __weak typeof(self) weakself = self; - [self.connectionManager sendConnectionRequest:self.performInteraction withEncryption:NO withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [self.connectionManager sendConnectionRequest:self.performInteraction withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { if (error != nil) { SDLLogE(@"Presenting choice set failed with response: %@, error: %@", response, error); weakself.internalError = error; @@ -262,7 +262,7 @@ NS_ASSUME_NONNULL_BEGIN SDLSetGlobalProperties *setProperties = [[SDLSetGlobalProperties alloc] init]; setProperties.keyboardProperties = self.originalKeyboardProperties; - [self.connectionManager sendConnectionRequest:setProperties withEncryption:NO withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [self.connectionManager sendConnectionRequest:setProperties withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { if (error != nil) { SDLLogE(@"Error resetting keyboard properties to values: %@, with error: %@", request, error); } diff --git a/SmartDeviceLink/SDLPresentKeyboardOperation.m b/SmartDeviceLink/SDLPresentKeyboardOperation.m index a51ab139c..b54f040fe 100644 --- a/SmartDeviceLink/SDLPresentKeyboardOperation.m +++ b/SmartDeviceLink/SDLPresentKeyboardOperation.m @@ -84,7 +84,7 @@ NS_ASSUME_NONNULL_BEGIN SDLSetGlobalProperties *setProperties = [[SDLSetGlobalProperties alloc] init]; setProperties.keyboardProperties = self.keyboardProperties; - [self.connectionManager sendConnectionRequest:setProperties withEncryption:NO withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [self.connectionManager sendConnectionRequest:setProperties withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { if (error != nil) { SDLLogE(@"Error setting keyboard properties to new value: %@, with error: %@", request, error); } @@ -96,7 +96,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)sdl_presentKeyboard { - [self.connectionManager sendConnectionRequest:self.performInteraction withEncryption:NO withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [self.connectionManager sendConnectionRequest:self.performInteraction withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { if (self.isCancelled) { [self finishOperation]; return; @@ -195,7 +195,7 @@ NS_ASSUME_NONNULL_BEGIN SDLSetGlobalProperties *setProperties = [[SDLSetGlobalProperties alloc] init]; setProperties.keyboardProperties = self.originalKeyboardProperties; - [self.connectionManager sendConnectionRequest:setProperties withEncryption:NO withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [self.connectionManager sendConnectionRequest:setProperties withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { if (error != nil) { SDLLogE(@"Error resetting keyboard properties to values: %@, with error: %@", request, error); } diff --git a/SmartDeviceLink/SDLProtocol.h b/SmartDeviceLink/SDLProtocol.h index 9eaa7b8db..f5f751098 100644 --- a/SmartDeviceLink/SDLProtocol.h +++ b/SmartDeviceLink/SDLProtocol.h @@ -108,17 +108,7 @@ extern NSString *const SDLProtocolSecurityErrorDomain; * * @param message A SDLRPCMessage message */ -- (void)sendRPC:(SDLRPCMessage *)message withEncryption:(BOOL)encryption; - -/** - * Sends an RPC to Core - * - * @param message A SDLRPCMessage message - * @param encryption Whether or not the message should be encrypted - * @param error A pointer to a NSError object - * @return YES if the message was created successfully, NO if not - */ -- (BOOL)sendRPC:(SDLRPCMessage *)message encrypted:(BOOL)encryption error:(NSError **)error; +- (void)sendRPC:(SDLRPCMessage *)message; /** * Sends an unencrypted message to Core diff --git a/SmartDeviceLink/SDLProtocol.m b/SmartDeviceLink/SDLProtocol.m index 54c54caa5..17ef74db0 100644 --- a/SmartDeviceLink/SDLProtocol.m +++ b/SmartDeviceLink/SDLProtocol.m @@ -256,8 +256,8 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Send Data -- (void)sendRPC:(SDLRPCMessage *)message withEncryption:(BOOL)encryption { - [self sendRPC:message encrypted:encryption error:nil]; +- (void)sendRPC:(SDLRPCMessage *)message { + [self sendRPC:message encrypted:message.isPayloadProtected error:nil]; } - (BOOL)sendRPC:(SDLRPCMessage *)message encrypted:(BOOL)encryption error:(NSError *__autoreleasing *)error { diff --git a/SmartDeviceLink/SDLProxy.h b/SmartDeviceLink/SDLProxy.h index 174648152..9049cf93f 100644 --- a/SmartDeviceLink/SDLProxy.h +++ b/SmartDeviceLink/SDLProxy.h @@ -94,9 +94,8 @@ NS_ASSUME_NONNULL_BEGIN * Sends a RPC to Core. * * @param message A SDLRPCMessage object - * @param encryption Flag indicating if the RPC needs to be encrypted */ -- (void)sendRPC:(SDLRPCMessage *)message withEncryption:(BOOL)encryption; +- (void)sendRPC:(SDLRPCMessage *)message; /** * Parses a dictionary object and notifies the subscribed delegates of the messages sent by Core. Some messages are also intercepted and handled by the library. diff --git a/SmartDeviceLink/SDLProxy.m b/SmartDeviceLink/SDLProxy.m index 6dada79b8..3b863e626 100644 --- a/SmartDeviceLink/SDLProxy.m +++ b/SmartDeviceLink/SDLProxy.m @@ -175,7 +175,7 @@ static float DefaultConnectionTimeout = 45.0; } SDLLogD(@"Mobile UIApplication state changed, sending to remote system: %@", HMIStatusRPC.hmiLevel); - [self sendRPC:HMIStatusRPC withEncryption:[[SDLPermissionManager sharedInstance] requestRequiresEncryption:HMIStatusRPC]]; + [self sendRPC:HMIStatusRPC]; } #pragma mark - Accessors @@ -279,17 +279,17 @@ static float DefaultConnectionTimeout = 45.0; #pragma mark - Message sending -- (void)sendRPC:(SDLRPCMessage *)message withEncryption:(BOOL)encryption { +- (void)sendRPC:(SDLRPCMessage *)message { if ([message.name isEqualToString:SDLRPCFunctionNameSubscribeButton]) { - BOOL handledRPC = [self sdl_adaptButtonSubscribeMessage:(SDLSubscribeButton *)message withEncryption:encryption]; + BOOL handledRPC = [self sdl_adaptButtonSubscribeMessage:(SDLSubscribeButton *)message]; if (handledRPC) { return; } } else if ([message.name isEqualToString:SDLRPCFunctionNameUnsubscribeButton]) { - BOOL handledRPC = [self sdl_adaptButtonUnsubscribeMessage:(SDLUnsubscribeButton *)message withEncryption:encryption]; + BOOL handledRPC = [self sdl_adaptButtonUnsubscribeMessage:(SDLUnsubscribeButton *)message]; if (handledRPC) { return; } } @try { - [self.protocol sendRPC:message withEncryption:encryption]; + [self.protocol sendRPC:message]; } @catch (NSException *exception) { SDLLogE(@"Proxy: Failed to send RPC message: %@", message.name); } @@ -297,15 +297,15 @@ static float DefaultConnectionTimeout = 45.0; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" -- (BOOL)sdl_adaptButtonSubscribeMessage:(SDLSubscribeButton *)message withEncryption:(BOOL)encryption { +- (BOOL)sdl_adaptButtonSubscribeMessage:(SDLSubscribeButton *)message { if ([SDLGlobals sharedGlobals].rpcVersion.major >= 5) { if ([message.buttonName isEqualToEnum:SDLButtonNameOk]) { SDLSubscribeButton *playPauseMessage = [message copy]; playPauseMessage.buttonName = SDLButtonNamePlayPause; @try { - [self.protocol sendRPC:message withEncryption:encryption]; - [self.protocol sendRPC:playPauseMessage withEncryption:encryption]; + [self.protocol sendRPC:message]; + [self.protocol sendRPC:playPauseMessage]; } @catch (NSException *exception) { SDLLogE(@"Proxy: Failed to send RPC message: %@", message.name); } @@ -322,7 +322,7 @@ static float DefaultConnectionTimeout = 45.0; okMessage.buttonName = SDLButtonNameOk; @try { - [self.protocol sendRPC:okMessage withEncryption:encryption]; + [self.protocol sendRPC:okMessage]; } @catch (NSException *exception) { SDLLogE(@"Proxy: Failed to send RPC message: %@", message.name); } @@ -334,15 +334,15 @@ static float DefaultConnectionTimeout = 45.0; return NO; } -- (BOOL)sdl_adaptButtonUnsubscribeMessage:(SDLUnsubscribeButton *)message withEncryption:(BOOL)encryption { +- (BOOL)sdl_adaptButtonUnsubscribeMessage:(SDLUnsubscribeButton *)message { if ([SDLGlobals sharedGlobals].rpcVersion.major >= 5) { if ([message.buttonName isEqualToEnum:SDLButtonNameOk]) { SDLUnsubscribeButton *playPauseMessage = [message copy]; playPauseMessage.buttonName = SDLButtonNamePlayPause; @try { - [self.protocol sendRPC:message withEncryption:encryption]; - [self.protocol sendRPC:playPauseMessage withEncryption:encryption]; + [self.protocol sendRPC:message]; + [self.protocol sendRPC:playPauseMessage]; } @catch (NSException *exception) { SDLLogE(@"Proxy: Failed to send RPC message: %@", message.name); } @@ -359,7 +359,7 @@ static float DefaultConnectionTimeout = 45.0; okMessage.buttonName = SDLButtonNameOk; @try { - [self.protocol sendRPC:okMessage withEncryption:encryption]; + [self.protocol sendRPC:okMessage]; } @catch (NSException *exception) { SDLLogE(@"Proxy: Failed to send RPC message: %@", message.name); } @@ -704,7 +704,7 @@ static float DefaultConnectionTimeout = 45.0; } // Send the RPC Request - [strongSelf sendRPC:request withEncryption:[[SDLPermissionManager sharedInstance] requestRequiresEncryption:request]]; + [strongSelf sendRPC:request]; }]; } @@ -739,7 +739,7 @@ static float DefaultConnectionTimeout = 45.0; SDLSystemRequest *iconURLSystemRequest = [[SDLSystemRequest alloc] initWithType:SDLRequestTypeIconURL fileName:request.url]; iconURLSystemRequest.bulkData = data; - [strongSelf sendRPC:iconURLSystemRequest withEncryption:[[SDLPermissionManager sharedInstance] requestRequiresEncryption:iconURLSystemRequest]]; + [strongSelf sendRPC:iconURLSystemRequest]; }]; } @@ -775,7 +775,7 @@ static float DefaultConnectionTimeout = 45.0; putFile.bulkData = data; // Send RPC Request - [strongSelf sendRPC:putFile withEncryption:[[SDLPermissionManager sharedInstance] requestRequiresEncryption:putFile]]; + [strongSelf sendRPC:putFile]; }]; } @@ -960,7 +960,7 @@ static float DefaultConnectionTimeout = 45.0; request.correlationID = [NSNumber numberWithInt:PoliciesCorrelationId]; request.data = [responseDictionary objectForKey:@"data"]; - [self sendRPC:request withEncryption:[[SDLPermissionManager sharedInstance] requestRequiresEncryption:request]]; + [self sendRPC:request]; } } @@ -993,7 +993,7 @@ static float DefaultConnectionTimeout = 45.0; [putFileRPCRequest setLength:[NSNumber numberWithUnsignedInteger:(NSUInteger)nBytesRead]]; [putFileRPCRequest setBulkData:data]; - [self sendRPC:putFileRPCRequest withEncryption:[[SDLPermissionManager sharedInstance] requestRequiresEncryption:putFileRPCRequest]]; + [self sendRPC:putFileRPCRequest]; } break; diff --git a/SmartDeviceLink/SDLRPCStruct.h b/SmartDeviceLink/SDLRPCStruct.h index 7813c960b..25db21f16 100644 --- a/SmartDeviceLink/SDLRPCStruct.h +++ b/SmartDeviceLink/SDLRPCStruct.h @@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SDLRPCStruct : NSObject <NSCopying> @property (strong, nonatomic, readonly) NSMutableDictionary<NSString *, id> *store; - +@property (assign, nonatomic, getter=isPayloadProtected) BOOL payloadProtected; /** * Convenience init * diff --git a/SmartDeviceLink/SDLRPCStruct.m b/SmartDeviceLink/SDLRPCStruct.m index 4a634959a..e3de83f73 100644 --- a/SmartDeviceLink/SDLRPCStruct.m +++ b/SmartDeviceLink/SDLRPCStruct.m @@ -18,6 +18,7 @@ NS_ASSUME_NONNULL_BEGIN } _store = [dict mutableCopy]; + _payloadProtected = NO; return self; } @@ -29,6 +30,7 @@ NS_ASSUME_NONNULL_BEGIN } _store = [NSMutableDictionary dictionary]; + _payloadProtected = NO; return self; } @@ -84,6 +86,7 @@ NS_ASSUME_NONNULL_BEGIN - (id)copyWithZone:(nullable NSZone *)zone { SDLRPCStruct *newStruct = [[[self class] allocWithZone:zone] initWithDictionary:_store]; + newStruct.payloadProtected = self.payloadProtected; return newStruct; } diff --git a/SmartDeviceLink/SDLSequentialRPCRequestOperation.m b/SmartDeviceLink/SDLSequentialRPCRequestOperation.m index c302297cf..43b025947 100644 --- a/SmartDeviceLink/SDLSequentialRPCRequestOperation.m +++ b/SmartDeviceLink/SDLSequentialRPCRequestOperation.m @@ -81,7 +81,7 @@ NS_ASSUME_NONNULL_BEGIN // Send the next request SDLRPCRequest *request = self.requests[self.currentRequestIndex]; - [self.connectionManager sendConnectionRequest:(__kindof SDLRPCRequest *)request withEncryption:NO withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [self.connectionManager sendConnectionRequest:(__kindof SDLRPCRequest *)request withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { self.requestsComplete++; // If this request failed and no request has yet failed, set our internal request failed to YES diff --git a/SmartDeviceLink/SDLSoftButtonReplaceOperation.m b/SmartDeviceLink/SDLSoftButtonReplaceOperation.m index 53033f420..c967e10a9 100644 --- a/SmartDeviceLink/SDLSoftButtonReplaceOperation.m +++ b/SmartDeviceLink/SDLSoftButtonReplaceOperation.m @@ -198,7 +198,7 @@ NS_ASSUME_NONNULL_BEGIN show.mainField1 = self.mainField1; show.softButtons = [softButtons copy]; - [self.connectionManager sendConnectionRequest:show withEncryption:NO withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [self.connectionManager sendConnectionRequest:show withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { if (error != nil) { SDLLogW(@"Failed to update soft buttons with text buttons: %@", error); } @@ -235,7 +235,7 @@ NS_ASSUME_NONNULL_BEGIN show.mainField1 = self.mainField1; show.softButtons = [textButtons copy]; - [self.connectionManager sendConnectionRequest:show withEncryption:NO withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [self.connectionManager sendConnectionRequest:show withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { if (error != nil) { SDLLogW(@"Failed to update soft buttons with text buttons: %@", error); } diff --git a/SmartDeviceLink/SDLSoftButtonTransitionOperation.m b/SmartDeviceLink/SDLSoftButtonTransitionOperation.m index 293924887..862df6c5e 100644 --- a/SmartDeviceLink/SDLSoftButtonTransitionOperation.m +++ b/SmartDeviceLink/SDLSoftButtonTransitionOperation.m @@ -53,7 +53,7 @@ NS_ASSUME_NONNULL_BEGIN newShow.mainField1 = self.mainField1; newShow.softButtons = [self sdl_currentStateSoftButtonsForObjects:self.softButtons]; - [self.connectionManager sendConnectionRequest:newShow withEncryption:NO withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [self.connectionManager sendConnectionRequest:newShow withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { if (error != nil) { SDLLogW(@"Failed to transition soft button to new state. Error: %@, Response: %@", error, response); self.internalError = error; diff --git a/SmartDeviceLink/SDLSystemCapabilityManager.m b/SmartDeviceLink/SDLSystemCapabilityManager.m index 7cf663fbb..ceeea6c3c 100644 --- a/SmartDeviceLink/SDLSystemCapabilityManager.m +++ b/SmartDeviceLink/SDLSystemCapabilityManager.m @@ -267,7 +267,7 @@ typedef NSString * SDLServiceID; */ - (void)sdl_sendGetSystemCapability:(SDLGetSystemCapability *)getSystemCapability completionHandler:(nullable SDLUpdateCapabilityHandler)handler { __weak typeof(self) weakSelf = self; - [self.connectionManager sendConnectionRequest:getSystemCapability withEncryption:NO withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [self.connectionManager sendConnectionRequest:getSystemCapability withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { if (error != nil) { // An error is returned if the request was unsuccessful or if a Generic Response was returned if (handler == nil) { return; } diff --git a/SmartDeviceLink/SDLTextAndGraphicManager.m b/SmartDeviceLink/SDLTextAndGraphicManager.m index 0646ff3d0..5692ddaf3 100644 --- a/SmartDeviceLink/SDLTextAndGraphicManager.m +++ b/SmartDeviceLink/SDLTextAndGraphicManager.m @@ -205,7 +205,7 @@ NS_ASSUME_NONNULL_BEGIN if (self.inProgressUpdate == nil) { return; } - [self.connectionManager sendConnectionRequest:self.inProgressUpdate withEncryption:NO withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [self.connectionManager sendConnectionRequest:self.inProgressUpdate withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { __strong typeof(weakSelf) strongSelf = weakSelf; SDLLogD(@"Text and Graphic update completed"); diff --git a/SmartDeviceLinkTests/TestMultipleFilesConnectionManager.m b/SmartDeviceLinkTests/TestMultipleFilesConnectionManager.m index a58f63e07..ef4756bda 100644 --- a/SmartDeviceLinkTests/TestMultipleFilesConnectionManager.m +++ b/SmartDeviceLinkTests/TestMultipleFilesConnectionManager.m @@ -19,8 +19,8 @@ NS_ASSUME_NONNULL_BEGIN @implementation TestMultipleFilesConnectionManager -- (void)sendConnectionRequest:(__kindof SDLRPCRequest *)request withEncryption:(BOOL)encryption withResponseHandler:(nullable SDLResponseHandler)handler { - [super sendConnectionRequest:request withEncryption:encryption withResponseHandler:handler]; +- (void)sendConnectionRequest:(__kindof SDLRPCRequest *)request withResponseHandler:(nullable SDLResponseHandler)handler { + [super sendConnectionRequest:request withResponseHandler:handler]; if ([[request name] isEqualToString:SDLRPCFunctionNamePutFile]) { SDLPutFile *putfileRequest = (SDLPutFile *)request; diff --git a/SmartDeviceLinkTests/TestUtilities/TestConnectionManager.m b/SmartDeviceLinkTests/TestUtilities/TestConnectionManager.m index 1d3a1190e..4f823a4e6 100644 --- a/SmartDeviceLinkTests/TestUtilities/TestConnectionManager.m +++ b/SmartDeviceLinkTests/TestUtilities/TestConnectionManager.m @@ -31,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN [self.receivedRequests addObject:rpc]; } -- (void)sendConnectionRequest:(__kindof SDLRPCRequest *)request withEncryption:(BOOL)encryption withResponseHandler:(nullable SDLResponseHandler)handler { +- (void)sendConnectionRequest:(__kindof SDLRPCRequest *)request withResponseHandler:(nullable SDLResponseHandler)handler { self.lastRequestBlock = handler; SDLRPCRequest *requestRPC = (SDLRPCRequest *)request; requestRPC.correlationID = [self test_nextCorrelationID]; @@ -39,12 +39,12 @@ NS_ASSUME_NONNULL_BEGIN } - (void)sendConnectionManagerRequest:(__kindof SDLRPCRequest *)request withResponseHandler:(nullable SDLResponseHandler)handler { - [self sendConnectionRequest:request withEncryption:NO withResponseHandler:handler]; + [self sendConnectionRequest:request withResponseHandler:handler]; } - (void)sendRequests:(nonnull NSArray<SDLRPCRequest *> *)requests progressHandler:(nullable SDLMultipleAsyncRequestProgressHandler)progressHandler completionHandler:(nullable SDLMultipleRequestCompletionHandler)completionHandler { [requests enumerateObjectsUsingBlock:^(SDLRPCRequest * _Nonnull request, NSUInteger idx, BOOL * _Nonnull stop) { - [self sendConnectionRequest:request withEncryption:NO withResponseHandler:nil]; + [self sendConnectionRequest:request withResponseHandler:nil]; if (progressHandler != nil) { progressHandler(request, nil, nil, (double)idx / (double)requests.count); @@ -56,7 +56,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)sendSequentialRequests:(nonnull NSArray<SDLRPCRequest *> *)requests progressHandler:(nullable SDLMultipleSequentialRequestProgressHandler)progressHandler completionHandler:(nullable SDLMultipleRequestCompletionHandler)completionHandler { [requests enumerateObjectsUsingBlock:^(SDLRPCRequest * _Nonnull request, NSUInteger idx, BOOL * _Nonnull stop) { - [self sendConnectionRequest:request withEncryption:NO withResponseHandler:nil]; + [self sendConnectionRequest:request withResponseHandler:nil]; progressHandler(request, nil, nil, (double)idx / (double)requests.count); }]; diff --git a/SmartDeviceLinkTests/TestUtilities/TestMultipleRequestsConnectionManager.m b/SmartDeviceLinkTests/TestUtilities/TestMultipleRequestsConnectionManager.m index 223444c42..b1935a8ab 100644 --- a/SmartDeviceLinkTests/TestUtilities/TestMultipleRequestsConnectionManager.m +++ b/SmartDeviceLinkTests/TestUtilities/TestMultipleRequestsConnectionManager.m @@ -28,8 +28,8 @@ [super sendConnectionRPC:rpc]; } -- (void)sendConnectionRequest:(__kindof SDLRPCRequest *)request withEncryption:(BOOL)encryption withResponseHandler:(nullable SDLResponseHandler)handler { - [super sendConnectionRequest:request withEncryption:NO withResponseHandler:handler]; +- (void)sendConnectionRequest:(__kindof SDLRPCRequest *)request withResponseHandler:(nullable SDLResponseHandler)handler { + [super sendConnectionRequest:request withResponseHandler:handler]; NSAssert([request.name isEqualToString:SDLRPCFunctionNameAddCommand], @"The TestMultipleRequestsConnectionManager is only setup for SDLAddCommand"); |