Open Secure Connection with SSL-TLS


Listing - Secure Connection Example Code
HTTPc_CONN_OBJ  conn;


/*
*********************************************************************************************************
*                                       HTTPcEx_ConnPrepare()
*
* Description : Example function to prepare the HTTPc Connection.
*
* Argument(s) : p_conn  Pointer to HTTPc Connection object to set up.
*
* Return(s)   : DEF_YES, if Connection preparation successful.
*               DEF_NO,  otherwise.
*********************************************************************************************************
*/

CPU_BOOLEAN  HTTPcEx_ConnPrepare (HTTPc_CONN_OBJ  *p_conn)
{ 
	HTTPc_ERR   err;

                                                                /* ---------------- INIT NEW CONNECTION --------------- */
    HTTPc_ConnClr(p_conn, &err);
    if (err != HTTPc_ERR_NONE) {
        return (DEF_FAIL);
    }

                                                                /* --------------- SET CONN'S CALLBACKS --------------- */
#if (HTTPc_CFG_MODE_ASYNC_TASK_EN == DEF_ENABLED)
    HTTPc_ConnSetParam(p_conn,
                       HTTPc_PARAM_TYPE_CONN_CONNECT_CALLBACK,
                      &HTTPcEx_ConnConnectCallback,
                      &err);
    if (err != HTTPc_ERR_NONE) {
        return (DEF_FAIL);
    }

    HTTPc_ConnSetParam(p_conn,
                       HTTPc_PARAM_TYPE_CONN_CLOSE_CALLBACK,
                      &HTTPcEx_ConnCloseCallback,
                      &err);
    if (err != HTTPc_ERR_NONE) {
        return (DEF_FAIL);
    }
#endif

                                                                /* --------- SET CONNECTION SECURE PARAMETERS --------- */
	HTTPc_ConnSetParam(p_conn,
                       HTTPc_PARAM_TYPE_SECURE_TRUST_CALLBACK
                      &HTTPcEx_ConnSecureCallback,
                      &err);
    if (err != HTTPc_ERR_NONE) {
        return (DEF_FAIL);
    }

    return (DEF_OK);
}


/*
*********************************************************************************************************
*                                       HTTPcEx_ConnCloseCallback()
*
* Description : Example Callback Function to validate public key from server.
*
* Argument(s) : p_cert_dn   Pointer to certificate distinguished name.
* 
*               reason      Reason why certificate is not trusted:
*                               NET_SOCK_SECURE_UNTRUSTED_BY_CA
*                               NET_SOCK_SECURE_EXPIRE_DATE
*                               NET_SOCK_SECURE_INVALID_DATE
*                               NET_SOCK_SECURE_SELF_SIGNED
*
* Return(s)   : DEF_YES, if certificate is valid.
*               DEF_NO,  otherwise.
*********************************************************************************************************
*/

CPU_BOOLEAN  HTTPcEx_ConnCloseCallback (void                              *p_cert_dn,
                                        NET_SOCK_SECURE_UNTRUSTED_REASON   reason)
{
    return (DEF_YES);
}