addRootCertificates('rootCertificates/solo.pem'); //} //if (filter_input(INPUT_GET, 'apple')) { $WebAuthn->addRootCertificates('rootCertificates/apple.pem'); //} //if (filter_input(INPUT_GET, 'yubico')) { $WebAuthn->addRootCertificates('rootCertificates/yubico.pem'); //} //if (filter_input(INPUT_GET, 'hypersecu')) { $WebAuthn->addRootCertificates('rootCertificates/hypersecu.pem'); //} //if (filter_input(INPUT_GET, 'google')) { $WebAuthn->addRootCertificates('rootCertificates/globalSign.pem'); $WebAuthn->addRootCertificates('rootCertificates/googleHardware.pem'); //} //if (filter_input(INPUT_GET, 'microsoft')) { $WebAuthn->addRootCertificates('rootCertificates/microsoftTpmCollection.pem'); //} //if (filter_input(INPUT_GET, 'mds')) { $WebAuthn->addRootCertificates('rootCertificates/mds'); //} } // ------------------------------------ // request for create arguments // ------------------------------------ if ($fn === 'getCreateArgs') { $createArgs = $WebAuthn->getCreateArgs(\hex2bin($userId), $userName, $userDisplayName, 60*4, $requireResidentKey, $userVerification, $crossPlatformAttachment); header('Content-Type: application/json'); print(json_encode($createArgs)); // save challange to session. you have to deliver it to processGet later. $_SESSION['challenge'] = $WebAuthn->getChallenge(); // ------------------------------------ // request for get arguments // ------------------------------------ } else if ($fn === 'getGetArgs') { $ids = []; if ($requireResidentKey) { if (!isset($_SESSION['registrations']) || !is_array($_SESSION['registrations']) || count($_SESSION['registrations']) === 0) { throw new Exception('we do not have any registrations in session to check the registration'); } } else { // load registrations from session stored there by processCreate. // normaly you have to load the credential Id's for a username // from the database. if (isset($_SESSION['registrations']) && is_array($_SESSION['registrations'])) { foreach ($_SESSION['registrations'] as $reg) { if ($reg->userId === $userId) { $ids[] = $reg->credentialId; } } } if (count($ids) === 0) { throw new Exception('no registrations in session for userId ' . $userId); } } $getArgs = $WebAuthn->getGetArgs($ids, 60*4, $typeUsb, $typeNfc, $typeBle, $typeHyb, $typeInt, $userVerification); header('Content-Type: application/json'); print(json_encode($getArgs)); // save challange to session. you have to deliver it to processGet later. $_SESSION['challenge'] = $WebAuthn->getChallenge(); // ------------------------------------ // process create // ------------------------------------ } else if ($fn === 'processCreate') { $clientDataJSON = base64_decode($post->clientDataJSON); $attestationObject = base64_decode($post->attestationObject); $challenge = $_SESSION['challenge']; // processCreate returns data to be stored for future logins. // in this example we store it in the php session. // Normaly you have to store the data in a database connected // with the user name. $data = $WebAuthn->processCreate($clientDataJSON, $attestationObject, $challenge, $userVerification === 'required', true, false); // add user infos $data->userId = $userId; $data->userName = $userName; $data->userDisplayName = $userDisplayName; if (!isset($_SESSION['registrations']) || !array_key_exists('registrations', $_SESSION) || !is_array($_SESSION['registrations'])) { $_SESSION['registrations'] = []; } $_SESSION['registrations'][] = $data; $msg = 'registration success.'; $return = new stdClass(); $return->success = true; $return->msg = $msg; header('Content-Type: application/json'); print(json_encode($return)); } } catch (Throwable $ex) { $return = new stdClass(); $return->success = false; $return->msg = $ex->getMessage(); header('Content-Type: application/json'); print(json_encode($return)); } ?> getCreateArgs(\hex2bin($userId), $userName, $userDisplayName, 60*4, $requireResidentKey, $userVerification); header('Content-Type: application/json'); print(json_encode($createArgs)); // Save challenge to session or somewhere else if needed } else if ($fn === 'getGetArgs') { // Get get arguments // Retrieve credential IDs from the database based on $userId $ids = []; // Fetch credential IDs from the database $getArgs = $WebAuthn->getGetArgs($ids, 60*4); header('Content-Type: application/json'); print(json_encode($getArgs)); // Save challenge to session or somewhere else if needed } else if ($fn === 'processCreate') { // Process create $clientDataJSON = base64_decode($post->clientDataJSON); $attestationObject = base64_decode($post->attestationObject); // Process create and store data in the database $data = $WebAuthn->processCreate($clientDataJSON, $attestationObject, $challenge, $userVerification === 'required', true, false); // Store registration data in the database $stmt = $conn->prepare("INSERT INTO registrations (userId, credentialId, publicKey, counter) VALUES (?, ?, ?, ?)"); $stmt->execute([$userId, $data->credentialId, $data->publicKey, $data->counter]); $msg = 'registration success.'; $return = new stdClass(); $return->success = true; $return->msg = $msg; header('Content-Type: application/json'); print(json_encode($return)); } } catch (Throwable $ex) { $return = new stdClass(); $return->success = false; $return->msg = $ex->getMessage(); header('Content-Type: application/json'); print(json_encode($return)); } */ ?>