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;
121 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
122  id <OFTLSStreamDelegate> delegate;
127 @property (nonatomic) bool verifiesCertificates;
132 @property OF_NULLABLE_PROPERTY (copy, nonatomic)
133  OFArray OF_GENERIC(OFX509Certificate *) *certificateChain;
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 
192 - (void)performClientHandshakeWithHost: (OFString *)host;
193 
201 - (void)asyncPerformServerHandshake;
202 
212 - (void)asyncPerformServerHandshakeWithRunLoopMode: (OFRunLoopMode)runLoopMode;
213 
220 - (void)performServerHandshake;
221 @end
222 
223 #ifdef __cplusplus
224 extern "C" {
225 #endif
226 
233 extern Class OFTLSStreamImplementation;
234 
242  OFTLSStreamErrorCode errorCode);
243 #ifdef __cplusplus
244 }
245 #endif
246 
247 OF_ASSUME_NONNULL_END
An abstract class for storing objects in an array.
Definition: OFArray.h:107
This protocol is implemented by classes which can be observed for readiness for reading by OFKernelEv...
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:41
A class that provides Transport Layer Security on top of a stream.
Definition: OFTLSStream.h:99
The certificate is for a different name.
Definition: OFTLSStream.h:44
An unknown error.
Definition: OFTLSStream.h:36
A base class for different types of streams.
Definition: OFStream.h:278
A class for handling strings.
Definition: OFString.h:142
OFString * OFTLSStreamErrorCodeDescription(OFTLSStreamErrorCode errorCode)
Returns a string description for the TLS stream error code.
Definition: OFTLSStream.m:53
Failed to verify certificate.
Definition: OFTLSStream.h:40
The certificate has an untrusted or unknown issuer.
Definition: OFTLSStream.h:42
An X.509 certificate, optionally with an associated private key.
Definition: OFX509Certificate.h:32
The certificate has been revoked.
Definition: OFTLSStream.h:48
OFTLSStreamErrorCode
An enum representing an error of an OFTLSStream.
Definition: OFTLSStream.h:34
This protocol is implemented by classes which can be observed for readiness for writing by OFKernelEv...
Initialization of the TLS context failed.
Definition: OFTLSStream.h:38
The certificate has expired or is not yet valid.
Definition: OFTLSStream.h:46
Class OFTLSStreamImplementation
The implementation for OFTLSStream to use.
Definition: OFTLSStream.m:38