Skip to content

Commit 1f28d9f

Browse files
committed
Updated GCDAsyncSocket to allow for specification of SSL cipher suites and DiffieHellman parameters (Mac OS X only). Thanks to Aidan Steele for the patch.
1 parent fa28d48 commit 1f28d9f

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

GCD/GCDAsyncSocket.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
extern NSString *const GCDAsyncSocketException;
1919
extern NSString *const GCDAsyncSocketErrorDomain;
2020

21+
#if !TARGET_OS_IPHONE
22+
extern NSString *const GCDAsyncSocketSSLCipherSuites;
23+
extern NSString *const GCDAsyncSocketSSLDiffieHellmanParameters;
24+
#endif
25+
2126
enum GCDAsyncSocketError
2227
{
2328
GCDAsyncSocketNoError = 0, // Never used

GCD/GCDAsyncSocket.m

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@
8181
NSString *const GCDAsyncSocketException = @"GCDAsyncSocketException";
8282
NSString *const GCDAsyncSocketErrorDomain = @"GCDAsyncSocketErrorDomain";
8383

84+
#if !TARGET_OS_IPHONE
85+
NSString *const GCDAsyncSocketSSLCipherSuites = @"GCDAsyncSocketSSLCipherSuites";
86+
NSString *const GCDAsyncSocketSSLDiffieHellmanParameters = @"GCDAsyncSocketSSLDiffieHellmanParameters";
87+
#endif
88+
8489
enum GCDAsyncSocketFlags
8590
{
8691
kDidStartDelegate = 1 << 0, // If set, disconnection results in delegate call
@@ -4818,6 +4823,8 @@ - (void)maybeStartTLS
48184823
// 5. kCFStreamSSLAllowsExpiredCertificates
48194824
// 6. kCFStreamSSLCertificates
48204825
// 7. kCFStreamSSLLevel
4826+
// 8. GCDAsyncSocketSSLCipherSuites
4827+
// 9. GCDAsyncSocketSSLDiffieHellmanParameters
48214828

48224829
id value;
48234830

@@ -4960,6 +4967,44 @@ - (void)maybeStartTLS
49604967
}
49614968
}
49624969

4970+
// 8. GCDAsyncSocketSSLCipherSuites
4971+
4972+
value = [tlsSettings objectForKey:GCDAsyncSocketSSLCipherSuites];
4973+
if (value)
4974+
{
4975+
NSArray *cipherSuites = (NSArray *)value;
4976+
NSUInteger numberCiphers = [cipherSuites count];
4977+
SSLCipherSuite ciphers[numberCiphers];
4978+
4979+
for (NSUInteger cipherIndex = 0; cipherIndex < numberCiphers; cipherIndex++)
4980+
{
4981+
NSNumber *cipherObject = [cipherSuites objectAtIndex:cipherIndex];
4982+
ciphers[cipherIndex] = [cipherObject shortValue];
4983+
}
4984+
4985+
status = SSLSetEnabledCiphers(sslContext, ciphers, numberCiphers);
4986+
if (status != noErr)
4987+
{
4988+
[self closeWithError:[self otherError:@"Error in SSLSetEnabledCiphers"]];
4989+
return;
4990+
}
4991+
}
4992+
4993+
// 9. GCDAsyncSocketSSLDiffieHellmanParameters
4994+
4995+
value = [tlsSettings objectForKey:GCDAsyncSocketSSLDiffieHellmanParameters];
4996+
if (value)
4997+
{
4998+
NSData *diffieHellmanData = (NSData *)value;
4999+
5000+
status = SSLSetDiffieHellmanParams(sslContext, [diffieHellmanData bytes], [diffieHellmanData length]);
5001+
if (status != noErr)
5002+
{
5003+
[self closeWithError:[self otherError:@"Error in SSLSetDiffieHellmanParams"]];
5004+
return;
5005+
}
5006+
}
5007+
49635008
// Setup the sslReadBuffer
49645009
//
49655010
// If there is any data in the partialReadBuffer,

0 commit comments

Comments
 (0)