From ffcb25798aaff584162b3443e755ac1543da86e1 Mon Sep 17 00:00:00 2001 From: Sachin Agrawal Date: Mon, 26 Jan 2015 14:48:18 -0800 Subject: [PATCH] Updated RI layer to register 'GetDtlsPSKCredentials' as callback RI layer now uses CARegisterDTLSCredentialsHandler method to register callback to retrieve credentials. Also, moved security sources and headers in separate directory as discussed previously for better integration with CA layer. Change-Id: I23f481a087d8400be0402ea2854fe3601580dfb6 Signed-off-by: Sachin Agrawal Reviewed-on: https://gerrit.iotivity.org/gerrit/241 Tested-by: jenkins-iotivity Reviewed-by: Doug Hudson Reviewed-by: Sashi Penta Reviewed-by: Sudarshan Prasad --- resource/csdk/SConscript | 6 ++- .../security/include/internal/ocsecurityinternal.h | 46 ++++++++++++++++++++++ .../csdk/{stack => security}/include/ocsecurity.h | 2 +- .../{stack => security}/include/ocsecurityconfig.h | 2 +- resource/csdk/{stack => security}/src/ocsecurity.c | 2 +- .../csdk/stack/samples/linux/secure/SConscript | 1 + resource/csdk/stack/src/ocstack.c | 9 +++-- 7 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 resource/csdk/security/include/internal/ocsecurityinternal.h rename resource/csdk/{stack => security}/include/ocsecurity.h (94%) rename resource/csdk/{stack => security}/include/ocsecurityconfig.h (96%) rename resource/csdk/{stack => security}/src/ocsecurity.c (97%) diff --git a/resource/csdk/SConscript b/resource/csdk/SConscript index 86e2af6..d218c26 100644 --- a/resource/csdk/SConscript +++ b/resource/csdk/SConscript @@ -32,6 +32,8 @@ liboctbstack_env.PrependUnique(CPPPATH = [ '../oc_logger/include', 'connectivity/inc', 'connectivity/api', + 'security/include', + 'security/include/internal', ]) if target_os not in ['arduino', 'windows', 'winrt']: @@ -73,8 +75,8 @@ liboctbstack_src = [ OCTBSTACK_SRC + 'ocobserve.c', OCTBSTACK_SRC + 'ocserverrequest.c', OCTBSTACK_SRC + 'occollection.c', - OCTBSTACK_SRC + 'ocsecurity.c', - OCTBSTACK_SRC + 'oicgroup.c' + OCTBSTACK_SRC + 'oicgroup.c', + 'security/src/ocsecurity.c' ] if target_os == 'arduino': liboctbstack = liboctbstack_env.StaticLibrary('octbstack', liboctbstack_src) diff --git a/resource/csdk/security/include/internal/ocsecurityinternal.h b/resource/csdk/security/include/internal/ocsecurityinternal.h new file mode 100644 index 0000000..6a2f638 --- /dev/null +++ b/resource/csdk/security/include/internal/ocsecurityinternal.h @@ -0,0 +1,46 @@ +//****************************************************************** +// +// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +#ifndef OC_SECURITY_INTERNAL_H +#define OC_SECURITY_INTERNAL_H + +#include "ocsecurityconfig.h" + +/** + * This callback is used by lower stack (i.e. CA layer) to retrieve PSK + * credentials from RI security layer. + * + * @param credInfo + * binary blob containing PSK credentials + * + * @retval none + */ +void GetDtlsPskCredentials(OCDtlsPskCredsBlob **credInfo); + + +/** + * This internal API removes/clears the global variable holding the security + * config data. This needs to be invoked when OIC stack is shutting down. + * + * @retval none + */ +void DeinitOCSecurityInfo(); + +#endif //OC_SECURITY_INTERNAL_H diff --git a/resource/csdk/stack/include/ocsecurity.h b/resource/csdk/security/include/ocsecurity.h similarity index 94% rename from resource/csdk/stack/include/ocsecurity.h rename to resource/csdk/security/include/ocsecurity.h index 0d71086..16f42b7 100644 --- a/resource/csdk/stack/include/ocsecurity.h +++ b/resource/csdk/security/include/ocsecurity.h @@ -1,6 +1,6 @@ //****************************************************************** // -// Copyright 2014 Intel Corporation All Rights Reserved. +// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved. // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // diff --git a/resource/csdk/stack/include/ocsecurityconfig.h b/resource/csdk/security/include/ocsecurityconfig.h similarity index 96% rename from resource/csdk/stack/include/ocsecurityconfig.h rename to resource/csdk/security/include/ocsecurityconfig.h index eaa06b4..c18e9f7 100644 --- a/resource/csdk/stack/include/ocsecurityconfig.h +++ b/resource/csdk/security/include/ocsecurityconfig.h @@ -1,6 +1,6 @@ //****************************************************************** // -// Copyright 2014 Intel Corporation All Rights Reserved. +// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved. // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // diff --git a/resource/csdk/stack/src/ocsecurity.c b/resource/csdk/security/src/ocsecurity.c similarity index 97% rename from resource/csdk/stack/src/ocsecurity.c rename to resource/csdk/security/src/ocsecurity.c index 0dd7aae..327bfc9 100644 --- a/resource/csdk/stack/src/ocsecurity.c +++ b/resource/csdk/security/src/ocsecurity.c @@ -41,7 +41,7 @@ void DeinitOCSecurityInfo() } // Internal API. Invoked by OC stack to retrieve credentials from this module -void OCGetDtlsPskCredentials(OCDtlsPskCredsBlob **credInfo) +void GetDtlsPskCredentials(OCDtlsPskCredsBlob **credInfo) { *credInfo = pskCredsBlob; } diff --git a/resource/csdk/stack/samples/linux/secure/SConscript b/resource/csdk/stack/samples/linux/secure/SConscript index 50e248b..af98e0e 100644 --- a/resource/csdk/stack/samples/linux/secure/SConscript +++ b/resource/csdk/stack/samples/linux/secure/SConscript @@ -9,6 +9,7 @@ samples_env.PrependUnique(CPPPATH = [ '../../../../ocsocket/include', '../../../../logger/include', '../../../../stack/include', + '../../../../security/include', '../../../../../../extlibs/cjson', '../../../../../oc_logger/include' ]) diff --git a/resource/csdk/stack/src/ocstack.c b/resource/csdk/stack/src/ocstack.c index 8a71307..5651728 100644 --- a/resource/csdk/stack/src/ocstack.c +++ b/resource/csdk/stack/src/ocstack.c @@ -35,6 +35,7 @@ #include "occoap.h" #include "ocmalloc.h" #include "ocserverrequest.h" +#include "ocsecurityinternal.h" #ifdef CA_INT #include "cacommon.h" @@ -86,10 +87,6 @@ OCStackResult getQueryFromUri(const char * uri, unsigned char** resourceType, ch //TODO: we should allow the server to define this #define MAX_OBSERVE_AGE (0x2FFFFUL) -//----------------------------------------------------------------------------- -// Externs -//----------------------------------------------------------------------------- -extern void DeinitOCSecurityInfo(); //----------------------------------------------------------------------------- // Internal API function @@ -1279,6 +1276,10 @@ OCStackResult OCInit(const char *ipAddr, uint16_t port, OCMode mode) myStackMode = mode; defaultDeviceHandler = NULL; +#if defined(CA_INT) && defined(__WITH_DTLS__) + caResult = CARegisterDTLSCredentialsHandler(GetDtlsPskCredentials); + result = (caResult == CA_STATUS_OK) ? OC_STACK_OK : OC_STACK_ERROR; +#endif //(CA_INT) && (__WITH_DTLS__) #ifdef WITH_PRESENCE PresenceTimeOutSize = sizeof(PresenceTimeOut)/sizeof(PresenceTimeOut[0]) - 1; #endif // WITH_PRESENCE -- 2.7.4