jens@49
|
1 |
//
|
jens@49
|
2 |
// TCPEndpoint+Certs.m
|
jens@49
|
3 |
// MYNetwork-iPhone
|
jens@49
|
4 |
//
|
jens@49
|
5 |
// Created by Jens Alfke on 5/21/09.
|
jens@49
|
6 |
// Copyright 2009 Jens Alfke. All rights reserved.
|
jens@49
|
7 |
//
|
jens@49
|
8 |
|
jens@49
|
9 |
#import "TCPEndpoint.h"
|
jens@49
|
10 |
#import "CollectionUtils.h"
|
jens@49
|
11 |
#import <Security/Security.h>
|
jens@49
|
12 |
|
jens@49
|
13 |
|
jens@49
|
14 |
/** These are some optional category methods for TCPEndpoint for dumping info about certificates.
|
jens@49
|
15 |
They're useful if you're working with SSL connections, but they do link against the Security
|
jens@49
|
16 |
framework, so they're moved into this extra file that you can choose to compile into your
|
jens@49
|
17 |
project or not.
|
jens@49
|
18 |
*/
|
jens@49
|
19 |
@implementation TCPEndpoint (Certificates)
|
jens@49
|
20 |
|
jens@49
|
21 |
|
jens@49
|
22 |
+ (NSString*) describeCert: (SecCertificateRef)cert {
|
jens@49
|
23 |
if (!cert)
|
jens@49
|
24 |
return @"(null)";
|
jens@49
|
25 |
NSString *desc;
|
jens@49
|
26 |
#if TARGET_OS_IPHONE && !defined(__SEC_TYPES__)
|
jens@49
|
27 |
CFStringRef summary = NULL;
|
jens@49
|
28 |
SecCertificateCopySubjectSummary(cert);
|
jens@49
|
29 |
desc = $sprintf(@"Certificate[%@]", summary);
|
jens@49
|
30 |
if(summary) CFRelease(summary);
|
jens@49
|
31 |
#else
|
jens@49
|
32 |
CFStringRef name=NULL;
|
jens@49
|
33 |
CFArrayRef emails=NULL;
|
jens@49
|
34 |
SecCertificateCopyCommonName(cert, &name);
|
jens@49
|
35 |
SecCertificateCopyEmailAddresses(cert, &emails);
|
jens@49
|
36 |
desc = $sprintf(@"Certificate[\"%@\", <%@>]",
|
jens@49
|
37 |
name, [(NSArray*)emails componentsJoinedByString: @">, <"]);
|
jens@49
|
38 |
if(name) CFRelease(name);
|
jens@49
|
39 |
if(emails) CFRelease(emails);
|
jens@49
|
40 |
#endif
|
jens@49
|
41 |
return desc;
|
jens@49
|
42 |
}
|
jens@49
|
43 |
|
jens@49
|
44 |
+ (NSString*) describeIdentity: (SecIdentityRef)identity {
|
jens@49
|
45 |
if (!identity)
|
jens@49
|
46 |
return @"(null)";
|
jens@49
|
47 |
SecCertificateRef cert;
|
jens@49
|
48 |
SecIdentityCopyCertificate(identity, &cert);
|
jens@49
|
49 |
return $sprintf(@"Identity[%@]", [self describeCert: cert]);
|
jens@49
|
50 |
}
|
jens@49
|
51 |
|
jens@49
|
52 |
|
jens@49
|
53 |
@end
|