Skip to content

Commit 151a30a

Browse files
committed
Removing SECURE_TRANSPORT macros. iOS 5+ is now required (and has been for awhile now)
1 parent c919bf6 commit 151a30a

File tree

2 files changed

+31
-128
lines changed

2 files changed

+31
-128
lines changed

GCD/GCDAsyncSocket.h

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -21,63 +21,19 @@
2121
@class GCDAsyncWritePacket;
2222
@class GCDAsyncSocketPreBuffer;
2323

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

6927
extern NSString *const GCDAsyncSocketQueueName;
7028
extern NSString *const GCDAsyncSocketThreadName;
7129

72-
#if SECURE_TRANSPORT_MAYBE_AVAILABLE
7330
extern NSString *const GCDAsyncSocketSSLCipherSuites;
7431
#if TARGET_OS_IPHONE
7532
extern NSString *const GCDAsyncSocketSSLProtocolVersionMin;
7633
extern NSString *const GCDAsyncSocketSSLProtocolVersionMax;
7734
#else
7835
extern NSString *const GCDAsyncSocketSSLDiffieHellmanParameters;
7936
#endif
80-
#endif
8137

8238
#define GCDAsyncSocketLoggingContext 65535
8339

@@ -923,8 +879,6 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
923879

924880
#endif
925881

926-
#if SECURE_TRANSPORT_MAYBE_AVAILABLE
927-
928882
/**
929883
* This method is only available from within the context of a performBlock: invocation.
930884
* See the documentation for the performBlock: method above.
@@ -933,8 +887,6 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
933887
**/
934888
- (SSLContextRef)sslContext;
935889

936-
#endif
937-
938890
#pragma mark Utilities
939891

940892
/**
@@ -1113,7 +1065,6 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
11131065
**/
11141066
- (void)socketDidSecure:(GCDAsyncSocket *)sock;
11151067

1116-
#if SECURE_TRANSPORT_MAYBE_AVAILABLE
11171068
/**
11181069
* Called to determine if the -socket:shouldTrustPeer: callback should be enabled.
11191070
* Returning YES here will set the SSL session option kSSLSessionOptionBreakOnServerAuth.
@@ -1133,5 +1084,5 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
11331084
* and closes the connection.
11341085
**/
11351086
- (BOOL)socket:(GCDAsyncSocket *)sock shouldTrustPeer:(SecTrustRef)trust;
1136-
#endif
1087+
11371088
@end

GCD/GCDAsyncSocket.m

Lines changed: 30 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,13 @@
113113
NSString *const GCDAsyncSocketQueueName = @"GCDAsyncSocket";
114114
NSString *const GCDAsyncSocketThreadName = @"GCDAsyncSocket-CFStream";
115115

116-
#if SECURE_TRANSPORT_MAYBE_AVAILABLE
117116
NSString *const GCDAsyncSocketSSLCipherSuites = @"GCDAsyncSocketSSLCipherSuites";
118117
#if TARGET_OS_IPHONE
119118
NSString *const GCDAsyncSocketSSLProtocolVersionMin = @"GCDAsyncSocketSSLProtocolVersionMin";
120119
NSString *const GCDAsyncSocketSSLProtocolVersionMax = @"GCDAsyncSocketSSLProtocolVersionMax";
121120
#else
122121
NSString *const GCDAsyncSocketSSLDiffieHellmanParameters = @"GCDAsyncSocketSSLDiffieHellmanParameters";
123122
#endif
124-
#endif
125123

