2018-09-27 23:56:48 +02:00
|
|
|
/*
|
|
|
|
* IXSocketAppleSSL.h
|
|
|
|
* Author: Benjamin Sergeant
|
2020-04-24 21:47:47 +02:00
|
|
|
* Copyright (c) 2017-2020 Machine Zone, Inc. All rights reserved.
|
2018-09-27 23:56:48 +02:00
|
|
|
*/
|
2020-04-24 21:47:47 +02:00
|
|
|
#ifdef IXWEBSOCKET_USE_SECURE_TRANSPORT
|
2018-09-27 23:56:48 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-12-15 01:28:11 +01:00
|
|
|
#include "IXCancellationRequest.h"
|
2019-05-30 17:46:50 +02:00
|
|
|
#include "IXSocket.h"
|
2019-09-23 03:43:57 +02:00
|
|
|
#include "IXSocketTLSOptions.h"
|
2018-09-27 23:56:48 +02:00
|
|
|
#include <Security/SecureTransport.h>
|
2019-05-30 17:46:50 +02:00
|
|
|
#include <Security/Security.h>
|
2018-09-27 23:56:48 +02:00
|
|
|
#include <mutex>
|
|
|
|
|
2019-02-21 03:59:07 +01:00
|
|
|
namespace ix
|
2018-09-27 23:56:48 +02:00
|
|
|
{
|
2019-05-12 20:43:21 +02:00
|
|
|
class SocketAppleSSL final : public Socket
|
2018-09-27 23:56:48 +02:00
|
|
|
{
|
|
|
|
public:
|
2019-09-23 03:43:57 +02:00
|
|
|
SocketAppleSSL(const SocketTLSOptions& tlsOptions, int fd = -1);
|
2018-09-27 23:56:48 +02:00
|
|
|
~SocketAppleSSL();
|
|
|
|
|
2019-12-18 19:43:05 +01:00
|
|
|
virtual bool accept(std::string& errMsg) final;
|
|
|
|
|
2019-02-21 03:59:07 +01:00
|
|
|
virtual bool connect(const std::string& host,
|
2018-09-27 23:56:48 +02:00
|
|
|
int port,
|
2018-12-10 02:56:20 +01:00
|
|
|
std::string& errMsg,
|
2018-12-15 01:28:11 +01:00
|
|
|
const CancellationRequest& isCancellationRequested) final;
|
2018-09-27 23:56:48 +02:00
|
|
|
virtual void close() final;
|
|
|
|
|
2019-01-06 05:53:50 +01:00
|
|
|
virtual ssize_t send(char* buffer, size_t length) final;
|
|
|
|
virtual ssize_t recv(void* buffer, size_t length) final;
|
2018-09-27 23:56:48 +02:00
|
|
|
|
|
|
|
private:
|
2019-12-24 01:30:38 +01:00
|
|
|
static std::string getSSLErrorDescription(OSStatus status);
|
|
|
|
static OSStatus writeToSocket(SSLConnectionRef connection, const void* data, size_t* len);
|
|
|
|
static OSStatus readFromSocket(SSLConnectionRef connection, void* data, size_t* len);
|
|
|
|
|
2020-03-21 01:00:18 +01:00
|
|
|
OSStatus tlsHandShake(std::string& errMsg,
|
|
|
|
const CancellationRequest& isCancellationRequested);
|
2020-03-21 00:57:27 +01:00
|
|
|
|
2018-09-27 23:56:48 +02:00
|
|
|
SSLContextRef _sslContext;
|
2019-05-30 17:46:50 +02:00
|
|
|
mutable std::mutex _mutex; // AppleSSL routines are not thread-safe
|
2019-09-23 03:43:57 +02:00
|
|
|
|
|
|
|
SocketTLSOptions _tlsOptions;
|
2018-09-27 23:56:48 +02:00
|
|
|
};
|
|
|
|
|
2019-05-30 17:46:50 +02:00
|
|
|
} // namespace ix
|
2020-04-24 21:47:47 +02:00
|
|
|
|
|
|
|
#endif // IXWEBSOCKET_USE_SECURE_TRANSPORT
|