1 //******************************************************************
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 #include "oic_malloc.h"
24 #include "ocpayload.h"
25 #include "ocpayloadcbor.h"
26 #include "payload_logging.h"
27 #include "psinterface.h"
28 #include "resourcemanager.h"
30 #include "srmresourcestrings.h"
31 #include "srmutility.h"
32 #include "amaclresource.h"
34 #define TAG "OIC_SRM_AMACL"
36 /** Default cbor payload size. This value is increased in case of CborErrorOutOfMemory.
37 * The value of payload size is increased until reaching belox max cbor size. */
38 static const uint16_t CBOR_SIZE = 1024;
40 /* Max cbor size payload. */
41 static const uint16_t CBOR_MAX_SIZE = 4400;
43 /** AMACL Map size - Number of mandatory items. */
44 static const uint8_t AMACL_MAP_SIZE = 3;
45 static const uint8_t AMACL_RSRC_MAP_SIZE = 1;
46 static const uint8_t AMACL_RLIST_MAP_SIZE = 3;
48 static OicSecAmacl_t *gAmacl = NULL;
49 static OCResourceHandle gAmaclHandle = NULL;
51 void DeleteAmaclList(OicSecAmacl_t* amacl)
55 OicSecAmacl_t *amaclTmp1 = NULL, *amaclTmp2 = NULL;
56 LL_FOREACH_SAFE(amacl, amaclTmp1, amaclTmp2)
58 LL_DELETE(amacl, amaclTmp1);
61 for (size_t i = 0; i < amaclTmp1->resourcesLen; i++)
63 OICFree(amaclTmp1->resources[i]);
65 OICFree(amaclTmp1->resources);
68 OICFree(amaclTmp1->amss);
70 // Clean Amacl node itself
76 OCStackResult AmaclToCBORPayload(const OicSecAmacl_t *amaclS, uint8_t **cborPayload,
79 if (NULL == amaclS || NULL == cborPayload || NULL != *cborPayload || NULL == cborSize)
81 return OC_STACK_INVALID_PARAM;
84 OCStackResult ret = OC_STACK_ERROR;
85 size_t cborLen = *cborSize;
96 int64_t cborEncoderResult = CborNoError;
98 CborEncoder rlistArray;
100 char *stRowner = NULL;
102 const OicSecAmacl_t *amacl = amaclS;
103 uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen);
104 VERIFY_NON_NULL(TAG, outPayload, ERROR);
105 cbor_encoder_init(&encoder, outPayload, cborLen, 0);
108 cborEncoderResult = cbor_encoder_create_map(&encoder, &amaclMap, AMACL_MAP_SIZE);
109 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding AMACL Map.");
111 // resources -- Mandatory
112 cborEncoderResult = cbor_encode_text_string(&amaclMap, OIC_JSON_RESOURCES_NAME,
113 strlen(OIC_JSON_RESOURCES_NAME));
114 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding Resource Name Tag.");
116 cborEncoderResult = cbor_encoder_create_map(&amaclMap, &rsrcMap, AMACL_RSRC_MAP_SIZE);
117 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding Resource Map.");
120 cborEncoderResult = cbor_encode_text_string(&rsrcMap, OIC_JSON_RLIST_NAME,
121 strlen(OIC_JSON_RLIST_NAME));
122 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding RLIST Name Tag.");
124 // TODO : Need to input array length by OicSecAmacl_t->resources->rlistLen based on spec.
125 cborEncoderResult = cbor_encoder_create_array(&rsrcMap, &rlistArray, amacl->resourcesLen);
126 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding RLIST Array.");
128 // TODO : Need to add OicSecAmacl_t->rlist as array rMap based on RAML spec.
129 for (size_t i = 0; i < amacl->resourcesLen; i++)
131 // TODO : Need to create rMap structure based on RAML spec.
133 cborEncoderResult = cbor_encoder_create_map(&rlistArray, &rMap, AMACL_RLIST_MAP_SIZE);
134 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding RLIST Map.");
136 cborEncoderResult = cbor_encode_text_string(&rMap, OIC_JSON_HREF_NAME,
137 strlen(OIC_JSON_HREF_NAME));
138 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding HREF Name Tag.");
139 cborEncoderResult = cbor_encode_text_string(&rMap, amacl->resources[i],
140 strlen(amacl->resources[i]));
141 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding HREF Value in Map.");
143 cborEncoderResult = cbor_encode_text_string(&rMap, OIC_JSON_RT_NAME,
144 strlen(OIC_JSON_RT_NAME));
145 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding RT Name Tag.");
147 // TODO : Need to assign real value of RT
148 cborEncoderResult = cbor_encode_text_string(&rMap, OIC_JSON_EMPTY_STRING,
149 strlen(OIC_JSON_EMPTY_STRING));
150 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding RT Value.");
152 cborEncoderResult = cbor_encode_text_string(&rMap, OIC_JSON_IF_NAME,
153 strlen(OIC_JSON_IF_NAME));
154 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding IF Name Tag.");
156 // TODO : Need to assign real value of IF
157 cborEncoderResult = cbor_encode_text_string(&rMap, OIC_JSON_EMPTY_STRING,
158 strlen(OIC_JSON_EMPTY_STRING));
159 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding IF Value.");
161 cborEncoderResult = cbor_encoder_close_container(&rlistArray, &rMap);
162 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Closing RLIST Array.");
165 cborEncoderResult = cbor_encoder_close_container(&rsrcMap, &rlistArray);
166 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Closing RLIST Array.");
169 cborEncoderResult = cbor_encoder_close_container(&amaclMap, &rsrcMap);
170 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Closing Resource Map.");
172 // TODO : Need to modify type of OicSecAmacl_t->amss based on RAML spec.
174 cborEncoderResult = cbor_encode_text_string(&amaclMap, OIC_JSON_AMS_NAME,
175 strlen(OIC_JSON_AMS_NAME));
176 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding AMSS Name Tag.");
178 cborEncoderResult = cbor_encoder_create_array(&amaclMap, &amss, amacl->amssLen);
179 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding AMS Name Array.");
180 for (size_t i = 0; i < amacl->amssLen; i++)
182 cborEncoderResult = cbor_encode_text_string(&amss, (const char *)amacl->amss[i].id,
183 sizeof(amacl->amss[i].id));
184 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding AMS Name Value.");
186 cborEncoderResult = cbor_encoder_close_container(&amaclMap, &amss);
187 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Closing AMSS Array.");
189 // TODO : Need to check owner property in the RAML spec.
190 // rowner -- Mandatory
191 cborEncoderResult = cbor_encode_text_string(&amaclMap, OIC_JSON_ROWNERID_NAME,
192 strlen(OIC_JSON_ROWNERID_NAME));
193 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding ROwnerID Name Tag.");
195 ret = ConvertUuidToStr(&amacl->rownerID, &stRowner);
196 VERIFY_SUCCESS(TAG, ret == OC_STACK_OK, ERROR);
197 cborEncoderResult = cbor_encode_text_string(&amaclMap, stRowner, strlen(stRowner));
198 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding ROwner Value.");
201 cborEncoderResult = cbor_encoder_close_container(&encoder, &amaclMap);
202 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Closing Amacl Map.");
204 if (CborNoError == cborEncoderResult)
206 *cborPayload = outPayload;
207 *cborSize = cbor_encoder_get_buffer_size(&encoder, outPayload);
212 if ((CborErrorOutOfMemory == cborEncoderResult) && (cborLen < CBOR_MAX_SIZE))
214 // reallocate and try again!
217 // Since the allocated initial memory failed, double the memory.
218 cborLen += cbor_encoder_get_buffer_size(&encoder, encoder.end);
219 cborEncoderResult = CborNoError;
220 ret = AmaclToCBORPayload(amaclS, cborPayload, &cborLen);
221 if (OC_STACK_OK == ret)
228 if (CborNoError != cborEncoderResult || ret != OC_STACK_OK)
234 ret = OC_STACK_ERROR;
240 OCStackResult CBORPayloadToAmacl(const uint8_t *cborPayload, size_t size,
241 OicSecAmacl_t **secAmacl)
243 if (NULL == cborPayload || NULL == secAmacl || NULL != *secAmacl || 0 == size)
245 return OC_STACK_INVALID_PARAM;
250 OCStackResult ret = OC_STACK_ERROR;
252 CborValue amaclCbor = { .parser = NULL };
253 CborParser parser = { .end = NULL };
254 CborError cborFindResult = CborNoError;
256 cbor_parser_init(cborPayload, size, 0, &parser, &amaclCbor);
257 OicSecAmacl_t *headAmacl = (OicSecAmacl_t *)OICCalloc(1, sizeof(OicSecAmacl_t));
259 CborValue amaclMap = { .parser = NULL };
260 cborFindResult = cbor_value_enter_container(&amaclCbor, &amaclMap);
261 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering Amacl Map.");
263 while(cbor_value_is_valid(&amaclMap) && cbor_value_is_text_string(&amaclMap))
267 cborFindResult = cbor_value_dup_text_string(&amaclMap, &name, &len, NULL);
268 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Amacl Data Name Tag.");
269 cborFindResult = cbor_value_advance(&amaclMap);
270 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Amacl Data Value.");
272 //CborType type = cbor_value_get_type(&amaclMap);
274 // Resources -- Mandatory
275 if (0 == strcmp(OIC_JSON_RESOURCES_NAME, name))
278 CborValue rsrcMap = { .parser = NULL };
279 cborFindResult = cbor_value_enter_container(&amaclMap, &rsrcMap);
280 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering Resource Map");
282 while(cbor_value_is_valid(&rsrcMap) && cbor_value_is_text_string(&rsrcMap))
285 char *rsrcName = NULL;
286 size_t rsrcNameLen = 0;
287 cborFindResult = cbor_value_dup_text_string(&rsrcMap, &rsrcName, &rsrcNameLen, NULL);
288 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Resource Data Name Tag.");
289 cborFindResult = cbor_value_advance(&rsrcMap);
290 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Resource Data Value.");
293 if (0 == strcmp(OIC_JSON_RLIST_NAME, rsrcName))
296 // TODO : Need to assign array length to OicSecAmacl_t->resources->rlistLen based of RAML spec.
297 cborFindResult = cbor_value_get_array_length(&rsrcMap, &headAmacl->resourcesLen);
298 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Rlist Array Len.");
300 CborValue rsrcArray = { .parser = NULL };
303 cborFindResult = cbor_value_enter_container(&rsrcMap, &rsrcArray);
304 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering Rlist Array");
306 // TODO : Need to check data structure of OicSecAmacl_t based on RAML spec.
307 headAmacl->resources = (char **) OICCalloc(headAmacl->resourcesLen, sizeof(*headAmacl->resources));
308 VERIFY_NON_NULL(TAG, headAmacl->resources, ERROR);
310 while (cbor_value_is_valid(&rsrcArray))
313 CborValue rMap = { .parser = NULL };
314 cborFindResult = cbor_value_enter_container(&rsrcArray, &rMap);
315 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering Rlist Map");
317 while(cbor_value_is_valid(&rMap) && cbor_value_is_text_string(&rMap))
319 char *rMapName = NULL;
320 size_t rMapNameLen = 0;
321 cborFindResult = cbor_value_dup_text_string(&rMap, &rMapName, &rMapNameLen, NULL);
322 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding RMap Data Name Tag.");
323 cborFindResult = cbor_value_advance(&rMap);
324 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding RMap Data Value.");
327 if (0 == strcmp(OIC_JSON_HREF_NAME, rMapName))
329 // TODO : Need to check data structure of OicSecAmacl_t based on RAML spec.
330 cborFindResult = cbor_value_dup_text_string(&rMap, &headAmacl->resources[i++], &len, NULL);
331 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Href Value.");
335 if (0 == strcmp(OIC_JSON_RT_NAME, rMapName))
337 // TODO : Need to check data structure of OicSecAmacl_t and assign based on RAML spec.
339 cborFindResult = cbor_value_dup_text_string(&rMap, &rtData, &len, NULL);
340 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding RT Value.");
345 if (0 == strcmp(OIC_JSON_IF_NAME, rMapName))
347 // TODO : Need to check data structure of OicSecAmacl_t and assign based on RAML spec.
349 cborFindResult = cbor_value_dup_text_string(&rMap, &ifData, &len, NULL);
350 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding IF Value.");
354 if (cbor_value_is_valid(&rMap))
356 cborFindResult = cbor_value_advance(&rMap);
357 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Advancing Rlist Map.");
362 if (cbor_value_is_valid(&rsrcArray))
364 cborFindResult = cbor_value_advance(&rsrcArray);
365 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Advancing Resource Array.");
370 if (cbor_value_is_valid(&rsrcMap))
372 cborFindResult = cbor_value_advance(&rsrcMap);
373 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Advancing Resource Map.");
380 // TODO : Need to modify type of OicSecAmacl_t->amss based on RAML spec.
382 if (0 == strcmp(OIC_JSON_AMS_NAME, name))
385 CborValue amsArray = { .parser = NULL };
386 cborFindResult = cbor_value_get_array_length(&amaclMap, &headAmacl->amssLen);
387 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding AMS Array Len.");
388 cborFindResult = cbor_value_enter_container(&amaclMap, &amsArray);
389 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering AMS Array Container.");
390 headAmacl->amss = (OicUuid_t *)OICCalloc(headAmacl->amssLen, sizeof(*headAmacl->amss));
391 VERIFY_NON_NULL(TAG, headAmacl->amss, ERROR);
392 while (cbor_value_is_valid(&amsArray) && cbor_value_is_text_string(&amsArray))
395 cborFindResult = cbor_value_dup_text_string(&amsArray, &amssId, &len, NULL);
396 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding AMS Id.");
397 cborFindResult = cbor_value_advance(&amsArray);
398 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Advancing AMS.");
399 memcpy(headAmacl->amss[i++].id, (OicUuid_t *)amssId, len);
404 // Rowner -- Mandatory
405 if (0 == strcmp(OIC_JSON_ROWNERID_NAME, name) && cbor_value_is_text_string(&amaclMap))
407 char *stRowner = NULL;
408 cborFindResult = cbor_value_dup_text_string(&amaclMap, &stRowner, &len, NULL);
409 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding ROwner Value.");
411 ret = ConvertStrToUuid(stRowner, &headAmacl->rownerID);
412 VERIFY_SUCCESS(TAG, ret == OC_STACK_OK, ERROR);
416 //if (CborMapType != type && cbor_value_is_valid(&amaclMap))
417 if (cbor_value_is_valid(&amaclMap))
419 cborFindResult = cbor_value_advance(&amaclMap);
420 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Advancing Amacl Map.");
425 *secAmacl = headAmacl;
429 if (CborNoError != cborFindResult)
431 DeleteAmaclList(headAmacl);
434 ret = OC_STACK_ERROR;
439 static OCEntityHandlerResult HandleAmaclGetRequest (const OCEntityHandlerRequest * ehRequest)
441 // Convert Amacl data into JSON for transmission
443 uint8_t *cborPayload = NULL;
444 OCStackResult res = AmaclToCBORPayload(gAmacl, &cborPayload, &size);
446 OCEntityHandlerResult ehRet = (res == OC_STACK_OK) ? OC_EH_OK : OC_EH_ERROR;
448 // Send response payload to request originator
449 ehRet = ((SendSRMResponse(ehRequest, ehRet, cborPayload, size)) == OC_STACK_OK) ?
450 OC_EH_OK : OC_EH_ERROR;
452 OICFree(cborPayload);
454 OIC_LOG_V (DEBUG, TAG, "%s RetVal %d", __func__ , ehRet);
458 static OCEntityHandlerResult HandleAmaclPostRequest (const OCEntityHandlerRequest * ehRequest)
460 OCEntityHandlerResult ehRet = OC_EH_ERROR;
462 // Convert CBOR Amacl data into binary. This will also validate the Amacl data received.
463 uint8_t *payload = ((OCSecurityPayload *) ehRequest->payload)->securityData;
464 size_t size = ((OCSecurityPayload *) ehRequest->payload)->payloadSize;
467 OicSecAmacl_t *newAmacl = NULL;
468 OCStackResult res = CBORPayloadToAmacl(payload, size, &newAmacl);
469 if (newAmacl && OC_STACK_OK == res)
471 // Append the new Amacl to existing Amacl
472 LL_APPEND(gAmacl, newAmacl);
474 // Convert Amacl data into JSON for update to persistent storage.
475 uint8_t *cborPayload = NULL;
476 res = AmaclToCBORPayload(gAmacl, &cborPayload, &size);
477 if (cborPayload && (OC_STACK_OK == res) &&
478 (OC_STACK_OK == UpdateSecureResourceInPS(OIC_JSON_AMACL_NAME, cborPayload, size)))
480 ehRet = OC_EH_RESOURCE_CREATED;
482 OICFree(cborPayload);
487 // Send payload to request originator
488 if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, NULL, 0))
491 OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandleAmaclPostRequest");
494 OIC_LOG_V(DEBUG, TAG, "%s RetVal %d", __func__ , ehRet);
499 * This internal method is the entity handler for Amacl resources and
500 * will handle REST request (GET/PUT/POST/DEL) for them.
502 static OCEntityHandlerResult AmaclEntityHandler (OCEntityHandlerFlag flag,
503 OCEntityHandlerRequest * ehRequest,
504 void* callbackParameter)
506 (void) callbackParameter;
507 OCEntityHandlerResult ehRet = OC_EH_ERROR;
514 if (flag & OC_REQUEST_FLAG)
516 OIC_LOG (DEBUG, TAG, "Flag includes OC_REQUEST_FLAG");
517 switch (ehRequest->method)
520 ehRet = HandleAmaclGetRequest(ehRequest);
524 ehRet = HandleAmaclPostRequest(ehRequest);
529 SendSRMResponse(ehRequest, ehRet, NULL, 0);
537 * This internal method is used to create '/oic/sec/amacl' resource.
539 static OCStackResult CreateAmaclResource()
541 OCStackResult ret = OCCreateResource(&gAmaclHandle,
542 OIC_RSRC_TYPE_SEC_AMACL,
543 OC_RSRVD_INTERFACE_DEFAULT,
549 if (OC_STACK_OK != ret)
551 OIC_LOG (FATAL, TAG, "Unable to instantiate Amacl resource");
552 DeInitAmaclResource();
557 OCStackResult InitAmaclResource()
559 OCStackResult ret = OC_STACK_ERROR;
561 uint8_t *data = NULL;
563 ret = GetSecureVirtualDatabaseFromPS(OIC_JSON_AMACL_NAME, &data, &size);
565 // If database read failed
566 if (OC_STACK_OK != ret)
568 OIC_LOG(DEBUG, TAG, "ReadSVDataFromPS failed");
572 // Read AMACL resource from PS
573 ret = CBORPayloadToAmacl(data, size, &gAmacl);
574 if (OC_STACK_OK != ret)
576 OIC_LOG(DEBUG, TAG, "ReadAMACLresourcefromPS failed");
581 // Instantiate 'oic/sec/amacl' resource
582 ret = CreateAmaclResource();
584 if (OC_STACK_OK != ret)
586 DeInitAmaclResource();
591 void DeInitAmaclResource()
593 OCDeleteResource(gAmaclHandle);
596 DeleteAmaclList(gAmacl);
600 OCStackResult AmaclGetAmsDeviceId(const char *resource, OicUuid_t *amsDeviceId)
602 OicSecAmacl_t *amacl = NULL;
604 VERIFY_NON_NULL(TAG, resource, ERROR);
605 VERIFY_NON_NULL(TAG, amsDeviceId, ERROR);
607 LL_FOREACH(gAmacl, amacl)
609 for(size_t i = 0; i < amacl->resourcesLen; i++)
611 if (0 == strncmp((amacl->resources[i]), resource, strlen(amacl->resources[i])))
613 //Returning the ID of the first AMS service for the resource
614 memcpy(amsDeviceId, &amacl->amss[0], sizeof(*amsDeviceId));
621 return OC_STACK_ERROR;
624 OCStackResult SetAmaclRownerId(const OicUuid_t* newROwner)
626 OCStackResult ret = OC_STACK_ERROR;
627 uint8_t *cborPayload = NULL;
629 OicUuid_t prevId = {.id={0}};
631 if(NULL == newROwner)
633 ret = OC_STACK_INVALID_PARAM;
637 ret = OC_STACK_NO_RESOURCE;
640 if(newROwner && gAmacl)
642 memcpy(prevId.id, gAmacl->rownerID.id, sizeof(prevId.id));
643 memcpy(gAmacl->rownerID.id, newROwner->id, sizeof(newROwner->id));
645 ret = AmaclToCBORPayload(gAmacl, &cborPayload, &size);
646 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
648 ret = UpdateSecureResourceInPS(OIC_JSON_AMACL_NAME, cborPayload, size);
649 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
651 OICFree(cborPayload);
657 OICFree(cborPayload);
658 memcpy(gAmacl->rownerID.id, prevId.id, sizeof(prevId.id));
662 OCStackResult GetAmaclRownerId(OicUuid_t *rowneruuid)
664 OCStackResult retVal = OC_STACK_ERROR;
667 *rowneruuid = gAmacl->rownerID;
668 retVal = OC_STACK_OK;