mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core&ui: upgrade simplewebauthn
This commit is contained in:
9 files changed
+20
-26
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import path from 'path';
|
||||
import { generateRegistrationOptions, verifyRegistrationResponse } from '@simplewebauthn/server';
|
||||
import { isoBase64URL, isoUint8Array } from '@simplewebauthn/server/helpers';
|
||||
import yaml from 'js-yaml';
|
||||
import { pick } from 'lodash';
|
||||
import { Binary, ObjectId } from 'mongodb';
|
||||
@@ -288,12 +289,12 @@ class HomeSecurityHandler extends Handler {
|
||||
const options = await generateRegistrationOptions({
|
||||
rpName: system.get('server.name'),
|
||||
rpID: this.getAuthnHost(),
|
||||
userID: this.user._id.toString(),
|
||||
userID: isoUint8Array.fromUTF8String(this.user._id.toString()),
|
||||
userDisplayName: this.user.uname,
|
||||
userName: `${this.user.uname}(${this.user.mail})`,
|
||||
attestationType: 'direct',
|
||||
excludeCredentials: this.user._authenticators.map((c) => ({
|
||||
id: c.credentialID.buffer,
|
||||
id: isoBase64URL.fromBuffer(c.credentialID.buffer),
|
||||
type: 'public-key',
|
||||
})),
|
||||
authenticatorSelection: {
|
||||
@@ -316,12 +317,13 @@ class HomeSecurityHandler extends Handler {
|
||||
}).catch(() => { throw new ValidationError('verify'); });
|
||||
if (!verification.verified) throw new ValidationError('verify');
|
||||
const info = verification.registrationInfo;
|
||||
const id = Buffer.from(info.credentialID);
|
||||
const id = isoBase64URL.toBuffer(info.credential.id);
|
||||
if (this.user._authenticators.find((c) => c.credentialID.buffer.toString() === id.toString())) throw new ValidationError('authenticator');
|
||||
this.user._authenticators.push({
|
||||
...info,
|
||||
counter: info.credential.counter,
|
||||
credentialID: new Binary(id),
|
||||
credentialPublicKey: new Binary(Buffer.from(info.credentialPublicKey)),
|
||||
credentialPublicKey: new Binary(Buffer.from(info.credential.publicKey)),
|
||||
attestationObject: new Binary(Buffer.from(info.attestationObject)),
|
||||
name,
|
||||
regat: Date.now(),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { generateAuthenticationOptions, verifyAuthenticationResponse } from '@simplewebauthn/server';
|
||||
import { isoBase64URL } from '@simplewebauthn/server/helpers';
|
||||
import moment from 'moment-timezone';
|
||||
import type { Binary } from 'mongodb';
|
||||
import type { Context } from '../context';
|
||||
@@ -144,8 +145,7 @@ class UserWebauthnHandler extends Handler {
|
||||
if (!udoc.authn) throw new AuthOperationError('authn', 'disabled');
|
||||
const options = await generateAuthenticationOptions({
|
||||
allowCredentials: udoc._authenticators.map((authenticator) => ({
|
||||
id: authenticator.credentialID.buffer,
|
||||
type: 'public-key',
|
||||
id: isoBase64URL.fromBuffer(authenticator.credentialID.buffer),
|
||||
})),
|
||||
rpID: this.getAuthnHost(),
|
||||
userVerification: 'preferred',
|
||||
@@ -169,10 +169,10 @@ class UserWebauthnHandler extends Handler {
|
||||
expectedChallenge: challenge,
|
||||
expectedOrigin: this.request.headers.origin,
|
||||
expectedRPID: this.getAuthnHost(),
|
||||
authenticator: {
|
||||
credential: {
|
||||
...authenticator,
|
||||
credentialID: authenticator.credentialID.buffer,
|
||||
credentialPublicKey: authenticator.credentialPublicKey.buffer,
|
||||
id: isoBase64URL.fromBuffer(authenticator.credentialID.buffer),
|
||||
publicKey: authenticator.credentialPublicKey.buffer,
|
||||
},
|
||||
}).catch(() => null);
|
||||
if (!verification?.verified) throw new ValidationError('authenticator');
|
||||
|
||||
Reference in new issue
Block a user