ObjFW
Loading...
Searching...
No Matches
OFTLSStream.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2026 Jonathan Schleifer <js@nil.im>
3 *
4 * All rights reserved.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License version 3.0 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * version 3.0 for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * version 3.0 along with this program. If not, see
17 * <https://www.gnu.org/licenses/>.
18 */
19
20#import "OFStream.h"
21#import "OFRunLoop.h"
22#import "OFX509Certificate.h"
23
24OF_ASSUME_NONNULL_BEGIN
25
27
28@class OFArray OF_GENERIC(ObjectType);
29@class OFTLSStream;
30
50
56@protocol OFTLSStreamDelegate <OFStreamDelegate>
57@optional
67- (void)stream: (OFTLSStream *)stream
68 didPerformClientHandshakeWithHost: (OFString *)host
69 exception: (nullable id)exception;
70
79- (void)streamDidPerformServerHandshake: (OFTLSStream *)stream
80 exception: (nullable id)exception;
81@end
82
101{
102 OFStream <OFReadyForReadingObserving, OFReadyForWritingObserving>
103 *_underlyingStream;
104 bool _verifiesCertificates;
105 OFArray OF_GENERIC(OFX509Certificate *) *_Nullable _certificateChain;
106 uintptr_t _atEndOfStream; /* Change type on ABI bump */
107 OF_RESERVE_IVARS(OFTLSStream, 2)
108}
109
113@property (readonly, nonatomic) OFStream <OFReadyForReadingObserving,
114 OFReadyForWritingObserving> *underlyingStream;
122@property OF_NULLABLE_PROPERTY (assign, nonatomic)
123 id <OFTLSStreamDelegate> delegate;
128@property (nonatomic) bool verifiesCertificates;
133@property OF_NULLABLE_PROPERTY (copy, nonatomic)
135
136- (instancetype)init OF_UNAVAILABLE;
137
146+ (instancetype)streamWithStream: (OFStream <OFReadyForReadingObserving,
147 OFReadyForWritingObserving> *)stream;
148
160- (instancetype)initWithStream: (OFStream <OFReadyForReadingObserving,
161 OFReadyForWritingObserving> *)stream
162 OF_DESIGNATED_INITIALIZER;
163
172- (void)asyncPerformClientHandshakeWithHost: (OFString *)host;
173
183- (void)asyncPerformClientHandshakeWithHost: (OFString *)host
184 runLoopMode: (OFRunLoopMode)runLoopMode;
185
195- (void)performClientHandshakeWithHost: (OFString *)host;
196
205
215- (void)asyncPerformServerHandshakeWithRunLoopMode: (OFRunLoopMode)runLoopMode;
216
226@end
227
228#ifdef __cplusplus
229extern "C" {
230#endif
238extern Class OFTLSStreamImplementation;
239
247 OFTLSStreamErrorCode errorCode);
248#ifdef __cplusplus
249}
250#endif
251
252OF_ASSUME_NONNULL_END
OFConstantString * OFRunLoopMode
A mode for an OFRunLoop.
Definition OFRunLoop.h:46
OFTLSStreamErrorCode
An enum representing an error of an OFTLSStream.
Definition OFTLSStream.h:34
@ OFTLSStreamErrorCodeCertificatedExpired
The certificate has expired or is not yet valid.
Definition OFTLSStream.h:46
@ OFTLSStreamErrorCodeInitializationFailed
Initialization of the TLS context failed.
Definition OFTLSStream.h:38
@ OFTLSStreamErrorCodeCertificateIssuerUntrusted
The certificate has an untrusted or unknown issuer.
Definition OFTLSStream.h:42
@ OFTLSStreamErrorCodeUnknown
An unknown error.
Definition OFTLSStream.h:36
@ OFTLSStreamErrorCodeCertificateNameMismatch
The certificate is for a different name.
Definition OFTLSStream.h:44
@ OFTLSStreamErrorCodeCertificateRevoked
The certificate has been revoked.
Definition OFTLSStream.h:48
@ OFTLSStreamErrorCodeCertificateVerificationFailed
Failed to verify certificate.
Definition OFTLSStream.h:40
OFString * OFTLSStreamErrorCodeDescription(OFTLSStreamErrorCode errorCode)
Returns a string description for the TLS stream error code.
Definition OFTLSStream.m:53
Class OFTLSStreamImplementation
The implementation for OFTLSStream to use.
Definition OFTLSStream.m:38
An abstract class for storing objects in an array.
Definition OFArray.h:111
instancetype init()
Initializes an already allocated object.
Definition OFObject.m:674
id copy()
Returns the class.
Definition OFObject.m:1329
A base class for different types of streams.
Definition OFStream.h:280
A class for handling strings.
Definition OFString.h:144
A class that provides Transport Layer Security on top of a stream.
Definition OFTLSStream.h:102
void asyncPerformServerHandshake()
Asynchronously performs the TLS server handshake and calls the delegate afterwards.
Definition OFTLSStream.m:233
bool verifiesCertificates
Whether certificates are verified. Default is true.
Definition OFTLSStream.h:129
id< OFTLSStreamDelegate > delegate
The delegate for asynchronous operations on the stream.
Definition OFTLSStream.h:124
OFArray * certificateChain
The certificate chain to use.
Definition OFTLSStream.m:165
void performServerHandshake()
Performs the TLS server handshake.
Definition OFTLSStream.m:243
An X.509 certificate, optionally with an associated private key.
Definition OFX509Certificate.h:33
This protocol is implemented by classes which can be observed for readiness for reading by OFKernelEv...
Definition OFKernelEventObserver.h:84
This protocol is implemented by classes which can be observed for readiness for writing by OFKernelEv...
Definition OFKernelEventObserver.h:98