Asynchronous User Confirm
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / sample / sampleserver_mfg.cpp
index 90ed672..88ff489 100644 (file)
@@ -46,6 +46,7 @@
 #include "pkix_interface.h"
 #include "hw_emul/hw_interface.h"
 #include "oxmverifycommon.h"
+#include "casecurityinterface.h"
 
 #define TAG "SAMPLE_MANUFACTURER_CERT"
 
@@ -405,9 +406,8 @@ void handleSigInt(int signum)
     }
 }
 
-OCStackResult confirmCB(void * ctx)
+OCStackResult confirmCB_thread()
 {
-    OC_UNUSED(ctx);
     for (;;)
     {
         int userConfirm;
@@ -423,17 +423,49 @@ OCStackResult confirmCB(void * ctx)
         }
         if (1 == userConfirm)
         {
+            SendUserConfirm(true);
             break;
         }
         else if (0 == userConfirm)
         {
-            return OC_STACK_USER_DENIED_REQ;
+            SendUserConfirm(false);
+            break;
         }
         printf("   Entered Wrong Number. Please Enter Again\n");
     }
     return OC_STACK_OK;
 }
 
+OCStackResult confirmCB(void * ctx)
+{
+    OC_UNUSED(ctx);
+    pthread_t threadId;
+    pthread_create (&threadId, NULL, &confirmCB_thread, NULL);
+    return OC_STACK_OK;
+}
+
+void confirmNoCertCB(CACertificateVerificationStatus_t status)
+{
+    if (CA_CERTIFICATE_VERIFY_SUCCESS_MUTUAL == status)
+    {
+        printf("   > Peer certificate verification successful");
+    }
+    else if (CA_CERTIFICATE_VERIFY_NO_CERT == status)
+    {
+        printf("   > Peer has not provided certificate\n");
+    }
+    else if (CA_CERTIFICATE_VERIFY_FAILED == status)
+    {
+        printf("   > Peer certificate verification failed\n");
+    }
+    return;
+}
+
+void informOxmSelCB(OicSecOxm_t oxmSel)\r
+{\r
+    printf("   > OXM selected: 0x%x\n", oxmSel);\r
+}\r
+\r
 FILE* server_fopen(const char *path, const char *mode)
 {
     (void)path;
@@ -476,7 +508,9 @@ int main(int argc, char **argv)
     // Initialize Persistent Storage for SVR database
     OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, unlink, NULL, NULL};
 
-    SetUserConfirmCB(NULL, confirmCB);
+    SetAsyncUserConfirmCB(NULL, confirmCB);
+    SetInformOxmSelCB(informOxmSelCB);
+    CAsetCertificateVerificationCallback(confirmNoCertCB);
 
     OCRegisterPersistentStorageHandler(&ps);