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