ObjOpenSSL  Diff

Differences From Artifact [adabc1fce4]:

To Artifact [f6177e4bd6]:


1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







/*
 * Copyright (c) 2011, Florian Zeitz <florob@babelmonkeys.de>
 * Copyright (c) 2011, 2012, 2013, 2015, Jonathan Schleifer <js@nil.im>
 * Copyright (c) 2011, 2012, 2013, 2015, 2021, Jonathan Schleifer <js@nil.im>
 *
 * https://fossil.nil.im/objopenssl
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice is present in all copies.
 *
94
95
96
97
98
99
100
101

102
103
104
105
106
107
108
109
94
95
96
97
98
99
100

101

102
103
104
105
106
107
108







-
+
-







}

- (instancetype)initWithX509Struct: (X509 *)certificate
{
	self = [super init];

	@try {
		_certificate = X509_dup(certificate);
		if ((_certificate = X509_dup(certificate)) == NULL)
		if (_certificate == NULL)
			@throw [OFInitializationFailedException
			    exceptionWithClass: self.class];
	} @catch (id e) {
		[self release];
		@throw e;
	}

328
329
330
331
332
333
334
335

336
337
338
339
340
341
342
327
328
329
330
331
332
333

334
335
336
337
338
339
340
341







-
+








	service = [service stringByAppendingString: @"."];
	serviceLength = service.length;

	for (OFString *name in assertedNames) {
		if ([name hasPrefix: service]) {
			OFString *asserted;
			asserted = [name substringWithRange: of_range(
			asserted = [name substringWithRange: OFRangeMake(
			    serviceLength, name.length - serviceLength)];
			if ([self X509_isAssertedDomain: asserted
					    equalDomain: domain]) {
				objc_autoreleasePoolPop(pool);
				return true;
			}
		}
354
355
356
357
358
359
360
361

362
363
364
365
366
367
368

369
370
371

372
373
374
375

376
377
378
379
380
381
382
353
354
355
356
357
358
359

360
361
362
363
364
365
366

367
368
369

370
371
372
373

374
375
376
377
378
379
380
381







-
+






-
+


-
+



-
+







	 * left-most label and matches only the left-most label with it.
	 * E.g. *.example.com matches foo.example.com,
	 * but not foo.bar.example.com
	 */

	size_t firstDot;

	if ([asserted caseInsensitiveCompare: domain] == OF_ORDERED_SAME)
	if ([asserted caseInsensitiveCompare: domain] == OFOrderedSame)
		return true;

	if (![asserted hasPrefix: @"*."])
		return false;

	asserted = [asserted substringWithRange:
	    of_range(2, asserted.length - 2)];
	    OFRangeMake(2, asserted.length - 2)];

	firstDot = [domain rangeOfString: @"."].location;
	if (firstDot == OF_NOT_FOUND)
	if (firstDot == OFNotFound)
		return false;

	domain = [domain substringWithRange:
	    of_range(firstDot + 1, domain.length - firstDot - 1)];
	    OFRangeMake(firstDot + 1, domain.length - firstDot - 1)];

	if ([asserted caseInsensitiveCompare: domain] == 0)
		return true;

	return false;
}

408
409
410
411
412
413
414
415

416
417
418
419
420
421

422
423
424
425
426
427

428
429
430
431
432
433
434
407
408
409
410
411
412
413

414
415
416
417
418
419

420
421
422
423
424
425

426
427
428
429
430
431
432
433







-
+





-
+





-
+







}


- (X509OID *)X509_stringFromASN1Object: (ASN1_OBJECT *)object
{
	X509OID *ret;
	int length, bufferLength = 256;
	char *buffer = of_alloc(1, bufferLength);
	char *buffer = OFAllocMemory(1, bufferLength);

	@try {
		while ((length = OBJ_obj2txt(buffer, bufferLength, object,
		    1)) > bufferLength) {
			bufferLength = length;
			buffer = of_realloc(buffer, 1, bufferLength);
			buffer = OFResizeMemory(buffer, 1, bufferLength);
		}

		ret = [[[X509OID alloc]
		    initWithUTF8String: buffer] autorelease];
	} @finally {
		free(buffer);
		OFFreeMemory(buffer);
	}

	return ret;
}

- (OFString *)X509_stringFromASN1String: (ASN1_STRING *)str
{