{
if (memcmp(desc, credInfo->creds[index].id, DTLS_PSK_ID_LEN) == 0)
{
- if(NULL != ctx->peers && DTLS_SERVER == ctx->peers->role )
+ // TODO SRM needs identity of the remote end-point with every data packet to
+ // perform access control management. tinyDTLS 'frees' the handshake parameters
+ // data structure when handshake completes. Therefore, currently this is a
+ // workaround to cache remote end-point identity when tinyDTLS asks for PSK.
+ stCADtlsAddrInfo_t *addrInfo = (stCADtlsAddrInfo_t *)session;
+ char peerAddr[MAX_ADDR_STR_SIZE_CA] = { 0 };
+ uint16_t port = 0;
+ CAConvertAddrToName(&(addrInfo->addr.st), peerAddr, &port);
+
+ if(CA_STATUS_OK != CAAddIdToPeerInfoList(peerAddr, port, desc, descLen) )
{
- // TODO SRM needs identity of the remote end-point with every data packet to
- // perform access control management. tinyDTLS 'frees' the handshake parameters
- // data structure when handshake completes. Therefore, currently this is a
- // workaround to cache remote end-point identity when tinyDTLS asks for PSK.
- stCADtlsAddrInfo_t *addrInfo = (stCADtlsAddrInfo_t *)session;
- char peerAddr[MAX_ADDR_STR_SIZE_CA] = { 0 };
- uint16_t port = 0;
- CAConvertAddrToName(&(addrInfo->addr.st), peerAddr, &port);
-
- CAResult_t result = CAAddIdToPeerInfoList(peerAddr, port, desc, descLen);
- if(CA_STATUS_OK != result )
- {
- OIC_LOG(ERROR, NET_DTLS_TAG, "Fail to add peer id to gDtlsPeerInfoList");
- }
+ OIC_LOG(ERROR, NET_DTLS_TAG, "Fail to add peer id to gDtlsPeerInfoList");
}
memcpy(result, credInfo->creds[index].psk, DTLS_PSK_PSK_LEN);
ret = DTLS_PSK_PSK_LEN;
ByteArray caPubKey = BYTE_ARRAY_INITIALIZER;
unsigned char ca_pub_key[PUBLIC_KEY_SIZE];
+ if ( !ctx || !session || !cert || !x || !y)
+ {
+ return -PKI_NULL_PASSED;
+ }
+
CAGetRootKey (&ca_pub_x, &ca_pub_y);
certDerCode.data = (uint8_t *)cert;
memcpy(x, crtChain[0].pubKey.data, xLen);
memcpy(y, crtChain[0].pubKey.data + PUBLIC_KEY_SIZE / 2, yLen);
+ stCADtlsAddrInfo_t *addrInfo = (stCADtlsAddrInfo_t *)session;
+ char peerAddr[MAX_ADDR_STR_SIZE_CA] = { 0 };
+ uint16_t port = 0;
+ CAConvertAddrToName(&(addrInfo->addr.st), peerAddr, &port);
- if (NULL != ctx->peers && DTLS_SERVER == ctx->peers->role )
+ CAResult_t result = CAAddIdToPeerInfoList(peerAddr, port,
+ crtChain[0].subject.data + DER_SUBJECT_HEADER_LEN + 2, crtChain[0].subject.data[DER_SUBJECT_HEADER_LEN + 1]);
+ if (CA_STATUS_OK != result )
{
- stCADtlsAddrInfo_t *addrInfo = (stCADtlsAddrInfo_t *)session;
- char peerAddr[MAX_ADDR_STR_SIZE_CA] = { 0 };
- uint16_t port = 0;
- CAConvertAddrToName(&(addrInfo->addr.st), peerAddr, &port);
-
- CAResult_t result = CAAddIdToPeerInfoList(peerAddr, port,
- crtChain[0].subject.data + DER_SUBJECT_HEADER_LEN + 2, crtChain[0].subject.data[DER_SUBJECT_HEADER_LEN + 1]);
- if (CA_STATUS_OK != result )
- {
- OIC_LOG(ERROR, NET_DTLS_TAG, "Fail to add peer id to gDtlsPeerInfoList");
- }
+ OIC_LOG(ERROR, NET_DTLS_TAG, "Fail to add peer id to gDtlsPeerInfoList");
}
-
exit:
- if (ret != 0) OIC_LOG(DEBUG, NET_DTLS_TAG, "Certificate verification FAILED\n");
- else OIC_LOG(DEBUG, NET_DTLS_TAG, "Certificate verification SUCCESS\n");
+ if (ret != 0)
+ {
+ OIC_LOG(DEBUG, NET_DTLS_TAG, "Certificate verification FAILED\n");
+ }
+ else
+ {
+ OIC_LOG(DEBUG, NET_DTLS_TAG, "Certificate verification SUCCESS\n");
+ }
return -ret;
}