126124
enum GCDAsyncSocketFlags
127125
{
@@ -891,12 +889,10 @@ @implementation GCDAsyncSocket
891889
CFReadStreamRef readStream;
892890
CFWriteStreamRef writeStream;
893891
#endif
894-
#if SECURE_TRANSPORT_MAYBE_AVAILABLE
895892
SSLContextRef sslContext;
896893
GCDAsyncSocketPreBuffer *sslPreBuffer;
897894
size_t sslWriteCachedLength;
898895
OSStatus sslErrCode;
899-
#endif
900896

901897
void *IsOnSocketQueueOrTargetQueueKey;
902898

@@ -2564,28 +2560,25 @@ - (void)closeWithError:(NSError *)error
25642560
}
25652561
}
25662562
#endif
2567-
#if SECURE_TRANSPORT_MAYBE_AVAILABLE
2563+
2564+
[sslPreBuffer reset];
2565+
sslErrCode = noErr;
2566+
2567+
if (sslContext)
25682568
{
2569-
[sslPreBuffer reset];
2570-
sslErrCode = noErr;
2569+
// Getting a linker error here about the SSLx() functions?
2570+
// You need to add the Security Framework to your application.
25712571

2572-
if (sslContext)
2573-
{
2574-
// Getting a linker error here about the SSLx() functions?
2575-
// You need to add the Security Framework to your application.
2576-
2577-
SSLClose(sslContext);
2578-
2579-
#if TARGET_OS_IPHONE
2580-
CFRelease(sslContext);
2581-
#else
2582-
SSLDisposeContext(sslContext);
2583-
#endif
2584-
2585-
sslContext = NULL;
2586-
}
2572+
SSLClose(sslContext);
2573+
2574+
#if TARGET_OS_IPHONE
2575+
CFRelease(sslContext);
2576+
#else
2577+
SSLDisposeContext(sslContext);
2578+
#endif
2579+
2580+
sslContext = NULL;
25872581
}
2588-
#endif
25892582

25902583
// For some crazy reason (in my opinion), cancelling a dispatch source doesn't
25912584
// invoke the cancel handler if the dispatch source is paused.
@@ -3634,12 +3627,10 @@ - (BOOL)usingCFStreamForTLS
36343627
- (BOOL)usingSecureTransportForTLS
36353628
{
36363629
#if TARGET_OS_IPHONE
3637-
{
36383630
return ![self usingCFStreamForTLS];
3639-
}
3631+
#else
3632+
return YES;
36403633
#endif
3641-
3642-
return YES;
36433634
}
36443635

36453636
- (void)suspendReadSource
@@ -3987,7 +3978,7 @@ - (void)flushSSLBuffers
39873978
return;
39883979
}
39893980

3990-
#if TARGET_OS_IPHONE
3981+
#if TARGET_OS_IPHONE
39913982

39923983
if ([self usingCFStreamForTLS])
39933984
{
@@ -4015,8 +4006,7 @@ - (void)flushSSLBuffers
40154006
return;
40164007
}
40174008

4018-
#endif
4019-
#if SECURE_TRANSPORT_MAYBE_AVAILABLE
4009+
#endif
40204010

40214011
__block NSUInteger estimatedBytesAvailable = 0;
40224012

@@ -4081,8 +4071,6 @@ - (void)flushSSLBuffers
40814071

40824072
} while (!done && estimatedBytesAvailable > 0);
40834073
}
4084-
4085-
#endif
40864074
}
40874075

40884076
- (void)doReadData
@@ -4159,8 +4147,6 @@ - (void)doReadData
41594147
{
41604148
estimatedBytesAvailable = socketFDBytesAvailable;
41614149

4162-
#if SECURE_TRANSPORT_MAYBE_AVAILABLE
4163-
41644150
if (flags & kSocketSecure)
41654151
{
41664152
// There are 2 buffers to be aware of here.
@@ -4197,8 +4183,6 @@ - (void)doReadData
41974183
estimatedBytesAvailable += sslInternalBufSize;
41984184
}
41994185

4200-
#endif
4201-
42024186
hasBytesAvailable = (estimatedBytesAvailable > 0);
42034187
}
42044188

@@ -4228,14 +4212,10 @@ - (void)doReadData
42284212
{
42294213
if ([self usingSecureTransportForTLS])
42304214
{
4231-
#if SECURE_TRANSPORT_MAYBE_AVAILABLE
4232-
42334215
// We are in the process of a SSL Handshake.
42344216
// We were waiting for incoming data which has just arrived.
42354217

42364218
[self ssl_continueSSLHandshake];
4237-
4238-
#endif
42394219
}
42404220
}
42414221
else
@@ -4459,8 +4439,6 @@ - (void)doReadData
44594439
}
44604440
else
44614441
{
4462-
#if SECURE_TRANSPORT_MAYBE_AVAILABLE
4463-
44644442
// The documentation from Apple states:
44654443
//
44664444
// "a read operation might return errSSLWouldBlock,
@@ -4514,8 +4492,6 @@ - (void)doReadData
45144492

45154493
// Do not modify socketFDBytesAvailable.
45164494
// It will be updated via the SSLReadFunction().
4517-
4518-
#endif
45194495
}
45204496
}
45214497
else
@@ -4817,9 +4793,7 @@ - (void)doReadEOF
48174793

