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 "payload_logging.h"
26 #include "psinterface.h"
27 #include "resourcemanager.h"
29 #include "srmresourcestrings.h"
30 #include "srmutility.h"
31 #include "amaclresource.h"
33 #define TAG "SRM-AMACL"
35 /** Default cbor payload size. This value is increased in case of CborErrorOutOfMemory.
36 * The value of payload size is increased until reaching belox max cbor size. */
37 static const uint16_t CBOR_SIZE = 1024;
39 /* Max cbor size payload. */
40 static const uint16_t CBOR_MAX_SIZE = 4400;
42 /** AMACL Map size - Number of mandatory items. */
43 static const uint8_t AMACL_MAP_SIZE = 3;
44 static const uint8_t AMACL_RSRC_MAP_SIZE = 1;
45 static const uint8_t AMACL_RLIST_MAP_SIZE = 3;
47 static OicSecAmacl_t *gAmacl = NULL;
48 static OCResourceHandle gAmaclHandle = NULL;
50 void DeleteAmaclList(OicSecAmacl_t* amacl)
54 OicSecAmacl_t *amaclTmp1 = NULL, *amaclTmp2 = NULL;
55 LL_FOREACH_SAFE(amacl, amaclTmp1, amaclTmp2)
57 LL_DELETE(amacl, amaclTmp1);
60 for (size_t i = 0; i < amaclTmp1->resourcesLen; i++)
62 OICFree(amaclTmp1->resources[i]);
64 OICFree(amaclTmp1->resources);
67 OICFree(amaclTmp1->amss);
69 // Clean Amacl node itself
75 static size_t OicSecAmaclCount(const OicSecAmacl_t *secAmacl)
78 for (const OicSecAmacl_t *amacl = secAmacl; amacl; amacl = amacl->next)
85 OCStackResult AmaclToCBORPayload(const OicSecAmacl_t *amaclS, uint8_t **cborPayload,
88 if (NULL == amaclS || NULL == cborPayload || NULL != *cborPayload || NULL == cborSize)
90 return OC_STACK_INVALID_PARAM;
93 OCStackResult ret = OC_STACK_ERROR;
94 size_t cborLen = *cborSize;
104 CborEncoder amaclMap;
105 int64_t cborEncoderResult = CborNoError;
107 CborEncoder rlistArray;
109 char *stRowner = NULL;
111 const OicSecAmacl_t *amacl = amaclS;
112 uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen);
113 VERIFY_NON_NULL(TAG, outPayload, ERROR);
114 cbor_encoder_init(&encoder, outPayload, cborLen, 0);
117 cborEncoderResult = cbor_encoder_create_map(&encoder, &amaclMap, AMACL_MAP_SIZE);
118 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding AMACL Map.");
120 // resources -- Mandatory
121 cborEncoderResult = cbor_encode_text_string(&amaclMap, OIC_JSON_RESOURCES_NAME,
122 strlen(OIC_JSON_RESOURCES_NAME));
123 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding Resource Name Tag.");
125 cborEncoderResult = cbor_encoder_create_map(&amaclMap, &rsrcMap, AMACL_RSRC_MAP_SIZE);
126 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding Resource Map.");
129 cborEncoderResult = cbor_encode_text_string(&rsrcMap, OIC_JSON_RLIST_NAME,
130 strlen(OIC_JSON_RLIST_NAME));
131 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding RLIST Name Tag.");
133 // TODO : Need to input array length by OicSecAmacl_t->resources->rlistLen based on spec.
134 cborEncoderResult = cbor_encoder_create_array(&rsrcMap, &rlistArray, amacl->resourcesLen);
135 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding RLIST Array.");
137 // TODO : Need to add OicSecAmacl_t->rlist as array rMap based on RAML spec.
138 for (size_t i = 0; i < amacl->resourcesLen; i++)
140 // TODO : Need to create rMap structure based on RAML spec.
142 cborEncoderResult = cbor_encoder_create_map(&rlistArray, &rMap, AMACL_RLIST_MAP_SIZE);
143 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding RLIST Map.");
145 cborEncoderResult = cbor_encode_text_string(&rMap, OIC_JSON_HREF_NAME,
146 strlen(OIC_JSON_HREF_NAME));
147 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding HREF Name Tag.");
148 cborEncoderResult = cbor_encode_text_string(&rMap, amacl->resources[i],
149 strlen(amacl->resources[i]));
150 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding HREF Value in Map.");
152 cborEncoderResult = cbor_encode_text_string(&rMap, OIC_JSON_RT_NAME,
153 strlen(OIC_JSON_RT_NAME));
154 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding RT Name Tag.");
156 // TODO : Need to assign real value of RT
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 RT Value.");
161 cborEncoderResult = cbor_encode_text_string(&rMap, OIC_JSON_IF_NAME,
162 strlen(OIC_JSON_IF_NAME));
163 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding IF Name Tag.");
165 // TODO : Need to assign real value of IF
166 cborEncoderResult = cbor_encode_text_string(&rMap, OIC_JSON_EMPTY_STRING,
167 strlen(OIC_JSON_EMPTY_STRING));
168 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding IF Value.");
170 cborEncoderResult = cbor_encoder_close_container(&rlistArray, &rMap);
171 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Closing RLIST Array.");
174 cborEncoderResult = cbor_encoder_close_container(&rsrcMap, &rlistArray);
175 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Closing RLIST Array.");
178 cborEncoderResult = cbor_encoder_close_container(&amaclMap, &rsrcMap);
179 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Closing Resource Map.");
181 // TODO : Need to modify type of OicSecAmacl_t->amss based on RAML spec.
183 cborEncoderResult = cbor_encode_text_string(&amaclMap, OIC_JSON_AMS_NAME,
184 strlen(OIC_JSON_AMS_NAME));
185 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding AMSS Name Tag.");
187 cborEncoderResult = cbor_encoder_create_array(&amaclMap, &amss, amacl->amssLen);
188 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding AMS Name Array.");
189 for (size_t i = 0; i < amacl->amssLen; i++)
191 cborEncoderResult = cbor_encode_text_string(&amss, (const char *)amacl->amss[i].id,
192 sizeof(amacl->amss[i].id));
193 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding AMS Name Value.");
195 cborEncoderResult = cbor_encoder_close_container(&amaclMap, &amss);
196 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Closing AMSS Array.");
198 // TODO : Need to check owner property in the RAML spec.
199 // rowner -- Mandatory
200 cborEncoderResult = cbor_encode_text_string(&amaclMap, OIC_JSON_ROWNERID_NAME,
201 strlen(OIC_JSON_ROWNERID_NAME));
202 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding ROwnerID Name Tag.");
204 ret = ConvertUuidToStr(&amacl->rownerID, &stRowner);
205 VERIFY_SUCCESS(TAG, ret == OC_STACK_OK, ERROR);
206 cborEncoderResult = cbor_encode_text_string(&amaclMap, stRowner, strlen(stRowner));
207 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding ROwner Value.");
210 cborEncoderResult = cbor_encoder_close_container(&encoder, &amaclMap);
211 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Closing Amacl Map.");
213 if (CborNoError == cborEncoderResult)
215 *cborPayload = outPayload;
216 *cborSize = encoder.ptr - outPayload;
221 if ((CborErrorOutOfMemory == cborEncoderResult) && (cborLen < CBOR_MAX_SIZE))
223 // reallocate and try again!
226 // Since the allocated initial memory failed, double the memory.
227 cborLen += encoder.ptr - encoder.end;
228 cborEncoderResult = CborNoError;
229 ret = AmaclToCBORPayload(amaclS, cborPayload, &cborLen);
230 if (OC_STACK_OK == ret)
237 if (CborNoError != cborEncoderResult || ret != OC_STACK_OK)
243 ret = OC_STACK_ERROR;
249 OCStackResult CBORPayloadToAmacl(const uint8_t *cborPayload, size_t size,
250 OicSecAmacl_t **secAmacl)
252 if (NULL == cborPayload || NULL == secAmacl || NULL != *secAmacl || 0 == size)
254 return OC_STACK_INVALID_PARAM;
259 OCStackResult ret = OC_STACK_ERROR;
261 CborValue amaclCbor = { .parser = NULL };
262 CborParser parser = { .end = NULL };
263 CborError cborFindResult = CborNoError;
265 cbor_parser_init(cborPayload, size, 0, &parser, &amaclCbor);
266 OicSecAmacl_t *headAmacl = (OicSecAmacl_t *)OICCalloc(1, sizeof(OicSecAmacl_t));
268 CborValue amaclMap = { .parser = NULL };
269 cborFindResult = cbor_value_enter_container(&amaclCbor, &amaclMap);
270 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering Amacl Map.");
272 while(cbor_value_is_valid(&amaclMap) && cbor_value_is_text_string(&amaclMap))
276 cborFindResult = cbor_value_dup_text_string(&amaclMap, &name, &len, NULL);
277 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Amacl Data Name Tag.");
278 cborFindResult = cbor_value_advance(&amaclMap);
279 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Amacl Data Value.");
281 //CborType type = cbor_value_get_type(&amaclMap);
283 // Resources -- Mandatory
284 if (0 == strcmp(OIC_JSON_RESOURCES_NAME, name))
287 CborValue rsrcMap = { .parser = NULL };
288 cborFindResult = cbor_value_enter_container(&amaclMap, &rsrcMap);
289 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering Resource Map");
291 while(cbor_value_is_valid(&rsrcMap) && cbor_value_is_text_string(&rsrcMap))
294 char *rsrcName = NULL;
295 size_t rsrcNameLen = 0;
296 cborFindResult = cbor_value_dup_text_string(&rsrcMap, &rsrcName, &rsrcNameLen, NULL);
297 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Resource Data Name Tag.");
298 cborFindResult = cbor_value_advance(&rsrcMap);
299 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Resource Data Value.");
302 if (0 == strcmp(OIC_JSON_RLIST_NAME, rsrcName))
305 // TODO : Need to assign array length to OicSecAmacl_t->resources->rlistLen based of RAML spec.
306 cborFindResult = cbor_value_get_array_length(&rsrcMap, &headAmacl->resourcesLen);
307 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Rlist Array Len.");
309 CborValue rsrcArray = { .parser = NULL };
312 cborFindResult = cbor_value_enter_container(&rsrcMap, &rsrcArray);
313 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering Rlist Array");
315 // TODO : Need to check data structure of OicSecAmacl_t based on RAML spec.
316 headAmacl->resources = (char **) OICCalloc(headAmacl->resourcesLen, sizeof(*headAmacl->resources));
317 VERIFY_NON_NULL(TAG, headAmacl->resources, ERROR);
319 while (cbor_value_is_valid(&rsrcArray))
322 CborValue rMap = { .parser = NULL };
323 cborFindResult = cbor_value_enter_container(&rsrcArray, &rMap);
324 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering Rlist Map");
326 while(cbor_value_is_valid(&rMap) && cbor_value_is_text_string(&rMap))
328 char *rMapName = NULL;
329 size_t rMapNameLen = 0;
330 cborFindResult = cbor_value_dup_text_string(&rMap, &rMapName, &rMapNameLen, NULL);
331 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding RMap Data Name Tag.");
332 cborFindResult = cbor_value_advance(&rMap);
333 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding RMap Data Value.");
336 if (0 == strcmp(OIC_JSON_HREF_NAME, rMapName))
338 // TODO : Need to check data structure of OicSecAmacl_t based on RAML spec.
339 cborFindResult = cbor_value_dup_text_string(&rMap, &headAmacl->resources[i++], &len, NULL);
340 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Href Value.");
344 if (0 == strcmp(OIC_JSON_RT_NAME, rMapName))
346 // TODO : Need to check data structure of OicSecAmacl_t and assign based on RAML spec.
348 cborFindResult = cbor_value_dup_text_string(&rMap, &rtData, &len, NULL);
349 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding RT Value.");
354 if (0 == strcmp(OIC_JSON_IF_NAME, rMapName))
356 // TODO : Need to check data structure of OicSecAmacl_t and assign based on RAML spec.
358 cborFindResult = cbor_value_dup_text_string(&rMap, &ifData, &len, NULL);
359 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding IF Value.");
363 if (cbor_value_is_valid(&rMap))
365 cborFindResult = cbor_value_advance(&rMap);
366 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Advancing Rlist Map.");
371 if (cbor_value_is_valid(&rsrcArray))
373 cborFindResult = cbor_value_advance(&rsrcArray);
374 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Advancing Resource Array.");
379 if (cbor_value_is_valid(&rsrcMap))
381 cborFindResult = cbor_value_advance(&rsrcMap);
382 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Advancing Resource Map.");
389 // TODO : Need to modify type of OicSecAmacl_t->amss based on RAML spec.
391 if (0 == strcmp(OIC_JSON_AMS_NAME, name))
394 CborValue amsArray = { .parser = NULL };
395 cborFindResult = cbor_value_get_array_length(&amaclMap, &headAmacl->amssLen);
396 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding AMS Array Len.");
397 cborFindResult = cbor_value_enter_container(&amaclMap, &amsArray);
398 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering AMS Array Container.");
399 headAmacl->amss = (OicUuid_t *)OICCalloc(headAmacl->amssLen, sizeof(*headAmacl->amss));
400 VERIFY_NON_NULL(TAG, headAmacl->amss, ERROR);
401 while (cbor_value_is_valid(&amsArray) && cbor_value_is_text_string(&amsArray))
404 cborFindResult = cbor_value_dup_text_string(&amsArray, &amssId, &len, NULL);
405 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding AMS Id.");
406 cborFindResult = cbor_value_advance(&amsArray);
407 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Advancing AMS.");
408 memcpy(headAmacl->amss[i++].id, (OicUuid_t *)amssId, len);
413 // Rowner -- Mandatory
414 if (0 == strcmp(OIC_JSON_ROWNERID_NAME, name) && cbor_value_is_text_string(&amaclMap))
416 char *stRowner = NULL;
417 cborFindResult = cbor_value_dup_text_string(&amaclMap, &stRowner, &len, NULL);
418 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding ROwner Value.");
420 ret = ConvertStrToUuid(stRowner, &headAmacl->rownerID);
421 VERIFY_SUCCESS(TAG, ret == OC_STACK_OK, ERROR);
425 //if (CborMapType != type && cbor_value_is_valid(&amaclMap))
426 if (cbor_value_is_valid(&amaclMap))
428 cborFindResult = cbor_value_advance(&amaclMap);
429 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Advancing Amacl Map.");
434 *secAmacl = headAmacl;
438 if (CborNoError != cborFindResult)
440 DeleteAmaclList(headAmacl);
443 ret = OC_STACK_ERROR;
448 static OCEntityHandlerResult HandleAmaclGetRequest (const OCEntityHandlerRequest * ehRequest)
450 // Convert Amacl data into JSON for transmission
452 uint8_t *cborPayload = NULL;
453 OCStackResult res = AmaclToCBORPayload(gAmacl, &cborPayload, &size);
455 OCEntityHandlerResult ehRet = (res == OC_STACK_OK) ? OC_EH_OK : OC_EH_ERROR;
457 // Send response payload to request originator
458 if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, cborPayload, size))
461 OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandleAmaclGetRequest");
463 OICFree(cborPayload);
465 OIC_LOG_V (DEBUG, TAG, "%s RetVal %d", __func__ , ehRet);
469 static OCEntityHandlerResult HandleAmaclPostRequest (const OCEntityHandlerRequest * ehRequest)
471 OCEntityHandlerResult ehRet = OC_EH_ERROR;
473 // Convert CBOR Amacl data into binary. This will also validate the Amacl data received.
474 uint8_t *payload = ((OCSecurityPayload *) ehRequest->payload)->securityData;
475 size_t size = ((OCSecurityPayload *) ehRequest->payload)->payloadSize;
478 OicSecAmacl_t *newAmacl = NULL;
479 OCStackResult res = CBORPayloadToAmacl(payload, size, &newAmacl);
480 if (newAmacl && OC_STACK_OK == res)
482 // Append the new Amacl to existing Amacl
483 LL_APPEND(gAmacl, newAmacl);
485 // Convert Amacl data into JSON for update to persistent storage.
486 uint8_t *cborPayload = NULL;
487 res = AmaclToCBORPayload(gAmacl, &cborPayload, &size);
488 if (cborPayload && (OC_STACK_OK == res) &&
489 (OC_STACK_OK == UpdateSecureResourceInPS(OIC_JSON_AMACL_NAME, cborPayload, size)))
491 ehRet = OC_EH_RESOURCE_CREATED;
493 OICFree(cborPayload);
498 // Send payload to request originator
499 if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, NULL, 0))
502 OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandleAmaclPostRequest");
505 OIC_LOG_V(DEBUG, TAG, "%s RetVal %d", __func__ , ehRet);
510 * This internal method is the entity handler for Amacl resources and
511 * will handle REST request (GET/PUT/POST/DEL) for them.
513 static OCEntityHandlerResult AmaclEntityHandler (OCEntityHandlerFlag flag,
514 OCEntityHandlerRequest * ehRequest,
515 void* callbackParameter)
517 (void) callbackParameter;
518 OCEntityHandlerResult ehRet = OC_EH_ERROR;
525 if (flag & OC_REQUEST_FLAG)
527 OIC_LOG (DEBUG, TAG, "Flag includes OC_REQUEST_FLAG");
528 switch (ehRequest->method)
531 ehRet = HandleAmaclGetRequest(ehRequest);
535 ehRet = HandleAmaclPostRequest(ehRequest);
540 SendSRMResponse(ehRequest, ehRet, NULL, 0);
548 * This internal method is used to create '/oic/sec/amacl' resource.
550 static OCStackResult CreateAmaclResource()
552 OCStackResult ret = OCCreateResource(&gAmaclHandle,
553 OIC_RSRC_TYPE_SEC_AMACL,
560 if (OC_STACK_OK != ret)
562 OIC_LOG (FATAL, TAG, "Unable to instantiate Amacl resource");
563 DeInitAmaclResource();
568 OCStackResult InitAmaclResource()
570 OCStackResult ret = OC_STACK_ERROR;
572 uint8_t *data = NULL;
574 ret = GetSecureVirtualDatabaseFromPS(OIC_JSON_AMACL_NAME, &data, &size);
576 // If database read failed
577 if (OC_STACK_OK != ret)
579 OIC_LOG(DEBUG, TAG, "ReadSVDataFromPS failed");
583 // Read AMACL resource from PS
584 ret = CBORPayloadToAmacl(data, size, &gAmacl);
585 if (OC_STACK_OK != ret)
587 OIC_LOG(DEBUG, TAG, "ReadAMACLresourcefromPS failed");
592 // Instantiate 'oic/sec/amacl' resource
593 ret = CreateAmaclResource();
595 if (OC_STACK_OK != ret)
597 DeInitAmaclResource();
602 void DeInitAmaclResource()
604 OCDeleteResource(gAmaclHandle);
607 DeleteAmaclList(gAmacl);
611 OCStackResult AmaclGetAmsDeviceId(const char *resource, OicUuid_t *amsDeviceId)
613 OicSecAmacl_t *amacl = NULL;
615 VERIFY_NON_NULL(TAG, resource, ERROR);
616 VERIFY_NON_NULL(TAG, amsDeviceId, ERROR);
618 LL_FOREACH(gAmacl, amacl)
620 for(size_t i = 0; i < amacl->resourcesLen; i++)
622 if (0 == strncmp((amacl->resources[i]), resource, strlen(amacl->resources[i])))
624 //Returning the ID of the first AMS service for the resource
625 memcpy(amsDeviceId, &amacl->amss[0], sizeof(*amsDeviceId));
632 return OC_STACK_ERROR;
635 OCStackResult SetAmaclRownerId(const OicUuid_t* newROwner)
637 OCStackResult ret = OC_STACK_ERROR;
638 uint8_t *cborPayload = NULL;
640 OicUuid_t prevId = {.id={0}};
642 if(NULL == newROwner)
644 ret = OC_STACK_INVALID_PARAM;
648 ret = OC_STACK_NO_RESOURCE;
651 if(newROwner && gAmacl)
653 memcpy(prevId.id, gAmacl->rownerID.id, sizeof(prevId.id));
654 memcpy(gAmacl->rownerID.id, newROwner->id, sizeof(newROwner->id));
656 ret = AmaclToCBORPayload(gAmacl, &cborPayload, &size);
657 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
659 ret = UpdateSecureResourceInPS(OIC_JSON_AMACL_NAME, cborPayload, size);
660 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
662 OICFree(cborPayload);
668 OICFree(cborPayload);
669 memcpy(gAmacl->rownerID.id, prevId.id, sizeof(prevId.id));
673 OCStackResult GetAmaclRownerId(OicUuid_t *rowneruuid)
675 OCStackResult retVal = OC_STACK_ERROR;
678 *rowneruuid = gAmacl->rownerID;
679 retVal = OC_STACK_OK;