kopia lustrzana https://github.com/cloudflare/wildebeest
MOW-115: improve logging for fetchKey failures
rodzic
68526d7530
commit
dd944f46db
|
@ -18,13 +18,14 @@ export async function verifySignature(parsedSignature: ParsedSignature, key: Cry
|
|||
)
|
||||
}
|
||||
|
||||
export async function fetchKey(parsedSignature: ParsedSignature): Promise<CryptoKey> {
|
||||
export async function fetchKey(parsedSignature: ParsedSignature): Promise<CryptoKey | null> {
|
||||
const url = parsedSignature.keyId
|
||||
const res = await fetch(url, {
|
||||
headers: { Accept: 'application/activity+json' },
|
||||
})
|
||||
if (!res.ok) {
|
||||
throw new Error(`failed to fetch keys from "${url}", returned ${res.status}: ${await res.text()}`)
|
||||
console.warn(`failed to fetch keys from "${url}", returned ${res.status}.`)
|
||||
return null
|
||||
}
|
||||
|
||||
const parsedResponse = (await res.json()) as Profile
|
||||
|
|
|
@ -14,6 +14,9 @@ import { generateDigestHeader } from 'wildebeest/backend/src/utils/http-signing-
|
|||
export const onRequest: PagesFunction<Env, any> = async ({ params, request, env }) => {
|
||||
const parsedSignature = parseRequest(request)
|
||||
const pubKey = await fetchKey(parsedSignature)
|
||||
if (pubKey === null) {
|
||||
return new Response('signature key not found', { status: 401 })
|
||||
}
|
||||
const valid = await verifySignature(parsedSignature, pubKey)
|
||||
if (!valid) {
|
||||
return new Response('invalid signature', { status: 401 })
|
||||
|
|
Ładowanie…
Reference in New Issue