This commit is contained in:
syuilo 2021-12-09 23:58:30 +09:00
parent 0abe2dfee0
commit c69b72e199
573 changed files with 3318 additions and 3318 deletions

View file

@ -7,7 +7,7 @@ import {
UserProfiles,
UserSecurityKeys,
AttestationChallenges,
Users
Users,
} from '@/models/index';
import config from '@/config/index';
import { procedures, hash } from '../../../2fa';
@ -22,21 +22,21 @@ export const meta = {
params: {
clientDataJSON: {
validator: $.str
validator: $.str,
},
attestationObject: {
validator: $.str
validator: $.str,
},
password: {
validator: $.str
validator: $.str,
},
challengeId: {
validator: $.str
validator: $.str,
},
name: {
validator: $.str
}
}
validator: $.str,
},
},
};
const rpIdHashReal = hash(Buffer.from(config.hostname, 'utf-8'));
@ -99,7 +99,7 @@ export default define(meta, async (ps, user) => {
clientDataHash: clientDataJSONHash,
credentialId,
publicKey,
rpIdHash
rpIdHash,
});
if (!verificationData.valid) throw new Error('signature invalid');
@ -107,7 +107,7 @@ export default define(meta, async (ps, user) => {
userId: user.id,
id: ps.challengeId,
registrationChallenge: true,
challenge: hash(clientData.challenge).toString('hex')
challenge: hash(clientData.challenge).toString('hex'),
});
if (!attestationChallenge) {
@ -116,7 +116,7 @@ export default define(meta, async (ps, user) => {
await AttestationChallenges.delete({
userId: user.id,
id: ps.challengeId
id: ps.challengeId,
});
// Expired challenge (> 5min old)
@ -134,17 +134,17 @@ export default define(meta, async (ps, user) => {
id: credentialIdString,
lastUsed: new Date(),
name: ps.name,
publicKey: verificationData.publicKey.toString('hex')
publicKey: verificationData.publicKey.toString('hex'),
});
// Publish meUpdated event
publishMainStream(user.id, 'meUpdated', await Users.pack(user.id, user, {
detail: true,
includeSecrets: true
includeSecrets: true,
}));
return {
id: credentialIdString,
name: ps.name
name: ps.name,
};
});