TCP/TCPEndpoint+Certs.m
author Jens Alfke <jens@mooseyard.com>
Sun May 24 15:03:39 2009 -0700 (2009-05-24)
changeset 49 20cccc7c26ee
permissions -rw-r--r--
Misc. tweaks made while porting Chatty to use MYNetwork.
* Allow -[BLIPConnection sendRequest:] to re-send an already-sent or received request.
* Allow use of the basic -init method for BLIPConnection.
* Some new convenience factory methods.
* Broke dependencies on Security.framework out into new TCPEndpoint+Certs.m source file, so client apps aren't forced to link against Security.
     1 //
     2 //  TCPEndpoint+Certs.m
     3 //  MYNetwork-iPhone
     4 //
     5 //  Created by Jens Alfke on 5/21/09.
     6 //  Copyright 2009 Jens Alfke. All rights reserved.
     7 //
     8 
     9 #import "TCPEndpoint.h"
    10 #import "CollectionUtils.h"
    11 #import <Security/Security.h>
    12 
    13 
    14 /** These are some optional category methods for TCPEndpoint for dumping info about certificates.
    15     They're useful if you're working with SSL connections, but they do link against the Security
    16     framework, so they're moved into this extra file that you can choose to compile into your
    17     project or not.
    18 */
    19 @implementation TCPEndpoint (Certificates)
    20 
    21 
    22 + (NSString*) describeCert: (SecCertificateRef)cert {
    23     if (!cert)
    24         return @"(null)";
    25     NSString *desc;
    26 #if TARGET_OS_IPHONE && !defined(__SEC_TYPES__)
    27     CFStringRef summary = NULL;
    28     SecCertificateCopySubjectSummary(cert);
    29     desc = $sprintf(@"Certificate[%@]", summary);
    30     if(summary) CFRelease(summary);
    31 #else
    32     CFStringRef name=NULL;
    33     CFArrayRef emails=NULL;
    34     SecCertificateCopyCommonName(cert, &name);
    35     SecCertificateCopyEmailAddresses(cert, &emails);
    36     desc = $sprintf(@"Certificate[\"%@\", <%@>]",
    37                     name, [(NSArray*)emails componentsJoinedByString: @">, <"]);
    38     if(name) CFRelease(name);
    39     if(emails) CFRelease(emails);
    40 #endif
    41     return desc;
    42 }
    43 
    44 + (NSString*) describeIdentity: (SecIdentityRef)identity {
    45     if (!identity)
    46         return @"(null)";
    47     SecCertificateRef cert;
    48     SecIdentityCopyCertificate(identity, &cert);
    49     return $sprintf(@"Identity[%@]", [self describeCert: cert]);
    50 }
    51 
    52 
    53 @end