Skip to content

Commit

Permalink
Merge pull request #1320 from SatbirTanda/feature/#1163/rpc_message_p…
Browse files Browse the repository at this point in the history
…rotection

Implement SDL-0207 RPC Message Protection
  • Loading branch information
joeljfischer committed Oct 10, 2019
2 parents 2e82d5e + e285356 commit af56e0a
Show file tree
Hide file tree
Showing 53 changed files with 1,300 additions and 81 deletions.
3 changes: 3 additions & 0 deletions SmartDeviceLink-iOS.podspec
Expand Up @@ -114,6 +114,7 @@ ss.public_header_files = [
'SmartDeviceLink/SDLECallConfirmationStatus.h',
'SmartDeviceLink/SDLECallInfo.h',
'SmartDeviceLink/SDLElectronicParkBrakeStatus.h',
'SmartDeviceLink/SDLEncryptionConfiguration.h',
'SmartDeviceLink/SDLEmergencyEvent.h',
'SmartDeviceLink/SDLEmergencyEventType.h',
'SmartDeviceLink/SDLEncodedSyncPData.h',
Expand Down Expand Up @@ -279,6 +280,7 @@ ss.public_header_files = [
'SmartDeviceLink/SDLPresetBankCapabilities.h',
'SmartDeviceLink/SDLPrimaryAudioSource.h',
'SmartDeviceLink/SDLPRNDL.h',
'SmartDeviceLink/SDLProtocolConstants.h',
'SmartDeviceLink/SDLPublishAppService.h',
'SmartDeviceLink/SDLPublishAppServiceResponse.h',
'SmartDeviceLink/SDLPutFile.h',
Expand Down Expand Up @@ -329,6 +331,7 @@ ss.public_header_files = [
'SmartDeviceLink/SDLSendHapticDataResponse.h',
'SmartDeviceLink/SDLSendLocation.h',
'SmartDeviceLink/SDLSendLocationResponse.h',
'SmartDeviceLink/SDLServiceEncryptionDelegate.h',
'SmartDeviceLink/SDLServiceUpdateReason.h',
'SmartDeviceLink/SDLSetAppIcon.h',
'SmartDeviceLink/SDLSetAppIconResponse.h',
Expand Down
86 changes: 85 additions & 1 deletion SmartDeviceLink-iOS.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions SmartDeviceLink.podspec
Expand Up @@ -115,6 +115,7 @@ sdefault.public_header_files = [
'SmartDeviceLink/SDLECallConfirmationStatus.h',
'SmartDeviceLink/SDLECallInfo.h',
'SmartDeviceLink/SDLElectronicParkBrakeStatus.h',
'SmartDeviceLink/SDLEncryptionConfiguration.h',
'SmartDeviceLink/SDLEmergencyEvent.h',
'SmartDeviceLink/SDLEmergencyEventType.h',
'SmartDeviceLink/SDLEncodedSyncPData.h',
Expand Down Expand Up @@ -280,6 +281,7 @@ sdefault.public_header_files = [
'SmartDeviceLink/SDLPresetBankCapabilities.h',
'SmartDeviceLink/SDLPrimaryAudioSource.h',
'SmartDeviceLink/SDLPRNDL.h',
'SmartDeviceLink/SDLProtocolConstants.h',
'SmartDeviceLink/SDLPublishAppService.h',
'SmartDeviceLink/SDLPublishAppServiceResponse.h',
'SmartDeviceLink/SDLPutFile.h',
Expand Down Expand Up @@ -330,6 +332,7 @@ sdefault.public_header_files = [
'SmartDeviceLink/SDLSendHapticDataResponse.h',
'SmartDeviceLink/SDLSendLocation.h',
'SmartDeviceLink/SDLSendLocationResponse.h',
'SmartDeviceLink/SDLServiceEncryptionDelegate.h',
'SmartDeviceLink/SDLServiceUpdateReason.h',
'SmartDeviceLink/SDLSetAppIcon.h',
'SmartDeviceLink/SDLSetAppIconResponse.h',
Expand Down
35 changes: 33 additions & 2 deletions SmartDeviceLink/SDLConfiguration.h
Expand Up @@ -13,6 +13,7 @@
@class SDLLockScreenConfiguration;
@class SDLLogConfiguration;
@class SDLStreamingMediaConfiguration;
@class SDLEncryptionConfiguration;

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -43,6 +44,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (copy, nonatomic, readonly) SDLFileManagerConfiguration *fileManagerConfig;

/**
* The encryption configuration.
*/
@property (copy, nonatomic, readonly) SDLEncryptionConfiguration *encryptionConfig;

/**
* Creates a new configuration to be passed to the SDLManager with custom lifecycle, lock screen and logging configurations.
*
Expand All @@ -62,7 +68,19 @@ NS_ASSUME_NONNULL_BEGIN
* @param fileManagerConfig The file manager configuration to be used or `defaultConfiguration` if nil.
* @return The configuration
*/
- (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig logging:(nullable SDLLogConfiguration *)logConfig fileManager:(nullable SDLFileManagerConfiguration *)fileManagerConfig;
- (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig logging:(nullable SDLLogConfiguration *)logConfig fileManager:(nullable SDLFileManagerConfiguration *)fileManagerConfig __deprecated_msg("Use initWithLifecycle:lockScreen:logging:fileManager:encryption: instead");

/**
* Creates a new configuration to be passed to the SDLManager with custom lifecycle, lock screen, logging, file manager and encryption configurations.
*
* @param lifecycleConfig The lifecycle configuration to be used.
* @param lockScreenConfig The lockscreen configuration to be used. If nil, the `enabledConfiguration` will be used.
* @param logConfig The logging configuration to be used. If nil, the `defaultConfiguration` will be used.
* @param fileManagerConfig The file manager configuration to be used or `defaultConfiguration` if nil.
* @param encryptionConfig The encryption configuration to be used. If nil, the `defaultConfiguration` will be used.
* @return The configuration
*/
- (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig logging:(nullable SDLLogConfiguration *)logConfig fileManager:(nullable SDLFileManagerConfiguration *)fileManagerConfig encryption:(nullable SDLEncryptionConfiguration *)encryptionConfig;

/**
* Creates a new configuration to be passed to the SDLManager with custom lifecycle, lock screen and logging configurations.
Expand Down Expand Up @@ -106,7 +124,20 @@ NS_ASSUME_NONNULL_BEGIN
* @param fileManagerConfig The file manager configuration to be used or `defaultConfiguration` if nil.
* @return The configuration
*/
- (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig logging:(nullable SDLLogConfiguration *)logConfig streamingMedia:(nullable SDLStreamingMediaConfiguration *)streamingMediaConfig fileManager:(nullable SDLFileManagerConfiguration *)fileManagerConfig;
- (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig logging:(nullable SDLLogConfiguration *)logConfig streamingMedia:(nullable SDLStreamingMediaConfiguration *)streamingMediaConfig fileManager:(nullable SDLFileManagerConfiguration *)fileManagerConfig __deprecated_msg("Use initWithLifecycle:lockScreen:logging:streamingMedia:fileManager:encryption: instead");

/**
* Creates a new configuration to be passed to the SDLManager with custom lifecycle, lock screen, logging, streaming media, file manager and encryption configurations.
*
* @param lifecycleConfig The lifecycle configuration to be used.
* @param lockScreenConfig The lockscreen configuration to be used. If nil, the `enabledConfiguration` will be used.
* @param logConfig The logging configuration to be used. If nil, the `defaultConfiguration` will be used.
* @param streamingMediaConfig The streaming media configuration to be used or nil if not used.
* @param fileManagerConfig The file manager configuration to be used or `defaultConfiguration` if nil.
* @param encryptionConfig The encryption configuration to be used. If nil, the `defaultConfiguration` will be used.
* @return The configuration
*/
- (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig logging:(nullable SDLLogConfiguration *)logConfig streamingMedia:(nullable SDLStreamingMediaConfiguration *)streamingMediaConfig fileManager:(nullable SDLFileManagerConfiguration *)fileManagerConfig encryption:(nullable SDLEncryptionConfiguration *)encryptionConfig;

/**
* Creates a new configuration to be passed to the SDLManager with custom lifecycle, lock screen, logging and streaming media configurations.
Expand Down
23 changes: 17 additions & 6 deletions SmartDeviceLink/SDLConfiguration.m
Expand Up @@ -13,6 +13,7 @@
#import "SDLLockScreenConfiguration.h"
#import "SDLLogConfiguration.h"
#import "SDLStreamingMediaConfiguration.h"
#import "SDLEncryptionConfiguration.h"

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -23,14 +24,18 @@ - (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfigur
}

- (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig {
return [self initWithLifecycle:lifecycleConfig lockScreen:lockScreenConfig logging:nil fileManager:nil];
return [self initWithLifecycle:lifecycleConfig lockScreen:lockScreenConfig logging:nil fileManager:nil encryption: nil];
}

- (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig logging:(nullable SDLLogConfiguration *)logConfig {
return [self initWithLifecycle:lifecycleConfig lockScreen:lockScreenConfig logging:logConfig fileManager:nil];
return [self initWithLifecycle:lifecycleConfig lockScreen:lockScreenConfig logging:logConfig fileManager:nil encryption: nil];
}

- (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig logging:(nullable SDLLogConfiguration *)logConfig fileManager:(nullable SDLFileManagerConfiguration *)fileManagerConfig {
return [self initWithLifecycle:lifecycleConfig lockScreen:lockScreenConfig logging:logConfig fileManager:fileManagerConfig encryption:nil];
}

- (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig logging:(nullable SDLLogConfiguration *)logConfig fileManager:(nullable SDLFileManagerConfiguration *)fileManagerConfig encryption:(nullable SDLEncryptionConfiguration *)encryptionConfig {
self = [super init];
if (!self) {
return nil;
Expand All @@ -40,6 +45,7 @@ - (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig l
_lockScreenConfig = lockScreenConfig ?: [SDLLockScreenConfiguration enabledConfiguration];
_loggingConfig = logConfig ?: [SDLLogConfiguration defaultConfiguration];
_fileManagerConfig = fileManagerConfig ?: [SDLFileManagerConfiguration defaultConfiguration];
_encryptionConfig = encryptionConfig ?: [SDLEncryptionConfiguration defaultConfiguration];

return self;
}
Expand All @@ -57,14 +63,18 @@ + (instancetype)configurationWithLifecycle:(SDLLifecycleConfiguration *)lifecycl
}

+ (instancetype)configurationWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig logging:(nullable SDLLogConfiguration *)logConfig fileManager:(nullable SDLFileManagerConfiguration *)fileManagerConfig {
return [[self alloc] initWithLifecycle:lifecycleConfig lockScreen:lockScreenConfig logging:logConfig fileManager:fileManagerConfig];
return [[self alloc] initWithLifecycle:lifecycleConfig lockScreen:lockScreenConfig logging:logConfig fileManager:fileManagerConfig encryption: nil];
}

- (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig logging:(nullable SDLLogConfiguration *)logConfig streamingMedia:(nullable SDLStreamingMediaConfiguration *)streamingMediaConfig {
return [self initWithLifecycle:lifecycleConfig lockScreen:lockScreenConfig logging:logConfig streamingMedia:streamingMediaConfig fileManager:nil];
return [self initWithLifecycle:lifecycleConfig lockScreen:lockScreenConfig logging:logConfig streamingMedia:streamingMediaConfig fileManager:nil encryption:nil];
}

- (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig logging:(nullable SDLLogConfiguration *)logConfig streamingMedia:(nullable SDLStreamingMediaConfiguration *)streamingMediaConfig fileManager:(nullable SDLFileManagerConfiguration *)fileManagerConfig {
return [self initWithLifecycle:lifecycleConfig lockScreen:lockScreenConfig logging:logConfig streamingMedia:streamingMediaConfig fileManager:fileManagerConfig encryption:nil];
}

- (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig logging:(nullable SDLLogConfiguration *)logConfig streamingMedia:(nullable SDLStreamingMediaConfiguration *)streamingMediaConfig fileManager:(nullable SDLFileManagerConfiguration *)fileManagerConfig encryption:(nullable SDLEncryptionConfiguration *)encryptionConfig {
self = [super init];
if (!self) {
return nil;
Expand All @@ -85,6 +95,7 @@ - (instancetype)initWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig l
}

_fileManagerConfig = fileManagerConfig ?: [SDLFileManagerConfiguration defaultConfiguration];
_encryptionConfig = encryptionConfig ?: [SDLEncryptionConfiguration defaultConfiguration];

return self;
}
Expand All @@ -94,13 +105,13 @@ + (instancetype)configurationWithLifecycle:(SDLLifecycleConfiguration *)lifecycl
}

+ (instancetype)configurationWithLifecycle:(SDLLifecycleConfiguration *)lifecycleConfig lockScreen:(nullable SDLLockScreenConfiguration *)lockScreenConfig logging:(nullable SDLLogConfiguration *)logConfig streamingMedia:(nullable SDLStreamingMediaConfiguration *)streamingMediaConfig fileManager:(nullable SDLFileManagerConfiguration *)fileManagerConfig {
return [[self alloc] initWithLifecycle:lifecycleConfig lockScreen:lockScreenConfig logging:logConfig streamingMedia:streamingMediaConfig fileManager:fileManagerConfig];
return [[self alloc] initWithLifecycle:lifecycleConfig lockScreen:lockScreenConfig logging:logConfig streamingMedia:streamingMediaConfig fileManager:fileManagerConfig encryption:nil];
}

#pragma mark - NSCopying

- (id)copyWithZone:(nullable NSZone *)zone {
SDLConfiguration *new = [[SDLConfiguration allocWithZone:zone] initWithLifecycle:_lifecycleConfig lockScreen:_lockScreenConfig logging:_loggingConfig streamingMedia:_streamingMediaConfig fileManager:_fileManagerConfig];
SDLConfiguration *new = [[SDLConfiguration allocWithZone:zone] initWithLifecycle:_lifecycleConfig lockScreen:_lockScreenConfig logging:_loggingConfig streamingMedia:_streamingMediaConfig fileManager:_fileManagerConfig encryption:_encryptionConfig];
return new;
}

Expand Down
47 changes: 47 additions & 0 deletions SmartDeviceLink/SDLEncryptionConfiguration.h
@@ -0,0 +1,47 @@
//
// SDLEncryptionConfiguration.h
// SmartDeviceLink
//
// Created by standa1 on 6/17/19.
// Copyright © 2019 smartdevicelink. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "SDLServiceEncryptionDelegate.h"

@protocol SDLSecurityType;

NS_ASSUME_NONNULL_BEGIN

@interface SDLEncryptionConfiguration : NSObject <NSCopying>

/**
* A set of security managers used to encrypt traffic data. Each OEM has their own proprietary security manager.
*/
@property (copy, nonatomic, nullable) NSArray<Class<SDLSecurityType>> *securityManagers;

/**
* A delegate callback that will tell you when an acknowledgement has occurred for starting as secure service.
*/
@property (copy, nonatomic, nullable) id<SDLServiceEncryptionDelegate> delegate;

/**
* Creates a default encryption configuration.
*
* @return A default configuration that may be customized.
*/
+ (instancetype)defaultConfiguration;

/**
Creates a secure configuration for each of the security managers provided.
@param securityManagers The security managers to be used.
@param delegate The delegate callback.
@return The configuration
*/
- (instancetype)initWithSecurityManagers:(nullable NSArray<Class<SDLSecurityType>> *)securityManagers delegate:(nullable id<SDLServiceEncryptionDelegate>)delegate;

@end

NS_ASSUME_NONNULL_END
45 changes: 45 additions & 0 deletions SmartDeviceLink/SDLEncryptionConfiguration.m
@@ -0,0 +1,45 @@
//
// SDLEncryptionConfiguration.m
// SmartDeviceLink
//
// Created by standa1 on 6/17/19.
// Copyright © 2019 smartdevicelink. All rights reserved.
//

#import "SDLEncryptionConfiguration.h"

NS_ASSUME_NONNULL_BEGIN

@implementation SDLEncryptionConfiguration

+ (instancetype)defaultConfiguration {
return [[self.class alloc] initWithSecurityManagers:nil delegate:nil];
}

- (instancetype)initWithSecurityManagers:(nullable NSArray<Class<SDLSecurityType>> *)securityManagers delegate:(nullable id<SDLServiceEncryptionDelegate>)delegate {
self = [super init];
if (!self) {
return nil;
}

_securityManagers = securityManagers;
_delegate = delegate;

return self;
}

#pragma mark - NSCopying

- (id)copyWithZone:(nullable NSZone *)zone {
SDLEncryptionConfiguration *newConfig = [[self.class allocWithZone:zone] init];

newConfig.securityManagers = self.securityManagers;
newConfig.delegate = self.delegate;

return newConfig;
}


@end

NS_ASSUME_NONNULL_END
59 changes: 59 additions & 0 deletions SmartDeviceLink/SDLEncryptionLifecycleManager.h
@@ -0,0 +1,59 @@
//
// SDLEncryptionLifecycleManager.h
// SmartDeviceLink
//
// Created by standa1 on 6/27/19.
// Copyright © 2019 smartdevicelink. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "SDLConnectionManagerType.h"
#import "SDLProtocolListener.h"

@class SDLEncryptionConfiguration;
@class SDLProtocol;

NS_ASSUME_NONNULL_BEGIN

@interface SDLEncryptionLifecycleManager : NSObject <SDLProtocolListener>

/**
* Whether or not the encryption session is connected.
*/
@property (assign, nonatomic, readonly, getter=isEncryptionReady) BOOL encryptionReady;


- (instancetype)init NS_UNAVAILABLE;

/**
Create a new encryption lifecycle manager for apps that need encryption.
@param connectionManager The pass-through for RPCs
@param configuration This session's configuration
@return A new encryption lifecycle manager
*/
- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager configuration:(SDLEncryptionConfiguration *)configuration;

/**
* Start the manager. This is used internally to get notified of the ACK message.
*/
- (void)startWithProtocol:(SDLProtocol *)protocol;

/**
* Stop the manager. This method is used internally.
*/
- (void)stop;

/**
* Check whether or not an RPC needs encryption.
*/
- (BOOL)rpcRequiresEncryption:(__kindof SDLRPCMessage *)rpc;

/**
* Attempt to manually start a secure service.
*/
- (void)startEncryptionService;

@end

NS_ASSUME_NONNULL_END

0 comments on commit af56e0a

Please sign in to comment.