IXWebSocket/ixwebsocket/IXSocketAppleSSL.h

53 lines
1.6 KiB
C
Raw Normal View History

2018-09-27 14:56:48 -07:00
/*
* IXSocketAppleSSL.h
* Author: Benjamin Sergeant
* Copyright (c) 2017-2020 Machine Zone, Inc. All rights reserved.
2018-09-27 14:56:48 -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>
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();
virtual bool accept(std::string& errMsg) final;
virtual bool connect(const std::string& host,
2018-09-27 14:56:48 -07:00
int port,
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;
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:
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);
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
#endif // IXWEBSOCKET_USE_SECURE_TRANSPORT