As reported by Jon Martinsson:
--------------------------------------------------
I have problems using the keychain framework to list the DN of a
cert. I want to retrieve the Subject, Issuer and other stuff from the
cert as strings. The following code crashed both on 10.3.5 and 10.4
DP.
Keychain *theKeychain = [[Keychain defaultKeychain] retain];
NSArray* identities = [theKeychain identities];
Identity *curIdentity = nil;
NSEnumerator *enumerator = nil;
enumerator = [identities objectEnumerator];
while (curIdentity = (Identity*)[enumerator nextObject]) {
Certificate* certificate = [[curIdentity certificate] retain];
NameList* nl = [[certificate issuer] retain];
NameListEnumerator* enumerator = [NameListEnumerator
enumeratorForNameList:nl];
DistinguishedName* dn = [[enumerator nextObject] retain]; //
get first
object only
BOOL classok = [dn isKindOfClass:[DistinguishedName class]];
// crashes here when requsting subject, run inifinite when
requesting issuer.
NSLog(@"string %@", [dn description]);
DistinguishedNameEnumerator* dnenumerator =
[DistinguishedNameEnumerator
enumeratorForDistinguishedName:dn];
TypeValuePair* tvp = nil;
while (tvp = [dnenumerator nextObject]) {
[tvp retain];
classok = [tvp isKindOfClass:[TypeValuePair class]];
NSString *d = [tvp description];
NSString *t = [tvp typeAsString];
NSLog(@"string %@", d);
NSLog(@"string %@", t);
}
}
}
--------------------------------------------------
The most likely culprit seems to be the TypeValuePair that [dn
description] creates to extract it's contents. I can't recall the exact
details off hand, but there was a bug/documentation-error in
Apple's implementation at one point where it would claim the pair
had both types encoded, but would in fact only have the BER part
(the other part would be gibberish). This was or should be fixed in
either 10.3 or 10.4 (can't recall which), but one way or another the
current code appears to be incorrect for 10.3 & 10.4 (most likely
works under 10.2, though).