113
113
NSString *const GCDAsyncSocketQueueName = @" GCDAsyncSocket" ;
114
114
NSString *const GCDAsyncSocketThreadName = @" GCDAsyncSocket-CFStream" ;
115
115
116
- #if SECURE_TRANSPORT_MAYBE_AVAILABLE
117
116
NSString *const GCDAsyncSocketSSLCipherSuites = @" GCDAsyncSocketSSLCipherSuites" ;
118
117
#if TARGET_OS_IPHONE
119
118
NSString *const GCDAsyncSocketSSLProtocolVersionMin = @" GCDAsyncSocketSSLProtocolVersionMin" ;
120
119
NSString *const GCDAsyncSocketSSLProtocolVersionMax = @" GCDAsyncSocketSSLProtocolVersionMax" ;
121
120
#else
122
121
NSString *const GCDAsyncSocketSSLDiffieHellmanParameters = @" GCDAsyncSocketSSLDiffieHellmanParameters" ;
123
122
#endif
124
- #endif
125
123
126
124
enum GCDAsyncSocketFlags
127
125
{
@@ -891,12 +889,10 @@ @implementation GCDAsyncSocket
891
889
CFReadStreamRef readStream;
892
890
CFWriteStreamRef writeStream;
893
891
#endif
894
- #if SECURE_TRANSPORT_MAYBE_AVAILABLE
895
892
SSLContextRef sslContext;
896
893
GCDAsyncSocketPreBuffer *sslPreBuffer;
897
894
size_t sslWriteCachedLength;
898
895
OSStatus sslErrCode;
899
- #endif
900
896
901
897
void *IsOnSocketQueueOrTargetQueueKey;
902
898
@@ -2564,28 +2560,25 @@ - (void)closeWithError:(NSError *)error
2564
2560
}
2565
2561
}
2566
2562
#endif
2567
- #if SECURE_TRANSPORT_MAYBE_AVAILABLE
2563
+
2564
+ [sslPreBuffer reset ];
2565
+ sslErrCode = noErr;
2566
+
2567
+ if (sslContext)
2568
2568
{
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.
2571
2571
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 ;
2587
2581
}
2588
- #endif
2589
2582
2590
2583
// For some crazy reason (in my opinion), cancelling a dispatch source doesn't
2591
2584
// invoke the cancel handler if the dispatch source is paused.
@@ -3634,12 +3627,10 @@ - (BOOL)usingCFStreamForTLS
3634
3627
- (BOOL )usingSecureTransportForTLS
3635
3628
{
3636
3629
#if TARGET_OS_IPHONE
3637
- {
3638
3630
return ![self usingCFStreamForTLS ];
3639
- }
3631
+ #else
3632
+ return YES ;
3640
3633
#endif
3641
-
3642
- return YES ;
3643
3634
}
3644
3635
3645
3636
- (void )suspendReadSource
@@ -3987,7 +3978,7 @@ - (void)flushSSLBuffers
3987
3978
return ;
3988
3979
}
3989
3980
3990
- #if TARGET_OS_IPHONE
3981
+ #if TARGET_OS_IPHONE
3991
3982
3992
3983
if ([self usingCFStreamForTLS ])
3993
3984
{
@@ -4015,8 +4006,7 @@ - (void)flushSSLBuffers
4015
4006
return ;
4016
4007
}
4017
4008
4018
- #endif
4019
- #if SECURE_TRANSPORT_MAYBE_AVAILABLE
4009
+ #endif
4020
4010
4021
4011
__block NSUInteger estimatedBytesAvailable = 0 ;
4022
4012
@@ -4081,8 +4071,6 @@ - (void)flushSSLBuffers
4081
4071
4082
4072
} while (!done && estimatedBytesAvailable > 0 );
4083
4073
}
4084
-
4085
- #endif
4086
4074
}
4087
4075
4088
4076
- (void )doReadData
@@ -4159,8 +4147,6 @@ - (void)doReadData
4159
4147
{
4160
4148
estimatedBytesAvailable = socketFDBytesAvailable;
4161
4149
4162
- #if SECURE_TRANSPORT_MAYBE_AVAILABLE
4163
-
4164
4150
if (flags & kSocketSecure )
4165
4151
{
4166
4152
// There are 2 buffers to be aware of here.
@@ -4197,8 +4183,6 @@ - (void)doReadData
4197
4183
estimatedBytesAvailable += sslInternalBufSize;
4198
4184
}
4199
4185
4200
- #endif
4201
-
4202
4186
hasBytesAvailable = (estimatedBytesAvailable > 0 );
4203
4187
}
4204
4188
@@ -4228,14 +4212,10 @@ - (void)doReadData
4228
4212
{
4229
4213
if ([self usingSecureTransportForTLS ])
4230
4214
{
4231
- #if SECURE_TRANSPORT_MAYBE_AVAILABLE
4232
-
4233
4215
// We are in the process of a SSL Handshake.
4234
4216
// We were waiting for incoming data which has just arrived.
4235
4217
4236
4218
[self ssl_continueSSLHandshake ];
4237
-
4238
- #endif
4239
4219
}
4240
4220
}
4241
4221
else
@@ -4459,8 +4439,6 @@ - (void)doReadData
4459
4439
}
4460
4440
else
4461
4441
{
4462
- #if SECURE_TRANSPORT_MAYBE_AVAILABLE
4463
-
4464
4442
// The documentation from Apple states:
4465
4443
//
4466
4444
// "a read operation might return errSSLWouldBlock,
@@ -4514,8 +4492,6 @@ - (void)doReadData
4514
4492
4515
4493
// Do not modify socketFDBytesAvailable.
4516
4494
// It will be updated via the SSLReadFunction().
4517
-
4518
- #endif
4519
4495
}
4520
4496
}
4521
4497
else
@@ -4817,9 +4793,7 @@ - (void)doReadEOF
4817
4793
4818
4794
if ([self usingSecureTransportForTLS ])
4819
4795
{
4820
- #if SECURE_TRANSPORT_MAYBE_AVAILABLE
4821
4796
error = [self sslError: errSSLClosedAbort];
4822
- #endif
4823
4797
}
4824
4798
}
4825
4799
else if (flags & kReadStreamClosed )
@@ -4894,25 +4868,21 @@ - (void)doReadEOF
4894
4868
{
4895
4869
if (error == nil )
4896
4870
{
4897
- #if SECURE_TRANSPORT_MAYBE_AVAILABLE
4898
- if ([self usingSecureTransportForTLS ])
4871
+ if ([self usingSecureTransportForTLS ])
4872
+ {
4873
+ if (sslErrCode != noErr && sslErrCode != errSSLClosedGraceful)
4899
4874
{
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];
4908
4876
}
4909
4877
else
4910
4878
{
4911
4879
error = [self connectionClosedError ];
4912
4880
}
4913
- #else
4914
- error = [self connectionClosedError ];
4915
- #endif
4881
+ }
4882
+ else
4883
+ {
4884
+ error = [self connectionClosedError ];
4885
+ }
4916
4886
}
4917
4887
[self closeWithError: error];
4918
4888
}
@@ -5273,14 +5243,10 @@ - (void)doWriteData
5273
5243
{
5274
5244
if ([self usingSecureTransportForTLS ])
5275
5245
{
5276
- #if SECURE_TRANSPORT_MAYBE_AVAILABLE
5277
-
5278
5246
// We are in the process of a SSL Handshake.
5279
5247
// We were waiting for available space in the socket's internal OS buffer to continue writing.
5280
5248
5281
5249
[self ssl_continueSSLHandshake ];
5282
-
5283
- #endif
5284
5250
}
5285
5251
}
5286
5252
else
@@ -5345,8 +5311,6 @@ - (void)doWriteData
5345
5311
}
5346
5312
else
5347
5313
{
5348
- #if SECURE_TRANSPORT_MAYBE_AVAILABLE
5349
-
5350
5314
// We're going to use the SSLWrite function.
5351
5315
//
5352
5316
// OSStatus SSLWrite(SSLContextRef context, const void *data, size_t dataLength, size_t *processed)
@@ -5477,8 +5441,6 @@ - (void)doWriteData
5477
5441
} // while (keepLooping)
5478
5442
5479
5443
} // if (hasNewDataToWrite)
5480
-
5481
- #endif
5482
5444
}
5483
5445
}
5484
5446
else
@@ -5818,11 +5780,9 @@ - (void)maybeStartTLS
5818
5780
}
5819
5781
#endif
5820
5782
5821
- if (IS_SECURE_TRANSPORT_AVAILABLE && canUseSecureTransport)
5783
+ if (canUseSecureTransport)
5822
5784
{
5823
- #if SECURE_TRANSPORT_MAYBE_AVAILABLE
5824
5785
[self ssl_startTLS ];
5825
- #endif
5826
5786
}
5827
5787
else
5828
5788
{
@@ -5837,8 +5797,6 @@ - (void)maybeStartTLS
5837
5797
#pragma mark Security via SecureTransport
5838
5798
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5839
5799
5840
- #if SECURE_TRANSPORT_MAYBE_AVAILABLE
5841
-
5842
5800
- (OSStatus)sslReadWithBuffer : (void *)buffer length : (size_t *)bufferLength
5843
5801
{
5844
5802
LogVerbose (@" sslReadWithBuffer:%p length:%lu " , buffer, (unsigned long )*bufferLength);
@@ -6560,8 +6518,6 @@ - (void)ssl_continueSSLHandshake
6560
6518
}
6561
6519
}
6562
6520
6563
- #endif
6564
-
6565
6521
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
6566
6522
#pragma mark Security via CFStream
6567
6523
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -7293,8 +7249,6 @@ - (BOOL)enableBackgroundingOnSocketWithCaveat // Deprecated in iOS 4.???
7293
7249
7294
7250
#endif
7295
7251
7296
- #if SECURE_TRANSPORT_MAYBE_AVAILABLE
7297
-
7298
7252
- (SSLContextRef)sslContext
7299
7253
{
7300
7254
if (!dispatch_get_specific (IsOnSocketQueueOrTargetQueueKey))
@@ -7306,8 +7260,6 @@ - (SSLContextRef)sslContext
7306
7260
return sslContext;
7307
7261
}
7308
7262
7309
- #endif
7310
-
7311
7263
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7312
7264
#pragma mark Class Utilities
7313
7265
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
0 commit comments