mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-13 16:22:39 +10:00
beginnings of download implementation
This commit is contained in:
@ -14,6 +14,8 @@ type ClientUtils = {
|
||||
fetchUser: () => Promise<User>;
|
||||
};
|
||||
|
||||
const NONCE_LENIENCE = 30_000;
|
||||
|
||||
export function defineClientEventHandler<T>(handler: EventHandlerFunction<T>) {
|
||||
return defineEventHandler(async (h3) => {
|
||||
const header = await getHeader(h3, "Authorization");
|
||||
@ -30,6 +32,21 @@ export function defineClientEventHandler<T>(handler: EventHandlerFunction<T>) {
|
||||
if (!clientId || !nonce || !signature)
|
||||
throw createError({ statusCode: 403 });
|
||||
|
||||
const nonceTime = parseInt(nonce);
|
||||
const current = Date.now();
|
||||
if (
|
||||
// If it was generated in the future
|
||||
nonceTime > current ||
|
||||
// Or more than thirty seconds ago
|
||||
nonceTime < current - NONCE_LENIENCE
|
||||
) {
|
||||
// We reject the request
|
||||
throw createError({
|
||||
statusCode: 403,
|
||||
statusMessage: "Nonce expired",
|
||||
});
|
||||
}
|
||||
|
||||
const ca = h3.context.ca;
|
||||
const certBundle = await ca.fetchClientCertificate(clientId);
|
||||
if (!certBundle)
|
||||
|
||||
Reference in New Issue
Block a user