Fixed the release of an CFDataRef object under garbage collection.
5 // Created by Jens Alfke on 5/14/08.
6 // Copyright 2008 Jens Alfke. All rights reserved.
9 #import "TCPEndpoint.h"
11 #import "CollectionUtils.h"
12 #import "ExceptionUtils.h"
13 #import <Security/Security.h>
16 NSString* const kTCPPropertySSLClientSideAuthentication = @"kTCPPropertySSLClientSideAuthentication";
19 @implementation TCPEndpoint
24 [_sslProperties release];
29 - (NSMutableDictionary*) SSLProperties {return _sslProperties;}
31 - (void) setSSLProperties: (NSMutableDictionary*)props
33 if( props != _sslProperties ) {
34 [_sslProperties release];
35 _sslProperties = [props mutableCopy];
39 - (void) setSSLProperty: (id)value forKey: (NSString*)key
42 if( ! _sslProperties )
43 _sslProperties = [[NSMutableDictionary alloc] init];
44 [_sslProperties setObject: value forKey: key];
46 [_sslProperties removeObjectForKey: key];
49 - (NSString*) securityLevel {return [_sslProperties objectForKey: (id)kCFStreamSSLLevel];}
50 - (void) setSecurityLevel: (NSString*)level {[self setSSLProperty: level forKey: (id)kCFStreamSSLLevel];}
52 - (void) setPeerToPeerIdentity: (SecIdentityRef)identity {
54 self.SSLProperties = $mdict(
55 {(id)kCFStreamSSLLevel, NSStreamSocketSecurityLevelTLSv1},
56 {kTCPPropertySSLCertificates, $array((id)identity)},
57 {kTCPPropertySSLAllowsAnyRoot, $true},
58 {kTCPPropertySSLPeerName, [NSNull null]},
59 {kTCPPropertySSLClientSideAuthentication, $object(kTCPAlwaysAuthenticate)});
62 - (void) tellDelegate: (SEL)selector withObject: (id)param
64 if( [_delegate respondsToSelector: selector] ) {
66 [_delegate performSelector: selector withObject: self withObject: param];
67 }catchAndReport(@"%@ delegate",self.class);
72 + (NSString*) describeCert: (SecCertificateRef)cert {
76 #if TARGET_OS_IPHONE && !defined(__SEC_TYPES__)
77 CFStringRef summary = NULL;
78 SecCertificateCopySubjectSummary(cert);
79 desc = $sprintf(@"Certificate[%@]", summary);
80 if(summary) CFRelease(summary);
82 CFStringRef name=NULL;
83 CFArrayRef emails=NULL;
84 SecCertificateCopyCommonName(cert, &name);
85 SecCertificateCopyEmailAddresses(cert, &emails);
86 desc = $sprintf(@"Certificate[\"%@\", <%@>]",
87 name, [(NSArray*)emails componentsJoinedByString: @">, <"]);
88 if(name) CFRelease(name);
89 if(emails) CFRelease(emails);
94 + (NSString*) describeIdentity: (SecIdentityRef)identity {
97 SecCertificateRef cert;
98 SecIdentityCopyCertificate(identity, &cert);
99 return $sprintf(@"Identity[%@]", [self describeCert: cert]);
107 Copyright (c) 2008, Jens Alfke <jens@mooseyard.com>. All rights reserved.
109 Redistribution and use in source and binary forms, with or without modification, are permitted
110 provided that the following conditions are met:
112 * Redistributions of source code must retain the above copyright notice, this list of conditions
113 and the following disclaimer.
114 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
115 and the following disclaimer in the documentation and/or other materials provided with the
118 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
119 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
120 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
121 BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
122 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
123 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
124 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
125 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.