ObjFW  Diff

Differences From Artifact [6023c3c0c6]:

  • File src/OFTLSStream.m — part of check-in [112eb62f7b] at 2021-11-13 20:28:25 on branch trunk — Add OFSecureTransportTLSStream

    This implements OFTLSStream using Apple's Secure Transport. While Secure
    Transport is declared deprecated by Apple, Apple so far has failed to
    provide a suitable replacement. They recommend Network.framework as a
    replacement, however it can neither work on arbitrary sockets, nor can
    it do STARTTLS. (user: js, size: 4220) [annotate] [blame] [check-ins using]

To Artifact [ab25ba8801]:


13
14
15
16
17
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34
35
36










37
38
39
40
41
42
43
 * file.
 */

#include "config.h"

#import "OFTLSStream.h"
#import "OFDate.h"
#ifdef HAVE_SECURE_TRANSPORT
# import "OFSecureTransportTLSStream.h"
#endif

#import "OFNotImplementedException.h"


@interface OFTLSStreamHandshakeDelegate: OFObject <OFTLSStreamDelegate>
{
@public
	bool _done;
	id _exception;
}
@end

Class OFTLSStreamImplementation = Nil;
static const OFRunLoopMode handshakeRunLoopMode =
    @"OFTLSStreamHandshakeRunLoopMode";











OFString *
OFTLSStreamErrorCodeDescription(OFTLSStreamErrorCode errorCode)
{
	switch (errorCode) {
	case OFTLSStreamErrorCodeInitializationFailed:
		return @"Initialization of TLS context failed";







<
<
<


>












>
>
>
>
>
>
>
>
>
>







13
14
15
16
17
18
19



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
 * file.
 */

#include "config.h"

#import "OFTLSStream.h"
#import "OFDate.h"




#import "OFNotImplementedException.h"
#import "OFTLSHandshakeFailedException.h"

@interface OFTLSStreamHandshakeDelegate: OFObject <OFTLSStreamDelegate>
{
@public
	bool _done;
	id _exception;
}
@end

Class OFTLSStreamImplementation = Nil;
static const OFRunLoopMode handshakeRunLoopMode =
    @"OFTLSStreamHandshakeRunLoopMode";

/*
 * References to exceptions. This is needed because they are only used by
 * subclasses that are in a different library.
 */
void
_references_to_exceptions_of_OFTLSStream(void)
{
	_OFTLSHandshakeFailedException_reference = 1;
}

OFString *
OFTLSStreamErrorCodeDescription(OFTLSStreamErrorCode errorCode)
{
	switch (errorCode) {
	case OFTLSStreamErrorCodeInitializationFailed:
		return @"Initialization of TLS context failed";
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

+ (instancetype)alloc
{
	if (self == [OFTLSStream class]) {
		if (OFTLSStreamImplementation != Nil)
			return [OFTLSStreamImplementation alloc];

#ifdef HAVE_SECURE_TRANSPORT
		return [OFSecureTransportTLSStream alloc];
#else
		@throw [OFNotImplementedException exceptionWithSelector: _cmd
								 object: self];
#endif
	}

	return [super alloc];
}

+ (instancetype)streamWithStream: (OFStream <OFReadyForReadingObserving,
				       OFReadyForWritingObserving> *)stream







<
<
<


<







78
79
80
81
82
83
84



85
86

87
88
89
90
91
92
93

+ (instancetype)alloc
{
	if (self == [OFTLSStream class]) {
		if (OFTLSStreamImplementation != Nil)
			return [OFTLSStreamImplementation alloc];




		@throw [OFNotImplementedException exceptionWithSelector: _cmd
								 object: self];

	}

	return [super alloc];
}

+ (instancetype)streamWithStream: (OFStream <OFReadyForReadingObserving,
				       OFReadyForWritingObserving> *)stream