diff options
author | Matthew Miller <matthew@millerti.me> | 2021-02-05 09:32:52 -0800 |
---|---|---|
committer | Matthew Miller <matthew@millerti.me> | 2021-02-05 09:32:52 -0800 |
commit | c09135e9b4166f8aa65a3396f0cd240704c2546b (patch) | |
tree | 0ab4e1fb538f7d2fd6dfbd1082c7e354c042eda6 | |
parent | b335d68bc328c4bbec2edf08c65c65683415399b (diff) |
Update example to v2.0.0
-rw-r--r-- | example/fido-conformance.ts | 30 | ||||
-rw-r--r-- | example/index.ts | 23 | ||||
-rw-r--r-- | example/package-lock.json | 40 | ||||
-rw-r--r-- | example/package.json | 3 | ||||
-rw-r--r-- | example/public/login/index.html | 2 | ||||
-rw-r--r-- | example/public/register/index.html | 2 |
6 files changed, 54 insertions, 46 deletions
diff --git a/example/fido-conformance.ts b/example/fido-conformance.ts index e9f192d..80371f8 100644 --- a/example/fido-conformance.ts +++ b/example/fido-conformance.ts @@ -2,6 +2,7 @@ import fs from 'fs'; import express from 'express'; import fetch from 'node-fetch'; +import base64url from 'base64url'; import { generateAttestationOptions, @@ -10,6 +11,10 @@ import { verifyAssertionResponse, MetadataService, } from '@simplewebauthn/server'; +import { + AssertionCredentialJSON, + AttestationCredentialJSON, +} from '@simplewebauthn/typescript-types'; import { MetadataStatement } from '@simplewebauthn/server/dist/metadata/metadataService'; import { LoggedInUser } from './example-server'; @@ -151,7 +156,7 @@ fidoConformanceRouter.post('/attestation/options', (req, res) => { * [FIDO2] Server Tests > MakeCredential Response */ fidoConformanceRouter.post('/attestation/result', async (req, res) => { - const { body } = req; + const body: AttestationCredentialJSON = req.body; const user = inMemoryUserDeviceDB[`${loggedInUsername}`]; @@ -169,20 +174,20 @@ fidoConformanceRouter.post('/attestation/result', async (req, res) => { return res.status(400).send({ errorMessage: error.message }); } - const { verified, authenticatorInfo } = verification; + const { verified, attestationInfo } = verification; - if (verified && authenticatorInfo) { - const { base64PublicKey, base64CredentialID, counter } = authenticatorInfo; + if (verified && attestationInfo) { + const { credentialPublicKey, credentialID, counter } = attestationInfo; - const existingDevice = user.devices.find(device => device.credentialID === base64CredentialID); + const existingDevice = user.devices.find(device => device.credentialID === credentialID); if (!existingDevice) { /** * Add the returned device to the user's list of devices */ user.devices.push({ - publicKey: base64PublicKey, - credentialID: base64CredentialID, + credentialPublicKey, + credentialID, counter, }); } @@ -228,7 +233,7 @@ fidoConformanceRouter.post('/assertion/options', (req, res) => { }); fidoConformanceRouter.post('/assertion/result', (req, res) => { - const { body } = req; + const body: AssertionCredentialJSON = req.body; const { id } = body; const user = inMemoryUserDeviceDB[`${loggedInUsername}`]; @@ -237,7 +242,8 @@ fidoConformanceRouter.post('/assertion/result', (req, res) => { const expectedChallenge = user.currentChallenge; const userVerification = user.currentAssertionUserVerification; - const existingDevice = user.devices.find(device => device.credentialID === id); + const credIDBuffer = base64url.toBuffer(id); + const existingDevice = user.devices.find(device => device.credentialID.equals(credIDBuffer)); if (!existingDevice) { throw new Error(`Could not find device matching ${id}`); @@ -258,12 +264,10 @@ fidoConformanceRouter.post('/assertion/result', (req, res) => { return res.status(400).send({ errorMessage: error.message }); } - const { verified, authenticatorInfo } = verification; + const { verified, assertionInfo } = verification; if (verified) { - const { counter } = authenticatorInfo; - - existingDevice.counter = counter; + existingDevice.counter = assertionInfo.newCounter; } return res.send({ diff --git a/example/index.ts b/example/index.ts index 1492395..1affe75 100644 --- a/example/index.ts +++ b/example/index.ts @@ -10,6 +10,7 @@ import fs from 'fs'; import express from 'express'; import dotenv from 'dotenv'; +import base64url from 'base64url'; dotenv.config(); @@ -23,6 +24,7 @@ import { } from '@simplewebauthn/server'; import type { AttestationCredentialJSON, + AssertionCredentialJSON, AuthenticatorDevice, } from '@simplewebauthn/typescript-types'; @@ -150,20 +152,20 @@ app.post('/verify-attestation', async (req, res) => { return res.status(400).send({ error: error.message }); } - const { verified, authenticatorInfo } = verification; + const { verified, attestationInfo } = verification; - if (verified && authenticatorInfo) { - const { base64PublicKey, base64CredentialID, counter } = authenticatorInfo; + if (verified && attestationInfo) { + const { credentialPublicKey, credentialID, counter } = attestationInfo; - const existingDevice = user.devices.find(device => device.credentialID === base64CredentialID); + const existingDevice = user.devices.find(device => device.credentialID === credentialID); if (!existingDevice) { /** * Add the returned device to the user's list of devices */ const newDevice: AuthenticatorDevice = { - publicKey: base64PublicKey, - credentialID: base64CredentialID, + credentialPublicKey, + credentialID, counter, }; user.devices.push(newDevice); @@ -205,16 +207,17 @@ app.get('/generate-assertion-options', (req, res) => { }); app.post('/verify-assertion', (req, res) => { - const { body } = req; + const body: AssertionCredentialJSON = req.body; const user = inMemoryUserDeviceDB[loggedInUserId]; const expectedChallenge = user.currentChallenge; let dbAuthenticator; + const bodyCredIDBuffer = base64url.toBuffer(body.rawId); // "Query the DB" here for an authenticator matching `credentialID` for (const dev of user.devices) { - if (dev.credentialID === body.id) { + if (dev.credentialID.equals(bodyCredIDBuffer)) { dbAuthenticator = dev; break; } @@ -238,11 +241,11 @@ app.post('/verify-assertion', (req, res) => { return res.status(400).send({ error: error.message }); } - const { verified, authenticatorInfo } = verification; + const { verified, assertionInfo } = verification; if (verified) { // Update the authenticator's counter in the DB to the newest count in the assertion - dbAuthenticator.counter = authenticatorInfo.counter; + dbAuthenticator.counter = assertionInfo.newCounter; } res.send({ verified }); diff --git a/example/package-lock.json b/example/package-lock.json index fa99105..f007060 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -45,14 +45,14 @@ } }, "@simplewebauthn/server": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@simplewebauthn/server/-/server-1.0.0.tgz", - "integrity": "sha512-6TUwhx12J9n3feWWYwMrSQvRBTLsa9C7PNt2RvzRuCmgQ5DNUbNzeqMVxvYT/QSaRIuqW0RLhE83iNyMJYJOCg==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@simplewebauthn/server/-/server-2.0.0.tgz", + "integrity": "sha512-bgZjS+7/D3DzU1Bo6XNiMHNgpjV7UIZjQCKcj6O1MweAQuN1+QxdJmtIfVoZ6AQleeyx6IQe6wthgqDkpnDNPA==", "requires": { "@peculiar/asn1-android": "^2.0.26", "@peculiar/asn1-schema": "^2.0.26", "@peculiar/asn1-x509": "^2.0.26", - "@simplewebauthn/typescript-types": "^1.0.0", + "@simplewebauthn/typescript-types": "^2.0.0", "base64url": "^3.0.1", "cbor": "^5.1.0", "elliptic": "^6.5.3", @@ -63,9 +63,9 @@ } }, "@simplewebauthn/typescript-types": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@simplewebauthn/typescript-types/-/typescript-types-1.0.0.tgz", - "integrity": "sha512-x06hFbgp2xVDTm6EHE7Rr3YNNl4e8fJgbObI3UiNVQLO2eLPea4IyVfsV4jODPvZ+gSYAAPN9Lesx2enxYAddw==" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@simplewebauthn/typescript-types/-/typescript-types-2.0.0.tgz", + "integrity": "sha512-gwpTgUbwbWOlPiZILe41+f06SUqv0ML7b+CPr6wJBkHxhIQyPgswvm+gtAyIFlz4CIngS98pn/0Z7MQpNhn6ug==" }, "@sindresorhus/is": { "version": "0.14.0", @@ -641,17 +641,17 @@ "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" }, "elliptic": { - "version": "6.5.3", - "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.3.tgz", - "integrity": "sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==", + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz", + "integrity": "sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==", "requires": { - "bn.js": "^4.4.0", - "brorand": "^1.0.1", + "bn.js": "^4.11.9", + "brorand": "^1.1.0", "hash.js": "^1.0.0", - "hmac-drbg": "^1.0.0", - "inherits": "^2.0.1", - "minimalistic-assert": "^1.0.0", - "minimalistic-crypto-utils": "^1.0.0" + "hmac-drbg": "^1.0.1", + "inherits": "^2.0.4", + "minimalistic-assert": "^1.0.1", + "minimalistic-crypto-utils": "^1.0.1" } }, "emoji-regex": { @@ -1329,11 +1329,11 @@ } }, "pvtsutils": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/pvtsutils/-/pvtsutils-1.1.1.tgz", - "integrity": "sha512-Evbhe6L4Sxwu4SPLQ4LQZhgfWDQO3qa1lju9jM5cxsQp8vE10VipcSmo7hiJW48TmiHgVLgDtC2TL6/+ND+IVg==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/pvtsutils/-/pvtsutils-1.1.2.tgz", + "integrity": "sha512-Yfm9Dsk1zfEpOWCaJaHfqtNXAFWNNHMFSCLN6jTnhuCCBCC2nqge4sAgo7UrkRBoAAYIL8TN/6LlLoNfZD/b5A==", "requires": { - "tslib": "^2.0.3" + "tslib": "^2.1.0" } }, "pvutils": { diff --git a/example/package.json b/example/package.json index 46c7628..0b756d3 100644 --- a/example/package.json +++ b/example/package.json @@ -11,7 +11,8 @@ "author": "", "license": "ISC", "dependencies": { - "@simplewebauthn/server": "1.0.0", + "@simplewebauthn/server": "2.0.0", + "base64url": "^3.0.1", "dotenv": "^8.2.0", "express": "^4.17.1", "node-fetch": "^2.6.0" diff --git a/example/public/login/index.html b/example/public/login/index.html index b279f3a..aadb238 100644 --- a/example/public/login/index.html +++ b/example/public/login/index.html @@ -3,7 +3,7 @@ <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> - <script src="https://unpkg.com/@simplewebauthn/browser@1.0.0/dist/simplewebauthn-browser.min.js"></script> + <script src="https://unpkg.com/@simplewebauthn/browser@2.0.0/dist/simplewebauthn-browser.min.js"></script> <link rel="stylesheet" href="../styles.css" /> <title>SimpleWebAuthn Example Site | Login</title> </head> diff --git a/example/public/register/index.html b/example/public/register/index.html index bdbc9e4..1a8865a 100644 --- a/example/public/register/index.html +++ b/example/public/register/index.html @@ -3,7 +3,7 @@ <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> - <script src="https://unpkg.com/@simplewebauthn/browser@1.0.0/dist/simplewebauthn-browser.min.js"></script> + <script src="https://unpkg.com/@simplewebauthn/browser@2.0.0/dist/simplewebauthn-browser.min.js"></script> <link rel="stylesheet" href="../styles.css" /> <title>SimpleWebAuthn Example Site | Register</title> </head> |