You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by cl...@apache.org on 2014/02/19 21:52:23 UTC

svn commit: r1569916 - in /qpid/trunk/qpid/cpp/src: amqp.cmake qpid/messaging/amqp/TcpTransport.h qpid/messaging/amqp/windows/ qpid/messaging/amqp/windows/SslTransport.cpp

Author: cliffjansen
Date: Wed Feb 19 20:52:23 2014
New Revision: 1569916

URL: http://svn.apache.org/r1569916
Log:
QPID-5549: windows ssl over AMQP 1.0

Added:
    qpid/trunk/qpid/cpp/src/qpid/messaging/amqp/windows/
    qpid/trunk/qpid/cpp/src/qpid/messaging/amqp/windows/SslTransport.cpp
Modified:
    qpid/trunk/qpid/cpp/src/amqp.cmake
    qpid/trunk/qpid/cpp/src/qpid/messaging/amqp/TcpTransport.h

Modified: qpid/trunk/qpid/cpp/src/amqp.cmake
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/amqp.cmake?rev=1569916&r1=1569915&r2=1569916&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/amqp.cmake (original)
+++ qpid/trunk/qpid/cpp/src/amqp.cmake Wed Feb 19 20:52:23 2014
@@ -171,6 +171,9 @@ if (BUILD_AMQP)
         )
 
     if (WIN32)
+        list (APPEND amqp_SOURCES qpid/messaging/amqp/windows/SslTransport.cpp)
+        list (APPEND amqpc_SOURCES qpid/messaging/amqp/windows/SslTransport.cpp)
+
         set(proton_dll  "${PROTON_LIBRARY_DIRS}/${PROTON_LIBRARIES}.dll")
         set(proton_dlld "${PROTON_LIBRARY_DIRS}/${PROTON_LIBRARIES}d.dll")
 

Modified: qpid/trunk/qpid/cpp/src/qpid/messaging/amqp/TcpTransport.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/messaging/amqp/TcpTransport.h?rev=1569916&r1=1569915&r2=1569916&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/messaging/amqp/TcpTransport.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/messaging/amqp/TcpTransport.h Wed Feb 19 20:52:23 2014
@@ -52,23 +52,26 @@ class TcpTransport : public Transport
     void close();
     const qpid::sys::SecuritySettings* getSecuritySettings();
 
-  private:
+  protected:
     boost::scoped_ptr<qpid::sys::Socket> socket;
     TransportContext& context;
     qpid::sys::AsynchConnector* connector;
     qpid::sys::AsynchIO* aio;
     boost::shared_ptr<qpid::sys::Poller> poller;
     std::string id;
-    bool closed;
-    qpid::sys::Mutex lock;
 
-    void connected(const qpid::sys::Socket&);
+    virtual ~TcpTransport() {}
+    virtual void connected(const qpid::sys::Socket&);
     void failed(const std::string& msg);
     void read(qpid::sys::AsynchIO&, qpid::sys::AsynchIOBufferBase*);
     void write(qpid::sys::AsynchIO&);
     void eof(qpid::sys::AsynchIO&);
     void disconnected(qpid::sys::AsynchIO&);
     void socketClosed(qpid::sys::AsynchIO&, const qpid::sys::Socket&);
+
+  private:
+    bool closed;
+    qpid::sys::Mutex lock;
 };
 }}} // namespace qpid::messaging::amqp
 