48184794
if ([self usingSecureTransportForTLS])
48194795
{
4820-
#if SECURE_TRANSPORT_MAYBE_AVAILABLE
48214796
error = [self sslError:errSSLClosedAbort];
4822-
#endif
48234797
}
48244798
}
48254799
else if (flags & kReadStreamClosed)
@@ -4894,25 +4868,21 @@ - (void)doReadEOF
48944868
{
48954869
if (error == nil)
48964870
{
4897-
#if SECURE_TRANSPORT_MAYBE_AVAILABLE
4898-
if ([self usingSecureTransportForTLS])
4871+
if ([self usingSecureTransportForTLS])
4872+
{
4873+
if (sslErrCode != noErr && sslErrCode != errSSLClosedGraceful)
48994874
{
4900-
if (sslErrCode != noErr && sslErrCode != errSSLClosedGraceful)
4901-
{
4902-
error = [self sslError:sslErrCode];
4903-
}
4904-
else
4905-
{
4906-
error = [self connectionClosedError];
4907-
}
4875+
error = [self sslError:sslErrCode];
49084876
}
49094877
else
49104878
{
49114879
error = [self connectionClosedError];
49124880
}
4913-
#else
4914-
error = [self connectionClosedError];
4915-
#endif
4881+
}
4882+
else
4883+
{
4884+
error = [self connectionClosedError];
4885+
}
49164886
}
49174887
[self closeWithError:error];
49184888
}
@@ -5273,14 +5243,10 @@ - (void)doWriteData
52735243
{
52745244
if ([self usingSecureTransportForTLS])
52755245
{
5276-
#if SECURE_TRANSPORT_MAYBE_AVAILABLE
5277-
52785246
// We are in the process of a SSL Handshake.
52795247
// We were waiting for available space in the socket's internal OS buffer to continue writing.
52805248

52815249
[self ssl_continueSSLHandshake];
5282-
5283-
#endif
52845250
}
52855251
}
52865252
else
@@ -5345,8 +5311,6 @@ - (void)doWriteData
53455311
}
53465312
else
53475313
{
5348-
#if SECURE_TRANSPORT_MAYBE_AVAILABLE
5349-
53505314
// We're going to use the SSLWrite function.
53515315
//
53525316
// OSStatus SSLWrite(SSLContextRef context, const void *data, size_t dataLength, size_t *processed)
@@ -5477,8 +5441,6 @@ - (void)doWriteData
54775441
} // while (keepLooping)
54785442

54795443
} // if (hasNewDataToWrite)
5480-
5481-
#endif
54825444
}
54835445
}
54845446
else
@@ -5818,11 +5780,9 @@ - (void)maybeStartTLS
58185780
}
58195781
#endif
58205782

5821-
if (IS_SECURE_TRANSPORT_AVAILABLE && canUseSecureTransport)
5783+
if (canUseSecureTransport)
58225784
{
5823-
#if SECURE_TRANSPORT_MAYBE_AVAILABLE
58245785
[self ssl_startTLS];
5825-
#endif
58265786
}
58275787
else
58285788
{
@@ -5837,8 +5797,6 @@ - (void)maybeStartTLS
58375797
#pragma mark Security via SecureTransport
58385798
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58395799

5840-
#if SECURE_TRANSPORT_MAYBE_AVAILABLE
5841-
58425800
- (OSStatus)sslReadWithBuffer:(void *)buffer length:(size_t *)bufferLength
58435801
{
58445802
LogVerbose(@"sslReadWithBuffer:%p length:%lu", buffer, (unsigned long)*bufferLength);
@@ -6560,8 +6518,6 @@ - (void)ssl_continueSSLHandshake
65606518
}
65616519
}
65626520

6563-
#endif
6564-
65656521
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
65666522
#pragma mark Security via CFStream
65676523
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -7293,8 +7249,6 @@ - (BOOL)enableBackgroundingOnSocketWithCaveat // Deprecated in iOS 4.???
72937249

72947250
#endif
72957251

7296-
#if SECURE_TRANSPORT_MAYBE_AVAILABLE
7297-
72987252
- (SSLContextRef)sslContext
72997253
{
73007254
if (!dispatch_get_specific(IsOnSocketQueueOrTargetQueueKey))
@@ -7306,8 +7260,6 @@ - (SSLContextRef)sslContext
73067260
return sslContext;
73077261
}
73087262

7309-
#endif
7310-
73117263
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
73127264
#pragma mark Class Utilities
73137265
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)