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

@@ -41,7 +41,7 @@ export default async (ctx: Koa.Context) => {
// Fetch user
const user = await Users.findOne({
usernameLower: username.toLowerCase(),
host: null
host: null,
}) as ILocalUser;
if (user == null) {
@@ -71,7 +71,7 @@ export default async (ctx: Koa.Context) => {
userId: user.id,
ip: ctx.ip,
headers: ctx.headers,
success: false
success: false,
});
error(status || 500, failure || { id: '4e30e80c-e338-45a0-8c8f-44455efa3b76' });
@@ -83,7 +83,7 @@ export default async (ctx: Koa.Context) => {
return;
} else {
await fail(403, {
id: '932c904e-9460-45b7-9ce6-7ed33be7eb2c'
id: '932c904e-9460-45b7-9ce6-7ed33be7eb2c',
});
return;
}
@@ -92,7 +92,7 @@ export default async (ctx: Koa.Context) => {
if (token) {
if (!same) {
await fail(403, {
id: '932c904e-9460-45b7-9ce6-7ed33be7eb2c'
id: '932c904e-9460-45b7-9ce6-7ed33be7eb2c',
});
return;
}
@@ -101,7 +101,7 @@ export default async (ctx: Koa.Context) => {
secret: profile.twoFactorSecret,
encoding: 'base32',
token: token,
window: 2
window: 2,
});
if (verified) {
@@ -109,14 +109,14 @@ export default async (ctx: Koa.Context) => {
return;
} else {
await fail(403, {
id: 'cdf1235b-ac71-46d4-a3a6-84ccce48df6f'
id: 'cdf1235b-ac71-46d4-a3a6-84ccce48df6f',
});
return;
}
} else if (body.credentialId) {
if (!same && !profile.usePasswordLessLogin) {
await fail(403, {
id: '932c904e-9460-45b7-9ce6-7ed33be7eb2c'
id: '932c904e-9460-45b7-9ce6-7ed33be7eb2c',
});
return;
}
@@ -127,24 +127,24 @@ export default async (ctx: Koa.Context) => {
userId: user.id,
id: body.challengeId,
registrationChallenge: false,
challenge: hash(clientData.challenge).toString('hex')
challenge: hash(clientData.challenge).toString('hex'),
});
if (!challenge) {
await fail(403, {
id: '2715a88a-2125-4013-932f-aa6fe72792da'
id: '2715a88a-2125-4013-932f-aa6fe72792da',
});
return;
}
await AttestationChallenges.delete({
userId: user.id,
id: body.challengeId
id: body.challengeId,
});
if (new Date().getTime() - challenge.createdAt.getTime() >= 5 * 60 * 1000) {
await fail(403, {
id: '2715a88a-2125-4013-932f-aa6fe72792da'
id: '2715a88a-2125-4013-932f-aa6fe72792da',
});
return;
}
@@ -155,12 +155,12 @@ export default async (ctx: Koa.Context) => {
.replace(/-/g, '+')
.replace(/_/g, '/'),
'base64'
).toString('hex')
).toString('hex'),
});
if (!securityKey) {
await fail(403, {
id: '66269679-aeaf-4474-862b-eb761197e046'
id: '66269679-aeaf-4474-862b-eb761197e046',
});
return;
}
@@ -171,7 +171,7 @@ export default async (ctx: Koa.Context) => {
clientDataJSON,
clientData,
signature: Buffer.from(body.signature, 'hex'),
challenge: challenge.challenge
challenge: challenge.challenge,
});
if (isValid) {
@@ -179,25 +179,25 @@ export default async (ctx: Koa.Context) => {
return;
} else {
await fail(403, {
id: '93b86c4b-72f9-40eb-9815-798928603d1e'
id: '93b86c4b-72f9-40eb-9815-798928603d1e',
});
return;
}
} else {
if (!same && !profile.usePasswordLessLogin) {
await fail(403, {
id: '932c904e-9460-45b7-9ce6-7ed33be7eb2c'
id: '932c904e-9460-45b7-9ce6-7ed33be7eb2c',
});
return;
}
const keys = await UserSecurityKeys.find({
userId: user.id
userId: user.id,
});
if (keys.length === 0) {
await fail(403, {
id: 'f27fd449-9af4-4841-9249-1f989b9fa4a4'
id: 'f27fd449-9af4-4841-9249-1f989b9fa4a4',
});
return;
}
@@ -215,15 +215,15 @@ export default async (ctx: Koa.Context) => {
id: challengeId,
challenge: hash(Buffer.from(challenge, 'utf-8')).toString('hex'),
createdAt: new Date(),
registrationChallenge: false
registrationChallenge: false,
});
ctx.body = {
challenge,
challengeId,
securityKeys: keys.map(key => ({
id: key.id
}))
id: key.id,
})),
};
ctx.status = 200;
return;

View File

@@ -57,7 +57,7 @@ export default async (ctx: Koa.Context) => {
}
const ticket = await RegistrationTickets.findOne({
code: invitationCode
code: invitationCode,
});
if (ticket == null) {
@@ -94,12 +94,12 @@ export default async (ctx: Koa.Context) => {
} else {
try {
const { account, secret } = await signup({
username, password, host
username, password, host,
});
const res = await Users.pack(account, account, {
detail: true,
includeSecrets: true
includeSecrets: true,
});
(res as any).token = secret;