Commit dbd1eb13 authored by junghun kim's avatar junghun kim Committed by Randeep

Added SSL Adapter to Support BLE.

1) SSL Adapter supported BLE.

Change-Id: I7b43c4573c100b6459e7794d20e2f21f548030b2
Signed-off-by: default avatarjunghun kim <jhun1105.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/13655Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Randeep's avatarRandeep Singh <randeep.s@samsung.com>
parent 505aee79
......@@ -28,9 +28,9 @@ extern "C" {
#include "cainterface.h"
/**
* Currently TLS supported adapters(2) WIFI and ETHENET for linux platform.
* Currently TLS supported adapters(3) WIFI, ETHENET and BLE for linux platform.
*/
#define MAX_SUPPORTED_ADAPTERS 2
#define MAX_SUPPORTED_ADAPTERS 3
typedef void (*CAPacketReceivedCallback)(const CASecureEndpoint_t *sep,
const void *data, size_t dataLength);
......
......@@ -484,6 +484,8 @@ static int GetAdapterIndex(CATransportAdapter_t adapter)
return 0;
case CA_ADAPTER_TCP:
return 1;
case CA_ADAPTER_GATT_BTLE:
return 2;
default:
OIC_LOG(ERROR, NET_SSL_TAG, "Unsupported adapter");
return -1;
......@@ -507,7 +509,7 @@ static int SendCallBack(void * tep, const unsigned char * data, size_t dataLen)
OIC_LOG_V(DEBUG, NET_SSL_TAG, "Adapter: %u", ((SslEndPoint_t * )tep)->sep.endpoint.adapter);
ssize_t sentLen = 0;
int adapterIndex = GetAdapterIndex(((SslEndPoint_t * )tep)->sep.endpoint.adapter);
if (0 == adapterIndex || 1 == adapterIndex)
if (0 <= adapterIndex && MAX_SUPPORTED_ADAPTERS > adapterIndex)
{
CAPacketSendCallback sendCallback = g_caSslContext->adapterCallbacks[adapterIndex].sendCallback;
sentLen = sendCallback(&(((SslEndPoint_t * )tep)->sep.endpoint), (const void *) data, dataLen);
......@@ -658,9 +660,11 @@ static int InitPKIX(CATransportAdapter_t adapter)
mbedtls_pk_init(&g_caSslContext->pkey);
mbedtls_x509_crl_init(&g_caSslContext->crl);
mbedtls_ssl_config * serverConf = (adapter == CA_ADAPTER_IP ?
mbedtls_ssl_config * serverConf = (adapter == CA_ADAPTER_IP ||
adapter == CA_ADAPTER_GATT_BTLE ?
&g_caSslContext->serverDtlsConf : &g_caSslContext->serverTlsConf);
mbedtls_ssl_config * clientConf = (adapter == CA_ADAPTER_IP ?
mbedtls_ssl_config * clientConf = (adapter == CA_ADAPTER_IP ||
adapter == CA_ADAPTER_GATT_BTLE ?
&g_caSslContext->clientDtlsConf : &g_caSslContext->clientTlsConf);
// optional
int ret = ParseChain(&g_caSslContext->crt, g_pkiInfo.crt.data, g_pkiInfo.crt.len);
......@@ -779,10 +783,14 @@ static SslEndPoint_t *GetSslPeer(const CAEndpoint_t *peer)
{
continue;
}
OIC_LOG_V(DEBUG, NET_SSL_TAG, "Compare [%s:%d] and [%s:%d]",
peer->addr, peer->port, tep->sep.endpoint.addr, tep->sep.endpoint.port);
if((0 == strncmp(peer->addr, tep->sep.endpoint.addr, MAX_ADDR_STR_SIZE_CA))
&& (peer->port == tep->sep.endpoint.port))
OIC_LOG_V(DEBUG, NET_SSL_TAG, "Compare [%s:%d] and [%s:%d] for %d adapter",
peer->addr, peer->port, tep->sep.endpoint.addr, tep->sep.endpoint.port,
peer->adapter);
if((peer->adapter == tep->sep.endpoint.adapter)
&& (0 == strncmp(peer->addr, tep->sep.endpoint.addr, MAX_ADDR_STR_SIZE_CA))
&& (peer->port == tep->sep.endpoint.port || CA_ADAPTER_GATT_BTLE == peer->adapter))
{
OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__);
return tep;
......@@ -1167,7 +1175,8 @@ static SslEndPoint_t * InitiateTlsHandshake(const CAEndpoint_t *endpoint)
VERIFY_NON_NULL_RET(endpoint, NET_SSL_TAG, "Param endpoint is NULL" , NULL);
mbedtls_ssl_config * config = (endpoint->adapter == CA_ADAPTER_IP ?
mbedtls_ssl_config * config = (endpoint->adapter == CA_ADAPTER_IP ||
endpoint->adapter == CA_ADAPTER_GATT_BTLE ?
&g_caSslContext->clientDtlsConf : &g_caSslContext->clientTlsConf);
tep = NewSslEndPoint(endpoint, config);
if (NULL == tep)
......@@ -1678,7 +1687,8 @@ CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, uint32_t d
SslEndPoint_t * peer = GetSslPeer(&sep->endpoint);
if (NULL == peer)
{
mbedtls_ssl_config * config = (sep->endpoint.adapter == CA_ADAPTER_IP ?
mbedtls_ssl_config * config = (sep->endpoint.adapter == CA_ADAPTER_IP ||
sep->endpoint.adapter == CA_ADAPTER_GATT_BTLE ?
&g_caSslContext->serverDtlsConf : &g_caSslContext->serverTlsConf);
peer = NewSslEndPoint(&sep->endpoint, config);
if (NULL == peer)
......@@ -1826,7 +1836,7 @@ CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, uint32_t d
else if (0 < ret)
{
int adapterIndex = GetAdapterIndex(peer->sep.endpoint.adapter);
if (0 == adapterIndex || adapterIndex == 1)
if (0 <= adapterIndex && MAX_SUPPORTED_ADAPTERS > adapterIndex)
{
g_caSslContext->adapterCallbacks[adapterIndex].recvCallback(&peer->sep, decryptBuffer, ret);
}
......@@ -1872,6 +1882,10 @@ void CAsetSslAdapterCallbacks(CAPacketReceivedCallback recvCallback,
g_caSslContext->adapterCallbacks[1].recvCallback = recvCallback;
g_caSslContext->adapterCallbacks[1].sendCallback = sendCallback;
break;
case CA_ADAPTER_GATT_BTLE:
g_caSslContext->adapterCallbacks[2].recvCallback = recvCallback;
g_caSslContext->adapterCallbacks[2].sendCallback = sendCallback;
break;
default:
OIC_LOG_V(ERROR, NET_SSL_TAG, "Unsupported adapter: %d", type);
}
......
......@@ -117,6 +117,10 @@ OCStackResult CreateSecureSessionJustWorksCallback(OTMContext_t* otmCtx)
endpoint.port = selDevInfo->securePort;
caresult = CAInitiateHandshake(&endpoint);
}
else if (CA_ADAPTER_GATT_BTLE == endpoint.adapter)
{
caresult = CAInitiateHandshake(&endpoint);
}
#ifdef __WITH_TLS__
else
{
......
......@@ -155,6 +155,10 @@ OCStackResult CreateSecureSessionRandomPinCallback(OTMContext_t* otmCtx)
endpoint.port = selDevInfo->securePort;
caresult = CAInitiateHandshake(&endpoint);
}
else if (CA_ADAPTER_GATT_BTLE == endpoint.adapter)
{
caresult = CAInitiateHandshake(&endpoint);
}
#ifdef __WITH_TLS__
else
{
......
......@@ -178,7 +178,8 @@ OCStackResult AddDevice(OCProvisionDev_t **ppDevicesList, OCDevAddr* endpoint,
ptr->endpoint = *endpoint;
ptr->doxm = doxm;
ptr->securePort = DEFAULT_SECURE_PORT;
ptr->securePort = (CT_ADAPTER_GATT_BTLE == connType) ?
endpoint->port : DEFAULT_SECURE_PORT;
ptr->next = NULL;
ptr->connType = connType;
ptr->devStatus = DEV_STATUS_ON; //AddDevice is called when discovery(=alive)
......@@ -245,7 +246,8 @@ static OCStackResult UpdateSecurePortOfDevice(OCProvisionDev_t **ppDevicesList,
return OC_STACK_ERROR;
}
ptr->securePort = securePort;
ptr->securePort = (OC_ADAPTER_GATT_BTLE == ptr->endpoint.adapter) ?
ptr->endpoint.port : securePort;
#ifdef __WITH_TLS__
ptr->tcpPort = tcpPort;
......@@ -448,21 +450,11 @@ bool PMGenerateQuery(bool isSecure,
OIC_LOG(ERROR, TAG, "Unknown address format.");
return false;
}
// snprintf return value check
if (snRet < 0)
{
OIC_LOG_V(ERROR, TAG, "PMGenerateQuery : Error (snprintf) %d\n", snRet);
return false;
}
else if ((size_t)snRet >= bufferSize)
{
OIC_LOG_V(ERROR, TAG, "PMGenerateQuery : Truncated (snprintf) %d\n", snRet);
return false;
}
break;
// TODO: We need to verify tinyDTLS in below cases
case CT_ADAPTER_GATT_BTLE:
snRet = snprintf(buffer, bufferSize, "%s%s%s",
prefix, address, uri);
break;
case CT_ADAPTER_RFCOMM_BTEDR:
OIC_LOG(ERROR, TAG, "Not supported connectivity adapter.");
return false;
......@@ -471,6 +463,18 @@ bool PMGenerateQuery(bool isSecure,
return false;
}
// snprintf return value check
if (snRet < 0)
{
OIC_LOG_V(ERROR, TAG, "PMGenerateQuery : Error (snprintf) %d\n", snRet);
return false;
}
else if ((size_t)snRet >= bufferSize)
{
OIC_LOG_V(ERROR, TAG, "PMGenerateQuery : Truncated (snprintf) %d\n", snRet);
return false;
}
return true;
}
......
......@@ -144,7 +144,7 @@ OCStackApplicationResult putReqCB(void*, OCDoHandle, OCClientResponse * clientRe
{
OIC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
OIC_LOG_PAYLOAD(INFO, clientResponse->payload);
OIC_LOG(INFO, TAG, ("=============> Put Response"));
OIC_LOG(INFO, TAG, "=============> Put Response");
}
return OC_STACK_DELETE_TRANSACTION;
}
......@@ -157,7 +157,7 @@ OCStackApplicationResult postReqCB(void *, OCDoHandle, OCClientResponse *clientR
{
OIC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
OIC_LOG_PAYLOAD(INFO, clientResponse->payload);
OIC_LOG(INFO, TAG, ("=============> Post Response"));
OIC_LOG(INFO, TAG, "=============> Post Response");
}
return OC_STACK_DELETE_TRANSACTION;
}
......@@ -171,7 +171,7 @@ OCStackApplicationResult getReqCB(void*, OCDoHandle, OCClientResponse * clientRe
OIC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
OIC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber);
OIC_LOG_PAYLOAD(INFO, clientResponse->payload);
OIC_LOG(INFO, TAG, ("=============> Get Response"));
OIC_LOG(INFO, TAG, "=============> Get Response");
}
return OC_STACK_DELETE_TRANSACTION;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment