Cache subject, issuer and SANs
This commit is contained in:
parent
38d625a887
commit
53932c0acb
2 changed files with 25 additions and 6 deletions
|
@ -41,10 +41,13 @@
|
||||||
@interface X509Certificate: OFObject
|
@interface X509Certificate: OFObject
|
||||||
{
|
{
|
||||||
X509 *crt;
|
X509 *crt;
|
||||||
|
OFDictionary *issuer;
|
||||||
|
OFDictionary *subject;
|
||||||
|
OFDictionary *subjectAlternativeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef OF_HAVE_PROPERTIES
|
#ifdef OF_HAVE_PROPERTIES
|
||||||
// @property (opts) Type *name;
|
@property (readonly) OFDictionary *issuer, *subject, *subjectAlternativeName;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
- initWithFile: (OFString*)file;
|
- initWithFile: (OFString*)file;
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#import "X509Certificate.h"
|
#import "X509Certificate.h"
|
||||||
|
|
||||||
#import <ObjFW/OFAutoreleasePool.h>
|
#import <ObjFW/OFAutoreleasePool.h>
|
||||||
|
#import <ObjFW/OFArray.h>
|
||||||
#import <ObjFW/OFDataArray.h>
|
#import <ObjFW/OFDataArray.h>
|
||||||
#import <ObjFW/OFDictionary.h>
|
#import <ObjFW/OFDictionary.h>
|
||||||
#import <ObjFW/OFFile.h>
|
#import <ObjFW/OFFile.h>
|
||||||
|
@ -79,6 +80,10 @@
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
{
|
{
|
||||||
|
[issuer release];
|
||||||
|
[subject release];
|
||||||
|
[subjectAlternativeName release];
|
||||||
|
|
||||||
if (crt != NULL)
|
if (crt != NULL)
|
||||||
X509_free(crt);
|
X509_free(crt);
|
||||||
|
|
||||||
|
@ -87,18 +92,29 @@
|
||||||
|
|
||||||
- (OFDictionary*)issuer
|
- (OFDictionary*)issuer
|
||||||
{
|
{
|
||||||
|
if (issuer == nil) {
|
||||||
X509_NAME *name = X509_get_issuer_name(crt);
|
X509_NAME *name = X509_get_issuer_name(crt);
|
||||||
return [self X509_dictionaryFromX509Name: name];
|
issuer = [[self X509_dictionaryFromX509Name: name] retain];
|
||||||
|
}
|
||||||
|
|
||||||
|
return issuer;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (OFDictionary*)subject
|
- (OFDictionary*)subject
|
||||||
{
|
{
|
||||||
|
if (subject == nil) {
|
||||||
X509_NAME *name = X509_get_subject_name(crt);
|
X509_NAME *name = X509_get_subject_name(crt);
|
||||||
return [self X509_dictionaryFromX509Name: name];
|
subject = [[self X509_dictionaryFromX509Name: name] retain];
|
||||||
|
}
|
||||||
|
|
||||||
|
return subject;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (OFDictionary*)subjectAlternativeName
|
- (OFDictionary*)subjectAlternativeName
|
||||||
{
|
{
|
||||||
|
if (subjectAlternativeName != nil)
|
||||||
|
return subjectAlternativeName;
|
||||||
|
|
||||||
int i = -1, j;
|
int i = -1, j;
|
||||||
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
|
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
|
||||||
OFMutableDictionary *ret = [OFMutableDictionary dictionary];
|
OFMutableDictionary *ret = [OFMutableDictionary dictionary];
|
||||||
|
@ -222,7 +238,7 @@
|
||||||
[ret retain];
|
[ret retain];
|
||||||
[pool release];
|
[pool release];
|
||||||
|
|
||||||
return [ret autorelease];
|
return (subjectAlternativeName = ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (OFDictionary*)X509_dictionaryFromX509Name: (X509_NAME*)name
|
- (OFDictionary*)X509_dictionaryFromX509Name: (X509_NAME*)name
|
||||||
|
|
Reference in a new issue