ObjOpenSSL  Diff

Differences From Artifact [63f0035223]:

To Artifact [756adaa84b]:


87
88
89
90
91
92
93


94
95









































































96
97
98
99
100
101
102
	if (mode & CRYPTO_LOCK)
		of_mutex_lock(&ssl_mutexes[n]);
	else
		of_mutex_unlock(&ssl_mutexes[n]);
}

@interface SSLSocket ()


- (void)SSL_super_close;
@end










































































@implementation SSLSocket
@synthesize delegate = _delegate, certificateFile = _certificateFile;
@synthesize privateKeyFile = _privateKeyFile;
@synthesize privateKeyPassphrase = _privateKeyPassphrase;
@synthesize certificateVerificationEnabled = _certificateVerificationEnabled;
@synthesize requestClientCertificatesEnabled =







>
>


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







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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
	if (mode & CRYPTO_LOCK)
		of_mutex_lock(&ssl_mutexes[n]);
	else
		of_mutex_unlock(&ssl_mutexes[n]);
}

@interface SSLSocket ()
- (void)SSL_startTLSWithExpectedHost: (OFString *)host
				port: (uint16_t)port;
- (void)SSL_super_close;
@end

@interface SSLSocket_ConnectContext: OFObject
{
	OFString *_host;
	uint16_t _port;
	id _target;
	SEL _selector;
	id _context;
}

- (instancetype)initWithHost: (OFString *)host
			port: (uint16_t)port
		      target: (id)target
		    selector: (SEL)selector
		     context: (id)context;
- (void)socketDidConnect: (SSLSocket *)sock
		 context: (id)context
	       exception: (id)exception;
@end

@implementation SSLSocket_ConnectContext
- (instancetype)initWithHost: (OFString *)host
			port: (uint16_t)port
		      target: (id)target
		    selector: (SEL)selector
		     context: (id)context
{
	self = [super init];

	@try {
		_host = [host copy];
		_port = port;
		_target = [target retain];
		_selector = selector;
		_context = [context retain];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_host release];
	[_target release];
	[_context release];

	[super dealloc];
}

- (void)socketDidConnect: (SSLSocket *)sock
		 context: (id)context
	       exception: (id)exception
{
	void (*func)(id, SEL, OFTCPSocket *, id, id) =
	    (void (*)(id, SEL, OFTCPSocket *, id, id))
	    [_target methodForSelector: _selector];

	if (exception == nil) {
		@try {
			[sock SSL_startTLSWithExpectedHost: _host
						      port: _port];
		} @catch (id e) {
			func(_target, _selector, sock, _context, e);
			return;
		}
	}

	func(_target, _selector, sock, _context, exception);
}
@end

@implementation SSLSocket
@synthesize delegate = _delegate, certificateFile = _certificateFile;
@synthesize privateKeyFile = _privateKeyFile;
@synthesize privateKeyPassphrase = _privateKeyPassphrase;
@synthesize certificateVerificationEnabled = _certificateVerificationEnabled;
@synthesize requestClientCertificatesEnabled =
277
278
279
280
281
282
283
284
285




286









287
288





289















290
291



292






293
294
295
296
297
298
299

- (void)startTLSWithExpectedHost: (OFString *)host
{
	[self SSL_startTLSWithExpectedHost: host
				      port: 0];
}

- (void)connectToHost: (OFString *)host
		 port: (uint16_t)port




{









	[super connectToHost: host
			port: port];





















	[self SSL_startTLSWithExpectedHost: host
				      port: port];



}







- (instancetype)accept
{
	SSLSocket *client = (SSLSocket *)[super accept];
	of_string_encoding_t encoding;

	if ((client->_SSL = SSL_new(ctx)) == NULL ||







|
|
>
>
>
>

>
>
>
>
>
>
>
>
>
|
|
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>
>
|
>
>
>
>
>
>







352
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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416

- (void)startTLSWithExpectedHost: (OFString *)host
{
	[self SSL_startTLSWithExpectedHost: host
				      port: 0];
}

- (void)asyncConnectToHost: (OFString *)host
		      port: (uint16_t)port
	       runLoopMode: (of_run_loop_mode_t)runLoopMode
		    target: (id)target
		  selector: (SEL)selector
		   context: (id)userContext
{
	void *pool = objc_autoreleasePoolPush();
	SSLSocket_ConnectContext *context;

	context = [[[SSLSocket_ConnectContext alloc]
	    initWithHost: host
		    port: port
		  target: target
		selector: selector
		 context: userContext] autorelease];
	[super asyncConnectToHost: host
			     port: port
		      runLoopMode: runLoopMode
			   target: context
			 selector: @selector(socketDidConnect:context:
				       exception:)
			  context: nil];

	objc_autoreleasePoolPop(pool);
}

#ifdef OF_HAVE_BLOCKS
- (void)asyncConnectToHost: (OFString *)host
		      port: (uint16_t)port
	       runLoopMode: (of_run_loop_mode_t)runLoopMode
		     block: (of_tcp_socket_async_connect_block_t)block
{
	[super asyncConnectToHost: host
			     port: port
		      runLoopMode: runLoopMode
			    block: ^ (SSLSocket *sock, id exception) {
		if (exception == nil) {
			@try {
				[sock SSL_startTLSWithExpectedHost: host
							      port: port];
			} @catch (id e) {
				block(sock, e);
				return;
			}
		}

		block(sock, exception);
	}];
}
#endif

- (instancetype)accept
{
	SSLSocket *client = (SSLSocket *)[super accept];
	of_string_encoding_t encoding;

	if ((client->_SSL = SSL_new(ctx)) == NULL ||