Exemplo n.º 1
0
             var req = document.getElementById('request');
             console.log("Register callback", data);
             if(data.errorCode && data.errorCode != 0) {
                 alert("registration failed with errror: " + data.errorCode);
                 return;
             }
             reg.value=JSON.stringify(data);
             req.value=JSON.stringify(request);
             form.submit();
         });
     }, 1000);
     <?php 
 } else {
     if ($_POST['doRegister']) {
         try {
             $data = $u2f->doRegister(json_decode($_POST['request']), json_decode($_POST['doRegister']));
             echo "var registration = '" . json_encode($data) . "';\n";
             ?>
     addRegistration(registration);
     alert("registration successful!");
     <?php 
         } catch (u2flib_server\Error $e) {
             echo "alert('error:" . $e->getMessage() . "');\n";
         }
     } else {
         if (isset($_POST['startAuthenticate'])) {
             $regs = json_decode($_POST['registrations']);
             $data = $u2f->getAuthenticateData($regs);
             echo "var registrations = " . $_POST['registrations'] . ";\n";
             echo "var request = " . json_encode($data) . ";\n";
             ?>
Exemplo n.º 2
0
         console.log("Authenticate callback", data);
         auth.value=JSON.stringify(data);
         user.value = username;
         form.submit();
     });
 }, 1000);
 <?php 
                 } catch (Exception $e) {
                     echo "alert('error: " . $e->getMessage() . "');";
                 }
                 break;
         }
     } else {
         if ($_POST['register2']) {
             try {
                 $reg = $u2f->doRegister(json_decode($_SESSION['regReq']), json_decode($_POST['register2']));
                 addReg($user->id, $reg);
             } catch (Exception $e) {
                 echo "alert('error: " . $e->getMessage() . "');";
             } finally {
                 $_SESSION['regReq'] = null;
             }
         } else {
             if ($_POST['authenticate2']) {
                 try {
                     $reg = $u2f->doAuthenticate(json_decode($_SESSION['authReq']), getRegs($user->id), json_decode($_POST['authenticate2']));
                     updateReg($reg);
                     echo "alert('success: " . $reg->counter . "');";
                 } catch (Exception $e) {
                     echo "alert('error: " . $e->getMessage() . "');";
                 } finally {
Exemplo n.º 3
0
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage $include_cert of doRegister() method only accepts boolean.
  */
 public function testDoRegisterInvalidInclude_cert()
 {
     $req = json_decode('{"version":"U2F_V2","challenge":"yKA0x075tjJ-GE7fKTfnzTOSaNUOWQxRd9TWz5aFOg8","appId":"http://demo.example.com"}');
     $resp = json_decode('{ "registrationData": "BQQtEmhWVgvbh-8GpjsHbj_d5FB9iNoRL8mNEq34-ANufKWUpVdIj6BSB_m3eMoZ3GqnaDy3RA5eWP8mhTkT1Ht3QAk1GsmaPIQgXgvrBkCQoQtMFvmwYPfW5jpRgoMPFxquHS7MTt8lofZkWAK2caHD-YQQdaRBgd22yWIjPuWnHOcwggLiMIHLAgEBMA0GCSqGSIb3DQEBCwUAMB0xGzAZBgNVBAMTEll1YmljbyBVMkYgVGVzdCBDQTAeFw0xNDA1MTUxMjU4NTRaFw0xNDA2MTQxMjU4NTRaMB0xGzAZBgNVBAMTEll1YmljbyBVMkYgVGVzdCBFRTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABNsK2_Uhx1zOY9ym4eglBg2U5idUGU-dJK8mGr6tmUQflaNxkQo6IOc-kV4T6L44BXrVeqN-dpCPr-KKlLYw650wDQYJKoZIhvcNAQELBQADggIBAJVAa1Bhfa2Eo7TriA_jMA8togoA2SUE7nL6Z99YUQ8LRwKcPkEpSpOsKYWJLaR6gTIoV3EB76hCiBaWN5HV3-CPyTyNsM2JcILsedPGeHMpMuWrbL1Wn9VFkc7B3Y1k3OmcH1480q9RpYIYr-A35zKedgV3AnvmJKAxVhv9GcVx0_CewHMFTryFuFOe78W8nFajutknarupekDXR4tVcmvj_ihJcST0j_Qggeo4_3wKT98CgjmBgjvKCd3Kqg8n9aSDVWyaOZsVOhZj3Fv5rFu895--D4qiPDETozJIyliH-HugoQpqYJaTX10mnmMdCa6aQeW9CEf-5QmbIP0S4uZAf7pKYTNmDQ5z27DVopqaFw00MIVqQkae_zSPX4dsNeeoTTXrwUGqitLaGap5ol81LKD9JdP3nSUYLfq0vLsHNDyNgb306TfbOenRRVsgQS8tJyLcknSKktWD_Qn7E5vjOXprXPrmdp7g5OPvrbz9QkWa1JTRfo2n2AXV02LPFc-UfR9bWCBEIJBxvmbpmqt0MnBTHWnth2b0CU_KJTDCY3kAPLGbOT8A4KiI73pRW-e9SWTaQXskw3Ei_dHRILM_l9OXsqoYHJ4Dd3tbfvmjoNYggSw4j50l3unI9d1qR5xlBFpW5sLr8gKX4bnY4SR2nyNiOQNLyPc0B0nW502aMEUCIQDTGOX-i_QrffJDY8XvKbPwMuBVrOSO-ayvTnWs_WSuDQIgZ7fMAvD_Ezyy5jg6fQeuOkoJi8V2naCtzV-HTly8Nww=", "clientData": "eyAiY2hhbGxlbmdlIjogInlLQTB4MDc1dGpKLUdFN2ZLVGZuelRPU2FOVU9XUXhSZDlUV3o1YUZPZzgiLCAib3JpZ2luIjogImh0dHA6XC9cL2RlbW8uZXhhbXBsZS5jb20iLCAidHlwIjogIm5hdmlnYXRvci5pZC5maW5pc2hFbnJvbGxtZW50IiB9" }');
     $this->u2f->doRegister($req, $resp, 'bar');
 }
Exemplo n.º 4
0
if (array_key_exists('r', $options)) {
    $mode = "register";
} elseif (array_key_exists('a', $options)) {
    if (!array_key_exists('R', $options)) {
        print "a registration must be supplied with -R";
        exit(1);
    }
    $regs = json_decode('[' . $options['R'] . ']');
    $mode = "authenticate";
} else {
    print "-r or -a must be used\n";
    exit(1);
}
if (!array_key_exists('o', $options)) {
    print "origin must be supplied with -o\n";
    exit(1);
}
$u2f = new u2flib_server\U2F($options['o']);
if ($mode === "register") {
    $challenge = $u2f->getRegisterData();
} elseif ($mode === "authenticate") {
    $challenge = $u2f->getAuthenticateData($regs);
}
print json_encode($challenge[0]) . "\n";
$response = fgets(STDIN);
if ($mode === "register") {
    $result = $u2f->doRegister($challenge[0], json_decode($response));
} elseif ($mode === "authenticate") {
    $result = $u2f->doAuthenticate($challenge, $regs, json_decode($response));
}
print json_encode($result) . "\n";