From 4536668a99c836329753e75a17c479ff81e7d4a8 Mon Sep 17 00:00:00 2001 From: Dmitriy Zhuravlev Date: Thu, 8 Sep 2016 12:22:27 +0300 Subject: [PATCH] Exposing CASelectCipherSuite to OC layer Select the cipher suite for TLS/DTLS handshake Change-Id: Idb346fc2c5eb3bfa7f624562ef72a02c37db821b Signed-off-by: Dmitriy Zhuravlev Reviewed-on: https://gerrit.iotivity.org/gerrit/11567 Tested-by: jenkins-iotivity Reviewed-by: Randeep Singh --- resource/include/CAManager.h | 14 ++++++++++++++ resource/src/CAManager.cpp | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/resource/include/CAManager.h b/resource/include/CAManager.h index d10437d..3a19a07 100644 --- a/resource/include/CAManager.h +++ b/resource/include/CAManager.h @@ -67,6 +67,20 @@ namespace OC * @return Returns currently assigned port number. */ uint16_t getAssignedPortNumber(OCTransportAdapter adapter, OCTransportFlags flag); + +#if defined(__WITH_DTLS__) || defined(__WITH_TLS__) + /** + * Select the cipher suite for TLS/DTLS handshake. + * @param cipher cipher suite (Note : Make sure endianness). + * 0x35 : TLS_RSA_WITH_AES_256_CBC_SHA + * 0xC018 : TLS_ECDH_anon_WITH_AES_128_CBC_SHA + * 0xC037 : TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 + * 0xC0AE : TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 + * @param adapter transport adapter type. + * @return Returns ::OC_STACK_OK if success. + */ + OCStackResult setCipherSuite(const uint16_t cipher, OCTransportAdapter adapter); +#endif // defined(__WITH_DTLS__) || defined(__WITH_TLS__) } } diff --git a/resource/src/CAManager.cpp b/resource/src/CAManager.cpp index 384b6ec..d32a7a0 100644 --- a/resource/src/CAManager.cpp +++ b/resource/src/CAManager.cpp @@ -28,6 +28,7 @@ #include "OCApi.h" #include "CAManager.h" #include "cautilinterface.h" +#include "casecurityinterface.h" using namespace OC; @@ -115,3 +116,10 @@ uint16_t CAManager::getAssignedPortNumber(OCTransportAdapter adapter, OCTranspor { return CAGetAssignedPortNumber((CATransportAdapter_t) adapter, (CATransportFlags_t) flag); } +#if defined(__WITH_DTLS__) || defined(__WITH_TLS__) +OCStackResult CAManager::setCipherSuite(const uint16_t cipher, OCTransportAdapter adapter) +{ + CAResult_t ret = CASelectCipherSuite(cipher, (CATransportAdapter_t) adapter); + return convertCAResultToOCResult(ret); +} +#endif // defined(__WITH_DTLS__) || defined(__WITH_TLS__) -- 2.7.4