How to enable SSL over ActiveMQ using C client

2019-04-13 03:37发布

问题:

I have configured [ActiveMQ]http://activemq.apache.org/) with ssl context by following RedHat's SSL/TLS Tutorial. Then I converted the client keystore file in ActiveMQ/conf directory to .pem format. For this I followed Converting a Java Keystore into PEM Format on Stack Overflow.

After both steps I tried with an Eclipse Paho MQTT C Client to connect to a ActiveMQ Broker over SSL, but it returns status -1.

The code is as follows:

MQTTClient client;
MQTTClient_connectOptions conn_opts =MQTTClient_connectOptions_initializer;
MQTTClient_message pubmsg = MQTTClient_message_initializer;
MQTTClient_deliveryToken token;
MQTTClient_SSLOptions ssl_opts = MQTTClient_SSLOptions_initializer;
int rc;
MQTTClient_create(&client, ADDRESS, CLIENTID,
    MQTTCLIENT_PERSISTENCE_NONE, NULL);
conn_opts.keepAliveInterval = 20;
conn_opts.cleansession = 1;
conn_opts.ssl = &ssl_opts;
conn_opts.ssl->keyStore = "amq-client.pem";    
conn_opts.ssl->privateKeyPassword = "password";   
conn_opts.ssl->enabledCipherSuites = "DEFAULT";
conn_opts.ssl->enableServerCertAuth = 0;   
MQTTClient_setCallbacks(client, NULL, connlost, msgarrvd, delivered);
if ((rc = MQTTClient_connect(client, &conn_opts)) !=     MQTTCLIENT_SUCCESS)
{
    printf("Failed to connect, return code %d\n", rc);
    exit(-1);       
}

Are there any mistakes in my configuration?

Please help me to fix this issue