ObjOpenSSL  Check-in [d7e54e7735]

Overview
Comment:Adjust to ObjFW changes
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d7e54e7735a60271c0fa70e8db6039ca4d314db7e2dae7a8b6d44b3b86d2d85c
User & Date: js on 2018-12-08 17:28:13
Other Links: manifest | tags
Context
2018-12-21
21:45
Adjust to ObjFW changes check-in: def7f8346a user: js tags: trunk
2018-12-08
17:28
Adjust to ObjFW changes check-in: d7e54e7735 user: js tags: trunk
2018-11-10
10:59
Update buildsys check-in: 7c3cddfa2e user: js tags: trunk
Changes

Modified src/SSLSocket.h from [1ced025d5c] to [482ed92e1f].

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
OF_ASSUME_NONNULL_BEGIN

@class X509Certificate;

@interface SSLSocket: OFTCPSocket <OFTLSSocket>
{
	SSL *_SSL;
	id <OFTLSSocketDelegate> _delegate;
	OFString *_certificateFile, *_privateKeyFile;
	const char *_privateKeyPassphrase;
	bool _certificateVerificationEnabled;
	bool _requestClientCertificatesEnabled;
}

@property (nonatomic, getter=isRequestClientCertificatesEnabled)







<







29
30
31
32
33
34
35

36
37
38
39
40
41
42
OF_ASSUME_NONNULL_BEGIN

@class X509Certificate;

@interface SSLSocket: OFTCPSocket <OFTLSSocket>
{
	SSL *_SSL;

	OFString *_certificateFile, *_privateKeyFile;
	const char *_privateKeyPassphrase;
	bool _certificateVerificationEnabled;
	bool _requestClientCertificatesEnabled;
}

@property (nonatomic, getter=isRequestClientCertificatesEnabled)

Modified src/SSLSocket.m from [756adaa84b] to [f2bb7cedd4].

1
2
3
4
5
6
7
8
9
/*
 * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016
 *     Jonathan Schleifer <js@heap.zone>
 * Copyright (c) 2011, Florian Zeitz <florob@babelmonkeys.de>
 * Copyright (c) 2011, Jos Kuijpers <jos@kuijpersvof.nl>
 *
 * https://heap.zone/git/objopenssl.git
 *
 * Permission to use, copy, modify, and/or distribute this software for any

|







1
2
3
4
5
6
7
8
9
/*
 * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
 *     Jonathan Schleifer <js@heap.zone>
 * Copyright (c) 2011, Florian Zeitz <florob@babelmonkeys.de>
 * Copyright (c) 2011, Jos Kuijpers <jos@kuijpersvof.nl>
 *
 * https://heap.zone/git/objopenssl.git
 *
 * Permission to use, copy, modify, and/or distribute this software for any
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
178
179
180

@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 =
    _requestClientCertificatesEnabled;

+ (void)load







|

>


|
<
<


|
>
|
|
<
<
<
<
<


|
|
>
|
|
<
<




>


|
|
<
>










>
>
|
|
|




|
|
|

<
<
<
<
<
|
|
|
|
>
|
>
>
>
|
|
|
>
>
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>




>
|







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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192

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

@interface SSLSocket_ConnectDelegate: OFObject <OFTLSSocketDelegate>
{
	SSLSocket *_socket;
	OFString *_host;
	uint16_t _port;
	id <OFTLSSocketDelegate> _delegate;


}

- (instancetype)initWithSocket: (SSLSocket *)sock
			  host: (OFString *)host
			  port: (uint16_t)port
		      delegate: (id <OFTLSSocketDelegate>)delegate;





@end

@implementation SSLSocket_ConnectDelegate
- (instancetype)initWithSocket: (SSLSocket *)sock
			  host: (OFString *)host
			  port: (uint16_t)port
		      delegate: (id <OFTLSSocketDelegate>)delegate


{
	self = [super init];

	@try {
		_socket = [sock retain];
		_host = [host copy];
		_port = port;
		_delegate = [delegate retain];


		[_socket setDelegate: self];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	if ([_socket delegate] == self)
		[_socket setDelegate: _delegate];

	[_socket release];
	[_delegate release];

	[super dealloc];
}

-     (void)socket: (OF_KINDOF(OFTCPSocket *))sock
  didConnectToHost: (OFString *)host
	      port: (uint16_t)port
{





	@try {
		[sock SSL_startTLSWithExpectedHost: _host
					      port: _port];
	} @catch (id e) {
		[_socket setDelegate: _delegate];
		[_delegate		   socket: sock
		    didFailToConnectWithException: e
					     host: host
					     port: port];
		return;
	}

	[_socket setDelegate: _delegate];
	[_delegate    socket: sock
	    didConnectToHost: host
			port: port];
}

-		   (void)socket: (OF_KINDOF(OFTCPSocket *))sock
  didFailToConnectWithException: (id)exception
			   host: (OFString *)host
			   port: (uint16_t)port
{
	[_socket setDelegate: _delegate];

	return [_delegate	   socket: sock
	    didFailToConnectWithException: exception
				     host: host
				     port: port];
}
@end

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

+ (void)load
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
	[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







<
<
<


|

|
>
|
|
<
<
|


|
<
<
<
<







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
	[self SSL_startTLSWithExpectedHost: host
				      port: 0];
}

- (void)asyncConnectToHost: (OFString *)host
		      port: (uint16_t)port
	       runLoopMode: (of_run_loop_mode_t)runLoopMode



{
	void *pool = objc_autoreleasePoolPush();
	SSLSocket_ConnectDelegate *connectDelegate;

	connectDelegate = [[[SSLSocket_ConnectDelegate alloc]
	    initWithSocket: self
		      host: host
		      port: port


		  delegate: _delegate] autorelease];
	[super asyncConnectToHost: host
			     port: port
		      runLoopMode: runLoopMode];





	objc_autoreleasePoolPop(pool);
}

#ifdef OF_HAVE_BLOCKS
- (void)asyncConnectToHost: (OFString *)host
		      port: (uint16_t)port