diff --git a/Example/TSKitiOSTestApp/Podfile b/Example/TSKitiOSTestApp/Podfile index e5d403d7..a9fc04d7 100644 --- a/Example/TSKitiOSTestApp/Podfile +++ b/Example/TSKitiOSTestApp/Podfile @@ -2,8 +2,8 @@ platform :ios, '8.0' source 'https://github.com/CocoaPods/Specs.git' target 'TSKitiOSTestApp' do + pod 'SocketRocket', git: 'https://github.com/WhisperSystems/SocketRocket.git', branch: 'pluggable-security-policies' pod 'SignalServiceKit', :path => '../../SignalServiceKit.podspec' - pod 'SocketRocket', git: 'https://github.com/WhisperSystems/SocketRocket.git', branch: 'signal-ios' target 'TSKitiOSTestAppTests' do inherit! :search_paths diff --git a/Example/TSKitiOSTestApp/Podfile.lock b/Example/TSKitiOSTestApp/Podfile.lock index dfc8c5a0..a4812749 100644 --- a/Example/TSKitiOSTestApp/Podfile.lock +++ b/Example/TSKitiOSTestApp/Podfile.lock @@ -34,7 +34,7 @@ PODS: - Mantle/extobjc (2.0.7) - ProtocolBuffers (1.9.10) - Reachability (3.2) - - SignalServiceKit (0.0.4): + - SignalServiceKit (0.0.6): - '25519' - AFNetworking - AxolotlKit @@ -105,18 +105,18 @@ PODS: DEPENDENCIES: - SignalServiceKit (from `../../SignalServiceKit.podspec`) - - SocketRocket (from `https://github.com/WhisperSystems/SocketRocket.git`, branch `signal-ios`) + - SocketRocket (from `https://github.com/WhisperSystems/SocketRocket.git`, branch `pluggable-security-policies`) EXTERNAL SOURCES: SignalServiceKit: :path: "../../SignalServiceKit.podspec" SocketRocket: - :branch: signal-ios + :branch: pluggable-security-policies :git: https://github.com/WhisperSystems/SocketRocket.git CHECKOUT OPTIONS: SocketRocket: - :commit: 587ad297eb63eb0d64d4caeb32a7da646ad1132b + :commit: 934ee5a2959a5de4322394ad5d7807fbcd61b959 :git: https://github.com/WhisperSystems/SocketRocket.git SPEC CHECKSUMS: @@ -129,7 +129,7 @@ SPEC CHECKSUMS: Mantle: bc40bb061d8c2c6fb48d5083e04d928c3b7f73d9 ProtocolBuffers: d088180c10072b3d24a9939a6314b7b9bcc2340b Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96 - SignalServiceKit: e27a3025c2d5c61696386e44a50ac8d2fe83151e + SignalServiceKit: 850620cd1535f8628474121e7ea142ff1fe236a6 SocketRocket: 3f77ec2104cc113add553f817ad90a77114f5d43 SQLCipher: 4c768761421736a247ed6cf412d9045615d53dff SSKeychain: c71293fa57216a40ab06c23f4085387583293de4 @@ -137,6 +137,6 @@ SPEC CHECKSUMS: UnionFind: c33be5adb12983981d6e827ea94fc7f9e370f52d YapDatabase: c00f4197bba2fea17bdbd82c8e8e3f7104b6fa67 -PODFILE CHECKSUM: 6bebc6fc58d19a6a56c27878035f7a074da10006 +PODFILE CHECKSUM: 2954694f716c25ed9c0cbb599e1dae9612f0da5e COCOAPODS: 1.0.1 diff --git a/SignalServiceKit.podspec b/SignalServiceKit.podspec index 970228c7..a8e2fad9 100644 --- a/SignalServiceKit.podspec +++ b/SignalServiceKit.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = "SignalServiceKit" - s.version = "0.0.5" + s.version = "0.0.6" s.summary = "An Objective-C library for communicating with the Signal messaging service." s.description = <<-DESC diff --git a/src/Network/API/TSNetworkManager.m b/src/Network/API/TSNetworkManager.m index 8a7ebc1c..6c274afc 100644 --- a/src/Network/API/TSNetworkManager.m +++ b/src/Network/API/TSNetworkManager.m @@ -8,7 +8,7 @@ #import -#import "AFSecurityOWSPolicy.h" +#import "OWSHTTPSecurityPolicy.h" #import "NSURLSessionDataTask+StatusCode.h" #import "TSAccountManager.h" @@ -45,7 +45,7 @@ - (id)init { self.operationManager = [[AFHTTPSessionManager alloc] initWithBaseURL:[[NSURL alloc] initWithString:textSecureServerURL] sessionConfiguration:sessionConf]; - self.operationManager.securityPolicy = [AFSecurityOWSPolicy OWS_PinningPolicy]; + self.operationManager.securityPolicy = [OWSHTTPSecurityPolicy sharedPolicy]; } return self; } diff --git a/src/Network/WebSockets/TSSocketManager.m b/src/Network/WebSockets/TSSocketManager.m index e581fa40..e339e65a 100644 --- a/src/Network/WebSockets/TSSocketManager.m +++ b/src/Network/WebSockets/TSSocketManager.m @@ -14,7 +14,7 @@ #import "TSSocketManager.h" #import "TSStorageManager+keyingMaterial.h" -#import "AFSecurityOWSPolicy.h" +#import "OWSWebsocketSecurityPolicy.h" #import "Cryptography.h" #define kWebSocketHeartBeat 30 @@ -100,9 +100,8 @@ + (void)becomeActive { [textSecureWebSocketAPI stringByAppendingString:[[self sharedManager] webSocketAuthenticationString]]; NSURL *webSocketConnectURL = [NSURL URLWithString:webSocketConnect]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:webSocketConnectURL]; - request.SR_securityPolicy = [AFSecurityOWSPolicy OWS_PinningPolicy]; - socket = [[SRWebSocket alloc] initWithURLRequest:request]; + socket = [[SRWebSocket alloc] initWithURLRequest:request securityPolicy:[OWSWebsocketSecurityPolicy sharedPolicy]]; socket.delegate = [self sharedManager]; [[self sharedManager] setWebsocket:socket]; @@ -226,10 +225,11 @@ - (void)webSocket:(SRWebSocket *)webSocket } - (void)webSocketHeartBeat { - @try { - [self.websocket sendPing:nil]; - } @catch (NSException *exception) { - DDLogWarn(@"Caught exception while trying to write on the socket %@", exception.debugDescription); + NSError *error; + + [self.websocket sendPing:nil error:&error]; + if (error) { + DDLogWarn(@"Error in websocket heartbeat: %@", error.localizedDescription); } } diff --git a/src/Security/AFSecurityOWSPolicy.h b/src/Security/AFSecurityOWSPolicy.h deleted file mode 100644 index 555535cd..00000000 --- a/src/Security/AFSecurityOWSPolicy.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// AFSecurityPolicyNone.h -// Signal -// -// Created by Fred on 01/09/15. -// Copyright © 2015 Open Whisper Systems. All rights reserved. -// - -#import -#import "AFSecurityPolicy.h" - -@interface AFSecurityOWSPolicy : AFSecurityPolicy - -+ (instancetype)OWS_PinningPolicy; - -@end diff --git a/src/Security/OWSHTTPSecurityPolicy.h b/src/Security/OWSHTTPSecurityPolicy.h new file mode 100644 index 00000000..10057838 --- /dev/null +++ b/src/Security/OWSHTTPSecurityPolicy.h @@ -0,0 +1,12 @@ +// +// Created by Fred on 01/09/15. +// Copyright © 2015 Open Whisper Systems. All rights reserved. +// + +#import + +@interface OWSHTTPSecurityPolicy : AFSecurityPolicy + ++ (instancetype)sharedPolicy; + +@end diff --git a/src/Security/AFSecurityOWSPolicy.m b/src/Security/OWSHTTPSecurityPolicy.m similarity index 87% rename from src/Security/AFSecurityOWSPolicy.m rename to src/Security/OWSHTTPSecurityPolicy.m index a75b9470..ad7dc14c 100644 --- a/src/Security/AFSecurityOWSPolicy.m +++ b/src/Security/OWSHTTPSecurityPolicy.m @@ -1,23 +1,21 @@ // -// AFSecurityPolicyNone.m -// Signal -// // Created by Fred on 01/09/15. // Copyright © 2015 Open Whisper Systems. All rights reserved. // +#import "OWSHTTPSecurityPolicy.h" + #import -#import "AFSecurityOWSPolicy.h" -@implementation AFSecurityOWSPolicy +@implementation OWSHTTPSecurityPolicy -+ (instancetype)OWS_PinningPolicy { - static AFSecurityOWSPolicy *sharedMyManager = nil; - @synchronized(self) { - if (sharedMyManager == nil) - sharedMyManager = [[self alloc] initWithOWSPolicy]; - } - return sharedMyManager; ++ (instancetype)sharedPolicy { + static OWSHTTPSecurityPolicy *httpSecurityPolicy = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + httpSecurityPolicy = [[self alloc] initWithOWSPolicy]; + }); + return httpSecurityPolicy; } - (instancetype)initWithOWSPolicy { @@ -84,7 +82,6 @@ - (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust forDomain:(NSString *)domai return YES; } - static BOOL AFServerTrustIsValid(SecTrustRef serverTrust) { BOOL isValid = NO; SecTrustResultType result; diff --git a/src/Security/OWSWebsocketSecurityPolicy.h b/src/Security/OWSWebsocketSecurityPolicy.h new file mode 100644 index 00000000..a259620a --- /dev/null +++ b/src/Security/OWSWebsocketSecurityPolicy.h @@ -0,0 +1,9 @@ +// Copyright © 2016 Open Whisper Systems. All rights reserved. + +#import + +@interface OWSWebsocketSecurityPolicy : SRSecurityPolicy + ++ (instancetype)sharedPolicy; + +@end diff --git a/src/Security/OWSWebsocketSecurityPolicy.m b/src/Security/OWSWebsocketSecurityPolicy.m new file mode 100644 index 00000000..15013d95 --- /dev/null +++ b/src/Security/OWSWebsocketSecurityPolicy.m @@ -0,0 +1,24 @@ +// Copyright © 2016 Open Whisper Systems. All rights reserved. + +#import "OWSWebsocketSecurityPolicy.h" + +#import +#import "OWSHTTPSecurityPolicy.h" + +@implementation OWSWebsocketSecurityPolicy + ++ (instancetype)sharedPolicy { + static OWSWebsocketSecurityPolicy *websocketSecurityPolicy = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + websocketSecurityPolicy = [[self alloc] initWithValidatesCertificateChain:NO]; + }); + return websocketSecurityPolicy; +} + +- (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust forDomain:(NSString *)domain { + // Delegate server trust to our existing HTTP policy. + return [[OWSHTTPSecurityPolicy sharedPolicy] evaluateServerTrust:serverTrust forDomain:domain]; +} + +@end