@fedify/fedify 2.2.19 → 2.2.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/attachment-arrays-CalAATqD.mjs +16 -0
- package/dist/{builder-UmydCxtK.mjs → builder-4ImvtjG4.mjs} +3 -3
- package/dist/callback-0KrwzutD.d.mts +2607 -0
- package/dist/{client-CSddvgWN.d.ts → client-9DPcy_Yx.d.ts} +16 -1
- package/dist/{client-CAM_bQXx.d.cts → client-B3ruDgWg.d.cts} +16 -1
- package/dist/{client-9F_u23dc.mjs → client-XYMC0Mmk.mjs} +189 -65
- package/dist/compat/attachment-arrays.test.d.mts +2 -0
- package/dist/compat/attachment-arrays.test.mjs +255 -0
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/outgoing-jsonld.test.mjs +1 -1
- package/dist/compat/public-audience.test.mjs +1 -1
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{context-tJbL_Hkw.d.cts → context-CjWuov0g.d.cts} +57 -14
- package/dist/{context-OkwEpc3-.d.ts → context-DZqI2LJD.d.ts} +57 -14
- package/dist/{deno-CD-8UlUi.mjs → deno-AWk3S2Ug.mjs} +1 -1
- package/dist/docloader-Bogpjg4d.mjs +125 -0
- package/dist/federation/attachment-responses.test.d.mts +2 -0
- package/dist/federation/attachment-responses.test.mjs +182 -0
- package/dist/federation/builder.test.mjs +1 -1
- package/dist/federation/collection.test.mjs +1 -1
- package/dist/federation/delivery-attachments.test.d.mts +2 -0
- package/dist/federation/delivery-attachments.test.mjs +288 -0
- package/dist/federation/handler.test.mjs +208 -16
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox.test.mjs +2 -2
- package/dist/federation/middleware.test.mjs +1567 -30
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.d.cts +2 -2
- package/dist/federation/mod.d.ts +2 -2
- package/dist/federation/mod.js +1 -1
- package/dist/federation/negotiation.test.mjs +1 -1
- package/dist/federation/retry.test.mjs +1 -1
- package/dist/federation/send.test.mjs +723 -68
- package/dist/federation/temporal.test.mjs +25 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{http-BBBUbwKh.mjs → http-B3wCvgu8.mjs} +199 -99
- package/dist/{http-DrUG4fPS.cjs → http-BNaPJVnF.cjs} +178 -107
- package/dist/{http-DJK2udgX.js → http-BpdLaGy8.js} +177 -106
- package/dist/{http-Dl00HXr4.d.ts → http-C8qLHs_Z.d.cts} +3 -4
- package/dist/{http-DqZhyEso.d.cts → http-D8WmcRAF.d.ts} +3 -4
- package/dist/{inbox-Dca_0fwc.mjs → inbox-DLy6WBXU.mjs} +1 -1
- package/dist/{key-DolXUaLH.mjs → key-Bhc8cQC7.mjs} +3 -2
- package/dist/{kv-cache-Bk3V1Tiu.cjs → kv-cache-Bj3CY9Jo.cjs} +59 -17
- package/dist/{kv-cache-DDm80t1K.js → kv-cache-CvjLUQTf.js} +60 -18
- package/dist/{ld-rTdIfZ63.mjs → ld-DTeykI0e.mjs} +153 -21
- package/dist/ld-signature-Dgz_b89j.mjs +23 -0
- package/dist/{middleware-BWOwEGpy.cjs → middleware-BSQP4d9p.cjs} +642 -149
- package/dist/{middleware-B4-Rzdi3.cjs → middleware-CWOzxb3o.cjs} +1 -1
- package/dist/{middleware-DYK_res8.mjs → middleware-DkMsC5mQ.mjs} +1 -1
- package/dist/{middleware-BimXKBcP.js → middleware-Dx1iwFk8.js} +641 -149
- package/dist/{middleware-CpXoRHs3.mjs → middleware-dlGvSrXl.mjs} +452 -122
- package/dist/{mod-D2JyWtW3.d.cts → mod-BmxqcEnU.d.ts} +30 -13
- package/dist/{mod-a6kmB8xD.d.cts → mod-DWEx2D4q.d.cts} +1 -1
- package/dist/{mod-DQGjRJUG.d.ts → mod-DnPmz3-S.d.ts} +1 -1
- package/dist/{mod-ej_rLx8h.d.ts → mod-INjDw-m0.d.cts} +30 -13
- package/dist/{mod-B6LmugJ4.d.ts → mod-REfljt0T.d.ts} +4 -10
- package/dist/{mod-V2vDnYNu.d.cts → mod-UvIGUHqW.d.cts} +4 -10
- package/dist/mod.cjs +5 -5
- package/dist/mod.d.cts +8 -8
- package/dist/mod.d.ts +8 -8
- package/dist/mod.js +5 -5
- package/dist/nodeinfo/client.test.mjs +764 -18
- package/dist/nodeinfo/handler.test.mjs +1 -1
- package/dist/nodeinfo/mod.cjs +1 -1
- package/dist/nodeinfo/mod.d.cts +1 -1
- package/dist/nodeinfo/mod.d.ts +1 -1
- package/dist/nodeinfo/mod.js +1 -1
- package/dist/nodeinfo/types.test.mjs +1 -1
- package/dist/otel/exporter.test.mjs +292 -30
- package/dist/otel/mod.cjs +36 -30
- package/dist/otel/mod.d.cts +13 -0
- package/dist/otel/mod.d.ts +13 -0
- package/dist/otel/mod.js +36 -30
- package/dist/{outgoing-jsonld-amccRMrV.mjs → outgoing-jsonld-DHf_DYXp.mjs} +38 -8
- package/dist/{owner-CVfzyM5V.mjs → owner-BsA7qMHB.mjs} +2 -2
- package/dist/{proof-gOGM-sJS.mjs → proof-C63Hqt9N.mjs} +40 -15
- package/dist/{proof-DhaTTn-P.cjs → proof-Dbz6ApNP.cjs} +1190 -1007
- package/dist/{proof-CaQ4KG6y.js → proof-QV_o5ZqS.js} +1174 -1003
- package/dist/send-CAdpwbFX.mjs +416 -0
- package/dist/sig/http.test.mjs +528 -2
- package/dist/sig/key-types.test.d.mts +218 -0
- package/dist/sig/key-types.test.mjs +8 -0
- package/dist/sig/key.test.mjs +2 -2
- package/dist/sig/ld.test.mjs +573 -8
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.d.cts +3 -3
- package/dist/sig/mod.d.ts +3 -3
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +1 -1
- package/dist/sig/proof.test.mjs +96 -4
- package/dist/{temporal-CA4Y9hBJ.mjs → temporal-B3JGkVgk.mjs} +3 -5
- package/dist/testing/mod.d.mts +1 -2396
- package/dist/{types-DRPjmHVV.cjs → types-BWx7zw3Y.cjs} +187 -63
- package/dist/{types-miAYfiGO.js → types-Dx_w2JSM.js} +188 -64
- package/dist/utils/docloader.test.mjs +318 -34
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.d.cts +1 -1
- package/dist/utils/mod.d.ts +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +6 -6
- package/dist/docloader-D1ghurDJ.mjs +0 -83
- package/dist/send-D35Va72B.mjs +0 -260
- /package/dist/{activity-listener-ell7W1s9.mjs → activity-listener-tztVvlNb.mjs} +0 -0
- /package/dist/{collection-D-HqUuA2.mjs → collection-CA3V5zyK.mjs} +0 -0
- /package/dist/{negotiation-SQvQgUqe.mjs → negotiation-VnHNB0Q5.mjs} +0 -0
- /package/dist/{public-audience-DpJqzPuh.mjs → public-audience-4g3_Ze4y.mjs} +0 -0
- /package/dist/{retry-v_sGLH1d.mjs → retry-CXg_MBI-.mjs} +0 -0
- /package/dist/{types-J53Kw7so.mjs → types-BFowWFTT.mjs} +0 -0
|
@@ -4,7 +4,7 @@ globalThis.addEventListener = () => {};
|
|
|
4
4
|
import "../std__assert-DNZ4Liil.mjs";
|
|
5
5
|
import { r as assertFalse } from "../assert_throws-D4DNWrux.mjs";
|
|
6
6
|
import { t as assert } from "../assert-BhQd8QHP.mjs";
|
|
7
|
-
import { t as hasMalformedKnownTemporalLiteral } from "../temporal-
|
|
7
|
+
import { t as hasMalformedKnownTemporalLiteral } from "../temporal-B3JGkVgk.mjs";
|
|
8
8
|
import { test } from "@fedify/fixture";
|
|
9
9
|
//#region src/federation/temporal.test.ts
|
|
10
10
|
test("hasMalformedKnownTemporalLiteral() detects expanded proof timestamps", async () => {
|
|
@@ -67,5 +67,29 @@ test("hasMalformedKnownTemporalLiteral() ignores custom-typed as:closed values",
|
|
|
67
67
|
"@type": "https://example.com/ns#customDateTime"
|
|
68
68
|
}] }, void 0));
|
|
69
69
|
});
|
|
70
|
+
test("hasMalformedKnownTemporalLiteral() accepts date-times without seconds", async () => {
|
|
71
|
+
for (const published of [
|
|
72
|
+
"2024-01-01T10:00Z",
|
|
73
|
+
"2024-01-01T10:00+09:00",
|
|
74
|
+
"2024-01-01T10:00-05:00",
|
|
75
|
+
"2024-01-01T10:00",
|
|
76
|
+
"2024-01-01T10:00.5Z",
|
|
77
|
+
"2024-01-01T10:00.5+09:00",
|
|
78
|
+
"2024-01-01T10:00.5-05:00",
|
|
79
|
+
"2024-01-01T10:00.5"
|
|
80
|
+
]) assertFalse(await hasMalformedKnownTemporalLiteral({ "https://www.w3.org/ns/activitystreams#published": [{
|
|
81
|
+
"@value": published,
|
|
82
|
+
"@type": "http://www.w3.org/2001/XMLSchema#dateTime"
|
|
83
|
+
}] }, void 0), published);
|
|
84
|
+
});
|
|
85
|
+
test("hasMalformedKnownTemporalLiteral() mirrors the as:closed decoder for date-times without seconds", async () => {
|
|
86
|
+
const closed = (value) => ({ "https://www.w3.org/ns/activitystreams#closed": [{
|
|
87
|
+
"@value": value,
|
|
88
|
+
"@type": "http://www.w3.org/2001/XMLSchema#dateTime"
|
|
89
|
+
}] });
|
|
90
|
+
assertFalse(await hasMalformedKnownTemporalLiteral(closed("2024-01-01T10:00.5Z"), void 0));
|
|
91
|
+
assert(await hasMalformedKnownTemporalLiteral(closed("2024-02-31T10:00.5Z"), void 0));
|
|
92
|
+
assert(await hasMalformedKnownTemporalLiteral(closed("Sat, 01 Jan 2024 10:00:00 GMT"), void 0));
|
|
93
|
+
});
|
|
70
94
|
//#endregion
|
|
71
95
|
export {};
|
|
@@ -5,7 +5,7 @@ import { r as createRequestContext } from "../context-Dk_tacqz.mjs";
|
|
|
5
5
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
6
6
|
import "../std__assert-DNZ4Liil.mjs";
|
|
7
7
|
import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
|
|
8
|
-
import { o as createFederation, s as handleWebFinger } from "../middleware-
|
|
8
|
+
import { o as createFederation, s as handleWebFinger } from "../middleware-dlGvSrXl.mjs";
|
|
9
9
|
import { test } from "@fedify/fixture";
|
|
10
10
|
import { Image, Link, Person, Tombstone } from "@fedify/vocab";
|
|
11
11
|
//#region src/federation/webfinger.test.ts
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { n as version, t as name } from "./deno-
|
|
4
|
+
import { n as version, t as name } from "./deno-AWk3S2Ug.mjs";
|
|
5
5
|
import { i as validateAcceptSignature, n as fulfillAcceptSignature, r as parseAcceptSignature } from "./accept-Dd__NiUL.mjs";
|
|
6
|
-
import { i as fetchKeyDetailed, s as validateCryptoKey } from "./key-
|
|
6
|
+
import { i as fetchKeyDetailed, s as validateCryptoKey } from "./key-Bhc8cQC7.mjs";
|
|
7
7
|
import { CryptographicKey } from "@fedify/vocab";
|
|
8
8
|
import { SpanStatusCode, trace } from "@opentelemetry/api";
|
|
9
9
|
import { FetchError } from "@fedify/vocab-runtime";
|
|
10
|
+
import { asCryptoKey } from "@fedify/vocab-runtime/internal";
|
|
10
11
|
import { getLogger } from "@logtape/logtape";
|
|
11
12
|
import { ATTR_HTTP_REQUEST_HEADER, ATTR_HTTP_REQUEST_METHOD, ATTR_URL_FULL } from "@opentelemetry/semantic-conventions";
|
|
12
13
|
import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
|
|
@@ -26,12 +27,13 @@ const DOUBLE_KNOCK_TRANSPORT_RETRY_DELAY_MS = 100;
|
|
|
26
27
|
*/
|
|
27
28
|
async function signRequest(request, privateKey, keyId, options = {}) {
|
|
28
29
|
validateCryptoKey(privateKey, "private");
|
|
30
|
+
const signingKey = asCryptoKey(privateKey);
|
|
29
31
|
return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("http_signatures.sign", async (span) => {
|
|
30
32
|
try {
|
|
31
33
|
const spec = options.spec ?? "draft-cavage-http-signatures-12";
|
|
32
34
|
let signed;
|
|
33
|
-
if (spec === "rfc9421") signed = await signRequestRfc9421(request,
|
|
34
|
-
else signed = await signRequestDraft(request,
|
|
35
|
+
if (spec === "rfc9421") signed = await signRequestRfc9421(request, signingKey, keyId, span, options.currentTime, options.body, options.rfc9421);
|
|
36
|
+
else signed = await signRequestDraft(request, signingKey, keyId, span, options.currentTime, options.body);
|
|
35
37
|
if (span.isRecording()) {
|
|
36
38
|
span.setAttribute(ATTR_HTTP_REQUEST_METHOD, signed.method);
|
|
37
39
|
span.setAttribute(ATTR_URL_FULL, signed.url);
|
|
@@ -849,10 +851,10 @@ async function createRedirectRequest(request, location, body, validateRedirect)
|
|
|
849
851
|
cache: request.cache
|
|
850
852
|
});
|
|
851
853
|
}
|
|
852
|
-
async function fetchDoubleKnockRequest(request, signedRequest, signal) {
|
|
854
|
+
async function fetchDoubleKnockRequest(session, request, signedRequest, signal) {
|
|
853
855
|
const maxAttempts = request.method === "GET" || request.method === "HEAD" ? 2 : 1;
|
|
854
856
|
for (let attempt = 1;; attempt++) try {
|
|
855
|
-
return await fetch(signedRequest, {
|
|
857
|
+
return await session.fetch(signedRequest, {
|
|
856
858
|
redirect: "manual",
|
|
857
859
|
signal
|
|
858
860
|
});
|
|
@@ -913,108 +915,206 @@ function getAbortReason(signal) {
|
|
|
913
915
|
* @since 1.6.0
|
|
914
916
|
*/
|
|
915
917
|
async function doubleKnock(request, identity, options = {}) {
|
|
916
|
-
|
|
918
|
+
const { response } = await doubleKnockCore(request, identity, options, openGlobalFetchHop);
|
|
919
|
+
return response;
|
|
917
920
|
}
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
921
|
+
/**
|
|
922
|
+
* Performs a double-knock request like {@link doubleKnock}, opening a session
|
|
923
|
+
* for every hop with the given function, and passes the final response to
|
|
924
|
+
* the given function. The final session is closed after `consume` settles,
|
|
925
|
+
* so `consume` must read or cancel the response body before it returns.
|
|
926
|
+
* This is not exported from any entry point.
|
|
927
|
+
* @param request The request to send.
|
|
928
|
+
* @param identity The identity to use for signing the request.
|
|
929
|
+
* @param options The options for double-knock requests.
|
|
930
|
+
* @param openHop The function to open a session for each hop. The session of
|
|
931
|
+
* a hop is closed before the next hop is opened.
|
|
932
|
+
* @param consume The function to consume the final response.
|
|
933
|
+
* @returns The value returned by `consume`.
|
|
934
|
+
*/
|
|
935
|
+
async function doubleKnockScoped(request, identity, options, openHop, consume) {
|
|
936
|
+
const { response, session } = await doubleKnockCore(request, identity, options, openHop);
|
|
937
|
+
try {
|
|
938
|
+
return await consume(response);
|
|
939
|
+
} catch (error) {
|
|
940
|
+
getLogger([
|
|
941
|
+
"fedify",
|
|
942
|
+
"sig",
|
|
943
|
+
"http"
|
|
944
|
+
]).debug("Failed to consume the response from {url}; closing the session: {error}", {
|
|
945
|
+
url: request.url,
|
|
946
|
+
error
|
|
947
|
+
});
|
|
948
|
+
throw error;
|
|
949
|
+
} finally {
|
|
950
|
+
await session.close();
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
* A hop session for {@link doubleKnock}: it uses the global `fetch()` without
|
|
955
|
+
* validating or pinning addresses, and its `close()` does nothing, so that
|
|
956
|
+
* the final response can be returned to the caller.
|
|
957
|
+
*/
|
|
958
|
+
function openGlobalFetchHop(url) {
|
|
959
|
+
const sessionUrl = new URL(url);
|
|
960
|
+
return Promise.resolve({
|
|
961
|
+
get url() {
|
|
962
|
+
return new URL(sessionUrl);
|
|
963
|
+
},
|
|
964
|
+
fetch: (input, init) => fetch(input, init),
|
|
965
|
+
close: () => Promise.resolve()
|
|
929
966
|
});
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
967
|
+
}
|
|
968
|
+
function isRedirectResponse(response) {
|
|
969
|
+
return response.status >= 300 && response.status < 400 && response.headers.has("Location");
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* Starts cancelling the body of a response that is not passed to the caller,
|
|
973
|
+
* without waiting for it to settle. The cancellation of a branch of a tee
|
|
974
|
+
* (e.g., a body cloned by a fetch mock) settles only after the other branch
|
|
975
|
+
* is cancelled too, per the Streams standard, so awaiting it could block
|
|
976
|
+
* forever. Failures are only logged.
|
|
977
|
+
*/
|
|
978
|
+
function cancelResponseBody(response, url) {
|
|
979
|
+
response.body?.cancel().catch((error) => {
|
|
980
|
+
getLogger([
|
|
942
981
|
"fedify",
|
|
943
982
|
"sig",
|
|
944
983
|
"http"
|
|
945
|
-
])
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
984
|
+
]).debug("Failed to cancel the response body from {url}: {error}", {
|
|
985
|
+
url,
|
|
986
|
+
error
|
|
987
|
+
});
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
async function doubleKnockCore(request, identity, options, openHop) {
|
|
991
|
+
const { specDeterminer, log, tracerProvider, signal } = options;
|
|
992
|
+
const maximumRedirection = options.maxRedirection ?? DEFAULT_MAX_REDIRECTION;
|
|
993
|
+
const visited = /* @__PURE__ */ new Set();
|
|
994
|
+
const body = options.body !== void 0 ? options.body : request.method !== "GET" && request.method !== "HEAD" ? await request.clone().arrayBuffer() : null;
|
|
995
|
+
let session = await openHop(request.url);
|
|
996
|
+
try {
|
|
997
|
+
for (let redirected = 0;; redirected++) {
|
|
998
|
+
visited.add(request.url);
|
|
999
|
+
const origin = new URL(request.url).origin;
|
|
1000
|
+
const firstTrySpec = specDeterminer == null ? "rfc9421" : await specDeterminer.determineSpec(origin);
|
|
1001
|
+
let signedRequest = await signRequest(request, identity.privateKey, identity.keyId, {
|
|
1002
|
+
spec: firstTrySpec,
|
|
1003
|
+
tracerProvider,
|
|
1004
|
+
body
|
|
1005
|
+
});
|
|
1006
|
+
log?.(signedRequest);
|
|
1007
|
+
let response = await fetchDoubleKnockRequest(session, request, signedRequest, signal);
|
|
1008
|
+
const firstRedirected = isRedirectResponse(response);
|
|
1009
|
+
if (!firstRedirected && (response.status === 400 || response.status === 401 || response.status > 401)) {
|
|
1010
|
+
const logger = getLogger([
|
|
1011
|
+
"fedify",
|
|
1012
|
+
"sig",
|
|
1013
|
+
"http"
|
|
1014
|
+
]);
|
|
1015
|
+
const acceptSigHeader = response.headers.get("Accept-Signature");
|
|
1016
|
+
if (acceptSigHeader != null) {
|
|
1017
|
+
const entries = validateAcceptSignature(parseAcceptSignature(acceptSigHeader));
|
|
1018
|
+
const localKeyId = identity.keyId.href;
|
|
1019
|
+
const localAlg = "rsa-v1_5-sha256";
|
|
1020
|
+
let fulfilled = false;
|
|
1021
|
+
let challengeRequest;
|
|
1022
|
+
for (const entry of entries) {
|
|
1023
|
+
const rfc9421 = fulfillAcceptSignature(entry, localKeyId, localAlg);
|
|
1024
|
+
if (rfc9421 == null) continue;
|
|
1025
|
+
logger.debug("Received Accept-Signature challenge; accumulating label {label} and components {components}.", {
|
|
1026
|
+
label: rfc9421.label,
|
|
1027
|
+
components: rfc9421.components
|
|
1028
|
+
});
|
|
1029
|
+
try {
|
|
1030
|
+
challengeRequest = await signRequest(challengeRequest ?? request, identity.privateKey, identity.keyId, {
|
|
1031
|
+
spec: "rfc9421",
|
|
1032
|
+
tracerProvider,
|
|
1033
|
+
body,
|
|
1034
|
+
rfc9421
|
|
1035
|
+
});
|
|
1036
|
+
fulfilled = true;
|
|
1037
|
+
} catch (error) {
|
|
1038
|
+
logger.debug("Failed to fulfill Accept-Signature challenge entry {label}: {error}", {
|
|
1039
|
+
label: entry.label,
|
|
1040
|
+
error
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
if (fulfilled && challengeRequest != null) {
|
|
1045
|
+
cancelResponseBody(response, request.url);
|
|
1046
|
+
signedRequest = challengeRequest;
|
|
1047
|
+
log?.(signedRequest);
|
|
1048
|
+
response = await session.fetch(signedRequest, {
|
|
1049
|
+
redirect: "manual",
|
|
1050
|
+
signal
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
1053
|
+
if (fulfilled && !isRedirectResponse(response)) {
|
|
1054
|
+
if (response.status < 300) {
|
|
1055
|
+
await specDeterminer?.rememberSpec(origin, "rfc9421");
|
|
1056
|
+
return {
|
|
1057
|
+
response,
|
|
1058
|
+
session
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
if (response.status !== 400 && response.status !== 401) return {
|
|
1062
|
+
response,
|
|
1063
|
+
session
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
if (!isRedirectResponse(response)) {
|
|
1068
|
+
const spec = firstTrySpec === "draft-cavage-http-signatures-12" ? "rfc9421" : "draft-cavage-http-signatures-12";
|
|
1069
|
+
getLogger([
|
|
1070
|
+
"fedify",
|
|
1071
|
+
"sig",
|
|
1072
|
+
"http"
|
|
1073
|
+
]).debug("Failed to verify with the spec {spec} ({status} {statusText}); retrying with spec {secondSpec}... (double-knocking)", {
|
|
1074
|
+
spec: firstTrySpec,
|
|
1075
|
+
secondSpec: spec,
|
|
1076
|
+
status: response.status,
|
|
1077
|
+
statusText: response.statusText
|
|
966
1078
|
});
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
1079
|
+
cancelResponseBody(response, request.url);
|
|
1080
|
+
signedRequest = await signRequest(request, identity.privateKey, identity.keyId, {
|
|
1081
|
+
spec,
|
|
1082
|
+
tracerProvider,
|
|
1083
|
+
body
|
|
972
1084
|
});
|
|
1085
|
+
log?.(signedRequest);
|
|
1086
|
+
response = await fetchDoubleKnockRequest(session, request, signedRequest, signal);
|
|
1087
|
+
if (!isRedirectResponse(response) && response.status !== 400 && response.status !== 401) await specDeterminer?.rememberSpec(origin, spec);
|
|
973
1088
|
}
|
|
974
|
-
}
|
|
975
|
-
if (
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
});
|
|
982
|
-
if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) return doubleKnock(await createRedirectRequest(request, response.headers.get("Location"), body, options.validateRedirect), identity, {
|
|
983
|
-
...options,
|
|
984
|
-
body
|
|
985
|
-
});
|
|
986
|
-
}
|
|
987
|
-
if (fulfilled && response.status < 300) {
|
|
988
|
-
await specDeterminer?.rememberSpec(origin, "rfc9421");
|
|
989
|
-
return response;
|
|
990
|
-
}
|
|
991
|
-
if (fulfilled && response.status !== 400 && response.status !== 401) return response;
|
|
992
|
-
}
|
|
993
|
-
const spec = firstTrySpec === "draft-cavage-http-signatures-12" ? "rfc9421" : "draft-cavage-http-signatures-12";
|
|
994
|
-
logger.debug("Failed to verify with the spec {spec} ({status} {statusText}); retrying with spec {secondSpec}... (double-knocking)", {
|
|
995
|
-
spec: firstTrySpec,
|
|
996
|
-
secondSpec: spec,
|
|
997
|
-
status: response.status,
|
|
998
|
-
statusText: response.statusText
|
|
999
|
-
});
|
|
1000
|
-
signedRequest = await signRequest(request, identity.privateKey, identity.keyId, {
|
|
1001
|
-
spec,
|
|
1002
|
-
tracerProvider,
|
|
1003
|
-
body
|
|
1004
|
-
});
|
|
1005
|
-
log?.(signedRequest);
|
|
1006
|
-
response = await fetchDoubleKnockRequest(request, signedRequest, signal);
|
|
1007
|
-
if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
|
|
1089
|
+
} else if (!firstRedirected) await specDeterminer?.rememberSpec(origin, firstTrySpec);
|
|
1090
|
+
if (!isRedirectResponse(response)) return {
|
|
1091
|
+
response,
|
|
1092
|
+
session
|
|
1093
|
+
};
|
|
1094
|
+
cancelResponseBody(response, request.url);
|
|
1095
|
+
await session.close();
|
|
1008
1096
|
if (redirected >= maximumRedirection) throw new FetchError(request.url, `Too many redirections (${redirected + 1})`);
|
|
1009
|
-
const
|
|
1097
|
+
const location = response.headers.get("Location");
|
|
1098
|
+
const redirectRequest = await createRedirectRequest(request, location, body, options.validateRedirect);
|
|
1010
1099
|
if (visited.has(redirectRequest.url)) throw new FetchError(request.url, `Redirect loop detected: ${redirectRequest.url}`);
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1100
|
+
request = redirectRequest;
|
|
1101
|
+
session = await openHop(request.url);
|
|
1102
|
+
}
|
|
1103
|
+
} catch (error) {
|
|
1104
|
+
try {
|
|
1105
|
+
await session.close();
|
|
1106
|
+
} catch (closeError) {
|
|
1107
|
+
getLogger([
|
|
1108
|
+
"fedify",
|
|
1109
|
+
"sig",
|
|
1110
|
+
"http"
|
|
1111
|
+
]).debug("Failed to close the session for {url}: {error}", {
|
|
1112
|
+
url: request.url,
|
|
1113
|
+
error: closeError
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
throw error;
|
|
1117
|
+
}
|
|
1018
1118
|
}
|
|
1019
1119
|
/**
|
|
1020
1120
|
* Performs a timing-safe equality comparison between two `Uint8Array` values.
|
|
@@ -1044,4 +1144,4 @@ function timingSafeEqual(a, b) {
|
|
|
1044
1144
|
return result === 0;
|
|
1045
1145
|
}
|
|
1046
1146
|
//#endregion
|
|
1047
|
-
export {
|
|
1147
|
+
export { formatRfc9421SignatureParameters as a, signRequest as c, verifyRequestDetailed as d, formatRfc9421Signature as i, timingSafeEqual as l, doubleKnock as n, parseRfc9421Signature as o, doubleKnockScoped as r, parseRfc9421SignatureInput as s, createRfc9421SignatureBase as t, verifyRequest as u };
|