} UserConfirmContext_t;
/**
+ * Context for getting user confirmation
+ */
+typedef struct UserAsyncConfirmContext
+{
+ UserConfirmCallback callback;
+ void * context;
+ bool userConfirmResult;
+ bool userConfirm;
+} UserAsyncConfirmContext_t;
+
+/**
* Context for notifying user input state
*/
typedef struct InputStateContext
void SetUserConfirmCB(void * ptr, UserConfirmCallback userConfirmCB);
/**
+ * Set asynchronous callback for getting user confirmation
+ */
+void SetAsyncUserConfirmCB(void * ptr, UserConfirmCallback userConfirmCB);
+
+/**
* Unset Callback for getting user confirmation
*/
void* UnsetUserConfirmCB();
/**
+ * Unset asynchronous callback for getting user confirmation
+ */
+void* UnsetAsyncUserConfirmCB();
+
+/**
* Set Callback for notifying user input state
*/
void SetInputStateCB(void * ptr, UserConfirmCallback userConfirmCB);
VerifyOptionBitmask_t verifyOption);
/**
+ * Call the Asynchronius Callback for Verifying Ownership Transfer process.
+ */
+OCStackResult VerifyUserConfirm();
+
+/**
+ * Get user asynchronous verification result
+ */
+void GetAsyncVerifyUserResult(bool * result, bool * confirm);
+
+/**
* Call the Callback for notifying user input state
*/
OCStackResult NotifyInputState(void);
+/**
+ * Callback to set user confirmation result.
+ *
+ * @param ctx Asynchronous confirmation context.
+ * @param confirmed User confirmation result.
+ *
+ * @retVal ::OC_STACK_OK
+ */
+OCStackResult SendUserConfirm(bool confirmed);
+
#ifdef __cplusplus
}
#endif
#include "pinoxmcommon.h"
#include "oxmverifycommon.h"
#include "octhread.h"
+#include "oic_time.h"
+#include "oic_string.h"
#if defined(__WITH_DTLS__) || defined (__WITH_TLS__)
#include "pkix_interface.h"
static oc_mutex g_mutexDoxm = NULL;
static bool g_isDoxmNull = false;
static OCResourceHandle gDoxmHandle = NULL;
+static oc_mutex g_mutexWait;
+static oc_thread g_waitConfirmThreadId;
+oc_cond g_condWait;
static InformOxmSelectedCallback_t g_InformOxmSelectedCallback = NULL;
static OicSecOxm_t gOicSecDoxmJustWorks = OIC_JUST_WORKS;
OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
}
+#if defined(__WITH_DTLS__) || defined (__WITH_TLS__)
+static OCEntityHandlerResult HandleDoxmPostRequest(OCEntityHandlerRequest * ehRequest);
+
+void * WaitConfirm(OCEntityHandlerRequest * ehRequest)
+{
+ bool confirmResult = false, confirmState = false;
+
+ oc_mutex_lock(g_mutexWait);
+ oc_cond_wait(g_condWait, g_mutexWait);
+ oc_cond_free(g_condWait);
+ oc_mutex_free(g_mutexWait);
+
+ GetAsyncVerifyUserResult(&confirmResult, &confirmState);
+ if (confirmResult == true)
+ {
+ gConfirmState = CONFIRM_STATE_ACCEPTED;
+ HandleDoxmPostRequest(ehRequest);
+ return NULL;
+ }
+ else
+ {
+ gConfirmState = CONFIRM_STATE_DENIED;
+ HandleDoxmPostRequest(ehRequest);
+ return NULL;
+ }
+}
+
+static OCEntityHandlerRequest *CopyRequest(OCEntityHandlerRequest *entityHandlerRequest)
+{
+ OIC_LOG(INFO, TAG, "Copying received request for slow response");
+
+ if (!entityHandlerRequest)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s: entityHandlerRequest is NULL", __func__);
+ return NULL;
+ }
+
+ OCEntityHandlerRequest *copyOfRequest =
+ (OCEntityHandlerRequest *)OICMalloc(sizeof(OCEntityHandlerRequest));
+ if(!copyOfRequest)
+ {
+ OIC_LOG(ERROR, TAG, "Copy failed due to allocation failure");
+ return NULL;
+ }
+
+ memcpy(copyOfRequest, entityHandlerRequest, sizeof(OCEntityHandlerRequest));
+
+ if (entityHandlerRequest->query)
+ {
+ copyOfRequest->query = OICStrdup(entityHandlerRequest->query);
+ if(!copyOfRequest->query)
+ {
+ OIC_LOG(ERROR, TAG, "Copy failed due to allocation failure");
+ OICFree(copyOfRequest);
+ return NULL;
+ }
+ }
+
+ if (entityHandlerRequest->payload)
+ {
+ copyOfRequest->payload =
+ (OCSecurityPayload *)OICMalloc(sizeof(OCSecurityPayload));
+ if(!copyOfRequest->payload)
+ {
+ OIC_LOG(ERROR, TAG, "Copy failed due to allocation failure");
+ OICFree(copyOfRequest->query);
+ OICFree(copyOfRequest);
+ return NULL;
+ }
+
+ if (((OCSecurityPayload *)copyOfRequest->payload)->securityData &&
+ ((OCSecurityPayload *)entityHandlerRequest->payload)->payloadSize)
+ {
+ ((OCSecurityPayload *)copyOfRequest->payload)->securityData =
+ (uint8_t *)OICMalloc(((OCSecurityPayload *)entityHandlerRequest->payload)->payloadSize);
+ if(!((OCSecurityPayload *)copyOfRequest->payload)->securityData)
+ {
+ OIC_LOG(ERROR, TAG, "Copy failed due to allocation failure");
+ OICFree(copyOfRequest->payload);
+ OICFree(copyOfRequest->query);
+ OICFree(copyOfRequest);
+ return NULL;
+ }
+
+ memcpy(((OCSecurityPayload *)copyOfRequest->payload)->securityData,
+ ((OCSecurityPayload *)entityHandlerRequest->payload)->securityData,
+ ((OCSecurityPayload *)entityHandlerRequest->payload)->payloadSize);
+
+ ((OCSecurityPayload *)(copyOfRequest->payload))->payloadSize =
+ ((OCSecurityPayload *)(entityHandlerRequest->payload))->payloadSize;
+
+ memcpy(((OCSecurityPayload *)copyOfRequest->payload)->securityData,
+ ((OCSecurityPayload *)entityHandlerRequest->payload)->securityData,
+ ((OCSecurityPayload *)entityHandlerRequest->payload)->payloadSize);
+ }
+
+ copyOfRequest->payload->type = entityHandlerRequest->payload->type;
+ copyOfRequest->messageID = entityHandlerRequest->messageID;
+ }
+
+ // Ignore vendor specific header options for example
+ copyOfRequest->numRcvdVendorSpecificHeaderOptions = 0;
+ copyOfRequest->rcvdVendorSpecificHeaderOptions = NULL;
+
+ if (copyOfRequest)
+ {
+ OIC_LOG(INFO, TAG, "Copied client request");
+ }
+ else
+ {
+ OIC_LOG(ERROR, TAG, "Error copying client request");
+ }
+ return copyOfRequest;
+}
+#endif // defined(__WITH_DTLS__) || defined (__WITH_TLS__)
+
static OCEntityHandlerResult HandleDoxmPostRequest(OCEntityHandlerRequest * ehRequest)
{
OIC_LOG (DEBUG, TAG, "Doxm EntityHandle processing POST request");
#if defined(__WITH_DTLS__) || defined (__WITH_TLS__)
else if (OIC_MANUFACTURER_CERTIFICATE == newDoxm->oxmSel || OIC_CON_MFG_CERT == newDoxm->oxmSel)
{
- //Get user confirmation
- if (false == newDoxm->owned &&
- false == isDuplicatedMsg &&
- memcmp(&(newDoxm->owner), &emptyOwner, sizeof(OicUuid_t)) != 0)
+ if (CONFIRM_STATE_ACCEPTED != gConfirmState && CONFIRM_STATE_DENIED != gConfirmState)
{
- gConfirmMsgId = ehRequest->messageID;
- gConfirmState = CONFIRM_STATE_WAIT;
- if (OC_STACK_OK != VerifyOwnershipTransfer(NULL, USER_CONFIRM))
+ //Get user confirmation
+ if (false == newDoxm->owned &&
+ false == isDuplicatedMsg &&
+ memcmp(&(newDoxm->owner), &emptyOwner, sizeof(OicUuid_t)) != 0)
{
- ehRet = OC_EH_NOT_ACCEPTABLE;
- gConfirmState = CONFIRM_STATE_DENIED;
- goto exit;
- }
- else
- {
- ehRet = OC_EH_OK;
- gConfirmState = CONFIRM_STATE_ACCEPTED;
+ gConfirmMsgId = ehRequest->messageID;
+ gConfirmState = CONFIRM_STATE_WAIT;
+
+ if (OC_STACK_OK != VerifyUserConfirm())
+ {
+ if (OC_STACK_OK != VerifyOwnershipTransfer(NULL, USER_CONFIRM))
+ {
+ ehRet = OC_EH_NOT_ACCEPTABLE;
+ gConfirmState = CONFIRM_STATE_DENIED;
+ goto exit;
+ }
+ }
+ else
+ {
+ OCEntityHandlerRequest * ehRequestCopy = CopyRequest(ehRequest);
+ VERIFY_NON_NULL(TAG, ehRequestCopy, ERROR);
+
+ g_condWait = oc_cond_new();
+ g_mutexWait = oc_mutex_new();
+ if (oc_thread_new (&g_waitConfirmThreadId, WaitConfirm, ehRequestCopy))
+ {
+ oc_thread_detach(g_waitConfirmThreadId);
+ }
+ return OC_EH_SLOW;
+ }
}
}
+ else if (CONFIRM_STATE_DENIED == gConfirmState)
+ {
+ ehRet = OC_EH_NOT_ACCEPTABLE;
+ goto exit;
+ }
//Save the owner's UUID to derive owner credential
memcpy(&(gDoxm->owner), &(newDoxm->owner), sizeof(OicUuid_t));
#include "srmresourcestrings.h"
#include "cainterface.h"
#include "oxmverifycommon.h"
+#include "octhread.h"
#define TAG "OIC_VERIFY_COMMON"
static DisplayNumContext_t gDisplayNumContext = { .callback = NULL, .context = NULL };
static UserConfirmContext_t gUserConfirmContext = { .callback = NULL, .context = NULL };
+static UserAsyncConfirmContext_t gUserAsyncConfirmContext = { .callback = NULL, .context = NULL, .userConfirm = false, .userConfirmResult = false };
static InputStateContext_t gInputStateContext = { .callback = NULL, .context = NULL };
+extern oc_cond g_condWait;
void SetDisplayNumCB(void * ptr, DisplayNumCallback displayNumCB)
{
return OC_STACK_OK;
}
+OCStackResult VerifyUserConfirm()
+{
+ OIC_LOG(DEBUG, TAG, "IN VerifyUserConfirm");
+ OIC_LOG_V(DEBUG, TAG, "gVerifyOption: %d", (int) gVerifyOption);
+ if (gVerifyOption)
+ {
+ if (!gUserAsyncConfirmContext.callback)
+ {
+ OIC_LOG(ERROR, TAG, "Callback to get user confirmation not registered");
+ return OC_STACK_ERROR;
+ }
+ OIC_LOG(DEBUG, TAG, "calling userAsyncConfirmCallback");
+ gUserAsyncConfirmContext.callback(&gUserAsyncConfirmContext);
+ }
+ OIC_LOG(DEBUG, TAG, "OUT VerifyUserConfirm");
+ return OC_STACK_OK;
+}
+
+void GetAsyncVerifyUserResult(bool * result, bool * confirm)
+{
+ *result = gUserAsyncConfirmContext.userConfirmResult;
+ *confirm = gUserAsyncConfirmContext.userConfirm;
+ return;
+}
+
+void SetAsyncUserConfirmCB(void * ptr, UserConfirmCallback userConfirmCB)
+{
+ OIC_LOG(DEBUG, TAG, "IN SetAsyncUserConfirmCB");
+ if (NULL == userConfirmCB)
+ {
+ OIC_LOG(ERROR, TAG, "Failed to set callback to confirm mutualVerifNum");
+ return;
+ }
+ gUserAsyncConfirmContext.callback = userConfirmCB;
+ gUserAsyncConfirmContext.context = ptr;
+ OIC_LOG(DEBUG, TAG, "OUT SetAsyncUserConfirmCB");
+}
+
+void* UnsetAsyncUserConfirmCB()
+{
+ OIC_LOG(DEBUG, TAG, "IN UnsetAsyncUserConfirmCB");
+ void *prevctx = gUserAsyncConfirmContext.context;
+ gUserAsyncConfirmContext.callback = NULL;
+ gUserAsyncConfirmContext.context = NULL;
+ OIC_LOG(DEBUG, TAG, "OUT UnsetAsyncUserConfirmCB");
+ return prevctx;
+}
+
+OCStackResult SendUserConfirm(bool confirmed)
+{
+ gUserAsyncConfirmContext.userConfirmResult = confirmed;
+ gUserAsyncConfirmContext.userConfirm = true;
+ oc_cond_signal(g_condWait);
+ return OC_STACK_OK;
+}
+
OCStackResult NotifyInputState(void)
{
OIC_LOG_V(DEBUG, TAG, "IN %s", __func__);