activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r943289 [1/2] - in /activemq/activemq-cpp/trunk/activemq-cpp: ./ src/main/ src/main/decaf/internal/ src/main/decaf/internal/net/ src/main/decaf/internal/net/ssl/ src/main/decaf/internal/net/ssl/openssl/ src/main/decaf/internal/net/tcp/ src/...
Date Tue, 11 May 2010 20:57:59 GMT
Author: tabish
Date: Tue May 11 20:57:57 2010
New Revision: 943289

URL: http://svn.apache.org/viewvc?rev=943289&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQCPP-140

Adds a large portion of the SSL provider framework and implementation for OpenSSL.

Added:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLContext.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLContext.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketException.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketException.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketInputStream.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketInputStream.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketOutputStream.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketOutputStream.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/GenericResource.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/Resource.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/Resource.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ResourceLifecycleManager.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ResourceLifecycleManager.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContext.cpp
      - copied, changed from r939856, activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContent.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContext.h
      - copied, changed from r939856, activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContent.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContextSpi.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContextSpi.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandom.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandom.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandomSpi.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandomSpi.h   (with props)
Removed:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContent.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContent.h
Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/pom.xml
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/DecafRuntime.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLSocketFactory.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLSocketFactory.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocket.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketInputStream.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Socket.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocket.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocket.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocketFactory.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocketFactory.h

