Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
63 views
in Technique[技术] by (71.8m points)

Solace Client in C with TLS support

I am trying to implement C client to connect and publish message to particular topic. I am getting below error while implementing ssl.

ERROR:
SDK WARNING Fri Feb 05 13:59:36.412 2021 solClientSession.c:3609              (7fb51ccfe740) Session '(c0,s1)_vpn-poc-d1': Client Certificate Authentication is not supported on unsecured sessions
ERROR:: Error in craeting session sol client.

Below is the implementation POC code.

#include "os.h"
#include "../inc/solclient/solClient.h"
#include "../inc/solclient/solClientMsg.h"


  /*****************************************************************************
   * sessionMessageReceiveCallback
   *
   * The message receive callback function is mandatory for session creation.
   *****************************************************************************/
solClient_rxMsgCallback_returnCode_t
sessionMessageReceiveCallback(solClient_opaqueSession_pt opaqueSession_p, solClient_opaqueMsg_pt msg_p, void* user_p)
{
    return SOLCLIENT_CALLBACK_OK;
}

/*****************************************************************************
 * sessionEventCallback
 *
 * The event callback function is mandatory for session creation.
 *****************************************************************************/
void
sessionEventCallback(solClient_opaqueSession_pt opaqueSession_p,
    solClient_session_eventCallbackInfo_pt eventInfo_p, void* user_p)
{
}

/*****************************************************************************
 * main
 *
 * The entry point to the application.
 *****************************************************************************/
