qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hari Pyla <ha...@vt.edu>
Subject SSL environment variables for C++ clients
Date Thu, 15 May 2014 15:11:34 GMT
Hi,
  I am setting the SSL client environment variables for a C++ client and 
I ran into the following issue.
When I set them at the command line and run the client program things 
works as expected. However, when I try to set them programmatically 
prior(in program order) to opening a connection, qpid seems to ignore 
the environment variables. I was wondering if there is anyway to specify 
the environment variables programmatically in the qpid C++ client.

===configuration===
1. version: qpid-0.28-rc2

2. /etc/qpidd.conf
acl-file=/etc/qpid/qpidd.acl
auth=yes
realm=QPID
no-data-dir=yes
sasl-config=/etc/sasl2/

log-to-stderr=no
log-enable=debug+
log-to-syslog=yes

ssl-cert-db=/tmp/test/server_db/
ssl-cert-password-file=/tmp/test/server_db/qpid-broker-pfile
ssl-cert-name=localhost
ssl-port=5671
require-encryption=yes
transport=ssl
ssl-require-client-authentication=yes
ssl-sasl-no-dict=no

3. modified C++ client (from 
http://svn.apache.org/repos/asf/qpid/trunk/qpid/cpp/examples/messaging/client.cpp)

#include <qpid/messaging/Address.h>
#include <qpid/messaging/Connection.h>
#include <qpid/messaging/Message.h>
#include <qpid/messaging/Receiver.h>
#include <qpid/messaging/Sender.h>
#include <qpid/messaging/Session.h>

#include<cstdlib>
#include<iostream>

#include<stdlib.h>
#include<sstream>

using namespace qpid::messaging;

using std::stringstream;
using std::string;

int main(int argc, char** argv)
{
     const char* url = "localhost:5671";
     std::string connectionOptions = 
"{username:admin,password:admin,transport:ssl}";

     setenv("QPID_SSL_CERT_NAME", "QpidCppClient", 1);
     setenv("QPID_SSL_CERT_DB", "/tmp/test/client_db", 1);
     setenv("QPID_SSL_CERT_PASSWORD_FILE", 
"/tmp/test/qpid-client-pfile", 1);

     Connection connection(url, connectionOptions);

     setenv("QPID_SSL_CERT_NAME", "QpidCppClient", 1);
     setenv("QPID_SSL_CERT_DB", "/tmp/test/client_db", 1);
     setenv("QPID_SSL_CERT_PASSWORD_FILE", 
"/tmp/test/qpid-client-pfile", 1);

     try
      {
         try
         {
             std::cout << "set QPID_SSL_CERT_NAME:" << 
getenv("QPID_SSL_CERT_NAME") << "\n";
             std::cout << "set QPID_SSL_CERT_DB:" << 
getenv("QPID_SSL_CERT_DB") << "\n";
             std::cout << "set QPID_SSL_CERT_PASSWORD_FILE:" << 
getenv("QPID_SSL_CERT_PASSWORD_FILE") << "\n";
             connection.open();
         }
         catch (const std::exception& e)
         {
             std::cout << e.what() << "\n";

             std::cout << "set QPID_SSL_CERT_NAME:" << 
getenv("QPID_SSL_CERT_NAME") << "\n";
             std::cout << "set QPID_SSL_CERT_DB:" << 
getenv("QPID_SSL_CERT_DB") << "\n";
             std::cout << "set QPID_SSL_CERT_PASSWORD_FILE:" << 
getenv("QPID_SSL_CERT_PASSWORD_FILE") << "\n";
         }

         Session session = connection.createSession();

         Sender sender = session.createSender("service_queue");

         Receiver receiver = session.createReceiver("#");
         Address responseQueue = receiver.getAddress();

         string s[] =
         {
             "Twas brillig, and the slithy toves",
             "Did gire and gymble in the wabe.",
             "All mimsy were the borogroves,",
             "And the mome raths outgrabe."
         };
       Message request;
         request.setReplyTo(responseQueue);
         for (int i=0; i<4; i++)
         {
             request.setContent(s[i]);
             sender.send(request);
             Message response = receiver.fetch();
             std::cout << request.getContent() << " -> " << 
response.getContent() << std::endl;
         }
         connection.close();
         return 0;

      }
      catch(const std::exception& error)
      {
         std::cout << error.what() << std::endl;
         connection.close();
      }
     return 1;
}

ii) compiled:
g++ -g -o test test.cpp -lqpidclient -lqpidmessaging

iii) run:
#./test
set QPID_SSL_CERT_NAME:QpidCppClient
set QPID_SSL_CERT_DB:/tmp/test/client_db
set QPID_SSL_CERT_PASSWORD_FILE:/tmp/test/qpid-client-pfile
Unknown protocol: ssl 
(/builddir/build/BUILD/qpid-0.28-rc2/cpp/src/qpid/client/Connector.cpp:52)
set QPID_SSL_CERT_NAME:QpidCppClient
set QPID_SSL_CERT_DB:/tmp/test/client_db
set QPID_SSL_CERT_PASSWORD_FILE:/tmp/test/qpid-client-pfile
Failed to connect (reconnect disabled)

Thanks,
--Hari




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


Mime
View raw message