Modified: activemq/activemq-cpp/trunk/activemq-cpp/pom.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/pom.xml?rev=943289&r1=943288&r2=943289&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/pom.xml (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/pom.xml Tue May 11 20:57:57 2010
@@ -136,7 +136,6 @@
                   <includes>**\*.c</includes>
                 </includes>
                 <excludes>
-                  <exclude>**/decaf/security/**\*.cpp</exclude>
                   <exclude>**/decaf/security_provider/**\*.cpp</exclude>
                   <exclude>**/decaf/internal/**/windows/**\*.cpp</exclude>
                 </excludes>
@@ -147,7 +146,6 @@
                   <includes>**\*.h</includes>
                 </includes>
                 <excludes>
-                  <exclude>**/decaf/security/**\*.h</exclude>
                   <exclude>**/decaf/security_provider/**\*.h</exclude>
                 </excludes>
               </headers>

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am?rev=943289&r1=943288&r2=943289&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am Tue May 11 20:57:57 2010
@@ -484,9 +484,17 @@ cc_sources = \
     decaf/internal/io/StandardErrorOutputStream.cpp \
     decaf/internal/io/StandardInputStream.cpp \
     decaf/internal/io/StandardOutputStream.cpp \
+    decaf/internal/net/Network.cpp \
     decaf/internal/net/URIEncoderDecoder.cpp \
     decaf/internal/net/URIHelper.cpp \
+    decaf/internal/net/ssl/DefaultSSLContext.cpp \
     decaf/internal/net/ssl/DefaultSSLSocketFactory.cpp \
+    decaf/internal/net/ssl/openssl/OpenSSLContextSpi.cpp \
+    decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp \
+    decaf/internal/net/ssl/openssl/OpenSSLSocketException.cpp \
+    decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.cpp \
+    decaf/internal/net/ssl/openssl/OpenSSLSocketInputStream.cpp \
+    decaf/internal/net/ssl/openssl/OpenSSLSocketOutputStream.cpp \
     decaf/internal/net/tcp/DefaultSocketFactory.cpp \
     decaf/internal/net/tcp/TcpSocket.cpp \
     decaf/internal/net/tcp/TcpSocketInputStream.cpp \
@@ -501,6 +509,8 @@ cc_sources = \
     decaf/internal/nio/ShortArrayBuffer.cpp \
     decaf/internal/util/ByteArrayAdapter.cpp \
     decaf/internal/util/HexStringParser.cpp \
+    decaf/internal/util/Resource.cpp \
+    decaf/internal/util/ResourceLifecycleManager.cpp \
     decaf/internal/util/TimerTaskHeap.cpp \
     decaf/internal/util/concurrent/SynchronizableImpl.cpp \
     decaf/internal/util/concurrent/unix/ConditionImpl.cpp \
@@ -563,7 +573,8 @@ cc_sources = \
     decaf/net/URL.cpp \
     decaf/net/URLDecoder.cpp \
     decaf/net/URLEncoder.cpp \
-    decaf/net/ssl/SSLContent.cpp \
+    decaf/net/ssl/SSLContext.cpp \
+    decaf/net/ssl/SSLContextSpi.cpp \
     decaf/net/ssl/SSLParameters.cpp \
     decaf/net/ssl/SSLSocket.cpp \
     decaf/net/ssl/SSLSocketFactory.cpp \
@@ -575,6 +586,8 @@ cc_sources = \
     decaf/nio/IntBuffer.cpp \
     decaf/nio/LongBuffer.cpp \
     decaf/nio/ShortBuffer.cpp \
+    decaf/security/SecureRandom.cpp \
+    decaf/security/SecureRandomSpi.cpp \
     decaf/util/Date.cpp \
     decaf/util/Properties.cpp \
     decaf/util/Random.cpp \
@@ -1150,10 +1163,18 @@ h_sources = \
     decaf/internal/io/StandardErrorOutputStream.h \
     decaf/internal/io/StandardInputStream.h \
     decaf/internal/io/StandardOutputStream.h \
+    decaf/internal/net/Network.h \
     decaf/internal/net/URIEncoderDecoder.h \
     decaf/internal/net/URIHelper.h \
     decaf/internal/net/URIType.h \
+    decaf/internal/net/ssl/DefaultSSLContext.h \
     decaf/internal/net/ssl/DefaultSSLSocketFactory.h \
+    decaf/internal/net/ssl/openssl/OpenSSLContextSpi.h \
+    decaf/internal/net/ssl/openssl/OpenSSLSocket.h \
+    decaf/internal/net/ssl/openssl/OpenSSLSocketException.h \
+    decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.h \
+    decaf/internal/net/ssl/openssl/OpenSSLSocketInputStream.h \
+    decaf/internal/net/ssl/openssl/OpenSSLSocketOutputStream.h \
     decaf/internal/net/tcp/DefaultSocketFactory.h \
     decaf/internal/net/tcp/TcpSocket.h \
     decaf/internal/net/tcp/TcpSocketInputStream.h \
@@ -1167,7 +1188,10 @@ h_sources = \
     decaf/internal/nio/LongArrayBuffer.h \
     decaf/internal/nio/ShortArrayBuffer.h \
     decaf/internal/util/ByteArrayAdapter.h \
+    decaf/internal/util/GenericResource.h \
     decaf/internal/util/HexStringParser.h \
+    decaf/internal/util/Resource.h \
+    decaf/internal/util/ResourceLifecycleManager.h \
     decaf/internal/util/TimerTaskHeap.h \
     decaf/internal/util/concurrent/ConditionImpl.h \
     decaf/internal/util/concurrent/MutexImpl.h \
@@ -1282,7 +1306,8 @@ h_sources = \
     decaf/net/URLEncoder.h \
     decaf/net/UnknownHostException.h \
     decaf/net/UnknownServiceException.h \
-    decaf/net/ssl/SSLContent.h \
+    decaf/net/ssl/SSLContext.h \
+    decaf/net/ssl/SSLContextSpi.h \
     decaf/net/ssl/SSLParameters.h \
     decaf/net/ssl/SSLSocket.h \
     decaf/net/ssl/SSLSocketFactory.h \
@@ -1298,6 +1323,26 @@ h_sources = \
     decaf/nio/LongBuffer.h \
     decaf/nio/ReadOnlyBufferException.h \
     decaf/nio/ShortBuffer.h \
+    decaf/security/GeneralSecurityException.h \
+    decaf/security/InvalidKeyException.h \
+    decaf/security/Key.h \
+    decaf/security/KeyException.h \
+    decaf/security/KeyManagementException.h \
+    decaf/security/NoSuchAlgorithmException.h \
+    decaf/security/NoSuchProviderException.h \
+    decaf/security/Principal.h \
+    decaf/security/PublicKey.h \
+    decaf/security/SecureRandom.h \
+    decaf/security/SecureRandomSpi.h \
+    decaf/security/SignatureException.h \
+    decaf/security/auth/x500/X500Principal.h \
+    decaf/security/cert/Certificate.h \
+    decaf/security/cert/CertificateEncodingException.h \
+    decaf/security/cert/CertificateException.h \
+    decaf/security/cert/CertificateExpiredException.h \
+    decaf/security/cert/CertificateNotYetValidException.h \
+    decaf/security/cert/CertificateParsingException.h \
+    decaf/security/cert/X509Certificate.h \
     decaf/util/AbstractCollection.h \
     decaf/util/AbstractList.h \
     decaf/util/AbstractMap.h \

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/DecafRuntime.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/DecafRuntime.cpp?rev=943289&r1=943288&r2=943289&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/DecafRuntime.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/DecafRuntime.cpp Tue May 11 20:57:57 2010
@@ -22,9 +22,11 @@
 #include <apr_pools.h>
 
 #include <decaf/lang/Thread.h>
+#include <decaf/internal/net/Network.h>
 
 using namespace decaf;
 using namespace decaf::internal;
+using namespace decaf::internal::net;
 using namespace decaf::lang;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -98,6 +100,9 @@ void Runtime::initializeRuntime( int arg
 
     // Initialize any Platform specific Threading primitives
     Thread::initThreading();
+
+    // Initialize the Networking layer.
+    Network::initializeNetworking();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -107,5 +112,12 @@ void Runtime::initializeRuntime() {
 
 ////////////////////////////////////////////////////////////////////////////////
 void Runtime::shutdownRuntime() {
+
+    // Shutdown the networking layer before Threading, many network routines need
+    // to be thread safe and require Threading primitives.
+    Network::shutdownNetworking();
+
+    // Threading is the last to by shutdown since most other parts of the Runtime
+    // need to make use of Thread primitives.
     Thread::shutdownThreading();
 }

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.cpp?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.cpp Tue May 11 20:57:57 2010
@@ -0,0 +1,99 @@
+/*
+ * 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 "Network.h"
+
+#include <decaf/lang/Exception.h>
+#include <decaf/lang/exceptions/IllegalStateException.h>
+#include <decaf/util/concurrent/Mutex.h>
+#include <decaf/internal/util/ResourceLifecycleManager.h>
+
+using namespace decaf;
+using namespace decaf::internal;
+using namespace decaf::internal::net;
+using namespace decaf::internal::util;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::util;
+using namespace decaf::util::concurrent;
+
+////////////////////////////////////////////////////////////////////////////////
+Network* Network::networkRuntime = NULL;
+
+////////////////////////////////////////////////////////////////////////////////
+namespace decaf{
+namespace internal{
+namespace net{
+
+    class NetworkData {
+    public:
+
+        ResourceLifecycleManager resources;
+        Mutex lock;
+
+    };
+
+}}}
+
+////////////////////////////////////////////////////////////////////////////////
+Network::Network() : data( new NetworkData() ) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Network::~Network() {
+    try{
+        delete this->data;
+    }
+    DECAF_CATCH_NOTHROW( Exception )
+    DECAF_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Network::addNetworkResource( Resource* value ) {
+    this->data->resources.addResource( value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Network* Network::getNetworkRuntime() {
+
+    if( Network::networkRuntime == NULL ) {
+        throw IllegalStateException(
+            __FILE__, __LINE__, "Network Runtime is not Initialized." );
+    }
+
+    return Network::networkRuntime;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Mutex* Network::getRuntimeLock() {
+
+    return &( this->data->lock );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Network::initializeNetworking() {
+
+    // Create the Network Runtime
+    Network::networkRuntime = new Network();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Network::shutdownNetworking() {
+
+    // Destory the Network Runtime.
+    delete Network::networkRuntime;
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.h?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.h Tue May 11 20:57:57 2010
@@ -0,0 +1,112 @@
+/*
+ * 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.
+ */
+
+#ifndef _DECAF_INTERNAL_NET_NETWORK_H_
+#define _DECAF_INTERNAL_NET_NETWORK_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/util/concurrent/Mutex.h>
+#include <decaf/internal/util/Resource.h>
+#include <decaf/internal/util/GenericResource.h>
+
+namespace decaf {
+namespace internal {
+namespace net {
+
+    class NetworkData;
+
+    /**
+     * Internal class used to manage Networking related resources and hide platform
+     * dependent calls from the higher level API.
+     *
+     * @since 1.0
+     */
+    class DECAF_API Network {
+    private:
+
+        NetworkData* data;
+
+        static Network* networkRuntime;
+
+    protected:
+
+        Network();
+
+    public:
+
+        virtual ~Network();
+
+        /**
+         * Gets a pointer to the Network Runtime's Lock object, this can be used by
+         * Network layer APIs to synchronize around certain actions such as adding
+         * a resource to the Network layer, etc.
+         *
+         * The pointer returned is owned by the Network runtime and should not be
+         * deleted or copied by the caller.
+         *
+         * @returns a pointer to the Network Runtime's single Lock instance.
+         */
+        decaf::util::concurrent::Mutex* getRuntimeLock();
+
+        /**
+         * Adds a Resource to the Network Runtime, this resource will be held by the
+         * runtime until the Library shutdown method is called at which time all the
+         * Resources held by the Network Runtime are destroyed.
+         *
+         * @param value
+         *      The Resource to add to the Network Runtime.
+         *
+         * @throw NullPointerException if the Resource value passed is null.
+         */
+        void addNetworkResource( decaf::internal::util::Resource* value );
+
+        template<typename T>
+        void addAsResource( T* value ) {
+
+            util::GenericResource<T>* resource = new util::GenericResource<T>( value );
+            this->addNetworkResource( resource );
+        }
+
+    public:   // Static methods
+
+        /**
+         * Gets the one and only instance of the Network class, if this is called before
+         * the Network layer has been initialized or after it has been shutdown then an
+         * IllegalStateException is thrown.
+         *
+         * @return pointer to the Network runtime for the Decaf library.
+         */
+        static Network* getNetworkRuntime();
+
+        /**
+         * Initialize the Networking layer.
+         */
+        static void initializeNetworking();
+
+        /**
+         * Shutdown the Network layer and free any associated resources, classes in the
+         * Decaf library that use the networking layer will now fail if used after calling
+         * the shutdown method.
+         */
+        static void shutdownNetworking();
+
+    };
+
+}}}
+
+#endif /* _DECAF_INTERNAL_NET_NETWORK_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLContext.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLContext.cpp?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLContext.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLContext.cpp Tue May 11 20:57:57 2010
@@ -0,0 +1,73 @@
+/*
+ * 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 "DefaultSSLContext.h"
+
+#include <decaf/io/IOException.h>
+
+#include <decaf/security/SecureRandom.h>
+#include <decaf/internal/net/Network.h>
+#include <decaf/internal/net/ssl/openssl/OpenSSLContextSpi.h>
+
+#include <memory>
+
+using namespace decaf;
+using namespace decaf::io;
+using namespace decaf::net;
+using namespace decaf::net::ssl;
+using namespace decaf::security;
+using namespace decaf::internal;
+using namespace decaf::internal::net;
+using namespace decaf::internal::net::ssl;
+using namespace decaf::internal::net::ssl::openssl;
+
+////////////////////////////////////////////////////////////////////////////////
+SSLContext* DefaultSSLContext::defaultSSLContext = NULL;
+
+////////////////////////////////////////////////////////////////////////////////
+DefaultSSLContext::DefaultSSLContext() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+DefaultSSLContext::~DefaultSSLContext() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SSLContext* DefaultSSLContext::getContext() {
+
+#ifdef HAVE_OPENSSL
+
+    if( defaultSSLContext == NULL ) {
+
+        std::auto_ptr<SecureRandom> random( new SecureRandom() );
+        std::auto_ptr<SSLContextSpi> contextSpi( new OpenSSLContextSpi() );
+
+        // TODO - This should eventually move to a call to SSLContext::init();
+        contextSpi->providerInit( random.release() );
+
+        // Update the default, this is the Application default from now on.
+        defaultSSLContext = new SSLContext( contextSpi.release() );
+
+        // Store the default in the Network Runtime, it will be destroyed when the
+        // Application calls the Decaf shutdownLibrary method.
+        Network::getNetworkRuntime()->addAsResource( defaultSSLContext );
+    }
+
+#endif
+
+    return defaultSSLContext;
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLContext.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLContext.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLContext.h?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLContext.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLContext.h Tue May 11 20:57:57 2010
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+
+#ifndef _DECAF_INTERNAL_NET_SSL_DEFAULTSSLCONTEXT_H_
+#define _DECAF_INTERNAL_NET_SSL_DEFAULTSSLCONTEXT_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/net/ssl/SSLContext.h>
+
+namespace decaf {
+namespace internal {
+namespace net {
+namespace ssl {
+
+    /**
+     * Default SSLContext manager for the Decaf library.  If the user doesn't supply or
+     * specify the SSLContext that they wish to use then we load the Decaf library's
+     * default SSLContext using whatever SSL provider is enabled an preferred.
+     *
+     * @since 1.0
+     */
+    class DefaultSSLContext {
+    private:
+
+        static decaf::net::ssl::SSLContext* defaultSSLContext;
+
+    protected:
+
+        DefaultSSLContext();
+
+    public:
+
+        virtual ~DefaultSSLContext();
+
+    public:
+
+        static decaf::net::ssl::SSLContext* getContext();
+
+    };
+
+}}}}
+
+#endif /* _DECAF_INTERNAL_NET_SSL_DEFAULTSSLCONTEXT_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLContext.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLSocketFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLSocketFactory.cpp?rev=943289&r1=943288&r2=943289&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLSocketFactory.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLSocketFactory.cpp Tue May 11 20:57:57 2010
@@ -64,8 +64,7 @@ std::vector<std::string> DefaultSSLSocke
 
 ////////////////////////////////////////////////////////////////////////////////
 Socket* DefaultSSLSocketFactory::createSocket( Socket* socket DECAF_UNUSED, std::string host DECAF_UNUSED,
-                                               int port DECAF_UNUSED, bool autoClose DECAF_UNUSED )
-    throw( decaf::io::IOException, decaf::net::UnknownHostException ) {
+                                               int port DECAF_UNUSED, bool autoClose DECAF_UNUSED ) {
 
     throw IOException( __FILE__, __LINE__, errorMessage.c_str() );
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLSocketFactory.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLSocketFactory.h?rev=943289&r1=943288&r2=943289&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLSocketFactory.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLSocketFactory.h Tue May 11 20:57:57 2010
@@ -73,8 +73,7 @@ namespace ssl {
         /**
          * {@inheritDoc}
          */
-        virtual decaf::net::Socket* createSocket( decaf::net::Socket* socket, std::string host, int port, bool autoClose )
-            throw( decaf::io::IOException, decaf::net::UnknownHostException );
+        virtual decaf::net::Socket* createSocket( decaf::net::Socket* socket, std::string host, int port, bool autoClose );
 
     };
 

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.cpp?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.cpp Tue May 11 20:57:57 2010
@@ -0,0 +1,244 @@
+/*
+ * 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 "OpenSSLContextSpi.h"
+
+#include <decaf/net/SocketFactory.h>
+#include <decaf/net/ssl/SSLParameters.h>
+#include <decaf/security/SecureRandom.h>
+#include <decaf/security/KeyManagementException.h>
+#include <decaf/lang/Thread.h>
+#include <decaf/lang/Pointer.h>
+#include <decaf/lang/ArrayPointer.h>
+#include <decaf/lang/exceptions/IllegalStateException.h>
+#include <decaf/util/concurrent/Mutex.h>
+#include <decaf/internal/net/ssl/openssl/OpenSSLSocketException.h>
+#include <decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.h>
+
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#ifdef HAVE_OPENSSL
+#include <openssl/ssl.h>
+#include <openssl/rand.h>
+#define SSL_LOCK_MUTEX CRYPTO_LOCK
+#else
+#define SSL_LOCK_MUTEX 1
+#endif
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::net;
+using namespace decaf::net::ssl;
+using namespace decaf::util;
+using namespace decaf::util::concurrent;
+using namespace decaf::security;
+using namespace decaf::internal;
+using namespace decaf::internal::net;
+using namespace decaf::internal::net::ssl;
+using namespace decaf::internal::net::ssl::openssl;
+
+////////////////////////////////////////////////////////////////////////////////
+namespace decaf {
+namespace internal {
+namespace net {
+namespace ssl {
+namespace openssl {
+
+    class ContextData {
+    public:
+
+        Mutex monitor;
+        Pointer<SocketFactory> clientSocketFactory;
+        Pointer<SecureRandom> random;
+        std::string password;
+
+        static Mutex* locks;
+        static std::string defaultCipherList;
+
+#ifdef HAVE_OPENSSL
+        SSL_CTX* openSSLContext;
+#endif
+
+    public:
+
+        ContextData( int size ) {
+            ContextData::locks = new Mutex[size];
+        }
+
+        ~ContextData() {
+
+#ifdef HAVE_OPENSSL
+            try{
+                SSL_CTX_free( this->openSSLContext );
+            } catch(...) {}
+#endif
+            delete [] locks;
+        }
+
+        // Used to allow OpenSSL to tell us when to lock / unlock a mutex for it.
+        static void lockCallback( int mode, int type, const char *, int ) {
+
+            if( mode & SSL_LOCK_MUTEX ) {
+                locks[type].lock();
+            } else {
+                locks[type].unlock();
+            }
+        }
+
+        // Returns to OpenSSL the password for a Certificate.
+        static int passwordCallback( char* buffer, int size, int, void* data ) {
+
+            ContextData* ctxData = static_cast<ContextData*>( data );
+
+            if( !ctxData->password.empty() ) {
+
+                size = size < (int)ctxData->password.size() ? size : (int)ctxData->password.size();
+                strncpy( buffer, ctxData->password.c_str(), size );
+                return size;
+            }
+
+            return 0;
+        }
+
+        static unsigned long getThreadId() {
+            return (unsigned long)Thread::getId();
+        }
+
+    };
+
+    Mutex* ContextData::locks = NULL;
+    std::string ContextData::defaultCipherList = "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH";
+
+}}}}}
+
+////////////////////////////////////////////////////////////////////////////////
+OpenSSLContextSpi::OpenSSLContextSpi() : data( NULL ) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+OpenSSLContextSpi::~OpenSSLContextSpi() {
+    try{
+
+#ifdef HAVE_OPENSSL
+        // Clean up all the OpenSSL resources.
+        CRYPTO_set_locking_callback( 0 );
+        EVP_cleanup();
+#endif
+
+        delete this->data;
+    }
+    DECAF_CATCH_NOTHROW( Exception )
+    DECAF_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OpenSSLContextSpi::providerInit( SecureRandom* random ) {
+
+    if( random == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "SecureRandom instance passed was NULL." );
+    }
+
+    try{
+
+#ifdef HAVE_OPENSSL
+
+        // General library initialization.
+        CRYPTO_malloc_init();
+        SSL_load_error_strings();
+        SSL_library_init();
+        OpenSSL_add_all_algorithms();
+
+        // Initialize our data object and store the RNG for later.
+        this->data = new ContextData( CRYPTO_num_locks() );
+        this->data->random.reset( random );
+        this->data->openSSLContext = SSL_CTX_new( SSLv23_method() );
+
+        // Setup the Crypto Library Thread callbacks.
+        CRYPTO_set_id_callback( &ContextData::getThreadId );
+        CRYPTO_set_locking_callback( &ContextData::lockCallback );
+
+        // Load the Library default CA paths and Context Options.
+        SSL_CTX_set_default_verify_paths( this->data->openSSLContext );
+        SSL_CTX_set_options( this->data->openSSLContext, SSL_OP_ALL | SSL_OP_NO_SSLv2 );
+        SSL_CTX_set_mode( this->data->openSSLContext, SSL_MODE_AUTO_RETRY );
+
+        // The Password Callback for cases where we need to open a Cert.
+        SSL_CTX_set_default_passwd_cb( this->data->openSSLContext, &ContextData::passwordCallback );
+        SSL_CTX_set_default_passwd_cb_userdata( this->data->openSSLContext, (void*)this->data );
+
+        // Sets the Default set of allowed Ciphers, this could be overridden by the system
+        // property: decaf.net.ssl.CipherSuites
+        if( SSL_CTX_set_cipher_list( this->data->openSSLContext, ContextData::defaultCipherList.c_str() ) != 1 ) {
+            throw OpenSSLSocketException( __FILE__, __LINE__ );
+        }
+
+        // Now seed the OpenSSL RNG.
+        std::vector<unsigned char> seed( 128 );
+        random->nextBytes( seed );
+        RAND_seed( (void*)( &seed[0] ), (int)seed.size() );
+
+#endif
+    }
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( KeyManagementException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, KeyManagementException )
+    DECAF_CATCHALL_THROW( KeyManagementException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SocketFactory* OpenSSLContextSpi::providerGetSocketFactory() {
+
+    try{
+
+        synchronized( &( this->data->monitor ) ) {
+            if( this->data->clientSocketFactory == NULL ) {
+                this->data->clientSocketFactory.reset( new OpenSSLSocketFactory( this ) );
+            }
+        }
+
+        return this->data->clientSocketFactory.get();
+    }
+    DECAF_CATCH_RETHROW( IllegalStateException )
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::vector<std::string> OpenSSLContextSpi::getDefaultCipherSuites() {
+
+    return std::vector<std::string>();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::vector<std::string> OpenSSLContextSpi::getSupportedCipherSuites() {
+
+    return std::vector<std::string>();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void* OpenSSLContextSpi::getOpenSSLCtx() {
+
+    return (void*)this->data->openSSLContext;
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.h?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.h Tue May 11 20:57:57 2010
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ */
+
+#ifndef _DECAF_INTERNAL_NET_SSL_OPENSSL_OPENSSLCONTEXTSPI_H_
+#define _DECAF_INTERNAL_NET_SSL_OPENSSL_OPENSSLCONTEXTSPI_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/net/ssl/SSLContextSpi.h>
+
+namespace decaf {
+namespace internal {
+namespace net {
+namespace ssl {
+namespace openssl {
+
+    class ContextData;
+
+    /**
+     * Provides an SSLContext that wraps the OpenSSL API.
+     *
+     * @since 1.0
+     */
+    class DECAF_API OpenSSLContextSpi : public decaf::net::ssl::SSLContextSpi {
+    private:
+
+        ContextData* data;
+
+    public:
+
+        OpenSSLContextSpi();
+
+        virtual ~OpenSSLContextSpi();
+
+        /**
+         * {@inheritDoc}
+         */
+        virtual void providerInit( security::SecureRandom* random );
+
+        /**
+         * {@inheritDoc}
+         */
+        virtual decaf::net::SocketFactory* providerGetSocketFactory();
+
+    private:
+
+        friend class OpenSSLSocket;
+        friend class OpenSSLSocketFactory;
+
+        std::vector<std::string> getDefaultCipherSuites();
+        std::vector<std::string> getSupportedCipherSuites();
+        void* getOpenSSLCtx();
+
+    };
+
+}}}}}
+
+#endif /* _DECAF_INTERNAL_NET_SSL_OPENSSL_OPENSSLCONTEXTSPI_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp Tue May 11 20:57:57 2010
@@ -0,0 +1,292 @@
+/*
+ * 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 "OpenSSLSocket.h"
+
+#ifdef HAVE_OPENSSL
+    #include <openssl/ssl.h>
+#endif
+
+#include <decaf/net/SocketImpl.h>
+#include <decaf/io/IOException.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
+#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::io;
+using namespace decaf::net;
+using namespace decaf::net::ssl;
+using namespace decaf::internal;
+using namespace decaf::internal::net;
+using namespace decaf::internal::net::ssl;
+using namespace decaf::internal::net::ssl::openssl;
+
+////////////////////////////////////////////////////////////////////////////////
+namespace decaf {
+namespace internal {
+namespace net {
+namespace ssl {
+namespace openssl {
+
+    class SocketData {
+    public:
+
+#ifdef HAVE_OPENSSL
+        SSL* ssl;
+#endif
+        bool needsClientAuth;
+        bool wantsClientAuth;
+
+    public:
+
+        SocketData() : ssl( NULL ), needsClientAuth( false ), wantsClientAuth( false ) {
+        }
+
+        ~SocketData() {
+            try{
+#ifdef HAVE_OPENSSL
+                if( ssl ) {
+                    SSL_free( ssl );
+                }
+#endif
+            } catch(...) {}
+        }
+
+    };
+
+}}}}}
+
+////////////////////////////////////////////////////////////////////////////////
+OpenSSLSocket::OpenSSLSocket( void* ssl ) : SSLSocket(), data( new SocketData() ) {
+
+    if( ssl == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "The OpenSSL SSL object instance passed was NULL." );
+    }
+
+#ifdef HAVE_OPENSSL
+    this->data->ssl = static_cast<SSL*>( ssl );
+#endif
+}
+
+////////////////////////////////////////////////////////////////////////////////
+OpenSSLSocket::~OpenSSLSocket() {
+    try{
+
+        SSLSocket::close();
+
+#ifdef HAVE_OPENSSL
+        if( this->data->ssl ) {
+            SSL_set_shutdown( this->data->ssl, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN );
+            SSL_shutdown( this->data->ssl );
+        }
+#endif
+
+        delete data;
+    }
+    DECAF_CATCH_NOTHROW( Exception )
+    DECAF_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::vector<std::string> OpenSSLSocket::getSupportedCipherSuites() const {
+
+    return std::vector<std::string>();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::vector<std::string> OpenSSLSocket::getSupportedProtocols() const {
+
+    return std::vector<std::string>();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::vector<std::string> OpenSSLSocket::getEnabledCipherSuites() const {
+
+    return std::vector<std::string>();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OpenSSLSocket::setEnabledCipherSuites( const std::vector<std::string>& suites DECAF_UNUSED ) {
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::vector<std::string> OpenSSLSocket::getEnabledProtocols() const {
+
+    return std::vector<std::string>();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OpenSSLSocket::setEnabledProtocols( const std::vector<std::string>& protocols DECAF_UNUSED ) {
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool OpenSSLSocket::getWantClientAuth() const {
+    return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OpenSSLSocket::setWantClientAuth( bool value DECAF_UNUSED ) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool OpenSSLSocket::getNeedClientAuth() const {
+    return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OpenSSLSocket::setNeedClientAuth( bool value DECAF_UNUSED ) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int OpenSSLSocket::read( unsigned char* buffer, int size, int offset, int length ) {
+
+    try{
+        if( this->isClosed() ){
+            throw IOException(
+                __FILE__, __LINE__, "The Stream has been closed" );
+        }
+
+        if( this->isInputShutdown() == true ) {
+            return -1;
+        }
+
+        if( length == 0 ) {
+            return 0;
+        }
+
+        if( buffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__, "Buffer passed is Null" );
+        }
+
+        if( size < 0 ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "size parameter out of Bounds: %d.", size );
+        }
+
+        if( offset > size || offset < 0 ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "offset parameter out of Bounds: %d.", offset );
+        }
+
+        if( length < 0 || length > size - offset ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "length parameter out of Bounds: %d.", length );
+        }
+
+        // Read data from the socket.
+        int result = SSL_read( ssl, buffer, bufferSize );
+
+        switch( SSL_get_error( ssl, result ) ) {
+            case SSL_ERROR_NONE:
+                return result;
+            case SSL_ERROR_ZERO_RETURN:
+                if( !isClosed() ) {
+                    this->shutdownInput();
+                    return -1;
+                }
+            default:
+                throw OpenSSLSocketException( __FILE__, __LINE__ );
+        }
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OpenSSLSocket::write( const unsigned char* buffer, int size, int offset, int length ) {
+
+    try{
+
+        if( length == 0 ) {
+            return;
+        }
+
+        if( buffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__,
+                "TcpSocketOutputStream::write - passed buffer is null" );
+        }
+
+        if( isClosed() ) {
+            throw IOException(
+                __FILE__, __LINE__,
+                "TcpSocketOutputStream::write - This Stream has been closed." );
+        }
+
+        if( size < 0 ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "size parameter out of Bounds: %d.", size );
+        }
+
+        if( offset > size || offset < 0 ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "offset parameter out of Bounds: %d.", offset );
+        }
+
+        if( length < 0 || length > size - offset ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "length parameter out of Bounds: %d.", length );
+        }
+
+        std::size_t remaining = length;
+
+        while( remaining > 0 && !isClosed() ) {
+
+            int written = SSL_write( ssl, buffer + offset, remaining );
+
+            switch( SSL_get_error( ssl, written ) ) {
+                case SSL_ERROR_NONE:
+                    offset += written;
+                    remaining -= written;
+                    break;
+                case SSL_ERROR_ZERO_RETURN:
+                    throw SocketException(
+                        __FILE__, __LINE__,
+                        "The connection was broken unexpectedly." );
+                default:
+                    throw OpenSSLSocketException( __FILE__, __LINE__ );
+            }
+        }
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int OpenSSLSocket::available() {
+
+    try{
+
+        if( !isClosed() ) {
+            return SSL_pending( this->data->ssl );
+        }
+
+        return -1;
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.h?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.h Tue May 11 20:57:57 2010
@@ -0,0 +1,155 @@
+/*
+ * 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.
+ */
+
+#ifndef _DECAF_INTERNAL_NET_SSL_OPENSSL_OPENSSLSOCKET_H_
+#define _DECAF_INTERNAL_NET_SSL_OPENSSL_OPENSSLSOCKET_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/net/ssl/SSLSocket.h>
+
+namespace decaf {
+namespace internal {
+namespace net {
+namespace ssl {
+namespace openssl {
+
+    class SocketData;
+
+    /**
+     * Wraps a a Normal Socket object and extends or overrides functions in that class to make
+     * use of the OpenSSL Socket API.
+     *
+     * @since 1.0
+     */
+    class DECAF_API OpenSSLSocket : public decaf::net::ssl::SSLSocket {
+    private:
+
+        SocketData* data;
+
+    public:
+
+        OpenSSLSocket( void* ssl );
+
+        virtual ~OpenSSLSocket();
+
+    public:
+
+        /**
+         * {@inheritDoc}
+         */
+        virtual std::vector<std::string> getSupportedCipherSuites() const;
+
+        /**
+         * {@inheritDoc}
+         */
+        virtual std::vector<std::string> getSupportedProtocols() const;
+
+        /**
+         * {@inheritDoc}
+         */
+        virtual std::vector<std::string> getEnabledCipherSuites() const;
+
+        /**
+         * {@inheritDoc}
+         */
+        virtual void setEnabledCipherSuites( const std::vector<std::string>& suites );
+
+        /**
+         * {@inheritDoc}
+         */
+        virtual std::vector<std::string> getEnabledProtocols() const;
+
+        /**
+         * {@inheritDoc}
+         */
+        virtual void setEnabledProtocols( const std::vector<std::string>& protocols );
+
+        /**
+         * {@inheritDoc}
+         */
+        virtual bool getWantClientAuth() const;
+
+        /**
+         * {@inheritDoc}
+         */
+        virtual void setWantClientAuth( bool value );
+
+        /**
+         * {@inheritDoc}
+         */
+        virtual bool getNeedClientAuth() const;
+
+        /**
+         * {@inheritDoc}
+         */
+        virtual void setNeedClientAuth( bool value );
+
+    public:
+
+        /**
+         * Reads the requested data from the Socket and write it into the passed in buffer.
+         *
+         * @param buffer
+         *      The buffer to read into
+         * @param size
+         *      The size of the specified buffer
+         * @param offset
+         *      The offset into the buffer where reading should start filling.
+         * @param length
+         *      The number of bytes past offset to fill with data.
+         *
+         * @return the actual number of bytes read or -1 if at EOF.
+         *
+         * @throw IOException if an I/O error occurs during the read.
+         * @throw NullPointerException if buffer is Null.
+         * @throw IndexOutOfBoundsException if offset + length is greater than buffer size.
+         */
+        int read( unsigned char* buffer, int size, int offset, int length );
+
+        /**
+         * Writes the specified data in the passed in buffer to the Socket.
+         *
+         * @param buffer
+         *      The buffer to write to the socket.
+         * @param size
+         *      The size of the specified buffer.
+         * @param offset
+         *      The offset into the buffer where the data to write starts at.
+         * @param length
+         *      The number of bytes past offset to write.
+         *
+         * @throw IOException if an I/O error occurs during the write.
+         * @throw NullPointerException if buffer is Null.
+         * @throw IndexOutOfBoundsException if offset + length is greater than buffer size.
+         */
+        void write( const unsigned char* buffer, int size, int offset, int length );
+
+        /**
+         * Gets the number of bytes in the Socket buffer that can be read without blocking.
+         *
+         * @returns the number of bytes that can be read from the Socket without blocking.
+         *
+         * @throws IOException if an I/O error occurs while performing this operation.
+         */
+        int available();
+
+    };
+
+}}}}}
+
+#endif /* _DECAF_INTERNAL_NET_SSL_OPENSSL_OPENSSLSOCKET_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketException.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketException.cpp?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketException.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketException.cpp Tue May 11 20:57:57 2010
@@ -0,0 +1,111 @@
+/*
+ * 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 "OpenSSLSocketException.h"
+
+#ifdef HAVE_OPENSSL
+#include <openssl/err.h>
+#endif
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::net;
+using namespace decaf::internal;
+using namespace decaf::internal::net;
+using namespace decaf::internal::net::ssl;
+using namespace decaf::internal::net::ssl::openssl;
+
+////////////////////////////////////////////////////////////////////////////////
+OpenSSLSocketException::OpenSSLSocketException() throw() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+OpenSSLSocketException::OpenSSLSocketException( const Exception& ex ) throw()
+: SocketException() {
+    *(Exception*)this = ex;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+OpenSSLSocketException::OpenSSLSocketException( const OpenSSLSocketException& ex ) throw()
+: SocketException() {
+    *(Exception*)this = ex;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+OpenSSLSocketException::OpenSSLSocketException( const char* file, const int lineNumber,
+                                                const std::exception* cause,
+                                                const char* msg, ... ) throw()
+: SocketException( cause ) {
+
+    va_list vargs;
+    va_start( vargs, msg );
+    buildMessage( msg, vargs );
+
+    // Set the first mark for this exception.
+    setMark( file, lineNumber );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+OpenSSLSocketException::OpenSSLSocketException( const std::exception* cause ) throw()
+: SocketException( cause ) {
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+OpenSSLSocketException::OpenSSLSocketException( const char* file, const int lineNumber,
+                                                const char* msg, ... ) throw()
+: SocketException() {
+
+    va_list vargs ;
+    va_start( vargs, msg );
+    buildMessage( msg, vargs );
+
+    // Set the first mark for this exception.
+    setMark( file, lineNumber );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+OpenSSLSocketException::OpenSSLSocketException( const char* file, const int lineNumber ) throw()
+: SocketException() {
+
+    // Get from the OpenSSL error Stack.
+    this->setMessage( this->getErrorString().c_str() );
+
+    // Set the first mark for this exception.
+    setMark( file, lineNumber );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+OpenSSLSocketException::~OpenSSLSocketException() throw() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string OpenSSLSocketException::getErrorString() const {
+
+    std::string returnValue = "Error occurred while accessing an OpenSSL library method:";
+
+#ifdef HAVE_OPENSSL
+    for( unsigned long e = ERR_get_error(); e; e = ERR_get_error() ) {
+        char msg[256];
+        ERR_error_string_n(e, msg, sizeof msg);
+        returnValue += "\n";
+        returnValue += msg;
+    }
+#endif
+
+    return returnValue;
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketException.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketException.h?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketException.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketException.h Tue May 11 20:57:57 2010
@@ -0,0 +1,145 @@
+/*
+ * 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.
+ */
+
+#ifndef _DECAF_INTERNAL_NET_SSL_OPENSSL_OPENSSLSOCKETEXCEPTION_H_
+#define _DECAF_INTERNAL_NET_SSL_OPENSSL_OPENSSLSOCKETEXCEPTION_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/net/SocketException.h>
+
+namespace decaf {
+namespace internal {
+namespace net {
+namespace ssl {
+namespace openssl {
+
+    /**
+     * Subclass of the standard SocketException that knows how to produce an error message
+     * from the OpenSSL error stack.
+     *
+     * @since 1.0
+     */
+    class DECAF_API OpenSSLSocketException : public decaf::net::SocketException {
+    public:
+
+        /**
+         * Creates an new OpenSSLSocketException with default values.
+         */
+        OpenSSLSocketException() throw();
+
+        /**
+         * Conversion Constructor from some other Exception.
+         *
+         * @param ex
+         *      An Exception object that should become this type of Exception.
+         */
+        OpenSSLSocketException( const Exception& ex ) throw();
+
+        /**
+         * Copy Constructor.
+         *
+         * @param ex
+         *      The OpenSSLSocketException whose values should be copied to this instance.
+         */
+        OpenSSLSocketException( const OpenSSLSocketException& ex ) throw();
+
+        /**
+         * Create a new OpenSSLSocketException and initializes the file name and line number
+         * where this message occurred.  Sets the message to report, using an optional list
+         * of arguments to parse into the message.
+         *
+         * @param file
+         *      The file name where exception occurs
+         * @param lineNumber
+         *      The line number where the exception occurred.
+         * @param cause
+         *      The exception that was the cause for this one to be thrown (can be null).
+         * @param msg
+         *      The error message to report.
+         * @param ...
+         *      The list of primitives that are formatted into the message.
+         */
+        OpenSSLSocketException( const char* file, const int lineNumber,
+                                const std::exception* cause,
+                                const char* msg, ... ) throw();
+
+        /**
+         * Creates a new OpenSSLSocketException with the passed exception set as the
+         * cause of this exception.
+         *
+         * @param cause
+         *      Pointer to the exception that caused this one to be thrown, the object
+         *      is cloned caller retains ownership.
+         */
+        OpenSSLSocketException( const std::exception* cause ) throw();
+
+        /**
+         * Create a new OpenSSLSocketException and initializes the file name and line number
+         * where this message occurred.  Sets the message to report, using an optional list
+         * of arguments to parse into the message.
+         *
+         * @param file
+         *      The file name where exception occurs.
+         * @param lineNumber
+         *      The line number where the exception occurred.
+         * @param msg
+         *      The error message to report.
+         * @param ...
+         *      The list of primitives that are formatted into the message
+         */
+        OpenSSLSocketException( const char* file, const int lineNumber, const char* msg, ... ) throw ();
+
+        /**
+         * Create a new OpenSSLSocketException and initializes the file name and line number
+         * where this message occurred.  Sets the message to report by getting the complete set
+         * of error messages from the OpenSSL error stack and concatenating them into one string.
+         *
+         * @param file
+         *      The file name where exception occurs.
+         * @param lineNumber
+         *      The line number where the exception occurred.
+         */
+        OpenSSLSocketException( const char* file, const int lineNumber ) throw();
+
+        /**
+         * Clones this exception.  This is useful for cases where you need to preserve
+         * the type of the original exception as well as the message.  All subclasses should
+         * override this method.
+         *
+         * @return a new Exception instance that is a copy of this Exception object.
+         */
+        virtual OpenSSLSocketException* clone() const {
+            return new OpenSSLSocketException( *this );
+        }
+
+        virtual ~OpenSSLSocketException() throw();
+
+    protected:
+
+        /**
+         * Gets and formats an error message string from the OpenSSL error stack.
+         *
+         * @returns a string containing the complete OpenSSL error string.
+         */
+        std::string getErrorString() const;
+
+    };
+
+}}}}}
+
+#endif /* _DECAF_INTERNAL_NET_SSL_OPENSSL_OPENSSLSOCKETEXCEPTION_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketException.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.cpp?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.cpp Tue May 11 20:57:57 2010
@@ -0,0 +1,98 @@
+/*
+ * 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 "OpenSSLSocketFactory.h"
+
+#include <decaf/lang/exceptions/NullPointerException.h>
+#include <decaf/lang/exceptions/UnsupportedOperationException.h>
+
+#include <decaf/internal/net/ssl/openssl/OpenSSLSocket.h>
+#include <decaf/internal/net/ssl/openssl/OpenSSLContextSpi.h>
+
+#ifdef HAVE_OPENSSL
+#include <openssl/ssl.h>
+#endif
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::io;
+using namespace decaf::net;
+using namespace decaf::internal;
+using namespace decaf::internal::net;
+using namespace decaf::internal::net::ssl;
+using namespace decaf::internal::net::ssl::openssl;
+
+////////////////////////////////////////////////////////////////////////////////
+OpenSSLSocketFactory::OpenSSLSocketFactory( OpenSSLContextSpi* parent ) : SSLSocketFactory(), parent( parent ) {
+
+    if( parent == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "Parent Pointer was NULL." );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+OpenSSLSocketFactory::~OpenSSLSocketFactory() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::vector<std::string> OpenSSLSocketFactory::getDefaultCipherSuites() {
+
+    return std::vector<std::string>();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::vector<std::string> OpenSSLSocketFactory::getSupportedCipherSuites() {
+
+    return std::vector<std::string>();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Socket* OpenSSLSocketFactory::createSocket() throw( decaf::io::IOException ) {
+
+    try{
+
+#ifdef HAVE_OPENSSL
+        // Create a new SSL object for the Socket then create a new unconnected Socket.
+        SSL_CTX* ctx = static_cast<SSL_CTX*>( this->parent->getOpenSSLCtx() );
+        return new OpenSSLSocket( SSL_new( ctx ) );
+#else
+        return NULL;
+#endif
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Socket* OpenSSLSocketFactory::createSocket( const std::string& name, int port )
+    throw( decaf::io::IOException, decaf::net::UnknownHostException ) {
+
+    return NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Socket* OpenSSLSocketFactory::createSocket( Socket* socket DECAF_UNUSED,
+                                            std::string host DECAF_UNUSED,
+                                            int port DECAF_UNUSED,
+                                            bool autoClose DECAF_UNUSED ) {
+
+    throw UnsupportedOperationException(
+        __FILE__, __LINE__, "Wrapped Sockets not yet Supported." );
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.h?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.h Tue May 11 20:57:57 2010
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+#ifndef _DECAF_INTERNAL_NET_SSL_OPENSSL_OPENSSLSOCKETFACTORY_H_
+#define _DECAF_INTERNAL_NET_SSL_OPENSSL_OPENSSLSOCKETFACTORY_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/net/ssl/SSLSocketFactory.h>
+
+namespace decaf {
+namespace internal {
+namespace net {
+namespace ssl {
+namespace openssl {
+
+    class OpenSSLContextSpi;
+
+    /**
+     * Client Socket Factory that creates SSL based client sockets using the OpenSSL library.
+     *
+     * @since 1.0
+     */
+    class DECAF_API OpenSSLSocketFactory : public decaf::net::ssl::SSLSocketFactory {
+    private:
+
+        OpenSSLContextSpi* parent;
+
+    public:
+
+        OpenSSLSocketFactory( OpenSSLContextSpi* parent );
+
+        virtual ~OpenSSLSocketFactory();
+
+        /**
+         * {@inheritDoc}
+         */
+        virtual decaf::net::Socket* createSocket() throw( decaf::io::IOException );
+
+        /**
+         * {@inheritDoc}
+         */
+        virtual decaf::net::Socket* createSocket( const std::string& name, int port )
+            throw( decaf::io::IOException, decaf::net::UnknownHostException );
+
+        /**
+         * {@inheritDoc}
+         */
+        virtual std::vector<std::string> getDefaultCipherSuites();
+
+        /**
+         * {@inheritDoc}
+         */
+        virtual std::vector<std::string> getSupportedCipherSuites();
+
+        /**
+         * {@inheritDoc}
+         */
+        virtual decaf::net::Socket* createSocket( decaf::net::Socket* socket, std::string host,
+                                                  int port, bool autoClose );
+
+    };
+
+}}}}}
+
+#endif /* _DECAF_INTERNAL_NET_SSL_OPENSSL_OPENSSLSOCKETFACTORY_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketInputStream.cpp?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketInputStream.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketInputStream.cpp Tue May 11 20:57:57 2010
@@ -0,0 +1,132 @@
+/*
+ * 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 "OpenSSLSocketInputStream.h"
+
+#include <decaf/internal/net/ssl/openssl/OpenSSLSocket.h>
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::io;
+using namespace decaf::internal;
+using namespace decaf::internal::net;
+using namespace decaf::internal::net::ssl;
+using namespace decaf::internal::net::ssl::openssl;
+
+////////////////////////////////////////////////////////////////////////////////
+OpenSSLSocketInputStream::OpenSSLSocketInputStream( OpenSSLSocket* socket ) :
+    InputStream(), socket( socket ), closed( false ) {
+
+    if( socket == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "Socket instance passed was NULL." );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+OpenSSLSocketInputStream::~OpenSSLSocketInputStream() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OpenSSLSocketInputStream::close() throw( decaf::io::IOException ) {
+
+    if( this->closed ) {
+        return;
+    }
+
+    try{
+        this->closed = true;
+        this->socket->close();
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int OpenSSLSocketInputStream::available() const throw ( io::IOException ){
+
+    if( this->closed ){
+        throw IOException(
+            __FILE__, __LINE__, "The stream is closed" );
+    }
+
+    return this->socket->available();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int OpenSSLSocketInputStream::doReadByte() throw ( IOException ){
+
+    if( this->closed ){
+        throw IOException(
+            __FILE__, __LINE__, "The stream is closed" );
+    }
+
+    try{
+
+        unsigned char buffer[1];
+        int result = this->socket->read( buffer, 1, 0, 1 );
+        return result == -1 ? result : buffer[0];
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int OpenSSLSocketInputStream::doReadArrayBounded( unsigned char* buffer, int size, int offset, int length )
+    throw ( decaf::io::IOException,
+            decaf::lang::exceptions::IndexOutOfBoundsException,
+            decaf::lang::exceptions::NullPointerException ) {
+
+    if( closed ){
+        throw IOException(
+            __FILE__, __LINE__, "The stream is closed" );
+    }
+
+    if( buffer == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "Buffer passed was NULL." );
+    }
+
+    try{
+        return this->socket->read( buffer, size, offset, length );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long OpenSSLSocketInputStream::skip( long long num )
+    throw ( IOException, UnsupportedOperationException ) {
+
+    try{
+
+        if( num == 0 ) {
+            return 0;
+        }
+
+        return InputStream::skip( num );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( UnsupportedOperationException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketInputStream.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketInputStream.h?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketInputStream.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketInputStream.h Tue May 11 20:57:57 2010
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+
+#ifndef _DECAF_INTERNAL_NET_SSL_OPENSSL_OPENSSLSOCKETINPUTSTREAM_H_
+#define _DECAF_INTERNAL_NET_SSL_OPENSSL_OPENSSLSOCKETINPUTSTREAM_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/io/InputStream.h>
+
+namespace decaf {
+namespace internal {
+namespace net {
+namespace ssl {
+namespace openssl {
+
+    class OpenSSLSocket;
+
+    /**
+     * An output stream for reading data from an OpenSSL Socket instance.
+     *
+     * @since 1.0
+     */
+    class DECAF_API OpenSSLSocketInputStream : public decaf::io::InputStream {
+    private:
+
+        OpenSSLSocket* socket;
+        volatile bool closed;
+
+    public:
+
+        OpenSSLSocketInputStream( OpenSSLSocket* socket );
+
+        virtual ~OpenSSLSocketInputStream();
+
+        /**
+         * {@inheritDoc}
+         */
+        virtual int available() const throw ( decaf::io::IOException );
+
+        /**
+         * Close - does nothing.  It is the responsibility of the owner
+         * of the socket object to close it.
+         *
+         * {@inheritDoc}
+         */
+        virtual void close() throw( decaf::io::IOException );
+
+        /**
+         * Not supported.
+         *
+         * {@inheritDoc}
+         */
+        virtual long long skip( long long num )
+            throw ( decaf::io::IOException,
+                    decaf::lang::exceptions::UnsupportedOperationException );
+
+    protected:
+
+        virtual int doReadByte() throw ( io::IOException );
+
+        virtual int doReadArrayBounded( unsigned char* buffer, int size, int offset, int length )
+            throw ( decaf::io::IOException,
+                    decaf::lang::exceptions::IndexOutOfBoundsException,
+                    decaf::lang::exceptions::NullPointerException );
+
+    };
+
+}}}}}
+
+#endif /* _DECAF_INTERNAL_NET_SSL_OPENSSL_OPENSSLSOCKETINPUTSTREAM_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketInputStream.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketOutputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketOutputStream.cpp?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketOutputStream.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketOutputStream.cpp Tue May 11 20:57:57 2010
@@ -0,0 +1,100 @@
+/*
+ * 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 "OpenSSLSocketOutputStream.h"
+
+#include <decaf/internal/net/ssl/openssl/OpenSSLSocket.h>
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::io;
+using namespace decaf::internal;
+using namespace decaf::internal::net;
+using namespace decaf::internal::net::ssl;
+using namespace decaf::internal::net::ssl::openssl;
+
+////////////////////////////////////////////////////////////////////////////////
+OpenSSLSocketOutputStream::OpenSSLSocketOutputStream( OpenSSLSocket* socket ) :
+    OutputStream(), socket( socket ), closed( false ) {
+
+    if( socket == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "TcpSocket instance passed was NULL." );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+OpenSSLSocketOutputStream::~OpenSSLSocketOutputStream() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OpenSSLSocketOutputStream::close() throw( decaf::io::IOException ) {
+
+    if( this->closed ) {
+        return;
+    }
+
+    try{
+        this->closed = true;
+        this->socket->close();
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OpenSSLSocketOutputStream::doWriteByte( unsigned char c ) throw ( IOException ) {
+
+    try{
+
+        // Treat the single byte case the same as an array.
+        this->doWriteArrayBounded( &c, 1, 0, 1 );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OpenSSLSocketOutputStream::doWriteArrayBounded( const unsigned char* buffer, int size, int offset, int length )
+    throw ( decaf::io::IOException,
+            decaf::lang::exceptions::NullPointerException,
+            decaf::lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
+        if( length == 0 ) {
+            return;
+        }
+
+        if( buffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__, "passed buffer is null" );
+        }
+
+        if( closed ) {
+            throw IOException(
+                __FILE__, __LINE__, "This Stream has been closed." );
+        }
+
+        this->socket->write( buffer, size, offset, length );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IOException )
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketOutputStream.cpp
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message