From 4d2c52c702f0229e91b92bb63a12e00976c6a140 Mon Sep 17 00:00:00 2001 From: Andrii Shtompel Date: Thu, 29 Sep 2016 16:41:20 +0300 Subject: [PATCH] [IOT-1347] OCCloudAclIdCreate or OCCloudAclIdGetByDevice API doesn't provide the ACL ID Directly Print aclId, gid, gp in external callbacks (application level, provisioning/sample module) Print acl, crl, group id list, invite response too. Change-Id: Ifb9f4ee996030894a31b4317c98a8159e345218b Signed-off-by: Andrii Shtompel Reviewed-on: https://gerrit.iotivity.org/gerrit/12563 Tested-by: jenkins-iotivity Reviewed-by: Kevin Kane Reviewed-by: Randeep Singh --- .../csdk/security/include/internal/crlresource.h | 7 + .../provisioning/sample/cloud/cloudCommon.c | 143 +++++++++++++++++++-- .../provisioning/sample/cloud/cloudWrapper.c | 52 ++++++++ .../provisioning/sample/cloud/cloudWrapper.h | 21 +++ .../csdk/security/provisioning/src/cloud/aclid.c | 2 +- .../security/provisioning/src/cloud/aclinvite.c | 5 - .../csdk/security/provisioning/src/cloud/crl.c | 2 +- resource/csdk/security/src/aclresource.c | 6 + resource/csdk/security/src/crlresource.c | 24 ++-- 9 files changed, 233 insertions(+), 29 deletions(-) diff --git a/resource/csdk/security/include/internal/crlresource.h b/resource/csdk/security/include/internal/crlresource.h index a2f135c..28ba5b1 100644 --- a/resource/csdk/security/include/internal/crlresource.h +++ b/resource/csdk/security/include/internal/crlresource.h @@ -120,6 +120,13 @@ void DeleteCrl(OicSecCrl_t *crl); */ OCStackResult getLastUpdateFromDB(char **lastUpdate); +/** + * This function prints OicSecCrl_t object + * + * @param crl crl object + */ +void printCrl(OicSecCrl_t *crl); + #ifdef __cplusplus } #endif diff --git a/resource/csdk/security/provisioning/sample/cloud/cloudCommon.c b/resource/csdk/security/provisioning/sample/cloud/cloudCommon.c index acf96ac..218922e 100644 --- a/resource/csdk/security/provisioning/sample/cloud/cloudCommon.c +++ b/resource/csdk/security/provisioning/sample/cloud/cloudCommon.c @@ -27,6 +27,8 @@ #include "cathreadpool.h" #include "ocpayload.h" #include "payload_logging.h" +#include "aclresource.h" +#include "crlresource.h" #include "ocprovisioningmanager.h" #include "utils.h" @@ -49,7 +51,7 @@ #define GITHUB_AUTH_LINK "https://github.com/login?return_to=%2Flogin%2Foauth%2Fauthorize%3Fclient_id%3Dea9c18f540323b0213d0%26redirect_uri%3Dhttp%253A%252F%252Fwww.example.com%252Foauth_callback%252F" -#define CLIENT_ONLY(mode) if (OC_SERVER == mode) { wrongRequest(); break; } +#define CLIENT_ONLY(mode) if (OC_SERVER == (mode)) { wrongRequest(); sendDataToServer = false; break; } static bool fExit = false; @@ -223,6 +225,106 @@ static void handleCB(void* ctx, OCStackResult result, void* data) unlockMenu(NULL); } +/** + * This function prints Acl id and calls default callback function handleCB() + * + * @param[in] ctx context + * @param[in] result result + * @param[in] aclId acl id + */ +static void handleAclIdCB(void* ctx, OCStackResult result, void* aclId) +{ + OIC_LOG_V(INFO, TAG, "Received Acl id = %s", (char *)aclId); + handleCB(ctx, result, aclId); + OICFree(aclId); +} + +/** + * This function prints group id and calls default callback function handleCB() + * + * @param[in] ctx context + * @param[in] result result + * @param[in] groupId group id + */ +static void handleAclCreateGroupCB(void* ctx, OCStackResult result, void* groupId) +{ + OIC_LOG_V(INFO, TAG, "Received gid = %s", (char *)groupId); + handleCB(ctx, result, groupId); + OICFree(groupId); +} + +/** + * This function prints group policy and calls default callback function handleCB() + * + * @param[in] ctx context + * @param[in] result result + * @param[in] gp group policy + */ +static void handleAclPolicyCheckCB(void* ctx, OCStackResult result, void* gp) +{ + OIC_LOG_V(INFO, TAG, "Received gp = %s", (char *)gp); + handleCB(ctx, result, gp); + OICFree(gp); +} + +/** + * This function prints received acl and calls default callback function handleCB() + * + * @param[in] ctx context + * @param[in] result result + * @param[in] acl acl + */ +static void handleAclIndividualGetInfoCB(void* ctx, OCStackResult result, void* acl) +{ + printACL((OicSecAcl_t* )acl); + handleCB(ctx, result, acl); + //can't delete acl here because its ACE's were added to gAcl + //TODO: changes in aclresources.c required to fix that +} + +/** + * This function prints received group id list and calls default callback function handleCB() + * + * @param[in] ctx context + * @param[in] result result + * @param[in] gidList group id list + */ +static void handleAclFindMyGroupCB(void* ctx, OCStackResult result, void* gidList) +{ + printStringArray((stringArray_t *)gidList); + handleCB(ctx, result, gidList); + clearStringArray((stringArray_t *)gidList); +} + +/** + * This function prints received acl and calls default callback function handleCB() + * + * @param[in] ctx context + * @param[in] result result + * @param[in] crl crl + */ +static void handleGetCrlCB(void* ctx, OCStackResult result, void* crl) +{ + printCrl((OicSecCrl_t *)crl); + handleCB(ctx, result, crl); + DeleteCrl((OicSecCrl_t *)crl); +} + +/** + * This function prints received invitation response and calls default callback function handleCB() + * + * @param[in] ctx context + * @param[in] result result + * @param[in] invite invitation response (it has inviteResponse_t* type) + */ +static void handleAclGetInvitationCB(void* ctx, OCStackResult result, void* invite) +{ + printInviteResponse((inviteResponse_t *)invite); + handleCB(ctx, result, invite); + clearInviteResponse((inviteResponse_t *)invite); + OICFree(invite); +} + static OCStackResult saveTrustCert(void) { OCStackResult res = OC_STACK_ERROR; @@ -275,6 +377,7 @@ static void userRequests(void *data) while (false == fExit) { OCStackResult res = OC_STACK_ERROR; + bool sendDataToServer = true; timeout = DEFAULT_RESPONSE_WAIT_TIME; //startup report printf("-----------------------------------------------------------\n"); @@ -307,6 +410,7 @@ static void userRequests(void *data) break; case HOST: readString(endPoint.addr, sizeof(endPoint.addr), "host ip address", DEFAULT_HOST); + sendDataToServer = false; break; case PORT: { @@ -315,19 +419,20 @@ static void userRequests(void *data) int tmp = 0; readInteger(&tmp, "port number", example); endPoint.port = tmp; + sendDataToServer = false; } break; case CRL_GET: - res = OCWrapperGetCRL(&endPoint, handleCB); + res = OCWrapperGetCRL(&endPoint, handleGetCrlCB); break; case CRL_POST: res = OCWrapperPostCRL(&endPoint, handleCB); break; case ACL_GROUP_CREATE: - res = OCWrapperAclCreateGroup(&endPoint, handleCB); + res = OCWrapperAclCreateGroup(&endPoint, handleAclCreateGroupCB); break; case ACL_GROUP_FIND: - res = OCWrapperAclFindMyGroup(&endPoint, handleCB); + res = OCWrapperAclFindMyGroup(&endPoint, handleAclFindMyGroupCB); break; case ACL_GROUP_DELETE: res = OCWrapperAclDeleteGroup(&endPoint, handleCB); @@ -351,7 +456,7 @@ static void userRequests(void *data) res = OCWrapperAclInviteUser(&endPoint, handleCB); break; case ACL_GROUP_GET_INVITE: - res = OCWrapperAclGetInvitation(&endPoint, handleCB); + res = OCWrapperAclGetInvitation(&endPoint, handleAclGetInvitationCB); break; case ACL_GROUP_DELETE_INVITE: res = OCWrapperAclDeleteInvitation(&endPoint, handleCB); @@ -360,19 +465,19 @@ static void userRequests(void *data) res = OCWrapperAclCancelInvitation(&endPoint, handleCB); break; case ACL_POLICY_CHECK_REQUEST: - res = OCWrapperAclPolicyCheck(&endPoint, handleCB); + res = OCWrapperAclPolicyCheck(&endPoint, handleAclPolicyCheckCB); break; case ACL_ID_GET_BY_DEVICE: - res = OCWrapperAclIdGetByDevice(&endPoint, handleCB); + res = OCWrapperAclIdGetByDevice(&endPoint, handleAclIdCB); break; case ACL_ID_CREATE: - res = OCWrapperAclIdCreate(&endPoint, handleCB); + res = OCWrapperAclIdCreate(&endPoint, handleAclIdCB); break; case ACL_ID_DELETE: res = OCWrapperAclIdDelete(&endPoint, handleCB); break; case ACL_INDIVIDUAL_GET_INFO: - res = OCWrapperAclIndividualGetInfo(&endPoint, handleCB); + res = OCWrapperAclIndividualGetInfo(&endPoint, handleAclIndividualGetInfoCB); break; case ACL_INDIVIDUAL_UPDATE_ACE: res = OCWrapperAclIndividualUpdateAce(&endPoint, handleCB); @@ -401,33 +506,45 @@ static void userRequests(void *data) break; case USE_RSA: CASelectCipherSuite(0x35, CA_ADAPTER_TCP); + sendDataToServer = false; break; case SAVE_TRUST_CERT: saveTrustCert(); + sendDataToServer = false; break; case USE_SECURE_CONN: { int tmp = 0; readInteger(&tmp, "CoAP protocol type", "0 - non-secure, 1 - secure"); setCoapPrefix(0 == tmp ? false : true); + sendDataToServer = false; } break; case EXIT: ca_mutex_free(mutex); ca_cond_free(cond); fExit = true; + sendDataToServer = false; break; default: wrongRequest(); + sendDataToServer = false; break; } //if requests were sent then wait response - if (res == OC_STACK_OK) + if (sendDataToServer) { - ca_mutex_lock(mutex); - ca_cond_wait_for(cond, mutex, timeout); - ca_mutex_unlock(mutex); + if (OC_STACK_OK == res) + { + ca_mutex_lock(mutex); + ca_cond_wait_for(cond, mutex, timeout); + ca_mutex_unlock(mutex); + } + else + { + OIC_LOG_V(ERROR, TAG, "Request returned an error %d", res); + } } } } diff --git a/resource/csdk/security/provisioning/sample/cloud/cloudWrapper.c b/resource/csdk/security/provisioning/sample/cloud/cloudWrapper.c index 50f32ec..8fb0923 100644 --- a/resource/csdk/security/provisioning/sample/cloud/cloudWrapper.c +++ b/resource/csdk/security/provisioning/sample/cloud/cloudWrapper.c @@ -3,6 +3,7 @@ #include "oic_malloc.h" #include "oic_string.h" #include "srmutility.h" +#include "aclresource.h" #include "utlist.h" #include "utils.h" @@ -160,6 +161,57 @@ static void readOptionalStringArray(stringArray_t *list, int length, const char* } } +void printStringArray(stringArray_t *list) +{ + if (NULL == list) + { + OIC_LOG(INFO, TAG, "Received NULL list"); + return; + } + + OIC_LOG_V(INFO, TAG, "List contains %zu items", list->length); + + for (size_t i = 0; i < list->length; i++) + { + OIC_LOG_V(INFO, TAG, "item[%zu] = %s", i, list->array[i]); + } +} + +void printInviteResponse(inviteResponse_t *in) +{ + if (NULL == in) + { + OIC_LOG(INFO, TAG, "Received NULL invitation response"); + return; + } + + OIC_LOG(INFO, TAG, "Received next invite gid list:"); + printStringArray(&in->invite.gidlist); + + OIC_LOG(INFO, TAG, "Received next invite mid list:"); + printStringArray(&in->invite.midlist); + + OIC_LOG(INFO, TAG, "Received next invited gid list:"); + printStringArray(&in->invited.gidlist); + + OIC_LOG(INFO, TAG, "Received next invited mid list:"); + printStringArray(&in->invited.midlist); +} + +void clearInviteResponse(inviteResponse_t *in) +{ + if (NULL == in) + { + return; + } + + clearStringArray(&in->invite.gidlist); + clearStringArray(&in->invite.midlist); + + clearStringArray(&in->invited.gidlist); + clearStringArray(&in->invited.midlist); +} + bool readFile(const char *name, OCByteString *out) { FILE *file = NULL; diff --git a/resource/csdk/security/provisioning/sample/cloud/cloudWrapper.h b/resource/csdk/security/provisioning/sample/cloud/cloudWrapper.h index a40a815..26613be 100644 --- a/resource/csdk/security/provisioning/sample/cloud/cloudWrapper.h +++ b/resource/csdk/security/provisioning/sample/cloud/cloudWrapper.h @@ -248,4 +248,25 @@ void readInteger(int* item, const char* description, const char* example); * */ int readFile(const char *name, OCByteString *out); +/** + * Print array of strings + * + * @param[in] list array of strings + */ +void printStringArray(stringArray_t *list); + +/** + * Print invitation response + * + * @param[in] in invitation response + */ +void printInviteResponse(inviteResponse_t *in); + +/** + * Clear invitation response + * + * @param[in] in invitation response + */ +void clearInviteResponse(inviteResponse_t *in); + #endif //OC_CLOUD_WRAPPER_H diff --git a/resource/csdk/security/provisioning/src/cloud/aclid.c b/resource/csdk/security/provisioning/src/cloud/aclid.c index c85c478..58b0ddc 100644 --- a/resource/csdk/security/provisioning/src/cloud/aclid.c +++ b/resource/csdk/security/provisioning/src/cloud/aclid.c @@ -180,8 +180,8 @@ static OCStackResult handleAclGetInfoResponse(void *ctx, void **data, OCClientRe OIC_LOG(ERROR, TAG, "Can't update ACL resource"); } + *data = acl; exit: - //can't delete acl because aces was added to gAcl OICFree(cbor); return result; } diff --git a/resource/csdk/security/provisioning/src/cloud/aclinvite.c b/resource/csdk/security/provisioning/src/cloud/aclinvite.c index 618734e..5a6933f 100644 --- a/resource/csdk/security/provisioning/src/cloud/aclinvite.c +++ b/resource/csdk/security/provisioning/src/cloud/aclinvite.c @@ -135,12 +135,7 @@ static OCStackResult handleAclGetInvitationResponse(void *ctx, void **data, OCCl } *data = answer; - exit: - if (result != OC_STACK_OK) - { - OICFree(answer); - } return result; } diff --git a/resource/csdk/security/provisioning/src/cloud/crl.c b/resource/csdk/security/provisioning/src/cloud/crl.c index 3c444dc..786b59d 100644 --- a/resource/csdk/security/provisioning/src/cloud/crl.c +++ b/resource/csdk/security/provisioning/src/cloud/crl.c @@ -61,8 +61,8 @@ static OCStackResult handleCrlGetResponse(void *ctx, void **data, OCClientRespon OIC_LOG(ERROR, TAG, "Can't update Crl resource"); } + *data = crl; exit: - DeleteCrl(crl); return result; } diff --git a/resource/csdk/security/src/aclresource.c b/resource/csdk/security/src/aclresource.c index 74646bc..a41f99e 100644 --- a/resource/csdk/security/src/aclresource.c +++ b/resource/csdk/security/src/aclresource.c @@ -2188,6 +2188,12 @@ void printACL(const OicSecAcl_t* acl) { OIC_LOG(INFO, TAG, "Print ACL:"); + if (NULL == acl) + { + OIC_LOG(INFO, TAG, "Received NULL acl"); + return; + } + char *rowner = NULL; if (OC_STACK_OK == ConvertUuidToStr(&acl->rownerID, &rowner)) { diff --git a/resource/csdk/security/src/crlresource.c b/resource/csdk/security/src/crlresource.c index 6b1aaff..46a82fb 100644 --- a/resource/csdk/security/src/crlresource.c +++ b/resource/csdk/security/src/crlresource.c @@ -75,16 +75,22 @@ void DeleteCrl(OicSecCrl_t *crl) } } -static void printCrl(const OicSecCrl_t *crl) +void printCrl(OicSecCrl_t *crl) { - OIC_LOG(DEBUG, TAG, "Crl object contain:"); - OIC_LOG_V(DEBUG, TAG, "id = %d", crl->CrlId); - OIC_LOG_V(DEBUG, TAG, "this update = %s", crl->ThisUpdate.data); - - OIC_LOG(DEBUG, TAG, "crl:"); - OIC_LOG_V(DEBUG, TAG, "encoding = %d", crl->CrlData.encoding); - OIC_LOG_V(DEBUG, TAG, "data (length = %zu):", crl->CrlData.len); - OIC_LOG_BUFFER(DEBUG, TAG, crl->CrlData.data, crl->CrlData.len); + if (NULL == crl) + { + OIC_LOG(INFO, TAG, "Received NULL CRL"); + return; + } + + OIC_LOG(INFO, TAG, "Crl object contain:"); + OIC_LOG_V(INFO, TAG, "id = %d", crl->CrlId); + OIC_LOG_V(INFO, TAG, "this update = %s", crl->ThisUpdate.data); + + OIC_LOG(INFO, TAG, "crl:"); + OIC_LOG_V(INFO, TAG, "encoding = %d", crl->CrlData.encoding); + OIC_LOG_V(INFO, TAG, "data (length = %zu):", crl->CrlData.len); + OIC_LOG_BUFFER(INFO, TAG, crl->CrlData.data, crl->CrlData.len); } static bool copyByteArray(const uint8_t *in, size_t in_len, uint8_t **out, size_t *out_len) -- 2.7.4