jens@49: // jens@49: // TCPEndpoint+Certs.m jens@49: // MYNetwork-iPhone jens@49: // jens@49: // Created by Jens Alfke on 5/21/09. jens@49: // Copyright 2009 Jens Alfke. All rights reserved. jens@49: // jens@49: jens@49: #import "TCPEndpoint.h" jens@49: #import "CollectionUtils.h" jens@49: #import jens@49: jens@49: jens@49: /** These are some optional category methods for TCPEndpoint for dumping info about certificates. jens@49: They're useful if you're working with SSL connections, but they do link against the Security jens@49: framework, so they're moved into this extra file that you can choose to compile into your jens@49: project or not. jens@49: */ jens@49: @implementation TCPEndpoint (Certificates) jens@49: jens@49: jens@49: + (NSString*) describeCert: (SecCertificateRef)cert { jens@49: if (!cert) jens@49: return @"(null)"; jens@49: NSString *desc; jens@49: #if TARGET_OS_IPHONE && !defined(__SEC_TYPES__) jens@49: CFStringRef summary = NULL; jens@49: SecCertificateCopySubjectSummary(cert); jens@49: desc = $sprintf(@"Certificate[%@]", summary); jens@49: if(summary) CFRelease(summary); jens@49: #else jens@49: CFStringRef name=NULL; jens@49: CFArrayRef emails=NULL; jens@49: SecCertificateCopyCommonName(cert, &name); jens@49: SecCertificateCopyEmailAddresses(cert, &emails); jens@49: desc = $sprintf(@"Certificate[\"%@\", <%@>]", jens@49: name, [(NSArray*)emails componentsJoinedByString: @">, <"]); jens@49: if(name) CFRelease(name); jens@49: if(emails) CFRelease(emails); jens@49: #endif jens@49: return desc; jens@49: } jens@49: jens@49: + (NSString*) describeIdentity: (SecIdentityRef)identity { jens@49: if (!identity) jens@49: return @"(null)"; jens@49: SecCertificateRef cert; jens@49: SecIdentityCopyCertificate(identity, &cert); jens@49: return $sprintf(@"Identity[%@]", [self describeCert: cert]); jens@49: } jens@49: jens@49: jens@49: @end