ObjFW
OFTLSStream.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2025 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 
24 OF_ASSUME_NONNULL_BEGIN
25 
28 @class OFArray OF_GENERIC(ObjectType);
29 @class OFTLSStream;
30 
34 typedef enum {
50 
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 {
103  *_underlyingStream;
104  bool _verifiesCertificates;
105  OFArray OF_GENERIC(OFX509Certificate *) *_Nullable _certificateChain;
106  OF_RESERVE_IVARS(OFTLSStream, 3)
107 }
108 
112 @property (readonly, nonatomic) OFStream <OFReadyForReadingObserving,
113  OFReadyForWritingObserving> *underlyingStream;
114 
121 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
122  id <OFTLSStreamDelegate> delegate;
123 
127 @property (nonatomic) bool verifiesCertificates;
128 
132 @property OF_NULLABLE_PROPERTY (copy, nonatomic)
133  OFArray OF_GENERIC(OFX509Certificate *) *certificateChain;
134 
135 - (instancetype)init OF_UNAVAILABLE;
136 
145 + (instancetype)streamWithStream: (OFStream <OFReadyForReadingObserving,
146  OFReadyForWritingObserving> *)stream;
147 
159 - (instancetype)initWithStream: (OFStream <OFReadyForReadingObserving,
161  OF_DESIGNATED_INITIALIZER;
162 
171 - (void)asyncPerformClientHandshakeWithHost: (OFString *)host;
172 
182 - (void)asyncPerformClientHandshakeWithHost: (OFString *)host
183  runLoopMode: (OFRunLoopMode)runLoopMode;
184 
194 - (void)performClientHandshakeWithHost: (OFString *)host;
195 
203 - (void)asyncPerformServerHandshake;
204 
214 - (void)asyncPerformServerHandshakeWithRunLoopMode: (OFRunLoopMode)runLoopMode;
215 
224 - (void)performServerHandshake;
225 @end
226 
227 #ifdef __cplusplus
228 extern "C" {
229 #endif
237 extern Class OFTLSStreamImplementation;
238 
246  OFTLSStreamErrorCode errorCode);
247 #ifdef __cplusplus
248 }
249 #endif
250 
251 OF_ASSUME_NONNULL_END
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:109
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:42
A base class for different types of streams.
Definition: OFStream.h:280
A class for handling strings.
Definition: OFString.h:143
A class that provides Transport Layer Security on top of a stream.
Definition: OFTLSStream.h:102
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
Definition: OFStream.h:176
Definition: OFTLSStream.h:56