summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSatbir Tanda <satbirtanda@gmail.com>2019-08-15 18:00:19 -0700
committerSatbir Tanda <satbirtanda@gmail.com>2019-08-15 18:00:19 -0700
commitc2523d123e85c89c78599ae75e4d58ef67b56257 (patch)
treecb1b19b629d0305c8b2e4021e281e8b33cb31a18
parent15131df748cd00f7e2867d866a299f74cbeeb191 (diff)
downloadsdl_ios-c2523d123e85c89c78599ae75e4d58ef67b56257.tar.gz
Check RPC payloadProtected in SDLProtocol layer
-rw-r--r--SmartDeviceLink/SDLEncryptionLifecycleManager.h7
-rw-r--r--SmartDeviceLink/SDLEncryptionLifecycleManager.m18
-rw-r--r--SmartDeviceLink/SDLLifecycleManager.m19
-rw-r--r--SmartDeviceLink/SDLPermissionManager.h5
-rw-r--r--SmartDeviceLink/SDLPermissionManager.m8
-rw-r--r--SmartDeviceLink/SDLProtocol.h11
-rw-r--r--SmartDeviceLink/SDLProtocol.m25
-rw-r--r--SmartDeviceLink/SDLProxy.h27
-rw-r--r--SmartDeviceLink/SDLProxy.m53
9 files changed, 120 insertions, 53 deletions
diff --git a/SmartDeviceLink/SDLEncryptionLifecycleManager.h b/SmartDeviceLink/SDLEncryptionLifecycleManager.h
index 5d6248c79..7c4eb7c58 100644
--- a/SmartDeviceLink/SDLEncryptionLifecycleManager.h
+++ b/SmartDeviceLink/SDLEncryptionLifecycleManager.h
@@ -47,12 +47,9 @@ NS_ASSUME_NONNULL_BEGIN
- (void)stop;
/**
- * Send an Encrypted 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 handler The handler that will be called when the response returns
+ * Check whether or not an RPC needs encryption
*/
-- (void)sendEncryptedRequest:(__kindof SDLRPCMessage *)request withResponseHandler:(nullable SDLResponseHandler)handler;
+- (BOOL)rpcRequiresEncryption:(__kindof SDLRPCMessage *)rpc;
@end
diff --git a/SmartDeviceLink/SDLEncryptionLifecycleManager.m b/SmartDeviceLink/SDLEncryptionLifecycleManager.m
index a6b7bfa15..cc5e0b181 100644
--- a/SmartDeviceLink/SDLEncryptionLifecycleManager.m
+++ b/SmartDeviceLink/SDLEncryptionLifecycleManager.m
@@ -71,21 +71,6 @@
SDLLogD(@"Stopping encryption manager");
}
-- (void)sendEncryptedRequest:(SDLRPCRequest *)request withResponseHandler:(SDLResponseHandler)handler {
- if (!self.protocol || !self.isEncryptionReady) {
- 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 responseHandler:handler];
-
- [self.rpcOperationQueue addOperation:op];
-}
-
- (BOOL)isEncryptionReady {
return [self.encryptionStateMachine isCurrentState:SDLEncryptionLifecycleManagerStateReady];
}
@@ -128,7 +113,6 @@
#pragma mark - State Machine
- (void)didEnterStateEncryptionStarting {
SDLLogD(@"Encryption manager is starting");
-
[self sdl_sendEncryptionStartService];
}
@@ -137,7 +121,7 @@
}
- (void)didEnterStateEncryptionStopped {
- SDLLogD(@"Encryption manager stopped");
+ SDLLogD(@"Encryption manager stopped");
}
#pragma mark - SDLProtocolListener
diff --git a/SmartDeviceLink/SDLLifecycleManager.m b/SmartDeviceLink/SDLLifecycleManager.m
index 89030fcf3..6b6e7ac23 100644
--- a/SmartDeviceLink/SDLLifecycleManager.m
+++ b/SmartDeviceLink/SDLLifecycleManager.m
@@ -237,13 +237,15 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask
self.proxy = [SDLProxy tcpProxyWithListener:self.notificationDispatcher
tcpIPAddress:self.configuration.lifecycleConfig.tcpDebugIPAddress
tcpPort:@(self.configuration.lifecycleConfig.tcpDebugPort).stringValue
- secondaryTransportManager:self.secondaryTransportManager];
+ secondaryTransportManager:self.secondaryTransportManager
+ encryptionLifecycleManager:self.encryptionLifecycleManager];
} else {
// we reuse our queue to run secondary transport manager's state machine
self.secondaryTransportManager = [[SDLSecondaryTransportManager alloc] initWithStreamingProtocolDelegate:self
serialQueue:self.lifecycleQueue];
self.proxy = [SDLProxy iapProxyWithListener:self.notificationDispatcher
- secondaryTransportManager:self.secondaryTransportManager];
+ secondaryTransportManager:self.secondaryTransportManager
+ encryptionLifecycleManager:self.encryptionLifecycleManager];
}
#pragma clang diagnostic pop
}
@@ -644,19 +646,6 @@ NSString *const BackgroundTaskTransportName = @"com.sdl.transport.backgroundTask
return;
}
- if (!request.isPayloadProtected && [self.permissionManager rpcRequiresEncryption:request]) {
- request.payloadProtected = YES;
- }
-
- if (request.isPayloadProtected && !self.encryptionLifecycleManager.isEncryptionReady) {
- SDLLogW(@"Encryption Manager not ready, request not sent (%@)", request);
- if (handler) {
- handler(request, nil, [NSError sdl_encryption_lifecycle_notReadyError]);
- }
-
- return;
- }
-
[self sdl_sendRequest:request withResponseHandler:handler];
}
diff --git a/SmartDeviceLink/SDLPermissionManager.h b/SmartDeviceLink/SDLPermissionManager.h
index e4e7d9cc6..038d34145 100644
--- a/SmartDeviceLink/SDLPermissionManager.h
+++ b/SmartDeviceLink/SDLPermissionManager.h
@@ -89,11 +89,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)removeObserverForIdentifier:(SDLPermissionObserverIdentifier)identifier;
-/**
- * Check whether or not an RPC needs encryption
- */
-- (BOOL)rpcRequiresEncryption:(__kindof SDLRPCMessage *)rpc;
-
@end
NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLink/SDLPermissionManager.m b/SmartDeviceLink/SDLPermissionManager.m
index d88737762..92d003c8c 100644
--- a/SmartDeviceLink/SDLPermissionManager.m
+++ b/SmartDeviceLink/SDLPermissionManager.m
@@ -354,14 +354,6 @@ NS_ASSUME_NONNULL_BEGIN
return [modifiedPermissions copy];
}
-
-- (BOOL)rpcRequiresEncryption:(__kindof SDLRPCMessage *)rpc {
- if (self.permissions[rpc.name].requireEncryption != nil) {
- return self.permissions[rpc.name].requireEncryption.boolValue;
- }
- return NO;
-}
-
@end
NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLink/SDLProtocol.h b/SmartDeviceLink/SDLProtocol.h
index f5f751098..67fe46a02 100644
--- a/SmartDeviceLink/SDLProtocol.h
+++ b/SmartDeviceLink/SDLProtocol.h
@@ -9,6 +9,7 @@
#import "SDLSecurityType.h"
#import "SDLTransportDelegate.h"
+@class SDLEncryptionLifecycleManager;
@class SDLProtocolHeader;
@class SDLProtocolRecievedMessageRouter;
@class SDLRPCMessage;
@@ -61,6 +62,16 @@ extern NSString *const SDLProtocolSecurityErrorDomain;
*/
@property (strong, nonatomic, readonly, nullable) NSString *authToken;
+#pragma mark - Init
+/**
+ * Initialize the protocol with an encryption lifecycle manager.
+ *
+ * @param encryptionLifecycleManager An encryption lifecycle manager.
+ *
+ * @return An instance of SDLProtocol
+ */
+- (instancetype)initWithEncryptionLifecycleManager:(SDLEncryptionLifecycleManager *)encryptionLifecycleManager;
+
#pragma mark - Sending
/**
diff --git a/SmartDeviceLink/SDLProtocol.m b/SmartDeviceLink/SDLProtocol.m
index 17ef74db0..f502bdb75 100644
--- a/SmartDeviceLink/SDLProtocol.m
+++ b/SmartDeviceLink/SDLProtocol.m
@@ -11,6 +11,7 @@
#import "SDLControlFramePayloadRegisterSecondaryTransportNak.h"
#import "SDLControlFramePayloadRPCStartService.h"
#import "SDLControlFramePayloadRPCStartServiceAck.h"
+#import "SDLEncryptionLifecycleManager.h"
#import "SDLLogMacros.h"
#import "SDLGlobals.h"
#import "SDLPrioritizedObjectCollection.h"
@@ -46,6 +47,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nullable, strong, nonatomic) SDLProtocolReceivedMessageRouter *messageRouter;
@property (strong, nonatomic) NSMutableDictionary<SDLServiceTypeBox *, SDLProtocolHeader *> *serviceHeaders;
@property (assign, nonatomic) int32_t hashId;
+@property (nonatomic, strong) SDLEncryptionLifecycleManager *encryptionLifecycleManager;
// Readonly public properties
@property (strong, nonatomic, readwrite, nullable) NSString *authToken;
@@ -73,6 +75,20 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
+- (instancetype)initWithEncryptionLifecycleManager:(SDLEncryptionLifecycleManager *)encryptionLifecycleManager {
+ if (self = [super init]) {
+ _messageID = 0;
+ _hashId = SDLControlFrameInt32NotFound;
+ _prioritizedCollection = [[SDLPrioritizedObjectCollection alloc] init];
+ _protocolDelegateTable = [NSHashTable weakObjectsHashTable];
+ _serviceHeaders = [[NSMutableDictionary alloc] init];
+ _messageRouter = [[SDLProtocolReceivedMessageRouter alloc] init];
+ _messageRouter.delegate = self;
+ _encryptionLifecycleManager = encryptionLifecycleManager;
+ }
+
+ return self;
+}
#pragma mark - Service metadata
- (BOOL)storeHeader:(SDLProtocolHeader *)header forServiceType:(SDLServiceType)serviceType {
@@ -257,6 +273,15 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Send Data
- (void)sendRPC:(SDLRPCMessage *)message {
+ if (!message.isPayloadProtected && [self.encryptionLifecycleManager rpcRequiresEncryption:message]) {
+ message.payloadProtected = YES;
+ }
+
+ if (message.isPayloadProtected && !self.encryptionLifecycleManager.isEncryptionReady) {
+ SDLLogW(@"Encryption Manager not ready, request not sent (%@)", message);
+ return;
+ }
+
[self sendRPC:message encrypted:message.isPayloadProtected error:nil];
}
diff --git a/SmartDeviceLink/SDLProxy.h b/SmartDeviceLink/SDLProxy.h
index 9049cf93f..237823baa 100644
--- a/SmartDeviceLink/SDLProxy.h
+++ b/SmartDeviceLink/SDLProxy.h
@@ -1,6 +1,7 @@
// SDLProxy.h
//
+@class SDLEncryptionLifecycleManager;
@class SDLProtocol;
@class SDLPutFile;
@class SDLRPCMessage;
@@ -63,7 +64,7 @@ NS_ASSUME_NONNULL_BEGIN
* @param secondaryTransportManager The secondary transport manager
* @return A SDLProxy object
*/
-+ (SDLProxy *)iapProxyWithListener:(id<SDLProxyListener>)delegate secondaryTransportManager:(nullable SDLSecondaryTransportManager *)secondaryTransportManager;
++ (SDLProxy *)iapProxyWithListener:(id<SDLProxyListener>)delegate secondaryTransportManager:(nullable SDLSecondaryTransportManager *)secondaryTransportManager __deprecated_msg("Use iapProxyWithListener:secondaryTransportManager:encryptionLifecycleManager: instead");
/**
* Creates a SDLProxy object with a TCP (WiFi) transport network connection.
@@ -74,7 +75,29 @@ NS_ASSUME_NONNULL_BEGIN
* @param secondaryTransportManager The secondary transport manager
* @return A SDLProxy object
*/
-+ (SDLProxy *)tcpProxyWithListener:(id<SDLProxyListener>)delegate tcpIPAddress:(NSString *)ipaddress tcpPort:(NSString *)port secondaryTransportManager:(nullable SDLSecondaryTransportManager *)secondaryTransportManager;
++ (SDLProxy *)tcpProxyWithListener:(id<SDLProxyListener>)delegate tcpIPAddress:(NSString *)ipaddress tcpPort:(NSString *)port secondaryTransportManager:(nullable SDLSecondaryTransportManager *)secondaryTransportManager __deprecated_msg("Use tcpProxyWithListener:tcpIPAddress:tcpPort:secondaryTransportManager:encryptionLifecycleManager: instead");
+
+/**
+ * Creates a SDLProxy object with an iap (USB / Bluetooth) transport network connection.
+ *
+ * @param delegate The subscriber
+ * @param secondaryTransportManager The secondary transport manager
+ * @param encryptionLifecycleManager The encryption life cycle manager
+ * @return A SDLProxy object
+ */
++ (SDLProxy *)iapProxyWithListener:(id<SDLProxyListener>)delegate secondaryTransportManager:(nullable SDLSecondaryTransportManager *)secondaryTransportManager encryptionLifecycleManager:(SDLEncryptionLifecycleManager *)encryptionLifecycleManager;
+
+/**
+ * Creates a SDLProxy object with a TCP (WiFi) transport network connection.
+ *
+ * @param delegate The subscriber
+ * @param ipaddress The IP address of Core
+ * @param port The port address of Core
+ * @param secondaryTransportManager The secondary transport manager
+ * @param encryptionLifecycleManager The encryption life cycle manager
+ * @return A SDLProxy object
+ */
++ (SDLProxy *)tcpProxyWithListener:(id<SDLProxyListener>)delegate tcpIPAddress:(NSString *)ipaddress tcpPort:(NSString *)port secondaryTransportManager:(nullable SDLSecondaryTransportManager *)secondaryTransportManager encryptionLifecycleManager:(SDLEncryptionLifecycleManager *)encryptionLifecycleManager;
/**
* Adds a delegate.
diff --git a/SmartDeviceLink/SDLProxy.m b/SmartDeviceLink/SDLProxy.m
index 3b863e626..ae65a2e39 100644
--- a/SmartDeviceLink/SDLProxy.m
+++ b/SmartDeviceLink/SDLProxy.m
@@ -8,6 +8,7 @@
#import "SDLAudioStreamingState.h"
#import "SDLLogMacros.h"
#import "SDLEncodedSyncPData.h"
+#import "SDLEncryptionLifecycleManager.h"
#import "SDLFileType.h"
#import "SDLFunctionID.h"
#import "SDLGlobals.h"
@@ -39,7 +40,6 @@
#import "SDLUnsubscribeButton.h"
#import "SDLVehicleType.h"
#import "SDLVersion.h"
-#import "SDLPermissionManager.h"
#import "SDLRPCParameterNames.h"
#import "SDLRPCFunctionNames.h"
@@ -108,6 +108,42 @@ static float DefaultConnectionTimeout = 45.0;
return self;
}
+- (instancetype)initWithTransport:(id<SDLTransportType>)transport delegate:(id<SDLProxyListener>)delegate secondaryTransportManager:(nullable SDLSecondaryTransportManager *)secondaryTransportManager encryptionLifecycleManager:(SDLEncryptionLifecycleManager *)encryptionLifecycleManager {
+ if (self = [super init]) {
+ SDLLogD(@"Framework Version: %@", self.proxyVersion);
+ _lsm = [[SDLLockScreenStatusManager alloc] init];
+ _mutableProxyListeners = [NSMutableSet setWithObject:delegate];
+ _securityManagers = [NSMutableDictionary dictionary];
+
+ _protocol = [[SDLProtocol alloc] initWithEncryptionLifecycleManager:encryptionLifecycleManager];
+ _transport = transport;
+ _transport.delegate = _protocol;
+
+ [_protocol.protocolDelegateTable addObject:self];
+ _protocol.transport = transport;
+
+ // make sure that secondary transport manager is started prior to starting protocol
+ if (secondaryTransportManager != nil) {
+ [secondaryTransportManager startWithPrimaryProtocol:_protocol];
+ }
+
+ [self.transport connect];
+
+ SDLLogV(@"Proxy transport initialization");
+
+ NSURLSessionConfiguration* configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
+ configuration.timeoutIntervalForRequest = DefaultConnectionTimeout;
+ configuration.timeoutIntervalForResource = DefaultConnectionTimeout;
+ configuration.requestCachePolicy = NSURLRequestUseProtocolCachePolicy;
+
+ _urlSession = [NSURLSession sessionWithConfiguration:configuration];
+
+ }
+
+ return self;
+}
+
+
+ (SDLProxy *)iapProxyWithListener:(id<SDLProxyListener>)delegate secondaryTransportManager:(nullable SDLSecondaryTransportManager *)secondaryTransportManager {
SDLIAPTransport *transport = [[SDLIAPTransport alloc] init];
SDLProxy *ret = [[SDLProxy alloc] initWithTransport:transport delegate:delegate secondaryTransportManager:secondaryTransportManager];
@@ -123,6 +159,21 @@ static float DefaultConnectionTimeout = 45.0;
return ret;
}
++ (SDLProxy *)iapProxyWithListener:(id<SDLProxyListener>)delegate secondaryTransportManager:(nullable SDLSecondaryTransportManager *)secondaryTransportManager encryptionLifecycleManager:(SDLEncryptionLifecycleManager *)encryptionLifecycleManager {
+ SDLIAPTransport *transport = [[SDLIAPTransport alloc] init];
+ SDLProxy *ret = [[SDLProxy alloc] initWithTransport:transport delegate:delegate secondaryTransportManager:secondaryTransportManager encryptionLifecycleManager:encryptionLifecycleManager];
+
+ return ret;
+}
+
++ (SDLProxy *)tcpProxyWithListener:(id<SDLProxyListener>)delegate tcpIPAddress:(NSString *)ipaddress tcpPort:(NSString *)port secondaryTransportManager:(nullable SDLSecondaryTransportManager *)secondaryTransportManager encryptionLifecycleManager:(SDLEncryptionLifecycleManager *)encryptionLifecycleManager {
+ SDLTCPTransport *transport = [[SDLTCPTransport alloc] initWithHostName:ipaddress portNumber:port];
+
+ SDLProxy *ret = [[SDLProxy alloc] initWithTransport:transport delegate:delegate secondaryTransportManager:secondaryTransportManager encryptionLifecycleManager:encryptionLifecycleManager];
+
+ return ret;
+}
+
- (void)dealloc {
if (self.protocol.securityManager != nil) {
[self.protocol.securityManager stop];