9
10
11
12
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
|
9
10
11
12
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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
|
-
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
*
* Alternatively, it may be distributed under the terms of the GNU General
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#import "OFObject.h"
#import "OFTCPSocket.h"
OF_ASSUME_NONNULL_BEGIN
/**
* @protocol OFTLSSocketDelegate OFTLSSocket.h ObjFW/OFTLSSocket.h
*
* A delegate for OFTLSSocket.
*/
@protocol OFTLSSocketDelegate <OFTCPSocketDelegate>
@end
/**
* @protocol OFTLSSocket OFTLSSocket.h ObjFW/OFTLSSocket.h
* @class OFTLSSocket OFTLSSocket.h ObjFW/OFTLSSocket.h
*
* @brief A protocol that should be implemented by 3rd-party libraries
* implementing TLS.
* @brief A class that provides Transport Layer Security on top of a TCP socket.
*
* This class is a class cluster and returns a suitable OFTLSSocket subclass,
* if available.
*
* Subclasses need to override @ref accept, @ref lowlevelReadIntoBuffer:length:,
* @ref lowlevelWriteBuffer:length:, @ref lowlevelIsAtEndOfStream and
* @ref startTLSForHost:port:. In order to get access to the lowlevel TCP
* methods (you cannot call `super`, as the class is abstract), the private
* methods @ref TCPAccept, @ref lowlevelTCPReadIntoBuffer:length:,
* @ref lowlevelTCPWriteBuffer:length: and @ref lowlevelTCPIsAtEndOfStream are
* provided.
*/
@interface OFTLSSocket: OFTCPSocket
{
bool _verifiesCertificates;
OF_RESERVE_IVARS(OFTLSSocket, 4)
}
/**
* @brief The delegate for asynchronous operations on the socket.
*
* @note The delegate is retained for as long as asynchronous operations are
* still ongoing.
*/
@property OF_NULLABLE_PROPERTY (assign, nonatomic)
@protocol OFTLSSocket
id <OFTLSSocketDelegate> delegate;
/**
* @brief Whether certificates are verified.
*
* The default is enabled.
*/
@property (nonatomic) bool verifiesCertificates;
/**
* @brief Initializes the TLS socket with the specified TCP socket as its
* underlying socket.
*
* @param socket The TCP socket to use as underlying socket
*/
- (instancetype)initWithSocket: (OFTCPSocket *)socket;
/**
* @brief Start TLS on the underlying socket with the assumption that it is
* connected to the specified host and port.
*
* @param host The host the socket is connected to, which is also used for
* verification
* @param port The port the socket is connected to
*/
- (void)startTLSForHost: (OFString *)host port: (uint16_t)port;
/**
* @brief This method should never be called directly. Only subclasses of
* @ref OFTLSSocket are allowed to call it.
*/
- (instancetype)TCPAccept;
/**
* @brief This method should never be called directly. Only subclasses of
* @ref OFTLSSocket are allowed to call it.
*/
- (size_t)lowlevelTCPReadIntoBuffer: (void *)buffer length: (size_t)length;
/**
* @brief This method should never be called directly. Only subclasses of
* @ref OFTLSSocket are allowed to call it.
*/
- (size_t)lowlevelTCPWriteBuffer: (const void *)buffer length: (size_t)length;
/**
* @brief This method should never be called directly. Only subclasses of
* @ref OFTLSSocket are allowed to call it.
*/
- (bool)lowlevelTCPIsAtEndOfStream;
@end
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief The concrete subclass of OFTLSSocket that should be used.
*/
extern Class _Nullable OFTLSSocketImplementation;
#ifdef __cplusplus
}
#endif
OF_ASSUME_NONNULL_END
|