google / u2f-ref-code

U2F reference implementations
BSD 3-Clause "New" or "Revised" License
588 stars 182 forks source link

Specifying a custom timeout causes an error #178

Open 0xdeafcafe opened 5 years ago

0xdeafcafe commented 5 years ago

I'm specifying a custom timeout like so:

const customTimeout = 60;

window.u2f.sign(appId, challenge, registeredKeys, res => {
    const signRes = res as SignResponse;

    if (signRes.clientData) {
        resolve(signRes);

        return;
    }

    const err = log.info('u2f_signing_failed', null, res);

    reject(err);
}, customTimeout);

However, when the timeout is hit it throws this error to the console: Error in event handler for (unknown): TypeError: Cannot read property 'write' of undefined

cpiper commented 5 years ago

I'm not familiar with the 'as SignResponse' syntax, but simplifying your example to:

window.u2f.sign('https://u2fdemo.appspot.com', 'asdf', [], res => {console.log(res)}, 2);

seems to work and logs the timeout error after 2 seconds.

0xdeafcafe commented 5 years ago

The SignResponse is just from typescript definitions (from https://github.com/lgarron/u2f-api-polyfill.d.ts) however as these are just definitions they should have no impact on the logic.

I'll try setting it to 2 tomorrow, but when I tried setting it to anything it was just failing.

cpiper commented 5 years ago

Ok, not really knowing Typescript, it seems like SignResponse only covers success cases, and this is a failure case so none of the fields match what you are assigning it to.