ObjFW
OFTLSSocket.h
1 /*
2  * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #import "OFObject.h"
17 
18 OF_ASSUME_NONNULL_BEGIN
19 
20 @class OFString;
21 @class OFDictionary OF_GENERIC(KeyType, ObjectType);
22 @protocol OFTLSSocket;
23 
30 @optional
45 - (bool)socket: (id <OFTLSSocket>)socket
46  shouldAcceptCertificate: (OFDictionary *)certificate;
47 @end
48 
55 @protocol OFTLSSocket
59 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
61 
65 @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *certificateFile;
66 
70 @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *privateKeyFile;
71 
78 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
79  const char *privateKeyPassphrase;
80 
86 @property (nonatomic) bool verifiesCertificates;
87 
94 - (instancetype)initWithSocket: (OFTCPSocket *)socket;
95 
105 - (void)startTLSWithExpectedHost: (nullable OFString *)host;
106 
116 - (void)setCertificateFile: (OFString *)certificateFile
117  forSNIHost: (OFString *)SNIHost;
118 
129 - (nullable OFString *)certificateFileForSNIHost: (OFString *)SNIHost;
130 
139 - (void)setPrivateKeyFile: (OFString *)privateKeyFile
140  forSNIHost: (OFString *)SNIHost;
141 
152 - (nullable OFString *)privateKeyFileForSNIHost: (OFString *)SNIHost;
153 
166 - (void)setPrivateKeyPassphrase: (const char *)privateKeyPassphrase
167  forSNIHost: (OFString *)SNIHost;
168 
181 - (nullable const char *)privateKeyPassphraseForSNIHost: (OFString *)SNIHost;
182 @end
183 
184 OF_ASSUME_NONNULL_END
struct objc_object * id
A pointer to any object.
Definition: ObjFWRT.h:90
An abstract class for storing objects in a dictionary.
Definition: OFDictionary.h:58
A class for handling strings.
Definition: OFString.h:132
A class which provides methods to create and use TCP sockets.
Definition: OFTCPSocket.h:67
Definition: OFTCPSocket.h:41
A protocol that should be implemented by 3rd-party libraries implementing TLS.
Definition: OFTLSSocket.h:55
OFString * privateKeyFile
The path to the PKCS#8 private key file to use.
Definition: OFTLSSocket.h:70
const char * privateKeyPassphrase
The passphrase to decrypt the PKCS#8 private key file.
Definition: OFTLSSocket.h:79
bool verifiesCertificates
Whether certificates are verified.
Definition: OFTLSSocket.h:86
id< OFTLSSocketDelegate > delegate
The delegate for the TLS socket.
Definition: OFTLSSocket.h:60
OFString * certificateFile
The path to the X.509 certificate file to use.
Definition: OFTLSSocket.h:65
A delegate for classes implementing the OFTLSSocket protocol.
Definition: OFTLSSocket.h:29