diff -r 9d67172bb323 -r aab592ac36fc TCP/TCPEndpoint.m --- a/TCP/TCPEndpoint.m Fri May 23 17:37:36 2008 -0700 +++ b/TCP/TCPEndpoint.m Tue May 05 23:24:50 2009 -0700 @@ -7,8 +7,10 @@ // #import "TCPEndpoint.h" - +#import "Test.h" +#import "CollectionUtils.h" #import "ExceptionUtils.h" +#import NSString* const kTCPPropertySSLClientSideAuthentication = @"kTCPPropertySSLClientSideAuthentication"; @@ -47,6 +49,15 @@ - (NSString*) securityLevel {return [_sslProperties objectForKey: (id)kCFStreamSSLLevel];} - (void) setSecurityLevel: (NSString*)level {[self setSSLProperty: level forKey: (id)kCFStreamSSLLevel];} +- (void) setPeerToPeerIdentity: (SecIdentityRef)identity { + Assert(identity); + self.SSLProperties = $mdict( + {(id)kCFStreamSSLLevel, NSStreamSocketSecurityLevelTLSv1}, + {kTCPPropertySSLCertificates, $array((id)identity)}, + {kTCPPropertySSLAllowsAnyRoot, $true}, + {kTCPPropertySSLPeerName, [NSNull null]}, + {kTCPPropertySSLClientSideAuthentication, $object(kTCPAlwaysAuthenticate)}); +} - (void) tellDelegate: (SEL)selector withObject: (id)param { @@ -58,6 +69,37 @@ } ++ (NSString*) describeCert: (SecCertificateRef)cert { + if (!cert) + return @"(null)"; + NSString *desc; +#if TARGET_OS_IPHONE && !defined(__SEC_TYPES__) + CFStringRef summary = NULL; + SecCertificateCopySubjectSummary(cert); + desc = $sprintf(@"Certificate[%@]", summary); + if(summary) CFRelease(summary); +#else + CFStringRef name=NULL; + CFArrayRef emails=NULL; + SecCertificateCopyCommonName(cert, &name); + SecCertificateCopyEmailAddresses(cert, &emails); + desc = $sprintf(@"Certificate[\"%@\", <%@>]", + name, [(NSArray*)emails componentsJoinedByString: @">, <"]); + if(name) CFRelease(name); + if(emails) CFRelease(emails); +#endif + return desc; +} + ++ (NSString*) describeIdentity: (SecIdentityRef)identity { + if (!identity) + return @"(null)"; + SecCertificateRef cert; + SecIdentityCopyCertificate(identity, &cert); + return $sprintf(@"Identity[%@]", [self describeCert: cert]); +} + + @end