From 5dc16a1b3bd30b1d7a264eb36a60e0ffbe67fcb1 Mon Sep 17 00:00:00 2001 From: Marcello Verona Date: Tue, 8 Oct 2019 23:58:51 +0200 Subject: [PATCH 1/5] Device name added. Device name added to the register function as optional parameters. --- WebAuthn/WebAuthn.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/WebAuthn/WebAuthn.php b/WebAuthn/WebAuthn.php index 91aa0de..c270c38 100644 --- a/WebAuthn/WebAuthn.php +++ b/WebAuthn/WebAuthn.php @@ -122,9 +122,12 @@ public function prepareChallengeForRegistration($username, $userid, $crossPlatfo * @param string $userwebauthn the exisitng webauthn field for the user from your * database (it's actaully a JSON string, but that's entirely internal to * this code) + * @param string $device_name the optional device name given by the user during + * the registration. The device name can be request with a prompt (check + * the example for an implementation) * @return string modified to store in the user's webauthn field in your database */ - public function register($info, $userwebauthn) + public function register($info, $userwebauthn, $device_name = '') { if (! is_string($info)) { $this->oops('info must be a string', 1); @@ -192,7 +195,10 @@ public function register($info, $userwebauthn) $publicKey = (object)array(); $publicKey->key = $ao->attData->keyBytes; $publicKey->id = $info->rawId; - //log($publicKey->key); + + if(is_string($device_name) && trim($device_name) != '') { + $publicKey->dname = trim($device_name); + } if (empty($userwebauthn)) { $userwebauthn = [$publicKey]; From 8932b1c64b20f09c47d6095393ba2cc641a4fb2b Mon Sep 17 00:00:00 2001 From: Marcello Verona Date: Wed, 9 Oct 2019 00:05:15 +0200 Subject: [PATCH 2/5] Added the device name to the example. --- example/index.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/example/index.php b/example/index.php index 9efe9f9..e81c831 100644 --- a/example/index.php +++ b/example/index.php @@ -76,8 +76,12 @@ function getuser($username){ if (empty($_SESSION['username'])) { oops('username not set'); } $user = getuser($_SESSION['username']); + /* get a device name from the user */ + $device_name = (isset($_POST['device_name']) && $_POST['device_name'] != '') + ? $_POST['device_name'] : ''; + /* The heart of the matter */ - $user->webauthnkeys = $webauthn->register($_POST['register'], $user->webauthnkeys); + $user->webauthnkeys = $webauthn->register($_POST['register'], $user->webauthnkeys, $device_name); /* Save the result to enable a challenge to be raised agains this newly created key in order to log in */ From 26f0b54566972cdb9a9b68a4c28798de26f91d26 Mon Sep 17 00:00:00 2001 From: Marcello Verona Date: Wed, 9 Oct 2019 00:14:15 +0200 Subject: [PATCH 3/5] Update index.php --- example/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/index.php b/example/index.php index e81c831..867446c 100644 --- a/example/index.php +++ b/example/index.php @@ -77,8 +77,8 @@ function getuser($username){ $user = getuser($_SESSION['username']); /* get a device name from the user */ - $device_name = (isset($_POST['device_name']) && $_POST['device_name'] != '') - ? $_POST['device_name'] : ''; + $device_name = (isset($_POST['dname']) && $_POST['dname'] != '') + ? $_POST['dname'] : ''; /* The heart of the matter */ $user->webauthnkeys = $webauthn->register($_POST['register'], $user->webauthnkeys, $device_name); From 6e0abcdc125a88db932ef28e7aa3ae4a901e1791 Mon Sep 17 00:00:00 2001 From: Marcello Verona Date: Fri, 11 Oct 2019 12:26:42 +0200 Subject: [PATCH 4/5] Added the JS prompt for the device name --- example/index.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/example/index.php b/example/index.php index 867446c..9435e8e 100644 --- a/example/index.php +++ b/example/index.php @@ -273,9 +273,10 @@ function getuser($username){ /* activate the key and get the response */ webauthnRegister(j.challenge, function(success, info){ if (success) { + var device_name = prompt('Provide a name for this device (e.g. "John\'s phone" o "Macbook Sandra")'); $.ajax({url: '/', method: 'POST', - data: {register: info}, + data: {register: info, dname: device_name}, dataType: 'json', success: function(j){ $('#iregisterform,#iregisterdokey').toggle(); From b48cc3d1b7721ab5c808812740b0708fcf35272f Mon Sep 17 00:00:00 2001 From: Marcello Verona Date: Fri, 11 Oct 2019 12:30:26 +0200 Subject: [PATCH 5/5] Added created datetime to webkey --- WebAuthn/WebAuthn.php | 1 + 1 file changed, 1 insertion(+) diff --git a/WebAuthn/WebAuthn.php b/WebAuthn/WebAuthn.php index c270c38..e64908b 100644 --- a/WebAuthn/WebAuthn.php +++ b/WebAuthn/WebAuthn.php @@ -195,6 +195,7 @@ public function register($info, $userwebauthn, $device_name = '') $publicKey = (object)array(); $publicKey->key = $ao->attData->keyBytes; $publicKey->id = $info->rawId; + $publicKey->datetime = date('c'); if(is_string($device_name) && trim($device_name) != '') { $publicKey->dname = trim($device_name);