ObjFW  Check-in [1a3613d573]

Overview
Comment:More consistency between TLS implementations

While GnuTLS and SecureTransport haven't shown in practice to need this,
this makes it more robust for future changes in those. In theory, both
could return less data on a read than they have buffered, meaning the
delimiter is not found but in the buffered data, which would then make
them have the same issue OpenSSL had with hanging connections (though
there the problem was that the BIO was not processed and never would
without the same change as in this commit).

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1a3613d573b5f6e92eed64a1c0ade99bd8cf10df9beffa23f17ffe89fb847c60
User & Date: js on 2023-09-10 12:11:53
Other Links: manifest | tags
Context
2023-09-10
12:26
Update ChangeLog check-in: dd51423e9c user: js tags: trunk
12:11
More consistency between TLS implementations check-in: 1a3613d573 user: js tags: trunk
2023-09-08
12:48
Update buildsys check-in: ec7204c581 user: js tags: trunk
Changes

Modified src/tls/OFGnuTLSTLSStream.m from [b0bb2b39ec] to [ba84ecba17].

15
16
17
18
19
20
21

22
23
24
25
26
27
28

#include "config.h"

#include <errno.h>

#import "OFGnuTLSTLSStream.h"
#import "OFData.h"


#import "OFAlreadyOpenException.h"
#import "OFInitializationFailedException.h"
#import "OFNotOpenException.h"
#import "OFReadFailedException.h"
#import "OFTLSHandshakeFailedException.h"
#import "OFWriteFailedException.h"







>







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

#include "config.h"

#include <errno.h>

#import "OFGnuTLSTLSStream.h"
#import "OFData.h"
#import "OFStream+Private.h"

#import "OFAlreadyOpenException.h"
#import "OFInitializationFailedException.h"
#import "OFNotOpenException.h"
#import "OFReadFailedException.h"
#import "OFTLSHandshakeFailedException.h"
#import "OFWriteFailedException.h"
188
189
190
191
192
193
194
















195
196
197
198
199
200
201
- (bool)hasDataInReadBuffer
{
	if (gnutls_record_check_pending(_session) > 0)
		return true;

	return super.hasDataInReadBuffer;
}

















- (void)asyncPerformClientHandshakeWithHost: (OFString *)host
				runLoopMode: (OFRunLoopMode)runLoopMode
{
	static const OFTLSStreamErrorCode initFailedErrorCode =
	    OFTLSStreamErrorCodeInitializationFailed;
	id exception = nil;







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







189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
- (bool)hasDataInReadBuffer
{
	if (gnutls_record_check_pending(_session) > 0)
		return true;

	return super.hasDataInReadBuffer;
}

- (bool)of_isWaitingForDelimiter
{
	/* FIXME: There should be a non-private API for this. */

	/*
	 * If we still have pending data in the session, we haven't processed
	 * it yet to see if our delimiter is in there. So return false here, as
	 * that will signal the stream as ready for reading, which in turn will
	 * cause a read and checking for the delimiter.
	 */
	if (gnutls_record_check_pending(_session) > 0)
		return false;

	return super.of_waitingForDelimiter;
}

- (void)asyncPerformClientHandshakeWithHost: (OFString *)host
				runLoopMode: (OFRunLoopMode)runLoopMode
{
	static const OFTLSStreamErrorCode initFailedErrorCode =
	    OFTLSStreamErrorCodeInitializationFailed;
	id exception = nil;

Modified src/tls/OFSecureTransportTLSStream.m from [c722ef4615] to [4775886a79].

14
15
16
17
18
19
20

21
22
23
24
25
26
27
 */

#include "config.h"

#include <errno.h>

#import "OFSecureTransportTLSStream.h"


#import "OFAlreadyOpenException.h"
#import "OFNotOpenException.h"
#import "OFReadFailedException.h"
#import "OFTLSHandshakeFailedException.h"
#import "OFWriteFailedException.h"








>







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 */

#include "config.h"

#include <errno.h>

#import "OFSecureTransportTLSStream.h"
#import "OFStream+Private.h"

#import "OFAlreadyOpenException.h"
#import "OFNotOpenException.h"
#import "OFReadFailedException.h"
#import "OFTLSHandshakeFailedException.h"
#import "OFWriteFailedException.h"

174
175
176
177
178
179
180



















181
182
183
184
185
186
187

	if (SSLGetBufferedReadSize(_context, &bufferSize) == noErr &&
	    bufferSize > 0)
		return true;

	return super.hasDataInReadBuffer;
}




















- (void)asyncPerformClientHandshakeWithHost: (OFString *)host
				runLoopMode: (OFRunLoopMode)runLoopMode
{
	static const OFTLSStreamErrorCode initFailedErrorCode =
	    OFTLSStreamErrorCodeInitializationFailed;
	id exception = nil;







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







175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207

	if (SSLGetBufferedReadSize(_context, &bufferSize) == noErr &&
	    bufferSize > 0)
		return true;

	return super.hasDataInReadBuffer;
}

- (bool)of_isWaitingForDelimiter
{
	size_t bufferSize;

	/* FIXME: There should be a non-private API for this. */

	/*
	 * If we still have pending data in the context, we haven't processed
	 * it yet to see if our delimiter is in there. So return false here, as
	 * that will signal the stream as ready for reading, which in turn will
	 * cause a read and checking for the delimiter.
	 */
	if (SSLGetBufferedReadSize(_context, &bufferSize) == noErr &&
	    bufferSize > 0)
		return false;

	return super.of_waitingForDelimiter;
}

- (void)asyncPerformClientHandshakeWithHost: (OFString *)host
				runLoopMode: (OFRunLoopMode)runLoopMode
{
	static const OFTLSStreamErrorCode initFailedErrorCode =
	    OFTLSStreamErrorCodeInitializationFailed;
	id exception = nil;