12
12
#import < Security/Security.h>
13
13
#import < Security/SecureTransport.h>
14
14
#import < dispatch/dispatch.h>
15
- #import < TargetConditionals.h>
16
15
#import < Availability.h>
17
16
18
17
#include < sys/socket.h> // AF_INET, AF_INET6
@@ -27,11 +26,15 @@ extern NSString *const GCDAsyncSocketErrorDomain;
27
26
extern NSString *const GCDAsyncSocketQueueName;
28
27
extern NSString *const GCDAsyncSocketThreadName;
29
28
30
- extern NSString *const GCDAsyncSocketSSLCipherSuites ;
29
+ extern NSString *const GCDAsyncSocketManuallyEvaluateTrust ;
31
30
#if TARGET_OS_IPHONE
31
+ extern NSString *const GCDAsyncSocketUseCFStreamForTLS;
32
+ #endif
33
+
34
+ extern NSString *const GCDAsyncSocketSSLCipherSuites;
32
35
extern NSString *const GCDAsyncSocketSSLProtocolVersionMin;
33
36
extern NSString *const GCDAsyncSocketSSLProtocolVersionMax;
34
- #else
37
+ #if !TARGET_OS_IPHONE
35
38
extern NSString *const GCDAsyncSocketSSLDiffieHellmanParameters;
36
39
#endif
37
40
@@ -629,31 +632,61 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
629
632
* the upgrade to TLS at the same time, without having to wait for the write to finish.
630
633
* Any reads or writes scheduled after this method is called will occur over the secured connection.
631
634
*
632
- * The possible keys and values for the TLS settings are well documented.
633
- * Standard keys are:
634
- *
635
- * - kCFStreamSSLLevel
636
- * - kCFStreamSSLAllowsExpiredCertificates
637
- * - kCFStreamSSLAllowsExpiredRoots
638
- * - kCFStreamSSLAllowsAnyRoot
639
- * - kCFStreamSSLValidatesCertificateChain
635
+ * The available keys are:
636
+ *
640
637
* - kCFStreamSSLPeerName
638
+ * The value must be of type NSString.
639
+ * It should match the name in the X.509 certificate given by the remote party.
640
+ * See the documentation for SSLSetPeerDomainName.
641
+ *
641
642
* - kCFStreamSSLCertificates
643
+ * The value must be of type NSArray.
644
+ * See the documentation for SSLSetCertificate.
645
+ *
642
646
* - kCFStreamSSLIsServer
643
- *
644
- * If SecureTransport is available on iOS:
645
- *
647
+ * The value must be of type NSNumber, encapsulationg a BOOL value.
648
+ * See the documentation for SSLCreateContext for iOS.
649
+ * This is optional for iOS. If not supplied, a NO value is the default.
650
+ * This is not needed for Mac OS X, and the value is ignored.
651
+ *
646
652
* - GCDAsyncSocketSSLCipherSuites
653
+ * The values must be of type NSArray.
654
+ * Each item within the array must be a NSNumber, encapsulating
655
+ * See the documentation for SSLSetEnabledCiphers.
656
+ * See also the SSLCipherSuite typedef.
657
+ *
647
658
* - GCDAsyncSocketSSLProtocolVersionMin
648
659
* - GCDAsyncSocketSSLProtocolVersionMax
660
+ * The value(s) must be of type NSNumber, encapsulting a SSLProtocol value.
661
+ * See the documentation for SSLSetProtocolVersionMin & SSLSetProtocolVersionMax.
662
+ * See also the SSLProtocol typedef.
663
+ *
664
+ * - GCDAsyncSocketSSLDiffieHellmanParameters () [Mac OS X only]
649
665
*
650
- * If SecureTransport is available on Mac OS X :
666
+ * The following keys are NOT available (and with throw an exception) :
651
667
*
652
- * - GCDAsyncSocketSSLCipherSuites
653
- * - GCDAsyncSocketSSLDiffieHellmanParameters;
668
+ * - kCFStreamSSLAllowsAnyRoot (UNAVAILABLE)
669
+ * You MUST use manualTrustEvaluation.
670
+ * Corresponding deprecated method: SSLSetAllowsAnyRoot
654
671
*
672
+ * - kCFStreamSSLAllowsExpiredRoots (UNAVAILABLE)
673
+ * You MUST use manualTrustEvaluation.
674
+ * Corresponding deprecated method: SSLSetAllowsExpiredRoots
675
+ *
676
+ * - kCFStreamSSLAllowsExpiredCertificates (UNAVAILABLE)
677
+ * You MUST use manualTrustEvaluation.
678
+ * Corresponding deprecated method: SSLSetAllowsExpiredCerts
679
+ *
680
+ * - kCFStreamSSLValidatesCertificateChain (UNAVAILABLE)
681
+ * You MUST use manualTrustEvaluation.
682
+ * Corresponding deprecated method: SSLSetEnableCertVerify
683
+ *
684
+ * - kCFStreamSSLLevel (UNAVAILABLE)
685
+ * You MUST use GCDAsyncSocketSSLProtocolVersionMin / Max instead.
686
+ * Corresponding deprecated method: SSLSetProtocolVersionEnabled
687
+ *
655
688
*
656
- * Please refer to Apple's documentation for associated values, as well as other possible keys .
689
+ * Please refer to Apple's documentation for corresponding SSLFunctions .
657
690
*
658
691
* If you pass in nil or an empty dictionary, the default settings will be used.
659
692
*
@@ -668,11 +701,9 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
668
701
* the default settings will not detect any problems since the certificate is valid.
669
702
* To properly secure your connection in this particular scenario you
670
703
* should set the kCFStreamSSLPeerName property to "MySecureServer.com".
671
- * If you do not know the peer name of the remote host in advance (for example, you're not sure
672
- * if it will be "domain.com" or "www.domain.com"), then you can use the default settings to validate the
673
- * certificate, and then use the X509Certificate class to verify the issuer after the socket has been secured.
674
- * The X509Certificate class is part of the CocoaAsyncSocket open source project.
675
- **/
704
+ *
705
+ * You can also perform additional validation via the certificate provided in socketDidSecure.
706
+ **/
676
707
- (void )startTLS : (NSDictionary *)tlsSettings ;
677
708
678
709
#pragma mark Advanced
@@ -1065,23 +1096,15 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
1065
1096
**/
1066
1097
- (void )socketDidSecure : (GCDAsyncSocket *)sock ;
1067
1098
1068
- /* *
1069
- * Called to determine if the -socket:shouldTrustPeer: callback should be enabled.
1070
- * Returning YES here will set the SSL session option kSSLSessionOptionBreakOnServerAuth.
1071
- *
1072
- * NOTE: Currently only implemented for client sockets. Returning YES in server socket
1073
- * will terminate the connection.
1074
- **/
1075
- - (BOOL )socketShouldManuallyEvaluateTrust : (GCDAsyncSocket *)sock ;
1076
-
1077
1099
/* *
1078
1100
* Allows a socket delegate to hook into the TLS handshake and manually validate
1079
1101
* the peer it's connecting to.
1080
1102
*
1081
- * This is only called if -socketShouldManuallyEvaluateTrust: returns YES.
1103
+ * This is only called if startTLS is invoked with options that include:
1104
+ * - GCDAsyncSocketManuallyEvaluateTrust == YES
1082
1105
*
1083
- * Returning YES continues the SSL handshake, returning NO terminates the handshake
1084
- * and closes the connection.
1106
+ * Returning YES continues the SSL handshake.
1107
+ * Returning NO terminates the handshake and closes the connection.
1085
1108
**/
1086
1109
- (BOOL )socket : (GCDAsyncSocket *)sock shouldTrustPeer : (SecTrustRef)trust ;
1087
1110
0 commit comments