mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-09 01:07:16 +01:00
217 lines
3.9 KiB
C++
217 lines
3.9 KiB
C++
|
//
|
||
|
// SecureStreamSocketImpl.cpp
|
||
|
//
|
||
|
// Library: NetSSL_Win
|
||
|
// Package: SSLSockets
|
||
|
// Module: SecureStreamSocketImpl
|
||
|
//
|
||
|
// Copyright (c) 2006-2014, Applied Informatics Software Engineering GmbH.
|
||
|
// and Contributors.
|
||
|
//
|
||
|
// SPDX-License-Identifier: BSL-1.0
|
||
|
//
|
||
|
|
||
|
|
||
|
#include "Poco/Net/SecureStreamSocketImpl.h"
|
||
|
#include "Poco/Net/SSLException.h"
|
||
|
#include "Poco/Thread.h"
|
||
|
|
||
|
|
||
|
namespace Poco {
|
||
|
namespace Net {
|
||
|
|
||
|
|
||
|
SecureStreamSocketImpl::SecureStreamSocketImpl(Context::Ptr pContext):
|
||
|
_impl(new StreamSocketImpl, pContext),
|
||
|
_lazyHandshake(false)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
SecureStreamSocketImpl::SecureStreamSocketImpl(StreamSocketImpl* pStreamSocket, Context::Ptr pContext):
|
||
|
_impl(pStreamSocket, pContext),
|
||
|
_lazyHandshake(false)
|
||
|
{
|
||
|
pStreamSocket->duplicate();
|
||
|
reset(_impl.sockfd());
|
||
|
}
|
||
|
|
||
|
|
||
|
SecureStreamSocketImpl::~SecureStreamSocketImpl()
|
||
|
{
|
||
|
reset();
|
||
|
}
|
||
|
|
||
|
|
||
|
SocketImpl* SecureStreamSocketImpl::acceptConnection(SocketAddress& clientAddr)
|
||
|
{
|
||
|
throw Poco::InvalidAccessException("Cannot acceptConnection() on a SecureStreamSocketImpl");
|
||
|
}
|
||
|
|
||
|
|
||
|
void SecureStreamSocketImpl::acceptSSL()
|
||
|
{
|
||
|
_impl.acceptSSL();
|
||
|
}
|
||
|
|
||
|
|
||
|
void SecureStreamSocketImpl::connect(const SocketAddress& address)
|
||
|
{
|
||
|
_impl.connect(address, !_lazyHandshake);
|
||
|
reset(_impl.sockfd());
|
||
|
}
|
||
|
|
||
|
|
||
|
void SecureStreamSocketImpl::connect(const SocketAddress& address, const Poco::Timespan& timeout)
|
||
|
{
|
||
|
_impl.connect(address, timeout, !_lazyHandshake);
|
||
|
reset(_impl.sockfd());
|
||
|
}
|
||
|
|
||
|
|
||
|
void SecureStreamSocketImpl::connectNB(const SocketAddress& address)
|
||
|
{
|
||
|
_impl.connectNB(address);
|
||
|
reset(_impl.sockfd());
|
||
|
}
|
||
|
|
||
|
|
||
|
void SecureStreamSocketImpl::connectSSL()
|
||
|
{
|
||
|
_impl.connectSSL(!_lazyHandshake);
|
||
|
}
|
||
|
|
||
|
|
||
|
void SecureStreamSocketImpl::bind(const SocketAddress& address, bool reuseAddress)
|
||
|
{
|
||
|
throw Poco::InvalidAccessException("Cannot bind() a SecureStreamSocketImpl");
|
||
|
}
|
||
|
|
||
|
|
||
|
void SecureStreamSocketImpl::listen(int backlog)
|
||
|
{
|
||
|
throw Poco::InvalidAccessException("Cannot listen() on a SecureStreamSocketImpl");
|
||
|
}
|
||
|
|
||
|
|
||
|
void SecureStreamSocketImpl::close()
|
||
|
{
|
||
|
reset();
|
||
|
_impl.close();
|
||
|
}
|
||
|
|
||
|
|
||
|
void SecureStreamSocketImpl::abort()
|
||
|
{
|
||
|
reset();
|
||
|
_impl.abort();
|
||
|
}
|
||
|
|
||
|
|
||
|
int SecureStreamSocketImpl::sendBytes(const void* buffer, int length, int flags)
|
||
|
{
|
||
|
return _impl.sendBytes(buffer, length, flags);
|
||
|
}
|
||
|
|
||
|
|
||
|
int SecureStreamSocketImpl::receiveBytes(void* buffer, int length, int flags)
|
||
|
{
|
||
|
return _impl.receiveBytes(buffer, length, flags);
|
||
|
}
|
||
|
|
||
|
|
||
|
int SecureStreamSocketImpl::sendTo(const void* buffer, int length, const SocketAddress& address, int flags)
|
||
|
{
|
||
|
throw Poco::InvalidAccessException("Cannot sendTo() on a SecureStreamSocketImpl");
|
||
|
}
|
||
|
|
||
|
|
||
|
int SecureStreamSocketImpl::receiveFrom(void* buffer, int length, SocketAddress& address, int flags)
|
||
|
{
|
||
|
throw Poco::InvalidAccessException("Cannot receiveFrom() on a SecureStreamSocketImpl");
|
||
|
}
|
||
|
|
||
|
|
||
|
void SecureStreamSocketImpl::sendUrgent(unsigned char data)
|
||
|
{
|
||
|
throw Poco::InvalidAccessException("Cannot sendUrgent() on a SecureStreamSocketImpl");
|
||
|
}
|
||
|
|
||
|
|
||
|
int SecureStreamSocketImpl::available()
|
||
|
{
|
||
|
return _impl.available();
|
||
|
}
|
||
|
|
||
|
|
||
|
void SecureStreamSocketImpl::shutdownReceive()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
void SecureStreamSocketImpl::shutdownSend()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
void SecureStreamSocketImpl::shutdown()
|
||
|
{
|
||
|
_impl.shutdown();
|
||
|
}
|
||
|
|
||
|
|
||
|
bool SecureStreamSocketImpl::secure() const
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool SecureStreamSocketImpl::havePeerCertificate() const
|
||
|
{
|
||
|
return _impl.peerCertificate() != 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
X509Certificate SecureStreamSocketImpl::peerCertificate() const
|
||
|
{
|
||
|
if (havePeerCertificate())
|
||
|
{
|
||
|
return X509Certificate(_impl.peerCertificate(), true);
|
||
|
}
|
||
|
else throw SSLException("No certificate available");
|
||
|
}
|
||
|
|
||
|
|
||
|
void SecureStreamSocketImpl::setLazyHandshake(bool flag)
|
||
|
{
|
||
|
_lazyHandshake = flag;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool SecureStreamSocketImpl::getLazyHandshake() const
|
||
|
{
|
||
|
return _lazyHandshake;
|
||
|
}
|
||
|
|
||
|
|
||
|
void SecureStreamSocketImpl::verifyPeerCertificate()
|
||
|
{
|
||
|
_impl.verifyPeerCertificate();
|
||
|
}
|
||
|
|
||
|
|
||
|
void SecureStreamSocketImpl::verifyPeerCertificate(const std::string& hostName)
|
||
|
{
|
||
|
_impl.verifyPeerCertificate(hostName);
|
||
|
}
|
||
|
|
||
|
|
||
|
int SecureStreamSocketImpl::completeHandshake()
|
||
|
{
|
||
|
_impl.completeHandshake();
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
} } // namespace Poco::Net
|