@@ -94,15 +94,15 @@ discard block |
||
| 94 | 94 | <?php |
| 95 | 95 | |
| 96 | 96 | if($_SERVER['REQUEST_METHOD'] === 'POST') { |
| 97 | - if(!$_POST['username']) { |
|
| 97 | + if(!$_POST['username']) { |
|
| 98 | 98 | echo "alert('no username provided!');"; |
| 99 | - } else if(!isset($_POST['action']) && !isset($_POST['register2']) && !isset($_POST['authenticate2'])) { |
|
| 99 | + } else if(!isset($_POST['action']) && !isset($_POST['register2']) && !isset($_POST['authenticate2'])) { |
|
| 100 | 100 | echo "alert('no action provided!');"; |
| 101 | - } else { |
|
| 101 | + } else { |
|
| 102 | 102 | $user = createAndGetUser($_POST['username']); |
| 103 | 103 | |
| 104 | 104 | if(isset($_POST['action'])) { |
| 105 | - switch($_POST['action']): |
|
| 105 | + switch($_POST['action']): |
|
| 106 | 106 | case 'register': |
| 107 | 107 | try { |
| 108 | 108 | $data = $u2f->getRegisterData(getRegs($user->id)); |
@@ -130,11 +130,11 @@ discard block |
||
| 130 | 130 | }); |
| 131 | 131 | }, 1000); |
| 132 | 132 | <?php |
| 133 | - } catch( Exception $e ) { |
|
| 133 | + } catch( Exception $e ) { |
|
| 134 | 134 | echo "alert('error: " . $e->getMessage() . "');"; |
| 135 | - } |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - break; |
|
| 137 | + break; |
|
| 138 | 138 | |
| 139 | 139 | case 'authenticate': |
| 140 | 140 | try { |
@@ -157,34 +157,34 @@ discard block |
||
| 157 | 157 | }); |
| 158 | 158 | }, 1000); |
| 159 | 159 | <?php |
| 160 | - } catch( Exception $e ) { |
|
| 160 | + } catch( Exception $e ) { |
|
| 161 | 161 | echo "alert('error: " . $e->getMessage() . "');"; |
| 162 | - } |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - break; |
|
| 164 | + break; |
|
| 165 | 165 | |
| 166 | - endswitch; |
|
| 166 | + endswitch; |
|
| 167 | 167 | } else if($_POST['register2']) { |
| 168 | - try { |
|
| 168 | + try { |
|
| 169 | 169 | $reg = $u2f->doRegister(json_decode($_SESSION['regReq']), json_decode($_POST['register2'])); |
| 170 | 170 | addReg($user->id, $reg); |
| 171 | - } catch( Exception $e ) { |
|
| 171 | + } catch( Exception $e ) { |
|
| 172 | 172 | echo "alert('error: " . $e->getMessage() . "');"; |
| 173 | - } finally { |
|
| 173 | + } finally { |
|
| 174 | 174 | $_SESSION['regReq'] = null; |
| 175 | - } |
|
| 175 | + } |
|
| 176 | 176 | } else if($_POST['authenticate2']) { |
| 177 | - try { |
|
| 177 | + try { |
|
| 178 | 178 | $reg = $u2f->doAuthenticate(json_decode($_SESSION['authReq']), getRegs($user->id), json_decode($_POST['authenticate2'])); |
| 179 | 179 | updateReg($reg); |
| 180 | 180 | echo "alert('success: " . $reg->counter . "');"; |
| 181 | - } catch( Exception $e ) { |
|
| 181 | + } catch( Exception $e ) { |
|
| 182 | 182 | echo "alert('error: " . $e->getMessage() . "');"; |
| 183 | - } finally { |
|
| 183 | + } finally { |
|
| 184 | 184 | $_SESSION['authReq'] = null; |
| 185 | - } |
|
| 185 | + } |
|
| 186 | + } |
|
| 186 | 187 | } |
| 187 | - } |
|
| 188 | 188 | } |
| 189 | 189 | ?> |
| 190 | 190 | </script> |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | $pdo->exec("create table if not exists registrations (id integer primary key, user_id integer, keyHandle varchar(255), publicKey varchar(255), certificate text, counter integer)"); |
| 46 | 46 | |
| 47 | 47 | $scheme = isset($_SERVER['HTTPS']) ? "https://" : "http://"; |
| 48 | -$u2f = new u2flib_server\U2F($scheme . $_SERVER['HTTP_HOST']); |
|
| 48 | +$u2f = new u2flib_server\U2F($scheme.$_SERVER['HTTP_HOST']); |
|
| 49 | 49 | |
| 50 | 50 | session_start(); |
| 51 | 51 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $sel = $pdo->prepare("select * from users where name = ?"); |
| 55 | 55 | $sel->execute(array($name)); |
| 56 | 56 | $user = $sel->fetch(); |
| 57 | - if(!$user) { |
|
| 57 | + if (!$user) { |
|
| 58 | 58 | $ins = $pdo->prepare("insert into users (name) values(?)"); |
| 59 | 59 | $ins->execute(array($name)); |
| 60 | 60 | $sel->execute(array($name)); |
@@ -93,25 +93,25 @@ discard block |
||
| 93 | 93 | <script> |
| 94 | 94 | <?php |
| 95 | 95 | |
| 96 | - if($_SERVER['REQUEST_METHOD'] === 'POST') { |
|
| 97 | - if(!$_POST['username']) { |
|
| 96 | + if ($_SERVER['REQUEST_METHOD'] === 'POST') { |
|
| 97 | + if (!$_POST['username']) { |
|
| 98 | 98 | echo "alert('no username provided!');"; |
| 99 | - } else if(!isset($_POST['action']) && !isset($_POST['register2']) && !isset($_POST['authenticate2'])) { |
|
| 99 | + } else if (!isset($_POST['action']) && !isset($_POST['register2']) && !isset($_POST['authenticate2'])) { |
|
| 100 | 100 | echo "alert('no action provided!');"; |
| 101 | 101 | } else { |
| 102 | 102 | $user = createAndGetUser($_POST['username']); |
| 103 | 103 | |
| 104 | - if(isset($_POST['action'])) { |
|
| 105 | - switch($_POST['action']): |
|
| 104 | + if (isset($_POST['action'])) { |
|
| 105 | + switch ($_POST['action']): |
|
| 106 | 106 | case 'register': |
| 107 | 107 | try { |
| 108 | 108 | $data = $u2f->getRegisterData(getRegs($user->id)); |
| 109 | 109 | |
| 110 | - list($req,$sigs) = $data; |
|
| 110 | + list($req, $sigs) = $data; |
|
| 111 | 111 | $_SESSION['regReq'] = json_encode($req); |
| 112 | - echo "var req = " . json_encode($req) . ";"; |
|
| 113 | - echo "var sigs = " . json_encode($sigs) . ";"; |
|
| 114 | - echo "var username = '" . $user->name . "';"; |
|
| 112 | + echo "var req = ".json_encode($req).";"; |
|
| 113 | + echo "var sigs = ".json_encode($sigs).";"; |
|
| 114 | + echo "var username = '".$user->name."';"; |
|
| 115 | 115 | ?> |
| 116 | 116 | setTimeout(function() { |
| 117 | 117 | console.log("Register: ", req); |
@@ -130,8 +130,8 @@ discard block |
||
| 130 | 130 | }); |
| 131 | 131 | }, 1000); |
| 132 | 132 | <?php |
| 133 | - } catch( Exception $e ) { |
|
| 134 | - echo "alert('error: " . $e->getMessage() . "');"; |
|
| 133 | + } catch (Exception $e) { |
|
| 134 | + echo "alert('error: ".$e->getMessage()."');"; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | break; |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | $_SESSION['authReq'] = $reqs; |
| 144 | 144 | echo "var req = $reqs;"; |
| 145 | - echo "var username = '" . $user->name . "';"; |
|
| 145 | + echo "var username = '".$user->name."';"; |
|
| 146 | 146 | ?> |
| 147 | 147 | setTimeout(function() { |
| 148 | 148 | console.log("sign: ", req); |
@@ -157,29 +157,29 @@ discard block |
||
| 157 | 157 | }); |
| 158 | 158 | }, 1000); |
| 159 | 159 | <?php |
| 160 | - } catch( Exception $e ) { |
|
| 161 | - echo "alert('error: " . $e->getMessage() . "');"; |
|
| 160 | + } catch (Exception $e) { |
|
| 161 | + echo "alert('error: ".$e->getMessage()."');"; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | break; |
| 165 | 165 | |
| 166 | 166 | endswitch; |
| 167 | - } else if($_POST['register2']) { |
|
| 167 | + } else if ($_POST['register2']) { |
|
| 168 | 168 | try { |
| 169 | 169 | $reg = $u2f->doRegister(json_decode($_SESSION['regReq']), json_decode($_POST['register2'])); |
| 170 | 170 | addReg($user->id, $reg); |
| 171 | - } catch( Exception $e ) { |
|
| 172 | - echo "alert('error: " . $e->getMessage() . "');"; |
|
| 171 | + } catch (Exception $e) { |
|
| 172 | + echo "alert('error: ".$e->getMessage()."');"; |
|
| 173 | 173 | } finally { |
| 174 | 174 | $_SESSION['regReq'] = null; |
| 175 | 175 | } |
| 176 | - } else if($_POST['authenticate2']) { |
|
| 176 | + } else if ($_POST['authenticate2']) { |
|
| 177 | 177 | try { |
| 178 | 178 | $reg = $u2f->doAuthenticate(json_decode($_SESSION['authReq']), getRegs($user->id), json_decode($_POST['authenticate2'])); |
| 179 | 179 | updateReg($reg); |
| 180 | - echo "alert('success: " . $reg->counter . "');"; |
|
| 181 | - } catch( Exception $e ) { |
|
| 182 | - echo "alert('error: " . $e->getMessage() . "');"; |
|
| 180 | + echo "alert('success: ".$reg->counter."');"; |
|
| 181 | + } catch (Exception $e) { |
|
| 182 | + echo "alert('error: ".$e->getMessage()."');"; |
|
| 183 | 183 | } finally { |
| 184 | 184 | $_SESSION['authReq'] = null; |
| 185 | 185 | } |