ObjOpenSSL  Check-in [e100eb1e52]

Overview
Comment:Cache subject, issuer and SANs
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e100eb1e5254058a19b3f550e738b8414cb8c9aaa93292b0b80829517e506a5a
User & Date: florob@babelmonkeys.de on 2011-11-01 14:36:17
Other Links: manifest | tags
Context
2011-11-01
15:09
Add methods for easier certificate verification check-in: b53c1ba1a8 user: florob@babelmonkeys.de tags: trunk
14:36
Cache subject, issuer and SANs check-in: e100eb1e52 user: florob@babelmonkeys.de tags: trunk
2011-10-29
22:50
Add defines for some common OIDs check-in: 5deab0aa50 user: florob@babelmonkeys.de tags: trunk
Changes

Modified src/X509Certificate.h from [50185c693b] to [685333962c].

37
38
39
40
41
42
43



44
45
46
47

48
49
50
51
52
53
54
37
38
39
40
41
42
43
44
45
46
47
48
49

50
51
52
53
54
55
56
57







+
+
+



-
+







#define OID_organizationalUnitName  @"2.5.4.11"

#define OID_SRVName @"1.3.6.1.5.5.7.8.7"

@interface X509Certificate: OFObject
{
	X509 *crt;
	OFDictionary *issuer;
	OFDictionary *subject;
	OFDictionary *subjectAlternativeName;
}

#ifdef OF_HAVE_PROPERTIES
// @property (opts) Type *name;
@property (readonly) OFDictionary *issuer, *subject, *subjectAlternativeName;
#endif

- initWithFile: (OFString*)file;
- initWithX509Struct: (X509*)cert;
- (OFDictionary*)issuer;
- (OFDictionary*)subject;
- (OFDictionary*)subjectAlternativeName;

Modified src/X509Certificate.m from [ea8865b8c0] to [19eeb8fa7d].

22
23
24
25
26
27
28

29
30
31
32
33
34
35
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36







+








#include <openssl/crypto.h>
#include <openssl/x509v3.h>

#import "X509Certificate.h"

#import <ObjFW/OFAutoreleasePool.h>
#import <ObjFW/OFArray.h>
#import <ObjFW/OFDataArray.h>
#import <ObjFW/OFDictionary.h>
#import <ObjFW/OFFile.h>
#import <ObjFW/OFInitializationFailedException.h>
#import <ObjFW/OFInvalidEncodingException.h>
#import <ObjFW/OFList.h>
#import <ObjFW/OFMutableDictionary.h>
75
76
77
78
79
80
81




82
83
84
85
86
87
88
89

90
91





92
93
94
95

96
97





98
99
100
101



102
103
104
105
106
107
108
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95


96
97
98
99
100
101
102
103
104
105


106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124







+
+
+
+








+
-
-
+
+
+
+
+




+
-
-
+
+
+
+
+




+
+
+







	}

	return self;
}

- (void)dealloc
{
	[issuer release];
	[subject release];
	[subjectAlternativeName release];

	if (crt != NULL)
		X509_free(crt);

	[super dealloc];
}

- (OFDictionary*)issuer
{
	if (issuer == nil) {
	X509_NAME *name = X509_get_issuer_name(crt);
	return [self X509_dictionaryFromX509Name: name];
		X509_NAME *name = X509_get_issuer_name(crt);
		issuer = [[self X509_dictionaryFromX509Name: name] retain];
	}

	return issuer;
}

- (OFDictionary*)subject
{
	if (subject == nil) {
	X509_NAME *name = X509_get_subject_name(crt);
	return [self X509_dictionaryFromX509Name: name];
		X509_NAME *name = X509_get_subject_name(crt);
		subject = [[self X509_dictionaryFromX509Name: name] retain];
	}

	return subject;
}

- (OFDictionary*)subjectAlternativeName
{
	if (subjectAlternativeName != nil)
		return subjectAlternativeName;

	int i = -1, j;
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFMutableDictionary *ret = [OFMutableDictionary dictionary];

	while ((i = X509_get_ext_by_NID(crt, NID_subject_alt_name, i)) != -1) {
		X509_EXTENSION *extension;
		STACK_OF(GENERAL_NAME) *values;
218
219
220
221
222
223
224
225

226
227
228
229
230
231
232
234
235
236
237
238
239
240

241
242
243
244
245
246
247
248







-
+







		i++; /* Next extension */
	}

	[ret makeImmutable];
	[ret retain];
	[pool release];

	return [ret autorelease];
	return (subjectAlternativeName = ret);
}

- (OFDictionary*)X509_dictionaryFromX509Name: (X509_NAME*)name
{
	int i;
	int count = X509_NAME_entry_count(name);
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];