You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by nm...@apache.org on 2007/10/27 16:16:25 UTC
svn commit: r589111 - in /activemq/activemq-cpp/branches/activemq-cpp-ssl:
./ m4/ src/main/ src/main/activemq/exceptions/ src/main/activemq/network/
src/main/activemq/support/ src/main/activemq/transport/filters/
src/test/activemq/network/
Author: nmittler
Date: Sat Oct 27 07:16:23 2007
New Revision: 589111
URL: http://svn.apache.org/viewvc?rev=589111&view=rev
Log:
[AMQCPP-140] applying patch amqcpp-ssl.patch3
Added:
activemq/activemq-cpp/branches/activemq-cpp-ssl/m4/ssl.m4 (with props)
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLError.cpp (with props)
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLError.h (with props)
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocket.cpp (with props)
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocket.h (with props)
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketFactory.cpp (with props)
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketFactory.h (with props)
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketInputStream.cpp (with props)
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketInputStream.h (with props)
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketOutputStream.cpp (with props)
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketOutputStream.h (with props)
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocketFactory.cpp (with props)
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocketFactory.h (with props)
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/SSLTransportFactory.cpp (with props)
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/SSLTransportFactory.h (with props)
Removed:
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SocketFactory.cpp
Modified:
activemq/activemq-cpp/branches/activemq-cpp-ssl/configure.ac
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/Makefile.am
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/exceptions/ActiveMQException.cpp
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SocketFactory.h
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SocketInputStream.h
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SocketOutputStream.h
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocket.cpp
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocket.h
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/support/InitDirector.cpp
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/TcpTransport.cpp
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/TcpTransport.h
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/TcpTransportFactory.cpp
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/TcpTransportFactory.h
activemq/activemq-cpp/branches/activemq-cpp-ssl/src/test/activemq/network/SocketFactoryTest.cpp
Modified: activemq/activemq-cpp/branches/activemq-cpp-ssl/configure.ac
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/configure.ac?rev=589111&r1=589110&r2=589111&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/configure.ac (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/configure.ac Sat Oct 27 07:16:23 2007
@@ -143,6 +143,9 @@
## supports addrinfo, defines HAVE_STRUCT_ADDRINFO.
CHECK_ADDRINFO()
+## Configure SSL.
+AMQ_FIND_SSL
+
## Execute Doxygen macros
DX_HTML_FEATURE(ON)
DX_CHM_FEATURE(OFF)
Added: activemq/activemq-cpp/branches/activemq-cpp-ssl/m4/ssl.m4
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/m4/ssl.m4?rev=589111&view=auto
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/m4/ssl.m4 (added)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/m4/ssl.m4 Sat Oct 27 07:16:23 2007
@@ -0,0 +1,140 @@
+dnl -------------------------------------------------------- -*- autoconf -*-
+dnl Copyright 2006 The Apache Software Foundation or its licensors, as
+dnl applicable.
+dnl
+dnl Licensed under the Apache License, Version 2.0 (the "License");
+dnl you may not use this file except in compliance with the License.
+dnl You may obtain a copy of the License at
+dnl
+dnl http://www.apache.org/licenses/LICENSE-2.0
+dnl
+dnl Unless required by applicable law or agreed to in writing, software
+dnl distributed under the License is distributed on an "AS IS" BASIS,
+dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+dnl See the License for the specific language governing permissions and
+dnl limitations under the License.
+
+dnl
+dnl SSL module
+dnl
+
+dnl
+dnl AMQ_FIND_SSL: look for ssl libraries and headers
+dnl
+AC_DEFUN([AMQ_FIND_SSL], [
+ amq_have_ssl=0
+
+ AC_ARG_WITH([ssl], [AC_HELP_STRING([--with-ssl], [enable SSL support])],
+ [
+ if test "$withval" = "yes"; then
+ AMQ_CHECK_OPENSSL
+ dnl add checks for other varieties of ssl here
+ fi
+ ], [
+ amq_have_ssl=0
+ ])
+
+ if test "$amq_have_ssl" = "1"; then
+ AC_DEFINE([AMQ_HAVE_SSL], 1, [Define that we have SSL capability])
+ fi
+
+])
+dnl
+
+AC_DEFUN([AMQ_CHECK_OPENSSL], [
+ amq_have_openssl=0
+ openssl_have_headers=0
+ openssl_have_libs=0
+
+ AC_ARG_WITH([openssl],
+ [AC_HELP_STRING([--with-openssl=DIR], [specify location of OpenSSL])],
+ [
+ if test "$withval" = "yes"; then
+ AC_CHECK_HEADERS(openssl/x509.h, [openssl_have_headers=1])
+ AC_CHECK_LIB(crypto, BN_init, AC_CHECK_LIB(ssl, SSL_connect, [openssl_have_libs=1],,-lcrypto))
+ if test "$openssl_have_headers" != "0" && test "$openssl_have_libs" != "0"; then
+ amq_have_openssl=1
+ fi
+ elif test "$withval" = "no"; then
+ amq_have_openssl=0
+ else
+ old_cppflags="$CPPFLAGS"
+ old_ldflags="$LDFLAGS"
+
+ openssl_CPPFLAGS="-I$withval/include"
+ openssl_LDFLAGS="-L$withval/lib "
+
+ AMQ_ADDTO(CPPFLAGS, [$openssl_CPPFLAGS])
+ AMQ_ADDTO(LDFLAGS, [$openssl_LDFLAGS])
+
+ AC_MSG_NOTICE(checking for openssl in $withval)
+ AC_CHECK_HEADERS(openssl/x509.h, [openssl_have_headers=1])
+ AC_CHECK_LIB(crypto, BN_init, AC_CHECK_LIB(ssl, SSL_connect, [openssl_have_libs=1],,-lcrypto))
+ if test "$openssl_have_headers" != "0" && test "$openssl_have_libs" != "0"; then
+ amq_have_openssl=1
+ AMQ_ADDTO(LDFLAGS, [-L$withval/lib])
+ AMQ_ADDTO(CXXFLAGS, [-I$withval/include])
+ AMQ_ADDTO(CFLAGS, [-I$withval/include])
+ fi
+
+ if test "$amq_have_openssl" != "1"; then
+ AC_CHECK_HEADERS(openssl/x509.h, [openssl_have_headers=1])
+ AC_CHECK_LIB(crypto, BN_init, AC_CHECK_LIB(ssl, SSL_connect, [openssl_have_libs=1],,-lcrypto))
+ if test "$openssl_have_headers" != "0" && test "$openssl_have_libs" != "0"; then
+ amq_have_openssl=1
+ AMQ_ADDTO(LDFLAGS, [-L$withval/lib])
+ AMQ_ADDTO(CXXFLAGS, [-I$withval/include])
+ AMQ_ADDTO(CFLAGS, [-I$withval/include])
+ fi
+ fi
+
+ CPPFLAGS="$old_cppflags"
+ LDFLAGS="$old_ldflags"
+ fi
+ ], [
+ AC_CHECK_HEADERS(openssl/x509.h, [openssl_have_headers=1])
+ AC_CHECK_LIB(crypto, BN_init, AC_CHECK_LIB(ssl, SSL_connect, [openssl_have_libs=1],,-lcrypto))
+ if test "$openssl_have_headers" != "0" && test "$openssl_have_libs" != "0"; then
+ amq_have_openssl=1
+ fi
+ ])
+
+
+ AC_SUBST(amq_have_openssl)
+
+ dnl Add the libraries we will need now that we have set amq_have_openssl correctly
+ if test "$amq_have_openssl" = "1"; then
+ AC_DEFINE([AMQ_HAVE_OPENSSL], 1, [Define that we have OpenSSL available])
+ AMQ_ADDTO(AMQ_LIBS,[-lssl -lcrypto])
+ AMQ_ADDTO(LIBS,[-lssl -lcrypto])
+ amq_have_ssl=1
+ fi
+])
+
+dnl
+dnl AMQ_ADDTO(variable, value)
+dnl
+dnl Add value to variable
+dnl
+AC_DEFUN([AMQ_ADDTO], [
+ if test "x$$1" = "x"; then
+ test "x$silent" != "xyes" && echo " setting $1 to \"$2\""
+ $1="$2"
+ else
+ amq_addto_bugger="$2"
+ for i in $amq_addto_bugger; do
+ amq_addto_duplicate="0"
+ for j in $$1; do
+ if test "x$i" = "x$j"; then
+ amq_addto_duplicate="1"
+ break
+ fi
+ done
+ if test $amq_addto_duplicate = "0"; then
+ test "x$silent" != "xyes" && echo " adding \"$i\" to $1"
+ $1="$$1 $i"
+ fi
+ done
+ fi
+])dnl
+
Propchange: activemq/activemq-cpp/branches/activemq-cpp-ssl/m4/ssl.m4
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/Makefile.am?rev=589111&r1=589110&r2=589111&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/Makefile.am Sat Oct 27 07:16:23 2007
@@ -75,8 +75,13 @@
activemq/network/TcpSocket.cpp \
activemq/network/BufferedSocket.cpp \
activemq/network/SocketOutputStream.cpp \
- activemq/network/SocketFactory.cpp \
+ activemq/network/TcpSocketFactory.cpp \
activemq/network/SocketError.cpp \
+ activemq/network/SSLSocket.cpp \
+ activemq/network/SSLSocketInputStream.cpp \
+ activemq/network/SSLSocketOutputStream.cpp \
+ activemq/network/SSLSocketFactory.cpp \
+ activemq/network/SSLError.cpp \
activemq/transport/TransportBuilder.cpp \
activemq/transport/TransportFactoryMap.cpp \
activemq/transport/TransportFilter.cpp \
@@ -90,6 +95,7 @@
activemq/transport/filters/AsyncSendTransportFactory.cpp \
activemq/transport/filters/TcpTransport.cpp \
activemq/transport/filters/TcpTransportFactory.cpp \
+ activemq/transport/filters/SSLTransportFactory.cpp \
activemq/transport/filters/LoggingTransport.cpp \
activemq/transport/filters/LoggingTransportFactory.cpp \
activemq/util/StringTokenizer.cpp \
Modified: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/exceptions/ActiveMQException.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/exceptions/ActiveMQException.cpp?rev=589111&r1=589110&r2=589111&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/exceptions/ActiveMQException.cpp (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/exceptions/ActiveMQException.cpp Sat Oct 27 07:16:23 2007
@@ -65,7 +65,7 @@
void ActiveMQException::buildMessage(const char* format, va_list& vargs)
{
// Allocate buffer with a guess of it's size
- int size = 128;
+ int size = 256;
// Format string
while( true ){
Added: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLError.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLError.cpp?rev=589111&view=auto
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLError.cpp (added)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLError.cpp Sat Oct 27 07:16:23 2007
@@ -0,0 +1,47 @@
+/*
+ * 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 "SSLError.h"
+#include <activemq/util/Config.h>
+
+#ifdef AMQ_HAVE_OPENSSL
+#include <openssl/err.h>
+
+using namespace activemq;
+using namespace activemq::network;
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned long SSLError::getErrorCode() {
+ return ERR_peek_last_error();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string SSLError::getErrorString() {
+
+ std::string returnValue;
+
+ 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;
+ }
+
+ return returnValue;
+}
+
+#endif /* AMQ_HAVE_OPENSSL */
Propchange: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLError.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLError.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLError.h?rev=589111&view=auto
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLError.h (added)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLError.h Sat Oct 27 07:16:23 2007
@@ -0,0 +1,50 @@
+/*
+ * 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 ACTIVEMQ_NETWORK_SSLERROR_H_
+#define ACTIVEMQ_NETWORK_SSLERROR_H_
+
+#include <string>
+#include <activemq/util/Config.h>
+
+#ifdef AMQ_HAVE_SSL
+
+namespace activemq{
+namespace network{
+
+ /**
+ * Static utility class to simplify handling of error codes
+ * for SSL operations.
+ */
+ class SSLError {
+ public:
+
+ /**
+ * Gets the last error appropriate for the platform.
+ */
+ static unsigned long getErrorCode();
+
+ /**
+ * Gets the string description for the last error.
+ */
+ static std::string getErrorString();
+ };
+}}
+
+#endif /* AMQ_HAVE_SSL */
+
+#endif /*ACTIVEMQ_NETWORK_SSLERROR_H_*/
Propchange: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLError.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocket.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocket.cpp?rev=589111&view=auto
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocket.cpp (added)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocket.cpp Sat Oct 27 07:16:23 2007
@@ -0,0 +1,348 @@
+/*
+ * 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 <activemq/util/Config.h>
+
+#include "SSLSocket.h"
+#include "SSLSocketInputStream.h"
+#include "SSLSocketOutputStream.h"
+#include "SSLError.h"
+#include "SocketError.h"
+
+#ifdef AMQ_HAVE_OPENSSL
+
+using namespace activemq::network;
+using namespace activemq::io;
+
+///////////////////////////////////////////////////////////////////////////////
+SSLSocket::SSLSocket() throw (SocketException)
+:
+ TcpSocket(),
+ ctx( SSL_CTX_new( SSLv3_client_method() )),
+ ssl( 0 ),
+ verify_peer( false )
+{
+ if( !ctx )
+ throw SocketException( __FILE__, __LINE__,
+ "Failed to allocate SSL context");
+}
+
+///////////////////////////////////////////////////////////////////////////////
+SSLSocket::SSLSocket( SocketHandle socketHandle ) throw (SocketException)
+:
+ TcpSocket(),
+ ctx( SSL_CTX_new( SSLv3_client_method() )),
+ ssl( 0 ),
+ verify_peer( false )
+{
+ if( !ctx )
+ throw SocketException( __FILE__, __LINE__,
+ "Failed to allocate SSL context - %s",
+ SSLError::getErrorString().c_str());
+
+ initializeSSL( socketHandle );
+
+ try {
+ this->socketHandle = socketHandle;
+ this->inputStream = new SSLSocketInputStream( socketHandle, ssl );
+ this->outputStream = new SSLSocketOutputStream( socketHandle, ssl );
+ }
+ AMQ_CATCH_RETHROW( SocketException )
+ AMQ_CATCHALL_THROW( SocketException )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+SSLSocket::~SSLSocket()
+{
+ // Pretend shutdown, we do not want the destructor to block.
+ TcpSocket::close();
+
+ if( ssl != 0 ) {
+ if( SSL_get_shutdown( ssl ) == 0 )
+ SSL_set_shutdown( ssl, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN );
+ SSL_shutdown( ssl );
+ }
+
+ if( ssl ) SSL_free( ssl );
+ if( ctx ) SSL_CTX_free( ctx );
+}
+
+void SSLSocket::connect(const char* host, int port) throw ( SocketException )
+{
+ if( ssl ) {
+ throw SocketException( __FILE__, __LINE__,
+ "SSLSocket::connect - Socket already connected."
+ " host: %s, port: %d", host, port );
+ }
+
+ TcpSocket::connect (host, port);
+ if( isConnected() ) {
+ while( true ){
+
+ int result = SSL_connect(ssl);
+
+ switch (SSL_get_error (ssl, result))
+ {
+ case SSL_ERROR_NONE:
+ // Apart from verification we are done.
+ verifyPeerCertificate( host );
+ return;
+
+ case SSL_ERROR_SSL:
+ case SSL_ERROR_ZERO_RETURN:
+ TcpSocket::close();
+ throw SocketException( __FILE__, __LINE__,
+ SSLError::getErrorString().c_str());
+
+ case SSL_ERROR_WANT_READ:
+ case SSL_ERROR_WANT_WRITE:
+ // Repeat the operation.
+ break;
+
+ case SSL_ERROR_SYSCALL:
+ TcpSocket::close();
+ throw SocketException( __FILE__, __LINE__,
+ SocketError::getErrorString().c_str() );
+ }
+ }
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void SSLSocket::verifyPeerCertificate( const char* host )
+ throw( SocketException )
+{
+ // Verify the certificate name.
+ if( verify_peer ) {
+ X509 *peer_cert = SSL_get_peer_certificate( ssl );
+
+ if( !peer_cert ) {
+ TcpSocket::close();
+ throw SocketException( __FILE__, __LINE__,
+ "No peer certificate for verify");
+ }
+
+ X509_NAME *subject = X509_get_subject_name( peer_cert );
+
+ std::string need_name (verify_name);
+ if( need_name.empty() ){
+ need_name = host;
+ }
+
+ bool match = false;
+ std::string peer_name;
+
+ int i = -1;
+ do {
+ i = X509_NAME_get_index_by_NID( subject, NID_commonName, i );
+ if( i >= 0 ) {
+ X509_NAME_ENTRY *name = X509_NAME_get_entry( subject, i );
+
+ unsigned char *cn;
+ if( ASN1_STRING_to_UTF8( &cn, name->value ) >= 0 ){
+ peer_name = reinterpret_cast<char*> (cn);
+ std::free( cn );
+
+ if( peer_name == need_name ){
+ match = true;
+ }
+ }
+ }
+ } while( i >= 0 && !match );
+
+ if( !match ){
+ TcpSocket::close();
+
+ if( peer_name.length() ){
+ throw SocketException( __FILE__, __LINE__,
+ "Peer certificate mismatch for %s"
+ " - peer name %s",
+ verify_name.c_str(),
+ peer_name.c_str() );
+ } else {
+ throw SocketException( __FILE__, __LINE__,
+ "Unable to find certificate CN");
+ }
+ }
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void SSLSocket::initialize() throw( SocketException )
+{
+ // Destroy the input stream.
+ if( inputStream != NULL ){
+ delete inputStream;
+ inputStream = NULL;
+ }
+
+ // Destroy the output stream.
+ if( outputStream != NULL ){
+ delete outputStream;
+ outputStream = NULL;
+ }
+
+ if( ssl ) {
+ SSL_free( ssl );
+ ssl = 0;
+ }
+ initializeSSL( socketHandle );
+
+ // Create an input/output stream for this socket.
+ inputStream = new SSLSocketInputStream( socketHandle, ssl );
+ outputStream = new SSLSocketOutputStream( socketHandle, ssl );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void SSLSocket::initializeSSL( SocketHandle handle )
+ throw (SocketException)
+{
+ ssl = SSL_new( ctx );
+ if( !ssl ){
+ throw SocketException( __FILE__, __LINE__,
+ "Failed to allocate SSL - %s",
+ SSLError::getErrorString().c_str());
+ }
+
+ BIO* bio = BIO_new( BIO_s_socket() );
+ if( !bio ){
+ throw SocketException( __FILE__, __LINE__,
+ "Failed to create BIO for SSL");
+ }
+
+ BIO_set_fd( bio, handle, BIO_NOCLOSE );
+ SSL_set_bio( ssl, bio, bio );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void SSLSocket::close() throw( cms::CMSException )
+{
+ // Close the input stream.
+ if( inputStream != NULL ){
+ inputStream->close();
+ }
+
+ // Close the output stream.
+ if( outputStream != NULL ){
+ outputStream->close();
+ }
+
+ if( ssl ) {
+ // The ssl can not yet be free'd, it is still use in the streams.
+ SSL_shutdown(ssl);
+ }
+ TcpSocket::close ();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void SSLSocket::setCAFilePath( std::string const& file,
+ std::string const& path )
+ throw( SocketException )
+{
+ if( file.length() || path.length() ) {
+
+ const char *c_file = file.length() ? file.c_str() : 0;
+ const char *c_path = path.length() ? path.c_str() : 0;
+
+ if( !SSL_CTX_load_verify_locations( ctx, c_file, c_path )) {
+ throw SocketException( __FILE__, __LINE__,
+ "Failed to load verify locations - %s",
+ SSLError::getErrorString().c_str());
+ }
+ }
+
+ // Should we do this automatically?
+ if( !SSL_CTX_set_default_verify_paths( ctx )) {
+ throw SocketException( __FILE__, __LINE__,
+ "Failed to load default verify locations - %s",
+ SSLError::getErrorString().c_str());
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void SSLSocket::setCertFile( std::string const& cert_file,
+ std::string const& key_file )
+ throw( SocketException )
+{
+ if( cert_file.length() ) {
+ if( !SSL_CTX_use_certificate_file( ctx, cert_file.c_str (),
+ SSL_FILETYPE_PEM )) {
+ throw SocketException( __FILE__, __LINE__,
+ "Failed to load certificate %s - %s",
+ cert_file.c_str(),
+ SSLError::getErrorString().c_str());
+ }
+
+ const char *c_key_file
+ = key_file.length() ? key_file.c_str() : cert_file.c_str();
+
+ if( !SSL_CTX_use_PrivateKey_file( ctx, c_key_file,
+ SSL_FILETYPE_PEM )) {
+ throw SocketException( __FILE__, __LINE__,
+ "Failed to load private key %s - %s",
+ c_key_file,
+ SSLError::getErrorString().c_str());
+ }
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void SSLSocket::setPassword( std::string const& password )
+ throw( SocketException )
+{
+ if( password.length() ) {
+ this->password = password;
+ void* data = static_cast<void*> (&this->password);
+
+ SSL_CTX_set_default_passwd_cb( ctx, password_cb );
+ SSL_CTX_set_default_passwd_cb_userdata( ctx, data );
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+int SSLSocket::password_cb( char* buffer, int size, int, void* data)
+{
+ std::string *password = static_cast<std::string*>( data );
+ std::strncpy( buffer, password->c_str(), size );
+ return password->length();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void SSLSocket::setVerifyPeer( bool value, std::string const& name )
+ throw( SocketException )
+{
+ verify_peer = value;
+ if( verify_peer ){
+ verify_name = name;
+ SSL_CTX_set_verify( ctx, SSL_VERIFY_PEER, 0);
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void SSLSocket::setCiphers( std::string const& ciphers )
+ throw( SocketException )
+{
+ if( ciphers.length() ){
+ if( SSL_CTX_set_cipher_list( ctx, ciphers.c_str() ) == 0){
+ throw SocketException( __FILE__, __LINE__,
+ "Failed to set ciphers %s - %s",
+ ciphers.c_str(),
+ SSLError::getErrorString().c_str());
+ }
+ }
+}
+
+#endif /* AMQ_HAVE_OPENSSL */
Propchange: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocket.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocket.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocket.h?rev=589111&view=auto
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocket.h (added)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocket.h Sat Oct 27 07:16:23 2007
@@ -0,0 +1,159 @@
+/*
+ * 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 ACTIVEMQ_NETWORK_SSLSOCKET_H
+#define ACTIVEMQ_NETWORK_SSLSOCKET_H
+
+#include <activemq/network/TcpSocket.h>
+#include <activemq/util/Config.h>
+
+#ifdef AMQ_HAVE_OPENSSL
+#include <openssl/ssl.h>
+
+namespace activemq{
+namespace network{
+
+ /**
+ * Platform-independent implementation of the SSL socket interface.
+ */
+ class SSLSocket : public TcpSocket
+ {
+ private:
+ SSL_CTX *ctx;
+ SSL *ssl;
+
+ /**
+ * Password for certificate and key files.
+ */
+ std::string password;
+
+ /**
+ * If peer certificate needs to be verified.
+ */
+ bool verify_peer;
+
+ /**
+ * Additional peer name that is accepted.
+ */
+ std::string verify_name;
+
+ protected:
+ /**
+ * Internal initialize for TcpSocket.
+ */
+ virtual void initialize () throw (SocketException);
+
+ /**
+ * Verify peer certificate if needed.
+ */
+ virtual void verifyPeerCertificate( const char* host)
+ throw (SocketException);
+
+ /**
+ * Initialize SSL connection structure.
+ */
+ virtual void initializeSSL( SocketHandle handle )
+ throw (SocketException);
+
+ /**
+ * OpenSSL password callback.
+ */
+ static int password_cb( char* buffer, int size, int rw, void* data);
+
+ public:
+
+ /**
+ * Construct a non-connected socket.
+ * @throws SocketException thrown one windows if the static initialization
+ * call to WSAStartup was not successful.
+ */
+ SSLSocket() throw (SocketException);
+
+ /**
+ * Construct a connected or bound socket based on given
+ * socket handle.
+ * @param socketHandle a socket handle to wrap in the object
+ */
+ SSLSocket( SocketHandle socketHandle ) throw (SocketException);
+
+ /**
+ * Destruct.
+ * Releases the socket handle but not
+ * gracefully shut down the connection.
+ */
+ virtual ~SSLSocket();
+
+ /**
+ * Connects to the specified destination. Closes this socket if
+ * connected to another destination.
+ * @param host The host of the server to connect to.
+ * @param port The port of the server to connect to.
+ * @throws IOException Thrown if a failure occurred in the connect.
+ */
+ void connect( const char* host, int port ) throw( SocketException );
+
+ /**
+ * Indicates whether or not this socket is connected to a destination.
+ * @return true if connected
+ */
+ bool isConnected() const{
+ return TcpSocket::isConnected() && ssl != 0;
+ }
+
+ /**
+ * Closes this object and deallocates the appropriate resources.
+ * @throws CMSException
+ */
+ void close() throw( cms::CMSException );
+
+ /**
+ * Set CA file and path.
+ */
+ virtual void setCAFilePath( std::string const& file,
+ std::string const& path )
+ throw( SocketException );
+
+ /**
+ * Set client certificate file and private key file.
+ */
+ virtual void setCertFile( std::string const& cert_file,
+ std::string const& key_file )
+ throw( SocketException );
+
+ /**
+ * Set password for key and possibly certificate.
+ */
+ virtual void setPassword( std::string const& password )
+ throw( SocketException );
+
+ /**
+ * If the peer should be verified.
+ */
+ virtual void setVerifyPeer( bool value, std::string const& name )
+ throw( SocketException );
+
+ /**
+ * Set cipher list for SSL.
+ */
+ virtual void setCiphers( std::string const& ciphers )
+ throw( SocketException );
+ };
+
+}}
+
+#endif /* AMQ_HAVE_OPENSSL */
+
+#endif /*ACTIVEMQ_NETWORK_SOCKET_H*/
Propchange: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocket.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketFactory.cpp?rev=589111&view=auto
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketFactory.cpp (added)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketFactory.cpp Sat Oct 27 07:16:23 2007
@@ -0,0 +1,163 @@
+/*
+ * 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 "SSLSocketFactory.h"
+#include "SSLSocket.h"
+#include "SocketException.h"
+
+#include <activemq/util/Properties.h>
+#include <activemq/util/Random.h>
+#include <activemq/concurrent/Thread.h>
+
+#include <stdio.h>
+
+#ifdef AMQ_HAVE_OPENSSL
+#include <openssl/ssl.h>
+#include <openssl/rand.h>
+#endif /* AMQ_HAVE_OPENSSL */
+
+using namespace std;
+using namespace activemq;
+using namespace activemq::util;
+using namespace activemq::network;
+using namespace activemq::exceptions;
+using namespace activemq::concurrent;
+
+#ifdef AMQ_HAVE_OPENSSL
+
+Mutex *SSLSocketFactory::locks = 0;
+
+void SSLSocketFactory::locking_cb( int mode, int type, const char *, int )
+{
+ if( mode & CRYPTO_LOCK )
+ locks[type].lock ();
+ else
+ locks[type].unlock ();
+}
+
+#endif /* AMQ_HAVE_OPENSSL */
+
+////////////////////////////////////////////////////////////////////////////////
+
+SSLSocketFactory::SSLSocketFactory()
+{
+#ifdef AMQ_HAVE_OPENSSL
+ manageLocks = false;
+
+ // Initialize only if locking callback is not yet set.
+ if( !CRYPTO_get_locking_callback() ){
+
+ // General library initialization.
+ CRYPTO_malloc_init();
+ SSL_load_error_strings();
+ SSL_library_init();
+ OpenSSL_add_all_algorithms();
+
+ // Set up threading.
+ if( !locks ){
+ manageLocks = true;
+ locks = new Mutex[CRYPTO_num_locks()];
+ CRYPTO_set_id_callback( &Thread::getId );
+ CRYPTO_set_locking_callback( &locking_cb );
+ }
+ }
+
+ // Seed the random number generator.
+ // Not really safe, but what can you do if the system does not have a good
+ // random source..
+ if( !RAND_status() ){
+ std::vector<unsigned char> data (64);
+ Random().nextBytes( data );
+#ifdef WIN32
+ RAND_seed( static_cast<const void *>( data._Myfirst ), (int)data.size() );
+#else
+ RAND_seed( static_cast<const void *>( data.data() ), data.size() );
+#endif
+ }
+
+#endif /* AMQ_HAVE_OPENSSL */
+}
+
+SSLSocketFactory::~SSLSocketFactory()
+{
+#ifdef AMQ_HAVE_OPENSSL
+
+ if( manageLocks ){
+ CRYPTO_set_locking_callback( 0 );
+ delete [] locks;
+ locks = 0;
+ }
+
+#endif /* AMQ_HAVE_OPENSSL */
+}
+
+TcpSocket* SSLSocketFactory::createTcpSocket(
+ const util::Properties &properties )
+ throw ( SocketException )
+{
+#ifdef AMQ_HAVE_OPENSSL
+ std::string ca_file
+ = properties.getProperty( "sslCAFile", "" );
+ std::string ca_path
+ = properties.getProperty( "sslCAPath", "" );
+
+ std::string cert_file
+ = properties.getProperty( "sslCertFile", "" );
+ std::string key_file
+ = properties.getProperty( "sslKeyFile", cert_file );
+
+ std::string password
+ = properties.getProperty( "sslPassword", "" );
+
+ bool verify_peer
+ = properties.getProperty( "sslVerifyPeer", "false" ) == "true";
+ std::string verify_name
+ = properties.getProperty( "sslVerifyName", "" );
+
+ std::string ciphers
+ = properties.getProperty( "sslCiphers", "" );
+
+ SSLSocket *socket = new SSLSocket();
+
+ try {
+ try {
+ socket->setPassword( password );
+ socket->setCAFilePath( ca_file, ca_path );
+ socket->setCertFile( cert_file, key_file );
+ socket->setVerifyPeer( verify_peer, verify_name );
+ socket->setCiphers( ciphers );
+ }
+ catch ( SocketException& ex ) {
+ ex.setMark( __FILE__, __LINE__ );
+ try{
+ delete socket;
+ } catch( SocketException& ex2 ){ /* Absorb */ }
+
+ throw ex;
+ }
+
+ return socket;
+ }
+ AMQ_CATCH_RETHROW( SocketException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, SocketException )
+ AMQ_CATCHALL_THROW( SocketException )
+
+#else /* not AMQ_HAVE_OPENSSL */
+
+ throw SocketException( __FILE__, __LINE__, "SSL is not available");
+
+#endif /* not AMQ_HAVE_OPENSSL */
+}
Propchange: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketFactory.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketFactory.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketFactory.h?rev=589111&view=auto
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketFactory.h (added)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketFactory.h Sat Oct 27 07:16:23 2007
@@ -0,0 +1,60 @@
+/*
+ * 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 _ACTIVEMQ_NETWORK_SSLSOCKETFACTORY_H_
+#define _ACTIVEMQ_NETWORK_SSLSOCKETFACTORY_H_
+
+#include <activemq/network/TcpSocketFactory.h>
+
+#include <activemq/concurrent/Mutex.h>
+
+namespace activemq{
+namespace network{
+
+ /**
+ * Socket Factory implementation for use in Creating SSL Sockets
+ *
+ * @see <code>SSLSocket</code>
+ */
+ class SSLSocketFactory : public TcpSocketFactory
+ {
+#ifdef AMQ_HAVE_OPENSSL
+
+ /**
+ * If we should manage locks.
+ */
+ bool manageLocks;
+
+ /**
+ * Locks for OpenSSL and callback to manage them.
+ */
+ static concurrent::Mutex *locks;
+ static void locking_cb( int mode, int n, const char* file, int line );
+
+#endif /* AMQ_HAVE_OPENSSL */
+
+ public:
+ SSLSocketFactory();
+ ~SSLSocketFactory();
+
+ virtual TcpSocket* createTcpSocket(
+ const util::Properties &properties )
+ throw ( SocketException );
+ };
+
+}}
+
+#endif /*_ACTIVEMQ_NETWORK_TCPSOCKETFACTORY_H_*/
Propchange: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketFactory.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketInputStream.cpp?rev=589111&view=auto
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketInputStream.cpp (added)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketInputStream.cpp Sat Oct 27 07:16:23 2007
@@ -0,0 +1,89 @@
+/*
+ * 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 <activemq/util/Config.h>
+
+#ifdef AMQ_HAVE_OPENSSL
+
+#include "SSLSocketInputStream.h"
+#include "SSLError.h"
+#include "SocketError.h"
+
+using namespace activemq;
+using namespace activemq::network;
+using namespace activemq::io;
+using namespace activemq::exceptions;
+using namespace std;
+
+////////////////////////////////////////////////////////////////////////////////
+SSLSocketInputStream::SSLSocketInputStream(
+ network::Socket::SocketHandle socket, SSL* ssl )
+ : SocketInputStream( socket ),
+ ssl( ssl )
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::size_t SSLSocketInputStream::read( unsigned char* buffer,
+ std::size_t bufferSize )
+ throw (IOException)
+{
+ int len = 0;
+
+ // Loop to ignore any signal interruptions and repeatble errors
+ // that occur during the read.
+ while( !closed ) {
+
+ // Read data from the socket.
+ len = SSL_read( ssl, buffer, bufferSize );
+
+ switch (SSL_get_error( ssl, len ))
+ {
+ case SSL_ERROR_NONE:
+ return len;
+
+ case SSL_ERROR_WANT_READ:
+ case SSL_ERROR_WANT_WRITE:
+ // Repeat the operation.
+ break;
+
+ case SSL_ERROR_ZERO_RETURN:
+ throw IOException( __FILE__, __LINE__,
+ "activemq::io::SSLSocketInputStream::read"
+ " - The connection is broken" );
+
+ case SSL_ERROR_SSL:
+ throw IOException( __FILE__, __LINE__,
+ "activemq::io::SSLSocketInputStream::read"
+ " - %s",
+ SSLError::getErrorString().c_str());
+
+ case SSL_ERROR_SYSCALL:
+ if( SocketError::getErrorCode() != SocketError::INTERRUPTED )
+ throw IOException( __FILE__, __LINE__,
+ "activemq::io::SSLSocketInputStream::read"
+ " - %s",
+ SocketError::getErrorString().c_str() );
+ break;
+ }
+ }
+
+ // Not reached, but avoid warnings.
+ return 0;
+}
+
+#endif /* AMQ_HAVE_OPENSSL */
Propchange: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketInputStream.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketInputStream.h?rev=589111&view=auto
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketInputStream.h (added)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketInputStream.h Sat Oct 27 07:16:23 2007
@@ -0,0 +1,64 @@
+/*
+ * 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 ACTIVEMQ_NETWORK_SSLSOCKETINPUTSTREAM_H_
+#define ACTIVEMQ_NETWORK_SSLSOCKETINPUTSTREAM_H_
+
+#include <activemq/network/SocketInputStream.h>
+#include <activemq/util/Config.h>
+
+#ifdef AMQ_HAVE_OPENSSL
+#include <openssl/ssl.h>
+
+namespace activemq{
+namespace network{
+
+ /**
+ * Input stream for performing reads on a socket. This
+ * class will only work properly for blocking sockets.
+ */
+ class SSLSocketInputStream : public SocketInputStream
+ {
+ private:
+
+ SSL* ssl;
+
+ public:
+
+ /**
+ * Constructor.
+ * @param socket the socket handle.
+ */
+ SSLSocketInputStream( Socket::SocketHandle socket, SSL* ssl );
+
+ /**
+ * Reads an array of bytes from the buffer. If no data
+ * is available, blocks until there is.
+ * @param buffer (out) the target buffer.
+ * @param bufferSize the size of the output buffer.
+ * @return The number of bytes read.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual std::size_t read( unsigned char* buffer,
+ std::size_t bufferSize )
+ throw (io::IOException);
+ };
+
+}}
+
+#endif /* AMQ_HAVE_OPENSSL */
+#endif /*ACTIVEMQ_NETWORK_SSLSOCKETINPUTSTREAM_H_*/
Propchange: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketInputStream.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketOutputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketOutputStream.cpp?rev=589111&view=auto
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketOutputStream.cpp (added)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketOutputStream.cpp Sat Oct 27 07:16:23 2007
@@ -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.
+ */
+
+#include "SSLSocketOutputStream.h"
+#include "SSLError.h"
+#include "SocketError.h"
+
+#ifdef AMQ_HAVE_OPENSSL
+
+using namespace activemq::network;
+using namespace activemq::io;
+using namespace std;
+
+////////////////////////////////////////////////////////////////////////////////
+SSLSocketOutputStream::SSLSocketOutputStream( Socket::SocketHandle socket,
+ SSL* ssl)
+ : SocketOutputStream( socket ),
+ ssl( ssl )
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SSLSocketOutputStream::write( const unsigned char* buffer, std::size_t len )
+ throw (IOException)
+{
+ std::size_t remaining = len;
+
+ while( remaining > 0 && !closed )
+ {
+ int len = SSL_write( ssl, buffer, remaining );
+
+ switch (SSL_get_error( ssl, len ))
+ {
+ case SSL_ERROR_NONE:
+ buffer += len;
+ remaining -= len;
+ break;
+
+ case SSL_ERROR_WANT_READ:
+ case SSL_ERROR_WANT_WRITE:
+ // Repeat the operation.
+ break;
+
+ case SSL_ERROR_ZERO_RETURN:
+ throw IOException( __FILE__, __LINE__,
+ "activemq::io::SSLSocketInputStream::write"
+ " - The connection is broken" );
+
+ case SSL_ERROR_SSL:
+ throw IOException( __FILE__, __LINE__,
+ "activemq::io::SSLSocketInputStream::write"
+ " - %s",
+ SSLError::getErrorString().c_str());
+
+ case SSL_ERROR_SYSCALL:
+ if( SocketError::getErrorCode() != SocketError::INTERRUPTED )
+ throw IOException( __FILE__, __LINE__,
+ "activemq::io::SSLSocketInputStream::write"
+ " - %s",
+ SocketError::getErrorString().c_str() );
+ break;
+ }
+ }
+}
+
+#endif /* AMQ_HAVE_OPENSSL */
Propchange: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketOutputStream.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketOutputStream.h?rev=589111&view=auto
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketOutputStream.h (added)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketOutputStream.h Sat Oct 27 07:16:23 2007
@@ -0,0 +1,63 @@
+/*
+ * 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 ACTIVEMQ_NETWORK_SSLSOCKETOUTPUTSTREAM_H_
+#define ACTIVEMQ_NETWORK_SSLSOCKETOUTPUTSTREAM_H_
+
+#include <activemq/network/SocketOutputStream.h>
+#include <activemq/concurrent/Mutex.h>
+#include <activemq/util/Config.h>
+
+#ifdef AMQ_HAVE_OPENSSL
+#include <openssl/ssl.h>
+
+namespace activemq{
+namespace network{
+
+ /**
+ * Output stream for performing write operations
+ * on a socket.
+ */
+ class SSLSocketOutputStream : public SocketOutputStream
+ {
+ private:
+
+ SSL* ssl;
+
+ public:
+
+ /**
+ * Constructor.
+ * @param socket the socket handle.
+ */
+ SSLSocketOutputStream( Socket::SocketHandle socket, SSL* ssl );
+
+ /**
+ * Writes an array of bytes to the output stream.
+ * @param buffer The array of bytes to write.
+ * @param len The number of bytes from the buffer to be written.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write( const unsigned char* buffer,
+ std::size_t len ) throw ( io::IOException );
+
+ };
+
+}}
+
+#endif /* AMQ_HAVE_OPENSSL */
+#endif /*ACTIVEMQ_NETWORK_SSLSOCKETOUTPUTSTREAM_H_*/
Propchange: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SSLSocketOutputStream.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SocketFactory.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SocketFactory.h?rev=589111&r1=589110&r2=589111&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SocketFactory.h (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SocketFactory.h Sat Oct 27 07:16:23 2007
@@ -26,27 +26,15 @@
class Socket;
/**
- * Socket Factory implementation for use in Creating Sockets
- * <p>
- * <p>
- * Property Options: <p>
- * Name Value <p>
- * ------------------------------------- <p>
- * inputBufferSize size in bytes of the buffered input stream buffer. Defaults to 10000.<p>
- * outputBufferSize size in bytes of the buffered output stream buffer. Defaults to 10000.<p>
- * soLinger linger time for the socket (in microseconds). Defaults to 0.<p>
- * soKeepAlive keep alive flag for the socket (true/false). Defaults to false.<p>
- * soReceiveBufferSize The size of the socket receive buffer (in bytes). Defaults to 2MB.<p>
- * soSendBufferSize The size of the socket send buffer (in bytes). Defaults to 2MB.<p>
- * soTimeout The timeout of socket IO operations (in microseconds). Defaults to 10000<p>
- *
+ * Socket Factory for use in Creating Sockets
+
* @see <code>Socket</code>
*/
class SocketFactory
{
public:
- virtual ~SocketFactory();
+ virtual ~SocketFactory() {};
/**
* Creates and returns a Socket dervied Object based on the values
@@ -55,9 +43,9 @@
* @param properties a IProperties pointer.
* @throws SocketException.
*/
- static Socket* createSocket( const std::string& uri,
+ virtual Socket* createSocket( const std::string& uri,
const util::Properties& properties )
- throw ( SocketException );
+ throw ( SocketException ) = 0;
};
Modified: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SocketInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SocketInputStream.h?rev=589111&r1=589110&r2=589111&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SocketInputStream.h (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SocketInputStream.h Sat Oct 27 07:16:23 2007
@@ -31,7 +31,7 @@
*/
class SocketInputStream : public io::InputStream
{
- private:
+ protected:
// The socket handle.
Socket::SocketHandle socket;
Modified: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SocketOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SocketOutputStream.h?rev=589111&r1=589110&r2=589111&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SocketOutputStream.h (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/SocketOutputStream.h Sat Oct 27 07:16:23 2007
@@ -31,7 +31,7 @@
*/
class SocketOutputStream : public io::OutputStream
{
- private:
+ protected:
// The socket.
Socket::SocketHandle socket;
Modified: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocket.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocket.cpp?rev=589111&r1=589110&r2=589111&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocket.cpp (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocket.cpp Sat Oct 27 07:16:23 2007
@@ -208,21 +208,7 @@
( const sockaddr * )&target_addr,
sizeof( target_addr ) ) );
- // Destroy the input stream.
- if( inputStream != NULL ){
- delete inputStream;
- inputStream = NULL;
- }
-
- // Destroy the output stream.
- if( outputStream != NULL ){
- delete outputStream;
- outputStream = NULL;
- }
-
- // Create an input/output stream for this socket.
- inputStream = new SocketInputStream( socketHandle );
- outputStream = new SocketOutputStream( socketHandle );
+ initialize ();
}
catch( SocketException& ex ) {
ex.setMark( __FILE__, __LINE__);
@@ -233,6 +219,26 @@
try{ close(); } catch( cms::CMSException& cx){ /* Absorb */ }
throw SocketException( __FILE__, __LINE__, "connect() caught unknown exception");
}
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void TcpSocket::initialize () throw( SocketException )
+{
+ // Destroy the input stream.
+ if( inputStream != NULL ){
+ delete inputStream;
+ inputStream = NULL;
+ }
+
+ // Destroy the output stream.
+ if( outputStream != NULL ){
+ delete outputStream;
+ outputStream = NULL;
+ }
+
+ // Create an input/output stream for this socket.
+ inputStream = new SocketInputStream( socketHandle );
+ outputStream = new SocketOutputStream( socketHandle );
}
////////////////////////////////////////////////////////////////////////////////
Modified: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocket.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocket.h?rev=589111&r1=589110&r2=589111&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocket.h (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocket.h Sat Oct 27 07:16:23 2007
@@ -36,7 +36,7 @@
*/
class TcpSocket : public Socket
{
- private:
+ protected:
/**
* The handle for this socket.
@@ -52,6 +52,11 @@
* The output stream for writing to this socket.
*/
SocketOutputStream* outputStream;
+
+ /**
+ * Create streams.
+ */
+ virtual void initialize () throw (SocketException);
public:
Added: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocketFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocketFactory.cpp?rev=589111&view=auto
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocketFactory.cpp (added)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocketFactory.cpp Sat Oct 27 07:16:23 2007
@@ -0,0 +1,143 @@
+/*
+ * 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 <activemq/network/TcpSocketFactory.h>
+#include <activemq/network/BufferedSocket.h>
+#include <activemq/network/TcpSocket.h>
+#include <activemq/util/Properties.h>
+#include <stdio.h>
+
+using namespace std;
+using namespace activemq;
+using namespace activemq::util;
+using namespace activemq::network;
+using namespace activemq::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+Socket* TcpSocketFactory::createSocket(
+ const std::string& uri,
+ const Properties& properties)
+ throw ( SocketException )
+{
+ try
+ {
+ // Ensure something is actually passed in for the URI
+ if( uri == "" )
+ {
+ throw SocketException( __FILE__, __LINE__,
+ "SocketTransport::start() - uri not provided" );
+ }
+
+ string dummy = uri;
+
+ // Extract the port.
+ std::size_t portIx = dummy.find( ':' );
+ if( portIx == string::npos )
+ {
+ throw SocketException( __FILE__, __LINE__,
+ "SocketTransport::start() - uri malformed - port not specified: %s", uri.c_str() );
+ }
+ string host = dummy.substr( 0, portIx );
+ string portString = dummy.substr( portIx + 1 );
+ int port;
+ if( sscanf( portString.c_str(), "%d", &port) != 1 )
+ {
+ throw SocketException( __FILE__, __LINE__,
+ "SocketTransport::start() - unable to extract port from uri: %s", uri.c_str() );
+ }
+
+ // Get the read buffer size.
+ int inputBufferSize = 10000;
+ dummy = properties.getProperty( "inputBufferSize", "10000" );
+ sscanf( dummy.c_str(), "%d", &inputBufferSize );
+
+ // Get the write buffer size.
+ int outputBufferSize = 10000;
+ dummy = properties.getProperty( "outputBufferSize", "10000" );
+ sscanf( dummy.c_str(), "%d", &outputBufferSize );
+
+ // Get the linger flag.
+ int soLinger = 0;
+ dummy = properties.getProperty( "soLinger", "0" );
+ sscanf( dummy.c_str(), "%d", &soLinger );
+
+ // Get the keepAlive flag.
+ bool soKeepAlive =
+ properties.getProperty( "soKeepAlive", "false" ) == "true";
+
+ // Get the socket receive buffer size.
+ int soReceiveBufferSize = -1;
+ dummy = properties.getProperty( "soReceiveBufferSize", "-1" );
+ sscanf( dummy.c_str(), "%d", &soReceiveBufferSize );
+
+ // Get the socket send buffer size.
+ int soSendBufferSize = -1;
+ dummy = properties.getProperty( "soSendBufferSize", "-1" );
+ sscanf( dummy.c_str(), "%d", &soSendBufferSize );
+
+ // Get the socket TCP_NODELAY flag.
+ bool tcpNoDelay =
+ properties.getProperty( "tcpNoDelay", "true" ) == "true";
+
+ // Now that we have all the elements that we wanted - let's do it!
+ // Create a TCP Socket and then Wrap it in a buffered socket
+ // so that users get the benefit of buffered reads and writes.
+ // The buffered socket will own the TcpSocket instance, and will
+ // clean it up when it is cleaned up.
+ TcpSocket* tcpSocket = createTcpSocket( properties );
+
+ try
+ {
+ // Connect the socket.
+ tcpSocket->connect( host.c_str(), port );
+
+ // Set the socket options.
+ tcpSocket->setSoLinger( soLinger );
+ tcpSocket->setKeepAlive( soKeepAlive );
+ tcpSocket->setTcpNoDelay( tcpNoDelay );
+
+ if( soReceiveBufferSize > 0 ){
+ tcpSocket->setReceiveBufferSize( soReceiveBufferSize );
+ }
+
+ if( soSendBufferSize > 0 ){
+ tcpSocket->setSendBufferSize( soSendBufferSize );
+ }
+
+ }
+ catch ( SocketException& ex )
+ {
+ ex.setMark( __FILE__, __LINE__ );
+ try{
+ delete tcpSocket;
+ } catch( SocketException& ex2 ){ /* Absorb */ }
+
+ throw ex;
+ }
+
+ return tcpSocket;
+ }
+ AMQ_CATCH_RETHROW( SocketException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, SocketException )
+ AMQ_CATCHALL_THROW( SocketException )
+}
+
+TcpSocket* TcpSocketFactory::createTcpSocket(
+ const util::Properties & )
+ throw ( SocketException )
+{
+ return new TcpSocket();
+}
Propchange: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocketFactory.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocketFactory.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocketFactory.h?rev=589111&view=auto
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocketFactory.h (added)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocketFactory.h Sat Oct 27 07:16:23 2007
@@ -0,0 +1,67 @@
+/*
+ * 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 _ACTIVEMQ_NETWORK_TCPSOCKETFACTORY_H_
+#define _ACTIVEMQ_NETWORK_TCPSOCKETFACTORY_H_
+
+#include <activemq/network/SocketFactory.h>
+
+namespace activemq{
+namespace network{
+
+ class TcpSocket;
+
+ /**
+ * Socket Factory implementation for use in Creating Sockets
+ * <p>
+ * <p>
+ * Property Options: <p>
+ * Name Value <p>
+ * ------------------------------------- <p>
+ * inputBufferSize size in bytes of the buffered input stream buffer. Defaults to 10000.<p>
+ * outputBufferSize size in bytes of the buffered output stream buffer. Defaults to 10000.<p>
+ * soLinger linger time for the socket (in microseconds). Defaults to 0.<p>
+ * soKeepAlive keep alive flag for the socket (true/false). Defaults to false.<p>
+ * soReceiveBufferSize The size of the socket receive buffer (in bytes). Defaults to 2MB.<p>
+ * soSendBufferSize The size of the socket send buffer (in bytes). Defaults to 2MB.<p>
+ * soTimeout The timeout of socket IO operations (in microseconds). Defaults to 10000<p>
+ *
+ * @see <code>Socket</code>
+ */
+ class TcpSocketFactory : public SocketFactory
+ {
+ virtual TcpSocket* createTcpSocket(
+ const util::Properties &properties )
+ throw ( SocketException );
+
+ public:
+
+ /**
+ * Creates and returns a TcpSocket dervied Object based on the values
+ * defined in the Properties Object that is passed in.
+ * @param the URI for the Socket Connection.
+ * @param properties a IProperties pointer.
+ * @throws SocketException.
+ */
+ Socket* createSocket( const std::string& uri,
+ const util::Properties& properties )
+ throw ( SocketException );
+
+ };
+
+}}
+
+#endif /*_ACTIVEMQ_NETWORK_TCPSOCKETFACTORY_H_*/
Propchange: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/network/TcpSocketFactory.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/support/InitDirector.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/support/InitDirector.cpp?rev=589111&r1=589110&r2=589111&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/support/InitDirector.cpp (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/support/InitDirector.cpp Sat Oct 27 07:16:23 2007
@@ -21,6 +21,7 @@
#include <activemq/transport/MockTransportFactory.h>
#include <activemq/transport/filters/AsyncSendTransportFactory.h>
#include <activemq/transport/filters/TcpTransportFactory.h>
+#include <activemq/transport/filters/SSLTransportFactory.h>
#include <activemq/transport/filters/LoggingTransportFactory.h>
#include <activemq/transport/filters/ResponseCorrelatorFactory.h>
#include <activemq/connector/stomp/StompConnectorFactory.h>
@@ -40,6 +41,7 @@
connector::stomp::StompConnectorFactory::getInstance();
connector::openwire::OpenWireConnectorFactory::getInstance();
transport::filters::TcpTransportFactory::getInstance();
+ transport::filters::SSLTransportFactory::getInstance();
transport::filters::AsyncSendTransportFactory::getInstance();
transport::filters::LoggingTransportFactory::getInstance();
transport::filters::ResponseCorrelatorFactory::getInstance();
Added: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/SSLTransportFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/SSLTransportFactory.cpp?rev=589111&view=auto
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/SSLTransportFactory.cpp (added)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/SSLTransportFactory.cpp Sat Oct 27 07:16:23 2007
@@ -0,0 +1,48 @@
+/*
+ * 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 "SSLTransportFactory.h"
+
+#include <activemq/transport/filters/TcpTransport.h>
+
+using namespace activemq;
+using namespace activemq::transport;
+using namespace activemq::transport::filters;
+using namespace activemq::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+TransportFactory& SSLTransportFactory::getInstance(void)
+{
+ // Create the one and only instance of the registrar
+ static TransportFactoryMapRegistrar registrar(
+ "ssl", new SSLTransportFactory() );
+
+ return registrar.getFactory();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Transport* SSLTransportFactory::createTransport(
+ const activemq::util::Properties& properties,
+ Transport* next,
+ bool own ) throw ( ActiveMQException ) {
+
+ try {
+ return new TcpTransport( sockets, properties, next, own );
+ }
+ AMQ_CATCH_RETHROW( ActiveMQException )
+ AMQ_CATCHALL_THROW( ActiveMQException )
+}
Propchange: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/SSLTransportFactory.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/SSLTransportFactory.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/SSLTransportFactory.h?rev=589111&view=auto
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/SSLTransportFactory.h (added)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/SSLTransportFactory.h Sat Oct 27 07:16:23 2007
@@ -0,0 +1,64 @@
+/*
+ * 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 _ACTIVEMQ_TRANSPORT_FILTERS_SSLTRANSPORTFACTORY_H_
+#define _ACTIVEMQ_TRANSPORT_FILTERS_SSLTRANSPORTFACTORY_H_
+
+#include <activemq/transport/TransportFactory.h>
+#include <activemq/transport/TransportFactoryMapRegistrar.h>
+#include <activemq/transport/IOTransportFactory.h>
+#include <activemq/network/SSLSocketFactory.h>
+#include <activemq/exceptions/ActiveMQException.h>
+
+namespace activemq{
+namespace transport{
+namespace filters{
+
+ /**
+ * Factory Responsible for creating the TcpTransport.
+ */
+ class SSLTransportFactory : public TransportFactory
+ {
+ public:
+
+ virtual ~SSLTransportFactory() {}
+
+ /**
+ * Creates a Transport instance.
+ * @param properties - Object that will hold transport config values
+ * @param next - the next transport in the chain, or NULL
+ * @param own - does the new Transport own the next
+ * @throws ActiveMQException if an error occurs.
+ */
+ virtual Transport* createTransport(
+ const activemq::util::Properties& properties,
+ Transport* next,
+ bool own ) throw ( exceptions::ActiveMQException );
+
+ /**
+ * Returns a reference to this TransportFactory
+ * @returns TransportFactory Reference
+ */
+ static TransportFactory& getInstance();
+
+ private:
+ network::SSLSocketFactory sockets;
+ };
+
+}}}
+
+#endif /*_ACTIVEMQ_TRANSPORT_FILTERS_SSLTRANSPORTFACTORY_H_*/
Propchange: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/SSLTransportFactory.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/TcpTransport.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/TcpTransport.cpp?rev=589111&r1=589110&r2=589111&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/TcpTransport.cpp (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/TcpTransport.cpp Sat Oct 27 07:16:23 2007
@@ -17,7 +17,7 @@
#include "TcpTransport.h"
-#include <activemq/network/SocketFactory.h>
+#include <activemq/network/TcpSocketFactory.h>
#include <activemq/transport/IOTransport.h>
#include <activemq/transport/TransportFactory.h>
#include <activemq/transport/TransportFactoryMap.h>
@@ -31,7 +31,8 @@
using namespace activemq::exceptions;
////////////////////////////////////////////////////////////////////////////////
-TcpTransport::TcpTransport( const activemq::util::Properties& properties,
+TcpTransport::TcpTransport( network::TcpSocketFactory& factory,
+ const activemq::util::Properties& properties,
Transport* next,
const bool own )
:
@@ -54,7 +55,7 @@
// Create the IO device we will be communicating over the
// wire with. This may need to change if we add more types
// of sockets, such as SSL.
- socket = SocketFactory::createSocket(
+ socket = factory.createSocket(
properties.getProperty( "transport.uri" ), properties );
// Cast it to an IO transport so we can wire up the socket
Modified: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/TcpTransport.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/TcpTransport.h?rev=589111&r1=589110&r2=589111&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/TcpTransport.h (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/TcpTransport.h Sat Oct 27 07:16:23 2007
@@ -20,6 +20,7 @@
#include <activemq/transport/TransportFilter.h>
#include <activemq/network/Socket.h>
+#include <activemq/network/TcpSocketFactory.h>
#include <activemq/util/Properties.h>
#include <activemq/io/LoggingInputStream.h>
#include <activemq/io/LoggingOutputStream.h>
@@ -59,7 +60,8 @@
* @param next the next transport in the chain
* @param own indicates if this transport owns the next.
*/
- TcpTransport( const activemq::util::Properties& properties,
+ TcpTransport( network::TcpSocketFactory& factory,
+ const activemq::util::Properties& properties,
Transport* next,
const bool own = true );
Modified: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/TcpTransportFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/TcpTransportFactory.cpp?rev=589111&r1=589110&r2=589111&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/TcpTransportFactory.cpp (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/TcpTransportFactory.cpp Sat Oct 27 07:16:23 2007
@@ -41,7 +41,7 @@
bool own ) throw ( ActiveMQException ) {
try {
- return new TcpTransport( properties, next, own );
+ return new TcpTransport( sockets, properties, next, own );
}
AMQ_CATCH_RETHROW( ActiveMQException )
AMQ_CATCHALL_THROW( ActiveMQException )
Modified: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/TcpTransportFactory.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/TcpTransportFactory.h?rev=589111&r1=589110&r2=589111&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/TcpTransportFactory.h (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/main/activemq/transport/filters/TcpTransportFactory.h Sat Oct 27 07:16:23 2007
@@ -21,6 +21,7 @@
#include <activemq/transport/TransportFactory.h>
#include <activemq/transport/TransportFactoryMapRegistrar.h>
#include <activemq/transport/IOTransportFactory.h>
+#include <activemq/network/TcpSocketFactory.h>
#include <activemq/exceptions/ActiveMQException.h>
namespace activemq{
@@ -54,6 +55,8 @@
*/
static TransportFactory& getInstance();
+ private:
+ network::TcpSocketFactory sockets;
};
}}}
Modified: activemq/activemq-cpp/branches/activemq-cpp-ssl/src/test/activemq/network/SocketFactoryTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-ssl/src/test/activemq/network/SocketFactoryTest.cpp?rev=589111&r1=589110&r2=589111&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-ssl/src/test/activemq/network/SocketFactoryTest.cpp (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-ssl/src/test/activemq/network/SocketFactoryTest.cpp Sat Oct 27 07:16:23 2007
@@ -20,7 +20,7 @@
CPPUNIT_TEST_SUITE_REGISTRATION( activemq::network::SocketFactoryTest );
#include <activemq/util/Properties.h>
-#include <activemq/network/SocketFactory.h>
+#include <activemq/network/TcpSocketFactory.h>
#include <activemq/network/TcpSocket.h>
using namespace activemq;
@@ -44,7 +44,7 @@
properties.setProperty("soLinger", "false");
- Socket* client = SocketFactory::createSocket(
+ Socket* client = TcpSocketFactory ().createSocket(
ostream.str(), properties );
synchronized(&serverThread.mutex)
@@ -103,7 +103,7 @@
properties.setProperty( "soLinger", "false" );
properties.setProperty( "tcpNoDelay", "true" );
- Socket* client = SocketFactory::createSocket(
+ Socket* client = TcpSocketFactory ().createSocket(
ostream.str(), properties );
TcpSocket* tcpSock = dynamic_cast<TcpSocket*>( client );