Skip to content

Commit 37dadc2

Browse files
committed
Use SecureTransport on iOS when possible. (Merge branch 'ios-secure-transport')
2 parents eda89a2 + f03e31b commit 37dadc2

File tree

5 files changed

+410
-125
lines changed

5 files changed

+410
-125
lines changed

GCD/GCDAsyncSocket.h

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,69 @@
1010

1111
#import <Foundation/Foundation.h>
1212
#import <Security/Security.h>
13+
#import <Security/SecureTransport.h>
1314
#import <dispatch/dispatch.h>
1415

1516
@class GCDAsyncReadPacket;
1617
@class GCDAsyncWritePacket;
1718

19+
#if TARGET_OS_IPHONE
20+
21+
// Compiling for iOS
22+
23+
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 50000 // iOS 5.0 supported
24+
25+
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 50000 // iOS 5.0 supported and required
26+
27+
#define IS_SECURE_TRANSPORT_AVAILABLE YES
28+
#define SECURE_TRANSPORT_MAYBE_AVAILABLE 1
29+
#define SECURE_TRANSPORT_MAYBE_UNAVAILABLE 0
30+
31+
#else // iOS 5.0 supported but not required
32+
33+
#ifndef NSFoundationVersionNumber_iPhoneOS_5_0
34+
#define NSFoundationVersionNumber_iPhoneOS_5_0 881.00
35+
#endif
36+
37+
#define IS_SECURE_TRANSPORT_AVAILABLE (NSFoundationVersionNumber >= NSFoundationVersionNumber_iPhoneOS_5_0)
38+
#define SECURE_TRANSPORT_MAYBE_AVAILABLE 1
39+
#define SECURE_TRANSPORT_MAYBE_UNAVAILABLE 1
40+
41+
#endif
42+
43+
#else // iOS 5.0 not supported
44+
45+
#define IS_SECURE_TRANSPORT_AVAILABLE NO
46+
#define SECURE_TRANSPORT_MAYBE_AVAILABLE 0
47+
#define SECURE_TRANSPORT_MAYBE_UNAVAILABLE 1
48+
49+
#endif
50+
51+
#else
52+
53+
// Compiling for Mac OS X
54+
55+
#define IS_SECURE_TRANSPORT_AVAILABLE YES
56+
#define SECURE_TRANSPORT_MAYBE_AVAILABLE 1
57+
#define SECURE_TRANSPORT_MAYBE_UNAVAILABLE 0
58+
59+
#endif
60+
1861
extern NSString *const GCDAsyncSocketException;
1962
extern NSString *const GCDAsyncSocketErrorDomain;
2063

2164
extern NSString *const GCDAsyncSocketQueueName;
2265
extern NSString *const GCDAsyncSocketThreadName;
2366

24-
#if !TARGET_OS_IPHONE
67+
#if SECURE_TRANSPORT_MAYBE_AVAILABLE
2568
extern NSString *const GCDAsyncSocketSSLCipherSuites;
69+
#if TARGET_OS_IPHONE
70+
extern NSString *const GCDAsyncSocketSSLProtocolVersionMin;
71+
extern NSString *const GCDAsyncSocketSSLProtocolVersionMax;
72+
#else
2673
extern NSString *const GCDAsyncSocketSSLDiffieHellmanParameters;
2774
#endif
75+
#endif
2876

2977
enum GCDAsyncSocketError
3078
{
@@ -82,7 +130,8 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
82130
CFStreamClientContext streamContext;
83131
CFReadStreamRef readStream;
84132
CFWriteStreamRef writeStream;
85-
#else
133+
#endif
134+
#if SECURE_TRANSPORT_MAYBE_AVAILABLE
86135
SSLContextRef sslContext;
87136
NSMutableData *sslReadBuffer;
88137
size_t sslWriteCachedLength;
@@ -681,7 +730,8 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
681730
* Any reads or writes scheduled after this method is called will occur over the secured connection.
682731
*
683732
* The possible keys and values for the TLS settings are well documented.
684-
* Some possible keys are:
733+
* Standard keys are:
734+
*
685735
* - kCFStreamSSLLevel
686736
* - kCFStreamSSLAllowsExpiredCertificates
687737
* - kCFStreamSSLAllowsExpiredRoots
@@ -691,6 +741,18 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
691741
* - kCFStreamSSLCertificates
692742
* - kCFStreamSSLIsServer
693743
*
744+
* If SecureTransport is available on iOS:
745+
*
746+
* - GCDAsyncSocketSSLCipherSuites
747+
* - GCDAsyncSocketSSLProtocolVersionMin
748+
* - GCDAsyncSocketSSLProtocolVersionMax
749+
*
750+
* If SecureTransport is available on Mac OS X:
751+
*
752+
* - GCDAsyncSocketSSLCipherSuites
753+
* - GCDAsyncSocketSSLDiffieHellmanParameters;
754+
*
755+
*
694756
* Please refer to Apple's documentation for associated values, as well as other possible keys.
695757
*
696758
* If you pass in nil or an empty dictionary, the default settings will be used.

0 commit comments

Comments
 (0)