summaryrefslogtreecommitdiffstats
path: root/contrib/libs/poco/NetSSL_OpenSSL/src/SecureStreamSocket.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /contrib/libs/poco/NetSSL_OpenSSL/src/SecureStreamSocket.cpp
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'contrib/libs/poco/NetSSL_OpenSSL/src/SecureStreamSocket.cpp')
-rw-r--r--contrib/libs/poco/NetSSL_OpenSSL/src/SecureStreamSocket.cpp287
1 files changed, 287 insertions, 0 deletions
diff --git a/contrib/libs/poco/NetSSL_OpenSSL/src/SecureStreamSocket.cpp b/contrib/libs/poco/NetSSL_OpenSSL/src/SecureStreamSocket.cpp
new file mode 100644
index 00000000000..f4766ca6f97
--- /dev/null
+++ b/contrib/libs/poco/NetSSL_OpenSSL/src/SecureStreamSocket.cpp
@@ -0,0 +1,287 @@
+//
+// SecureStreamSocket.cpp
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLSockets
+// Module: SecureStreamSocket
+//
+// Copyright (c) 2006-2010, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// SPDX-License-Identifier: BSL-1.0
+//
+
+
+#include "Poco/Net/SecureStreamSocket.h"
+#include "Poco/Net/SecureStreamSocketImpl.h"
+#include "Poco/Net/SocketImpl.h"
+#include "Poco/Net/SSLManager.h"
+#include "Poco/Exception.h"
+
+
+using Poco::InvalidArgumentException;
+
+
+namespace Poco {
+namespace Net {
+
+
+SecureStreamSocket::SecureStreamSocket():
+ StreamSocket(new SecureStreamSocketImpl(SSLManager::instance().defaultClientContext()))
+{
+}
+
+
+SecureStreamSocket::SecureStreamSocket(Context::Ptr pContext):
+ StreamSocket(new SecureStreamSocketImpl(pContext))
+{
+}
+
+
+SecureStreamSocket::SecureStreamSocket(Context::Ptr pContext, Session::Ptr pSession):
+ StreamSocket(new SecureStreamSocketImpl(pContext))
+{
+ useSession(pSession);
+}
+
+
+SecureStreamSocket::SecureStreamSocket(const SocketAddress& address):
+ StreamSocket(new SecureStreamSocketImpl(SSLManager::instance().defaultClientContext()))
+{
+ connect(address);
+}
+
+
+SecureStreamSocket::SecureStreamSocket(const SocketAddress& address, const std::string& hostName):
+ StreamSocket(new SecureStreamSocketImpl(SSLManager::instance().defaultClientContext()))
+{
+ static_cast<SecureStreamSocketImpl*>(impl())->setPeerHostName(hostName);
+ connect(address);
+}
+
+
+SecureStreamSocket::SecureStreamSocket(const SocketAddress& address, Context::Ptr pContext):
+ StreamSocket(new SecureStreamSocketImpl(pContext))
+{
+ connect(address);
+}
+
+
+SecureStreamSocket::SecureStreamSocket(const SocketAddress& address, Context::Ptr pContext, Session::Ptr pSession):
+ StreamSocket(new SecureStreamSocketImpl(pContext))
+{
+ useSession(pSession);
+ connect(address);
+}
+
+
+SecureStreamSocket::SecureStreamSocket(const SocketAddress& address, const std::string& hostName, Context::Ptr pContext):
+ StreamSocket(new SecureStreamSocketImpl(pContext))
+{
+ static_cast<SecureStreamSocketImpl*>(impl())->setPeerHostName(hostName);
+ connect(address);
+}
+
+
+SecureStreamSocket::SecureStreamSocket(const SocketAddress& address, const std::string& hostName, Context::Ptr pContext, Session::Ptr pSession):
+ StreamSocket(new SecureStreamSocketImpl(pContext))
+{
+ static_cast<SecureStreamSocketImpl*>(impl())->setPeerHostName(hostName);
+ useSession(pSession);
+ connect(address);
+}
+
+
+SecureStreamSocket::SecureStreamSocket(const Socket& socket):
+ StreamSocket(socket)
+{
+ if (!dynamic_cast<SecureStreamSocketImpl*>(impl()))
+ throw InvalidArgumentException("Cannot assign incompatible socket");
+}
+
+
+SecureStreamSocket::SecureStreamSocket(SocketImpl* pImpl):
+ StreamSocket(pImpl)
+{
+ if (!dynamic_cast<SecureStreamSocketImpl*>(impl()))
+ throw InvalidArgumentException("Cannot assign incompatible socket");
+}
+
+
+SecureStreamSocket::~SecureStreamSocket()
+{
+}
+
+
+SecureStreamSocket& SecureStreamSocket::operator = (const Socket& socket)
+{
+ if (dynamic_cast<SecureStreamSocketImpl*>(socket.impl()))
+ StreamSocket::operator = (socket);
+ else
+ throw InvalidArgumentException("Cannot assign incompatible socket");
+ return *this;
+}
+
+
+bool SecureStreamSocket::havePeerCertificate() const
+{
+ return static_cast<SecureStreamSocketImpl*>(impl())->havePeerCertificate();
+}
+
+
+X509Certificate SecureStreamSocket::peerCertificate() const
+{
+ return static_cast<SecureStreamSocketImpl*>(impl())->peerCertificate();
+}
+
+
+void SecureStreamSocket::setPeerHostName(const std::string& hostName)
+{
+ static_cast<SecureStreamSocketImpl*>(impl())->setPeerHostName(hostName);
+}
+
+
+const std::string& SecureStreamSocket::getPeerHostName() const
+{
+ return static_cast<SecureStreamSocketImpl*>(impl())->getPeerHostName();
+}
+
+
+SecureStreamSocket SecureStreamSocket::attach(const StreamSocket& streamSocket)
+{
+ SecureStreamSocketImpl* pImpl = new SecureStreamSocketImpl(static_cast<StreamSocketImpl*>(streamSocket.impl()), SSLManager::instance().defaultClientContext());
+ SecureStreamSocket result(pImpl);
+ if (pImpl->context()->isForServerUse())
+ pImpl->acceptSSL();
+ else
+ pImpl->connectSSL();
+ return result;
+}
+
+
+SecureStreamSocket SecureStreamSocket::attach(const StreamSocket& streamSocket, Context::Ptr pContext)
+{
+ SecureStreamSocketImpl* pImpl = new SecureStreamSocketImpl(static_cast<StreamSocketImpl*>(streamSocket.impl()), pContext);
+ SecureStreamSocket result(pImpl);
+ if (pImpl->context()->isForServerUse())
+ pImpl->acceptSSL();
+ else
+ pImpl->connectSSL();
+ return result;
+}
+
+
+SecureStreamSocket SecureStreamSocket::attach(const StreamSocket& streamSocket, Context::Ptr pContext, Session::Ptr pSession)
+{
+ SecureStreamSocketImpl* pImpl = new SecureStreamSocketImpl(static_cast<StreamSocketImpl*>(streamSocket.impl()), pContext);
+ SecureStreamSocket result(pImpl);
+ result.useSession(pSession);
+ if (pImpl->context()->isForServerUse())
+ pImpl->acceptSSL();
+ else
+ pImpl->connectSSL();
+ return result;
+}
+
+
+SecureStreamSocket SecureStreamSocket::attach(const StreamSocket& streamSocket, const std::string& peerHostName)
+{
+ SecureStreamSocketImpl* pImpl = new SecureStreamSocketImpl(static_cast<StreamSocketImpl*>(streamSocket.impl()), SSLManager::instance().defaultClientContext());
+ SecureStreamSocket result(pImpl);
+ result.setPeerHostName(peerHostName);
+ if (pImpl->context()->isForServerUse())
+ pImpl->acceptSSL();
+ else
+ pImpl->connectSSL();
+ return result;
+}
+
+
+SecureStreamSocket SecureStreamSocket::attach(const StreamSocket& streamSocket, const std::string& peerHostName, Context::Ptr pContext)
+{
+ SecureStreamSocketImpl* pImpl = new SecureStreamSocketImpl(static_cast<StreamSocketImpl*>(streamSocket.impl()), pContext);
+ SecureStreamSocket result(pImpl);
+ result.setPeerHostName(peerHostName);
+ if (pImpl->context()->isForServerUse())
+ pImpl->acceptSSL();
+ else
+ pImpl->connectSSL();
+ return result;
+}
+
+
+SecureStreamSocket SecureStreamSocket::attach(const StreamSocket& streamSocket, const std::string& peerHostName, Context::Ptr pContext, Session::Ptr pSession)
+{
+ SecureStreamSocketImpl* pImpl = new SecureStreamSocketImpl(static_cast<StreamSocketImpl*>(streamSocket.impl()), pContext);
+ SecureStreamSocket result(pImpl);
+ result.setPeerHostName(peerHostName);
+ result.useSession(pSession);
+ if (pImpl->context()->isForServerUse())
+ pImpl->acceptSSL();
+ else
+ pImpl->connectSSL();
+ return result;
+}
+
+
+Context::Ptr SecureStreamSocket::context() const
+{
+ return static_cast<SecureStreamSocketImpl*>(impl())->context();
+}
+
+
+void SecureStreamSocket::setLazyHandshake(bool flag)
+{
+ static_cast<SecureStreamSocketImpl*>(impl())->setLazyHandshake(flag);
+}
+
+
+bool SecureStreamSocket::getLazyHandshake() const
+{
+ return static_cast<SecureStreamSocketImpl*>(impl())->getLazyHandshake();
+}
+
+
+void SecureStreamSocket::verifyPeerCertificate()
+{
+ static_cast<SecureStreamSocketImpl*>(impl())->verifyPeerCertificate();
+}
+
+
+void SecureStreamSocket::verifyPeerCertificate(const std::string& hostName)
+{
+ static_cast<SecureStreamSocketImpl*>(impl())->verifyPeerCertificate(hostName);
+}
+
+
+int SecureStreamSocket::completeHandshake()
+{
+ return static_cast<SecureStreamSocketImpl*>(impl())->completeHandshake();
+}
+
+
+Session::Ptr SecureStreamSocket::currentSession()
+{
+ return static_cast<SecureStreamSocketImpl*>(impl())->currentSession();
+}
+
+
+void SecureStreamSocket::useSession(Session::Ptr pSession)
+{
+ static_cast<SecureStreamSocketImpl*>(impl())->useSession(pSession);
+}
+
+
+bool SecureStreamSocket::sessionWasReused()
+{
+ return static_cast<SecureStreamSocketImpl*>(impl())->sessionWasReused();
+}
+
+
+void SecureStreamSocket::abort()
+{
+ static_cast<SecureStreamSocketImpl*>(impl())->abort();
+}
+
+
+} } // namespace Poco::Net