Skip to content

Commit

Permalink
feat(WebAuthn): implement AttestationType "none"
Browse files Browse the repository at this point in the history
  • Loading branch information
Mik13 committed Sep 1, 2019
1 parent 929ed75 commit 0896449
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ endpoint.
- `[challengeEndpoint = '/response']` - the path of the challenge response
endpoint.
- `[logoutEndpoint = '/logout']` - the path of the logout endpoint.
- `[attestationType = 'direct']` - either direct, indirect or none

**`webauthn.initialize()`**

Expand Down
2 changes: 1 addition & 1 deletion src/AttestationChallengeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class AttestationChallengeBuilder {
return this
}

setAttestationType (attestation = Dictionaries.AttestationConveyancePreference.DIRECT) {
setAttestationType (attestation = Dictionaries.AttestationConveyancePreference.NONE) {
const values = Object.values(Dictionaries.AttestationConveyancePreference)

if (!values.includes(attestation)) {
Expand Down
27 changes: 25 additions & 2 deletions src/Webauthn.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const { Certificate } = require('@fidm/x509')
const MemoryAdapter = require('./MemoryAdapter')
const AttestationChallengeBuilder = require('./AttestationChallengeBuilder')
const AssertionChallengeBuilder = require('./AssertionChallengeBuilder')
const Dictionaries = require('./Dictionaries')

/**
* Webauthn RP
Expand All @@ -35,6 +36,7 @@ class Webauthn {
assertionEndpoint: '/login',
challengeEndpoint: '/response',
logoutEndpoint: '/logout',
attestationType: Dictionaries.AttestationConveyancePreference.DIRECT,
}, options)

// Map object for field names from req param to db name.
Expand Down Expand Up @@ -73,6 +75,7 @@ class Webauthn {

register (options = {}) {
const usernameField = this.config.usernameField || options.usernameField
const attestationType = this.config.attestationType || options.attestationType

return async (req, res, next) => {
if (!req.body) {
Expand Down Expand Up @@ -111,6 +114,7 @@ class Webauthn {
const attestation = new AttestationChallengeBuilder(this)
.setUserInfo(user)
// .setAuthenticator() // Forces TPM
.setAttestationType(attestationType)
.setRelyingPartyInfo({ name: this.config.rpName || options.rpName })
.build({ status: 'ok' })

Expand Down Expand Up @@ -237,7 +241,10 @@ class Webauthn {

try {
if (response.attestationObject !== undefined) {
result = Webauthn.verifyAuthenticatorAttestationResponse(response)
result = Webauthn.verifyAuthenticatorAttestationResponse(
response,
this.config.attestationType !== Dictionaries.AttestationConveyancePreference.DIRECT
)

if (result.verified) {
user.authenticator = result.authrInfo
Expand Down Expand Up @@ -334,7 +341,7 @@ class Webauthn {
* @ignore
*/

static verifyAuthenticatorAttestationResponse (webauthnResponse) {
static verifyAuthenticatorAttestationResponse (webauthnResponse, noneAttestationAllowed) {
const attestationBuffer = base64url.toBuffer(webauthnResponse.attestationObject);
const ctapMakeCredResp = cbor.decodeAllSync(attestationBuffer)[0];

Expand Down Expand Up @@ -367,6 +374,22 @@ class Webauthn {
}
}

// "none" attestation if allowed
} else if (ctapMakeCredResp.fmt === 'none' && noneAttestationAllowed) {
if (!(authrDataStruct.flags & 0x01)) // U2F_USER_PRESENTED
throw new Error('User was NOT presented durring authentication!');

const publicKey = Webauthn.COSEECDHAtoPKCS(authrDataStruct.COSEPublicKey)

response.authrInfo = {
fmt: 'none',
publicKey: base64url.encode(publicKey),
counter: authrDataStruct.counter,
credID: base64url.encode(authrDataStruct.credID)
}

response.verified = true;

} else if (ctapMakeCredResp.fmt === 'packed' && ctapMakeCredResp.attStmt.hasOwnProperty('x5c')) {
if (!(authrDataStruct.flags & 0x01)) // U2F_USER_PRESENTED
throw new Error('User was NOT presented durring authentication!');
Expand Down

0 comments on commit 0896449

Please sign in to comment.