IXWebSocket/ixwebsocket/IXSocketAppleSSL.h

48 lines
1.4 KiB
C
Raw Normal View History

2018-09-27 23:56:48 +02:00
/*
* IXSocketAppleSSL.h
* Author: Benjamin Sergeant
* Copyright (c) 2017-2018 Machine Zone, Inc. All rights reserved.
*/
#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>
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();
virtual bool accept(std::string& errMsg) final;
virtual bool connect(const std::string& host,
2018-09-27 23:56:48 +02:00
int port,
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;
virtual ssize_t send(char* buffer, size_t length) final;
virtual ssize_t send(const std::string& buffer) final;
virtual ssize_t recv(void* buffer, size_t length) final;
2018-09-27 23:56:48 +02: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);
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