ObjOpenSSL  Check-in [8cb0b716ea]

Overview
Comment:Break out some ASN.1 to OFString conversion functionality
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8cb0b716eaea87248bbf00cccaf9d901699c37cd891b83c98a6d42ca965ec7da
User & Date: florob@babelmonkeys.de on 2011-10-07 23:56:55
Other Links: manifest | tags
Context
2011-10-08
03:44
Add support for fetching some SAN types from X509 certificates check-in: ca9555b85f user: florob@babelmonkeys.de tags: trunk
2011-10-07
23:56
Break out some ASN.1 to OFString conversion functionality check-in: 8cb0b716ea user: florob@babelmonkeys.de tags: trunk
23:13
Very basic X509 class check-in: 057c289c6b user: florob@babelmonkeys.de tags: trunk
Changes

Modified src/X509Certificate.h from [a776e0422b] to [24b4f5fcd2].

35
36
37
38
39
40
41


42
#endif

- initWithFile: (OFString*)file;
- initWithStruct: (X509*)cert;
- (OFDictionary*)issuer;
- (OFDictionary*)subject;
- (OFDictionary*)X509_dictionaryFromX509Name: (X509_NAME*)name;


@end







>
>

35
36
37
38
39
40
41
42
43
44
#endif

- initWithFile: (OFString*)file;
- initWithStruct: (X509*)cert;
- (OFDictionary*)issuer;
- (OFDictionary*)subject;
- (OFDictionary*)X509_dictionaryFromX509Name: (X509_NAME*)name;
- (OFString*)X509_stringFromASN1Object: (ASN1_OBJECT*)obj;
- (OFString*) X509_stringFromASN1String: (ASN1_STRING*)str;
@end

Modified src/X509Certificate.m from [4b0c950416] to [235fa6b4e5].

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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139



























140
{
	int i;
	int count = X509_NAME_entry_count(name);
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFMutableDictionary *dict = [OFMutableDictionary dictionary];

	for (i = 0; i < count; i++) {
		int len, buf_len = 256;
		OFString *key, *value;
		char *buf = [self allocMemoryWithSize: buf_len];
		X509_NAME_ENTRY *entry = X509_NAME_get_entry(name, i);
		ASN1_OBJECT *obj = X509_NAME_ENTRY_get_object(entry);
		while ((len = OBJ_obj2txt(buf, buf_len, obj, 1)) > buf_len) {
			buf_len = len;

			[self resizeMemory: buf
				    toSize: buf_len];
		}
		key = [OFString stringWithUTF8String: buf];
		[self freeMemory: buf];

		if ([dict objectForKey: key] == nil)
			[dict setObject: [OFList list]
				 forKey: key];

		if (ASN1_STRING_to_UTF8((unsigned char**)&buf,
		    X509_NAME_ENTRY_get_data(entry)) < 0)
			@throw [OFInvalidEncodingException
				    exceptionWithClass: isa];
		value = [OFString stringWithUTF8String: buf];
		OPENSSL_free(buf);

		[[dict objectForKey: key] appendObject: value];
	}

	[dict makeImmutable];
	[dict retain];
	[pool release];

	return [dict autorelease];
}



























@end







<

<


<
<
>
|
<
<
<
<





<
<
<
<
<
<
|









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
{
	int i;
	int count = X509_NAME_entry_count(name);
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFMutableDictionary *dict = [OFMutableDictionary dictionary];

	for (i = 0; i < count; i++) {

		OFString *key, *value;

		X509_NAME_ENTRY *entry = X509_NAME_get_entry(name, i);
		ASN1_OBJECT *obj = X509_NAME_ENTRY_get_object(entry);


		ASN1_STRING *str = X509_NAME_ENTRY_get_data(entry);
		key = [self X509_stringFromASN1Object: obj];





		if ([dict objectForKey: key] == nil)
			[dict setObject: [OFList list]
				 forKey: key];







		value = [self X509_stringFromASN1String: str];
		[[dict objectForKey: key] appendObject: value];
	}

	[dict makeImmutable];
	[dict retain];
	[pool release];

	return [dict autorelease];
}


- (OFString*)X509_stringFromASN1Object: (ASN1_OBJECT*)obj
{
	int len, buf_len = 256;
	char *buf = [self allocMemoryWithSize: buf_len];
	OFString *ret;
	while ((len = OBJ_obj2txt(buf, buf_len, obj, 1)) > buf_len) {
		buf_len = len;
		[self resizeMemory: buf
			    toSize: buf_len];
	}
	ret = [OFString stringWithUTF8String: buf];
	[self freeMemory: buf];
	return ret;
}

- (OFString*) X509_stringFromASN1String: (ASN1_STRING*)str
{
	char *buf;
	OFString *ret;
	if (ASN1_STRING_to_UTF8((unsigned char**)&buf, str) < 0)
		@throw [OFInvalidEncodingException exceptionWithClass: isa];
	ret = [OFString stringWithUTF8String: buf];
	OPENSSL_free(buf);
	return ret;
}
@end