Added: qpid/trunk/qpid/cpp/src/qpid/messaging/amqp/windows/SslTransport.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/messaging/amqp/windows/SslTransport.cpp?rev=1569916&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/messaging/amqp/windows/SslTransport.cpp (added)
+++ qpid/trunk/qpid/cpp/src/qpid/messaging/amqp/windows/SslTransport.cpp Wed Feb 19 20:52:23 2014
@@ -0,0 +1,133 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include "qpid/messaging/amqp/TcpTransport.h"
+#include "qpid/messaging/amqp/TransportContext.h"
+#include "qpid/messaging/ConnectionOptions.h"
+#include "qpid/sys/SecuritySettings.h"
+#include "qpid/sys/ConnectionCodec.h"
+#include "qpid/sys/Poller.h"
+#include "qpid/log/Statement.h"
+#include <boost/bind.hpp>
+#include <boost/format.hpp>
+
+#include "qpid/sys/windows/check.h"
+#include "qpid/sys/windows/util.h"
+#include "qpid/sys/windows/SslAsynchIO.h"
+#include "qpid/sys/windows/SslCredential.h"
+
+using namespace qpid::sys;
+
+namespace qpid {
+namespace messaging {
+namespace amqp {
+
+class SslTransport : public TcpTransport
+{
+  public:
+    SslTransport(TransportContext&, boost::shared_ptr<qpid::sys::Poller> p);
+
+    void connect(const std::string& host, const std::string& port);
+    void negotiationDone(SECURITY_STATUS status);
+    const qpid::sys::SecuritySettings* getSecuritySettings();
+
+  private:
+    std::string brokerHost;
+    qpid::sys::windows::SslCredential sslCredential;
+    bool certLoaded;
+    qpid::sys::SecuritySettings securitySettings;
+
+    void connected(const qpid::sys::Socket&);
+};
+
+// Static constructor which registers connector here
+namespace {
+Transport* create(TransportContext& c, Poller::shared_ptr p)
+{
+    return new SslTransport(c, p);
+}
+
+struct StaticInit
+{
+    StaticInit()
+    {
+        Transport::add("ssl", &create);
+    };
+} init;
+}
+
+
+void SslTransport::negotiationDone(SECURITY_STATUS status)
+{
+    if (status == SEC_E_OK) {
+        connector = 0;
+        context.opened();
+        id = boost::str(boost::format("[%1%]") % socket->getFullAddress());
+    } else {
+        if (status == SEC_E_INCOMPLETE_CREDENTIALS && !certLoaded) {
+            // Server requested a client cert but we supplied none for the following reason:
+            failed(QPID_MSG(sslCredential.error()));
+        }
+        else
+            failed(QPID_MSG(qpid::sys::strError(status)));
+    }
+}
+
+SslTransport::SslTransport(TransportContext& c, boost::shared_ptr<Poller> p) : TcpTransport(c, p)
+{
+    const ConnectionOptions* options = context.getOptions();
+    const std::string& name = (options->sslCertName != "") ?
+        options->sslCertName : qpid::sys::ssl::SslOptions::global.certName;
+    certLoaded = sslCredential.load(name);
+    QPID_LOG(debug, "SslTransport created");
+}
+
+void SslTransport::connect(const std::string& host, const std::string& port)
+{
+    brokerHost = host;
+    TcpTransport::connect(host, port);
+}
+
+void SslTransport::connected(const Socket& s)
+{
+    aio = new qpid::sys::windows::ClientSslAsynchIO(brokerHost,
+                                                     s,
+                                                     sslCredential.handle(),
+                                                     boost::bind(&SslTransport::read, this, _1, _2),
+                                                     boost::bind(&SslTransport::eof, this, _1),
+                                                     boost::bind(&SslTransport::disconnected, this, _1),
+                                                     boost::bind(&SslTransport::socketClosed, this, _1, _2),
+                                                     0, // nobuffs
+                                                     boost::bind(&SslTransport::write, this, _1),
+                                                     boost::bind(&SslTransport::negotiationDone, this, _1));
+
+    aio->createBuffers(std::numeric_limits<uint16_t>::max());//note: AMQP 1.0 _can_ handle large frame sizes
+    aio->start(poller);
+}
+
+const qpid::sys::SecuritySettings* SslTransport::getSecuritySettings()
+{
+    securitySettings.ssf = socket->getKeyLen();
+    securitySettings.authid = "dummy";//set to non-empty string to enable external authentication
+    return &securitySettings;
+}
+
+}}} // namespace qpid::messaging::amqp



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org