int main(int argc, char* argv[])
{

    /*if (argc > 1) {
        printf("Usage: TopicPublisher
");
        return -1;
    }
*/

    /* Context */
    solClient_opaqueContext_pt context_p;
    solClient_context_createFuncInfo_t contextFuncInfo = SOLCLIENT_CONTEXT_CREATEFUNC_INITIALIZER;

    /* Session */
    solClient_opaqueSession_pt session_p;
    solClient_session_createFuncInfo_t sessionFuncInfo = SOLCLIENT_SESSION_CREATEFUNC_INITIALIZER;

    /* Session Properties */
    const char* sessionProps[40] = { 0, };
    int             propIndex = 0;

    /* Message */
    solClient_opaqueMsg_pt msg_p = NULL;
    solClient_destination_t destination;

    solClient_returnCode_t solReturnStatus = SOLCLIENT_OK;

    const char* text_p = "Hello World!!";

    /*************************************************************************
     * Initialize the API (and setup logging level)
     *************************************************************************/

     /* solClient needs to be initialized before any other API calls. */
    solReturnStatus = solClient_initialize(SOLCLIENT_LOG_DEFAULT_FILTER, NULL);
    if (solReturnStatus != SOLCLIENT_OK)
    {
        printf("ERROR:: Error in initiailizing sol client.
");
        return -1;
    }
    printf("TopicPublisher initializing...
");

    /*************************************************************************
     * Create a Context
     *************************************************************************/

     /*
      * Create a Context, and specify that the Context thread be created
      * automatically instead of having the application create its own
      * Context thread.
      */
    solReturnStatus = solClient_context_create(SOLCLIENT_CONTEXT_PROPS_DEFAULT_WITH_CREATE_THREAD,
        &context_p, &contextFuncInfo, sizeof(contextFuncInfo));
    if (solReturnStatus != SOLCLIENT_OK)
    {
        printf("ERROR:: Error in creating context sol client.
");
        return -1;
    }

    /*************************************************************************
     * Create and connect a Session
     *************************************************************************/

     /*
      * Message receive callback function and the Session event function
      * are both mandatory. In this sample, default functions are used.
      */
    sessionFuncInfo.rxMsgInfo.callback_p = sessionMessageReceiveCallback;
    sessionFuncInfo.rxMsgInfo.user_p = NULL;
    sessionFuncInfo.eventInfo.callback_p = sessionEventCallback;
    sessionFuncInfo.eventInfo.user_p = NULL;

    /* Configure the Session properties. */
    propIndex = 0;

    sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_HOST;
    sessionProps[propIndex++] = argv[1];

    sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_VPN_NAME;
    sessionProps[propIndex++] = argv[2];

    sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_USERNAME;
    sessionProps[propIndex++] = argv[3];

    sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_PASSWORD;
    sessionProps[propIndex++] = argv[4];

    sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_SSL_VALIDATE_CERTIFICATE;
    sessionProps[propIndex++] = SOLCLIENT_PROP_ENABLE_VAL;

    sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_AUTHENTICATION_SCHEME;
    sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_AUTHENTICATION_SCHEME_CLIENT_CERTIFICATE;

    sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_SSL_CLIENT_CERTIFICATE_FILE;
    sessionProps[propIndex++] = argv[5];

    sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_SSL_CLIENT_PRIVATE_KEY_FILE;
    sessionProps[propIndex++] = argv[6];

    sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_SSL_CLIENT_PRIVATE_KEY_FILE_PASSWORD;
    sessionProps[propIndex++] = argv[7];

    sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_REAPPLY_SUBSCRIPTIONS;
    sessionProps[propIndex++] = SOLCLIENT_PROP_ENABLE_VAL;

    sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_SSL_VALIDATE_CERTIFICATE;
    sessionProps[propIndex++] = SOLCLIENT_PROP_DISABLE_VAL;

    sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_SSL_EXCLUDED_PROTOCOLS;
    sessionProps[propIndex++] = "TLSv1.1";

    sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_RECONNECT_RETRIES;
    sessionProps[propIndex++] = "3";

    sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_CONNECT_RETRIES_PER_HOST;
    sessionProps[propIndex++] = "3";

    sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_SSL_VALIDATE_CERTIFICATE_DATE;
    sessionProps[propIndex++] = SOLCLIENT_PROP_DISABLE_VAL;

    sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_SSL_TRUST_STORE_DIR;
    sessionProps[propIndex++] = argv[8];

    sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_SSL_CIPHER_SUITES;
    sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_SSL_CIPHER_TLS_RSA_WITH_AES_128_CBC_SHA;

    sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_SSL_TRUSTED_COMMON_NAME_LIST;
    sessionProps[propIndex++] = "TEST";

    sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_SSL_CONNECTION_DOWNGRADE_TO;
    sessionProps[propIndex++] = "PLAIN_TEXT";

    sessionProps[propIndex] = NULL;
    printf("Total Properties set = %d
",propIndex);

    /* Create the Session. */
    solReturnStatus = solClient_session_create((char**)sessionProps,
        context_p,
        &session_p, &sessionFuncInfo, sizeof(sessionFuncInfo));
    if (solReturnStatus != SOLCLIENT_OK)
    {
        printf("ERROR:: Error in craeting session sol client.
");
        return -1;
    }

    /* Connect the Session. */
    solReturnStatus = solClient_session_connect(session_p);

    if (solReturnStatus != SOLCLIENT_OK)
    {
        printf("ERROR:: Error in connecting to session sol client.
");
        return -1;
    }
    printf("Connected.
");

    /*************************************************************************
     * Publish
     *************************************************************************/

     /* Allocate memory for the message that is to be sent. */
    solClient_msg_alloc(&msg_p);

    /* Set the message delivery mode. */
    solClient_msg_setDeliveryMode(msg_p, SOLCLIENT_DELIVERY_MODE_DIRECT);

    /* Set the destination. */
    destination.destType = SOLCLIENT_TOPIC_DESTINATION;
    destination.dest = argv[9];
    solClient_msg_setDestination(msg_p, &destination, sizeof(destination));

    /* Add some content to the message. */
    solClient_msg_setBinaryAttachment(msg_p, text_p, (solClient_uint32_t)strlen((char*)text_p));

    /* Send the message. */
    printf("About to send message '%s' to topic '%s'...
", (char*)text_p, argv[9]);
    solReturnStatus = solClient_session_sendMsg(session_p, msg_p);
    if (solReturnStatus != SOLCLIENT_OK)
    {
        printf("ERROR:: Error in sending data to topic.
");
    }

    /* Free the message. */
    printf("Message sent. Exiting.
");
    solReturnStatus = solClient_msg_free(&msg_p);
    if (solReturnStatus != SOLCLIENT_OK)
    {
        printf("ERROR:: Error in msg free sol client.
");
    }

    /*************************************************************************
     * Cleanup
     *************************************************************************/

     /* Cleanup solClient. */
    solReturnStatus = solClient_cleanup();

    if (solReturnStatus != SOLCLIENT_OK)
    {
        printf("ERROR:: Error in cleanup sol client.
");
    }

    return 0;
}

I might be using invalid certificates, is there any way to get the correct certificates from pubsub+ solace server?

question from:https://stackoverflow.com/questions/66063045/solace-client-in-c-with-tls-support

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...