ObjOpenSSL  Check-in [b3c83672df]

Overview
Comment:Support for async connecting
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: b3c83672df988eef54a98554a65c76eb8583b954f6f479755aad36493c111a76
User & Date: js on 2018-10-07 21:07:13
Other Links: manifest | tags
Context
2018-11-05
22:24
configure: Do not use pkg-config to find OpenSSL check-in: 32bcbfa301 user: js tags: trunk
2018-10-07
21:07
Support for async connecting check-in: b3c83672df user: js tags: trunk
2018-07-29
16:52
Adjust to ObjFW changes check-in: 406ed24bc9 user: js tags: trunk
Changes

Modified src/SSLConnectionFailedException.h from [9260d92004] to [52f2c04dd6].

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
	unsigned long _SSLError;
	long _verifyResult;
}

@property (readonly, nonatomic) unsigned long SSLError;
@property (readonly, nonatomic) long verifyResult;

+ (instancetype)exceptionWithHost: (OFString *)host
			     port: (uint16_t)port
			   socket: (id)socket OF_UNAVAILABLE;
+ (instancetype)exceptionWithHost: (OFString *)host
			     port: (uint16_t)port
			   socket: (id)socket
			    errNo: (int)errNo OF_UNAVAILABLE;
+ (instancetype)exceptionWithHost: (OFString *)host
			     port: (uint16_t)port
			   socket: (SSLSocket *)socket
			 SSLError: (unsigned long)SSLError;
+ (instancetype)exceptionWithHost: (OFString *)host
			     port: (uint16_t)port
			   socket: (SSLSocket *)socket
			 SSLError: (unsigned long)SSLError
		     verifyResult: (long)verifyResult;
- initWithHost: (OFString *)host
	  port: (uint16_t)port
	socket: (id)socket OF_UNAVAILABLE;
- initWithHost: (OFString *)host
	  port: (uint16_t)port
	socket: (id)socket
	 errNo: (int)errNo OF_UNAVAILABLE;
- initWithHost: (OFString *)host
	  port: (uint16_t)port
	socket: (SSLSocket *)socket
      SSLError: (unsigned long)SSLError;
- initWithHost: (OFString *)host
	  port: (uint16_t)port
	socket: (SSLSocket *)socket
      SSLError: (unsigned long)SSLError
  verifyResult: (long)verifyResult OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END







|


|












|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
	unsigned long _SSLError;
	long _verifyResult;
}

@property (readonly, nonatomic) unsigned long SSLError;
@property (readonly, nonatomic) long verifyResult;

+ (instancetype)exceptionWithHost: (nullable OFString *)host
			     port: (uint16_t)port
			   socket: (id)socket OF_UNAVAILABLE;
+ (instancetype)exceptionWithHost: (nullable OFString *)host
			     port: (uint16_t)port
			   socket: (id)socket
			    errNo: (int)errNo OF_UNAVAILABLE;
+ (instancetype)exceptionWithHost: (OFString *)host
			     port: (uint16_t)port
			   socket: (SSLSocket *)socket
			 SSLError: (unsigned long)SSLError;
+ (instancetype)exceptionWithHost: (OFString *)host
			     port: (uint16_t)port
			   socket: (SSLSocket *)socket
			 SSLError: (unsigned long)SSLError
		     verifyResult: (long)verifyResult;
- (instancetype)initWithHost: (nullable OFString *)host
			port: (uint16_t)port
		      socket: (id)socket OF_UNAVAILABLE;
- (instancetype)initWithHost: (nullable OFString *)host
			port: (uint16_t)port
		      socket: (id)socket
		       errNo: (int)errNo OF_UNAVAILABLE;
- (instancetype)initWithHost: (OFString *)host
			port: (uint16_t)port
		      socket: (SSLSocket *)socket
		    SSLError: (unsigned long)SSLError;
- (instancetype)initWithHost: (OFString *)host
			port: (uint16_t)port
		      socket: (SSLSocket *)socket
		    SSLError: (unsigned long)SSLError
		verifyResult: (long)verifyResult OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END

Modified src/SSLSocket.m from [63f0035223] to [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 ||