diff options
author | Andrew Stitcher <astitcher@apache.org> | 2012-10-24 05:51:38 +0000 |
---|---|---|
committer | Andrew Stitcher <astitcher@apache.org> | 2012-10-24 05:51:38 +0000 |
commit | 46ac396386fee5e816e5d3a9fae2355017e079bb (patch) | |
tree | c86c0f0d9d5693b92e09292f03bcdd0823c57068 /cpp/src | |
parent | 5d1d8481c376435051d5b24171dbb209c779b9ab (diff) | |
download | qpid-python-46ac396386fee5e816e5d3a9fae2355017e079bb.tar.gz |
QPID-4272: Large amounts of code are duplicated between the SSL and TCP transports
Add the security related functions to the Socket/Asynch interfaces
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1401560 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/qpid/broker/windows/SslProtocolFactory.cpp | 2 | ||||
-rw-r--r-- | cpp/src/qpid/sys/AsynchIO.h | 6 | ||||
-rw-r--r-- | cpp/src/qpid/sys/AsynchIOHandler.cpp | 16 | ||||
-rw-r--r-- | cpp/src/qpid/sys/AsynchIOHandler.h | 3 | ||||
-rw-r--r-- | cpp/src/qpid/sys/SecuritySettings.h | 2 | ||||
-rw-r--r-- | cpp/src/qpid/sys/Socket.h | 4 | ||||
-rw-r--r-- | cpp/src/qpid/sys/SslPlugin.cpp | 2 | ||||
-rw-r--r-- | cpp/src/qpid/sys/TCPIOPlugin.cpp | 2 | ||||
-rw-r--r-- | cpp/src/qpid/sys/posix/AsynchIO.cpp | 8 | ||||
-rw-r--r-- | cpp/src/qpid/sys/posix/BSDSocket.cpp | 10 | ||||
-rw-r--r-- | cpp/src/qpid/sys/posix/BSDSocket.h | 3 | ||||
-rw-r--r-- | cpp/src/qpid/sys/ssl/SslHandler.cpp | 4 | ||||
-rw-r--r-- | cpp/src/qpid/sys/ssl/SslHandler.h | 8 | ||||
-rw-r--r-- | cpp/src/qpid/sys/windows/AsynchIO.cpp | 9 | ||||
-rw-r--r-- | cpp/src/qpid/sys/windows/SslAsynchIO.cpp | 8 | ||||
-rw-r--r-- | cpp/src/qpid/sys/windows/SslAsynchIO.h | 3 | ||||
-rw-r--r-- | cpp/src/qpid/sys/windows/WinSocket.cpp | 10 | ||||
-rw-r--r-- | cpp/src/qpid/sys/windows/WinSocket.h | 3 |
18 files changed, 84 insertions, 19 deletions
diff --git a/cpp/src/qpid/broker/windows/SslProtocolFactory.cpp b/cpp/src/qpid/broker/windows/SslProtocolFactory.cpp index 5b801aa69f..fb7c95bf89 100644 --- a/cpp/src/qpid/broker/windows/SslProtocolFactory.cpp +++ b/cpp/src/qpid/broker/windows/SslProtocolFactory.cpp @@ -245,7 +245,7 @@ void SslProtocolFactory::established(sys::Poller::shared_ptr poller, const qpid::sys::Socket& s, sys::ConnectionCodec::Factory* f, bool isClient) { - sys::AsynchIOHandler* async = new sys::AsynchIOHandler(s.getFullAddress(), f); + sys::AsynchIOHandler* async = new sys::AsynchIOHandler(s.getFullAddress(), f, false); if (tcpNoDelay) { s.setTcpNoDelay(); diff --git a/cpp/src/qpid/sys/AsynchIO.h b/cpp/src/qpid/sys/AsynchIO.h index b2eaaac9de..8eed72d40d 100644 --- a/cpp/src/qpid/sys/AsynchIO.h +++ b/cpp/src/qpid/sys/AsynchIO.h @@ -21,9 +21,11 @@ * */ -#include "qpid/sys/IntegerTypes.h" #include "qpid/CommonImportExport.h" +#include "qpid/sys/IntegerTypes.h" +#include "qpid/sys/SecuritySettings.h" + #include <string.h> #include <boost/function.hpp> @@ -160,6 +162,8 @@ public: virtual void requestCallback(RequestCallback) = 0; virtual BufferBase* getQueuedBuffer() = 0; + virtual SecuritySettings getSecuritySettings() = 0; + protected: // Derived class manages lifetime; must be constructed using the // static create() method. Deletes not allowed from outside. diff --git a/cpp/src/qpid/sys/AsynchIOHandler.cpp b/cpp/src/qpid/sys/AsynchIOHandler.cpp index e766a0527a..99e745c698 100644 --- a/cpp/src/qpid/sys/AsynchIOHandler.cpp +++ b/cpp/src/qpid/sys/AsynchIOHandler.cpp @@ -51,7 +51,7 @@ struct ProtocolTimeoutTask : public sys::TimerTask { } }; -AsynchIOHandler::AsynchIOHandler(const std::string& id, ConnectionCodec::Factory* f) : +AsynchIOHandler::AsynchIOHandler(const std::string& id, ConnectionCodec::Factory* f, bool nodict0) : identifier(id), aio(0), factory(f), @@ -59,6 +59,7 @@ AsynchIOHandler::AsynchIOHandler(const std::string& id, ConnectionCodec::Factory reads(0), readError(false), isClient(false), + nodict(nodict0), readCredit(InfiniteCredit) {} @@ -118,6 +119,15 @@ void AsynchIOHandler::giveReadCredit(int32_t credit) { aio->startReading(); } +namespace { + SecuritySettings getSecuritySettings(AsynchIO* aio, bool nodict) + { + SecuritySettings settings = aio->getSecuritySettings(); + settings.nodict = nodict; + return settings; + } +} + void AsynchIOHandler::readbuff(AsynchIO& , AsynchIO::BufferBase* buff) { if (readError) { return; @@ -168,7 +178,7 @@ void AsynchIOHandler::readbuff(AsynchIO& , AsynchIO::BufferBase* buff) { QPID_LOG(debug, "RECV [" << identifier << "]: INIT(" << protocolInit << ")"); try { - codec = factory->create(protocolInit.getVersion(), *this, identifier, SecuritySettings()); + codec = factory->create(protocolInit.getVersion(), *this, identifier, getSecuritySettings(aio, nodict)); if (!codec) { //TODO: may still want to revise this... //send valid version header & close connection. @@ -226,7 +236,7 @@ void AsynchIOHandler::nobuffs(AsynchIO&) { void AsynchIOHandler::idle(AsynchIO&){ if (isClient && codec == 0) { - codec = factory->create(*this, identifier, SecuritySettings()); + codec = factory->create(*this, identifier, getSecuritySettings(aio, nodict)); write(framing::ProtocolInitiation(codec->getVersion())); // We've just sent the protocol negotiation so we can cancel the timeout for that // This is not ideal, because we've not received anything yet, but heartbeats will diff --git a/cpp/src/qpid/sys/AsynchIOHandler.h b/cpp/src/qpid/sys/AsynchIOHandler.h index fd0bc140e5..6e70606a04 100644 --- a/cpp/src/qpid/sys/AsynchIOHandler.h +++ b/cpp/src/qpid/sys/AsynchIOHandler.h @@ -51,6 +51,7 @@ class AsynchIOHandler : public OutputControl { uint32_t reads; bool readError; bool isClient; + bool nodict; AtomicValue<int32_t> readCredit; static const int32_t InfiniteCredit = -1; Mutex creditLock; @@ -59,7 +60,7 @@ class AsynchIOHandler : public OutputControl { void write(const framing::ProtocolInitiation&); public: - QPID_COMMON_EXTERN AsynchIOHandler(const std::string& id, qpid::sys::ConnectionCodec::Factory* f ); + QPID_COMMON_EXTERN AsynchIOHandler(const std::string& id, qpid::sys::ConnectionCodec::Factory* f, bool nodict); QPID_COMMON_EXTERN ~AsynchIOHandler(); QPID_COMMON_EXTERN void init(AsynchIO* a, Timer& timer, uint32_t maxTime); diff --git a/cpp/src/qpid/sys/SecuritySettings.h b/cpp/src/qpid/sys/SecuritySettings.h index bfcd08fd0f..d595cad660 100644 --- a/cpp/src/qpid/sys/SecuritySettings.h +++ b/cpp/src/qpid/sys/SecuritySettings.h @@ -21,6 +21,8 @@ * under the License. * */ +#include <string> + namespace qpid { namespace sys { diff --git a/cpp/src/qpid/sys/Socket.h b/cpp/src/qpid/sys/Socket.h index 2119566d99..ab59850969 100644 --- a/cpp/src/qpid/sys/Socket.h +++ b/cpp/src/qpid/sys/Socket.h @@ -85,6 +85,10 @@ public: virtual int read(void *buf, size_t count) const = 0; virtual int write(const void *buf, size_t count) const = 0; + + /* Transport security related: */ + virtual int getKeyLen() const = 0; + virtual std::string getClientAuthId() const = 0; }; /** Make the default socket for whatever platform we are executing on diff --git a/cpp/src/qpid/sys/SslPlugin.cpp b/cpp/src/qpid/sys/SslPlugin.cpp index 1cebadeab3..77cda40056 100644 --- a/cpp/src/qpid/sys/SslPlugin.cpp +++ b/cpp/src/qpid/sys/SslPlugin.cpp @@ -236,7 +236,7 @@ void SslMuxProtocolFactory::established(Poller::shared_ptr poller, const Socket& return; } - AsynchIOHandler* async = new AsynchIOHandler(s.getFullAddress(), f); + AsynchIOHandler* async = new AsynchIOHandler(s.getFullAddress(), f, false); if (tcpNoDelay) { s.setTcpNoDelay(); diff --git a/cpp/src/qpid/sys/TCPIOPlugin.cpp b/cpp/src/qpid/sys/TCPIOPlugin.cpp index 2ff47e982c..56f0158d37 100644 --- a/cpp/src/qpid/sys/TCPIOPlugin.cpp +++ b/cpp/src/qpid/sys/TCPIOPlugin.cpp @@ -148,7 +148,7 @@ AsynchIOProtocolFactory::AsynchIOProtocolFactory(const std::string& host, const void AsynchIOProtocolFactory::established(Poller::shared_ptr poller, const Socket& s, ConnectionCodec::Factory* f, bool isClient) { - AsynchIOHandler* async = new AsynchIOHandler(s.getFullAddress(), f); + AsynchIOHandler* async = new AsynchIOHandler(s.getFullAddress(), f, false); if (tcpNoDelay) { s.setTcpNoDelay(); diff --git a/cpp/src/qpid/sys/posix/AsynchIO.cpp b/cpp/src/qpid/sys/posix/AsynchIO.cpp index 31355627cd..a5a6937475 100644 --- a/cpp/src/qpid/sys/posix/AsynchIO.cpp +++ b/cpp/src/qpid/sys/posix/AsynchIO.cpp @@ -251,6 +251,7 @@ public: virtual void stopReading(); virtual void requestCallback(RequestCallback); virtual BufferBase* getQueuedBuffer(); + virtual SecuritySettings getSecuritySettings(); private: ~AsynchIO(); @@ -626,6 +627,13 @@ void AsynchIO::close(DispatchHandle& h) { } } +SecuritySettings AsynchIO::getSecuritySettings() { + SecuritySettings settings; + settings.ssf = socket.getKeyLen(); + settings.authid = socket.getClientAuthId(); + return settings; +} + } // namespace posix AsynchAcceptor* AsynchAcceptor::create(const Socket& s, diff --git a/cpp/src/qpid/sys/posix/BSDSocket.cpp b/cpp/src/qpid/sys/posix/BSDSocket.cpp index 265142f629..905696cb8b 100644 --- a/cpp/src/qpid/sys/posix/BSDSocket.cpp +++ b/cpp/src/qpid/sys/posix/BSDSocket.cpp @@ -252,4 +252,14 @@ int BSDSocket::getError() const return result; } +int BSDSocket::getKeyLen() const +{ + return 0; +} + +std::string BSDSocket::getClientAuthId() const +{ + return std::string(); +} + }} // namespace qpid::sys diff --git a/cpp/src/qpid/sys/posix/BSDSocket.h b/cpp/src/qpid/sys/posix/BSDSocket.h index 98d7eb6e4d..2ddc69e2f8 100644 --- a/cpp/src/qpid/sys/posix/BSDSocket.h +++ b/cpp/src/qpid/sys/posix/BSDSocket.h @@ -89,6 +89,9 @@ public: QPID_COMMON_EXTERN virtual int read(void *buf, size_t count) const; QPID_COMMON_EXTERN virtual int write(const void *buf, size_t count) const; + QPID_COMMON_EXTERN int getKeyLen() const; + QPID_COMMON_EXTERN std::string getClientAuthId() const; + protected: /** Create socket */ void createSocket(const SocketAddress&) const; diff --git a/cpp/src/qpid/sys/ssl/SslHandler.cpp b/cpp/src/qpid/sys/ssl/SslHandler.cpp index 6e079a8094..f6605da953 100644 --- a/cpp/src/qpid/sys/ssl/SslHandler.cpp +++ b/cpp/src/qpid/sys/ssl/SslHandler.cpp @@ -69,7 +69,7 @@ SslHandler::~SslHandler() { delete codec; } -void SslHandler::init(SslIO* a, Timer& timer, uint32_t maxTime) { +void SslHandler::init(AsynchIO* a, Timer& timer, uint32_t maxTime) { aio = a; // Start timer for this connection @@ -209,7 +209,7 @@ void SslHandler::idle(AsynchIO&){ aio->queueWriteClose(); } -SecuritySettings SslHandler::getSecuritySettings(SslIO* aio) +SecuritySettings SslHandler::getSecuritySettings(AsynchIO* aio) { SecuritySettings settings = aio->getSecuritySettings(); settings.nodict = nodict; diff --git a/cpp/src/qpid/sys/ssl/SslHandler.h b/cpp/src/qpid/sys/ssl/SslHandler.h index d25304b37e..aedfea1888 100644 --- a/cpp/src/qpid/sys/ssl/SslHandler.h +++ b/cpp/src/qpid/sys/ssl/SslHandler.h @@ -44,11 +44,9 @@ class TimerTask; namespace ssl { -class SslIO; - class SslHandler : public OutputControl { std::string identifier; - SslIO* aio; + AsynchIO* aio; ConnectionCodec::Factory* factory; ConnectionCodec* codec; bool readError; @@ -57,12 +55,12 @@ class SslHandler : public OutputControl { boost::intrusive_ptr<sys::TimerTask> timeoutTimerTask; void write(const framing::ProtocolInitiation&); - qpid::sys::SecuritySettings getSecuritySettings(SslIO* aio); + qpid::sys::SecuritySettings getSecuritySettings(AsynchIO* aio); public: SslHandler(std::string id, ConnectionCodec::Factory* f, bool nodict); ~SslHandler(); - void init(SslIO* a, Timer& timer, uint32_t maxTime); + void init(AsynchIO* a, Timer& timer, uint32_t maxTime); void setClient() { isClient = true; } diff --git a/cpp/src/qpid/sys/windows/AsynchIO.cpp b/cpp/src/qpid/sys/windows/AsynchIO.cpp index e7e966519d..7dcc5c5846 100644 --- a/cpp/src/qpid/sys/windows/AsynchIO.cpp +++ b/cpp/src/qpid/sys/windows/AsynchIO.cpp @@ -290,6 +290,8 @@ public: */ virtual BufferBase* getQueuedBuffer(); + virtual SecuritySettings getSecuritySettings(void); + private: ReadCallback readCallback; EofCallback eofCallback; @@ -657,6 +659,13 @@ void AsynchIO::close(void) { notifyClosed(); } +SecuritySettings AsynchIO::getSecuritySettings() { + SecuritySettings settings; + settings.ssf = socket.getKeyLen(); + settings.authid = socket.getClientAuthId(); + return settings; +} + void AsynchIO::readComplete(AsynchReadResult *result) { int status = result->getStatus(); size_t bytes = result->getTransferred(); diff --git a/cpp/src/qpid/sys/windows/SslAsynchIO.cpp b/cpp/src/qpid/sys/windows/SslAsynchIO.cpp index d263f00ab3..abb9d37395 100644 --- a/cpp/src/qpid/sys/windows/SslAsynchIO.cpp +++ b/cpp/src/qpid/sys/windows/SslAsynchIO.cpp @@ -241,11 +241,15 @@ AsynchIO::BufferBase* SslAsynchIO::getQueuedBuffer() { return sslBuff; } -unsigned int SslAsynchIO::getSslKeySize() { +SecuritySettings SslAsynchIO::getSecuritySettings() { SecPkgContext_KeyInfo info; memset(&info, 0, sizeof(info)); ::QueryContextAttributes(&ctxtHandle, SECPKG_ATTR_KEY_INFO, &info); - return info.KeySize; + + SecuritySettings settings; + settings.ssf = info.KeySize; + settings.authid = std::string(); + return settings; } void SslAsynchIO::negotiationDone() { diff --git a/cpp/src/qpid/sys/windows/SslAsynchIO.h b/cpp/src/qpid/sys/windows/SslAsynchIO.h index e9d9e8d629..74ecd2a02e 100644 --- a/cpp/src/qpid/sys/windows/SslAsynchIO.h +++ b/cpp/src/qpid/sys/windows/SslAsynchIO.h @@ -81,8 +81,7 @@ public: virtual void stopReading(); virtual void requestCallback(RequestCallback); virtual BufferBase* getQueuedBuffer(); - - QPID_COMMON_EXTERN unsigned int getSslKeySize(); + virtual SecuritySettings getSecuritySettings(void); protected: CredHandle credHandle; diff --git a/cpp/src/qpid/sys/windows/WinSocket.cpp b/cpp/src/qpid/sys/windows/WinSocket.cpp index c1ac31de76..cb321d1ffb 100644 --- a/cpp/src/qpid/sys/windows/WinSocket.cpp +++ b/cpp/src/qpid/sys/windows/WinSocket.cpp @@ -258,4 +258,14 @@ void WinSocket::setTcpNoDelay() const } } +int WinSocket::getKeyLen() const +{ + return 0; +} + +std::string WinSocket::getClientAuthId() const +{ + return std::string(); +} + }} // namespace qpid::sys diff --git a/cpp/src/qpid/sys/windows/WinSocket.h b/cpp/src/qpid/sys/windows/WinSocket.h index 17905a6133..3aad6e7178 100644 --- a/cpp/src/qpid/sys/windows/WinSocket.h +++ b/cpp/src/qpid/sys/windows/WinSocket.h @@ -95,6 +95,9 @@ public: QPID_COMMON_EXTERN virtual int read(void *buf, size_t count) const; QPID_COMMON_EXTERN virtual int write(const void *buf, size_t count) const; + QPID_COMMON_EXTERN int getKeyLen() const; + QPID_COMMON_EXTERN std::string getClientAuthId() const; + protected: /** Create socket */ void createSocket(const SocketAddress&) const; |