@fedify/fedify 2.5.0-dev.2446 → 2.5.0-dev.2492
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/README.md +3 -0
- package/dist/{activity-listener-C-BSbKI7.mjs → activity-listener-CELFAodc.mjs} +8 -4
- package/dist/{builder-Da8b9O6v.mjs → builder-DphK9v7f.mjs} +5 -5
- package/dist/{client-D-XP_Ccb.d.ts → client-3InDZbba.d.cts} +0 -1
- package/dist/{client-D-XP_Ccb.d.cts → client-3InDZbba.d.ts} +0 -1
- package/dist/{client-CEnNz8O7.mjs → client-5SIFzW3q.mjs} +113 -64
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{compound-proof-D1djO5fa.mjs → compound-proof-cYtvlTgF.mjs} +2 -2
- package/dist/{context-8Tu9kea0.mjs → context-COHd1Rsh.mjs} +2 -0
- package/dist/{context-BdB54V-A.d.ts → context-DQJE9YfH.d.ts} +332 -6
- package/dist/{context-CQ9H8vNW.d.cts → context-DSuL3YWx.d.cts} +332 -6
- package/dist/{deno-eNpfj4oR.mjs → deno-iOAA7iRN.mjs} +1 -1
- package/dist/docloader-DCZkiTeF.mjs +136 -0
- package/dist/{exporter-DThFfe7P.mjs → exporter-DVG68ozH.mjs} +36 -30
- package/dist/federation/builder.test.mjs +1 -1
- package/dist/federation/compound-fanout.test.mjs +6 -3
- package/dist/federation/handler-compound-proof.test.mjs +5 -5
- package/dist/federation/handler.test.mjs +22 -7
- package/dist/federation/hashlink-media.test.mjs +2 -2
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox-actorless.test.d.mts +2 -0
- package/dist/federation/inbox-actorless.test.mjs +487 -0
- package/dist/federation/inbox-authentication.test.d.mts +2 -0
- package/dist/federation/inbox-authentication.test.mjs +116 -0
- package/dist/federation/inbox-report.test.mjs +5 -5
- package/dist/federation/inbox-view.test.d.mts +2 -0
- package/dist/federation/inbox-view.test.mjs +369 -0
- package/dist/federation/inbox.test.mjs +22 -12
- package/dist/federation/metrics.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +470 -35
- package/dist/federation/mod.cjs +2 -1
- package/dist/federation/mod.d.cts +4 -4
- package/dist/federation/mod.d.ts +4 -4
- package/dist/federation/mod.js +8 -2
- package/dist/federation/mq.test.mjs +36 -1
- package/dist/federation/outgoing-proof.test.mjs +9 -6
- package/dist/federation/portable-actor.test.mjs +3 -3
- package/dist/federation/portable-chain.test.mjs +3 -3
- package/dist/federation/portable-collection.test.mjs +4 -4
- package/dist/federation/portable-delivery.test.mjs +2 -2
- package/dist/federation/portable-gateway-keys.test.mjs +13 -7
- package/dist/federation/portable-inbox.test.mjs +4 -4
- package/dist/federation/portable-parse-uri.test.mjs +1 -1
- package/dist/federation/portable-route-activity.test.mjs +2 -2
- package/dist/federation/portable.test.mjs +3 -3
- package/dist/federation/send.test.mjs +502 -93
- package/dist/federation/tasks/enqueue.test.mjs +3 -3
- package/dist/federation/tasks/tasks.test.mjs +4 -4
- package/dist/federation/temporal.test.mjs +1 -1
- package/dist/federation/webfinger.test.mjs +2 -2
- package/dist/{federation-BVH7drJA.cjs → federation-D0AZw_aw.cjs} +1415 -236
- package/dist/{http-BUJ5SFh6.mjs → http-BoJCMnjY.mjs} +204 -106
- package/dist/{http-DlNxxW_5.js → http-ChXUU_3c.js} +319 -123
- package/dist/{http-BfW3wyQ4.cjs → http-kv1LZw-r.cjs} +339 -125
- package/dist/inbox-BjihTKLo.mjs +312 -0
- package/dist/inbox-authentication-DflPYlLL.mjs +171 -0
- package/dist/inbox-view-D-skypg-.mjs +385 -0
- package/dist/{key-nYGY4QB9.d.cts → key-DbLNT-vA.d.ts} +1 -2
- package/dist/{key-DhsBxxZN.d.ts → key-DlHT4R6k.d.cts} +1 -2
- package/dist/{kv-cache-D_m3A241.mjs → kv-cache-Cmsyke4d.mjs} +1 -1
- package/dist/{kv-cache-7015lbrx.js → kv-cache-DQcte7ES.js} +73 -28
- package/dist/{kv-cache-kkBB0vbI.cjs → kv-cache-Ddh5sMxH.cjs} +72 -27
- package/dist/ld-CWVpo_NM.d.cts +250 -0
- package/dist/{ld-CD2CsPxq.mjs → ld-CdvcOEXQ.mjs} +52 -9
- package/dist/ld-Inagww4R.d.ts +250 -0
- package/dist/{metrics-D3LHk6Z4.mjs → metrics-CpxvUrBz.mjs} +1 -1
- package/dist/{middleware-N9eM16XE.js → middleware-BHb5toqA.js} +1413 -247
- package/dist/{middleware-CCDXvXOG.mjs → middleware-BKs2DLUF.mjs} +1 -1
- package/dist/{middleware-CzoWvrdZ.mjs → middleware-CoBLrTKX.mjs} +533 -132
- package/dist/{mod-B0dGgQsg.d.cts → mod-6TQ4UQZb.d.cts} +1 -1
- package/dist/mod-B4kBw1-8.d.ts +154 -0
- package/dist/{mod-DkhfZC1u.d.ts → mod-B7j30IQf.d.ts} +2 -9
- package/dist/mod-C1nT74IG.d.cts +154 -0
- package/dist/{mod-D0bxB8jS.d.ts → mod-CIeBgsOC.d.ts} +1 -1
- package/dist/{mod-B5-wdzmJ.d.cts → mod-YvA4Rk8J.d.cts} +2 -9
- package/dist/mod.cjs +6 -5
- package/dist/mod.d.cts +9 -9
- package/dist/mod.d.ts +9 -9
- package/dist/mod.js +6 -6
- package/dist/{mq-Dm1Wmtm-.mjs → mq-eF96QxUT.mjs} +6 -0
- package/dist/nodeinfo/client.test.mjs +337 -19
- package/dist/nodeinfo/handler.test.mjs +2 -2
- 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/otel/exporter.test.mjs +257 -1
- 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/{owner-C5-FVX6t.mjs → owner-DTnVpUKA.mjs} +3 -3
- package/dist/{portable-collection-Cony3_LC.mjs → portable-collection-CJeYTL61.mjs} +2 -2
- package/dist/{portable-collection-C-Z1SKDy.cjs → portable-collection-DciwBIia.cjs} +1 -1
- package/dist/{portable-collection-CC2zNAje.js → portable-collection-TmtpzD4E.js} +1 -1
- package/dist/{portable-key-DNc_flH-.mjs → portable-key-DcYok4ki.mjs} +1 -1
- package/dist/{proof-Cryb1c70.mjs → proof-GH7Poos_.mjs} +98 -10
- package/dist/{send-AF25pWaJ.mjs → send-BgGJh6pv.mjs} +174 -76
- package/dist/sig/compound-proof-discovery.test.mjs +1 -1
- package/dist/sig/compound-proof-producer.test.mjs +1 -1
- package/dist/sig/compound-proof-verification.test.mjs +2 -2
- package/dist/sig/compound-proof.test.mjs +2 -2
- package/dist/sig/http.test.mjs +553 -2
- package/dist/sig/key.test.mjs +1 -1
- package/dist/sig/ld.test.mjs +1 -1
- package/dist/sig/mitra-receive-interop.test.mjs +4 -4
- package/dist/sig/mitra-send-interop.test.mjs +3 -3
- 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/portable-collection.test.mjs +1 -1
- package/dist/sig/portable-interop.test.mjs +3 -3
- package/dist/sig/portable-key.test.mjs +5 -5
- package/dist/sig/proof.test.mjs +45 -5
- package/dist/sig/tootik-request-interop.test.mjs +4 -4
- package/dist/sig/tootik-send-interop.test.mjs +3 -3
- package/dist/sig/verification.test.mjs +3 -3
- package/dist/{temporal-BsAeuUJj.mjs → temporal-gJINzcL4.mjs} +1 -1
- package/dist/testing/kv.test.mjs +1 -1
- package/dist/testing/mod.d.mts +288 -2
- package/dist/testing/mod.mjs +2 -2
- package/dist/{testing-t8xDeJZ5.mjs → testing-Dbr21vZk.mjs} +1 -1
- package/dist/{types-_S2_MeLF.js → types-DUjZb4i6.js} +112 -63
- package/dist/{types-poIao40f.cjs → types-hKCCjii0.cjs} +111 -62
- package/dist/utils/docloader.test.mjs +344 -36
- package/dist/utils/kv-cache.test.mjs +1 -1
- 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 +7 -7
- package/dist/docloader-B-0nqOB1.mjs +0 -91
- package/dist/inbox-CHvMaIFX.mjs +0 -188
- package/dist/mod-BRpER-B0.d.ts +0 -320
- package/dist/mod-xAfaLS4T.d.cts +0 -320
- package/dist/owner-BF0L9cMt.d.cts +0 -78
- package/dist/owner-BSzr5-I8.d.ts +0 -78
|
@@ -3,12 +3,12 @@ import "urlpattern-polyfill";
|
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
4
|
import { m as parseKeyIdString } from "./portable-key-id-Ca30-hOa.mjs";
|
|
5
5
|
import { a as verificationObservation, i as triedKey, n as observeCheck, t as observeAttempt } from "./verification-Dpfcw8ml.mjs";
|
|
6
|
-
import { n as version, t as name } from "./deno-
|
|
7
|
-
import { n as getDurationMs, r as getFederationMetrics, s as measureSignatureKeyFetch } from "./metrics-
|
|
6
|
+
import { n as version, t as name } from "./deno-iOAA7iRN.mjs";
|
|
7
|
+
import { n as getDurationMs, r as getFederationMetrics, s as measureSignatureKeyFetch } from "./metrics-CpxvUrBz.mjs";
|
|
8
8
|
import { i as validateAcceptSignature, n as fulfillAcceptSignature, r as parseAcceptSignature } from "./accept-CPVqki78.mjs";
|
|
9
9
|
import { a as promoteKeyOwnerEvidence } from "./key-owner-evidence-APB6NpSk.mjs";
|
|
10
|
-
import {
|
|
11
|
-
import { n as resolvePortableActorKey, r as verifyPortableGatewayKeyDocument } from "./portable-key-
|
|
10
|
+
import { D as validateCryptoKey, b as bypassKeyCacheReads, w as fetchKeyDetailed } from "./ld-CdvcOEXQ.mjs";
|
|
11
|
+
import { n as resolvePortableActorKey, r as verifyPortableGatewayKeyDocument } from "./portable-key-DcYok4ki.mjs";
|
|
12
12
|
import { getLogger } from "@logtape/logtape";
|
|
13
13
|
import { CryptographicKey } from "@fedify/vocab";
|
|
14
14
|
import { SpanStatusCode, trace } from "@opentelemetry/api";
|
|
@@ -1116,10 +1116,10 @@ async function createRedirectRequest(request, location, body, validateRedirect)
|
|
|
1116
1116
|
cache: request.cache
|
|
1117
1117
|
});
|
|
1118
1118
|
}
|
|
1119
|
-
async function fetchDoubleKnockRequest(request, signedRequest, signal) {
|
|
1119
|
+
async function fetchDoubleKnockRequest(session, request, signedRequest, signal) {
|
|
1120
1120
|
const maxAttempts = request.method === "GET" || request.method === "HEAD" ? 2 : 1;
|
|
1121
1121
|
for (let attempt = 1;; attempt++) try {
|
|
1122
|
-
return await fetch(signedRequest, {
|
|
1122
|
+
return await session.fetch(signedRequest, {
|
|
1123
1123
|
redirect: "manual",
|
|
1124
1124
|
signal
|
|
1125
1125
|
});
|
|
@@ -1180,115 +1180,213 @@ function getAbortReason(signal) {
|
|
|
1180
1180
|
* @since 1.6.0
|
|
1181
1181
|
*/
|
|
1182
1182
|
async function doubleKnock(request, identity, options = {}) {
|
|
1183
|
-
|
|
1183
|
+
const { response } = await doubleKnockCore(request, identity, options, openGlobalFetchHop);
|
|
1184
|
+
return response;
|
|
1184
1185
|
}
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1186
|
+
/**
|
|
1187
|
+
* Performs a double-knock request like {@link doubleKnock}, opening a session
|
|
1188
|
+
* for every hop with the given function, and passes the final response to
|
|
1189
|
+
* the given function. The final session is closed after `consume` settles,
|
|
1190
|
+
* so `consume` must read or cancel the response body before it returns.
|
|
1191
|
+
* This is not exported from any entry point.
|
|
1192
|
+
* @param request The request to send.
|
|
1193
|
+
* @param identity The identity to use for signing the request.
|
|
1194
|
+
* @param options The options for double-knock requests.
|
|
1195
|
+
* @param openHop The function to open a session for each hop. The session of
|
|
1196
|
+
* a hop is closed before the next hop is opened.
|
|
1197
|
+
* @param consume The function to consume the final response.
|
|
1198
|
+
* @returns The value returned by `consume`.
|
|
1199
|
+
*/
|
|
1200
|
+
async function doubleKnockScoped(request, identity, options, openHop, consume) {
|
|
1201
|
+
const { response, session } = await doubleKnockCore(request, identity, options, openHop);
|
|
1202
|
+
try {
|
|
1203
|
+
return await consume(response);
|
|
1204
|
+
} catch (error) {
|
|
1205
|
+
getLogger([
|
|
1206
|
+
"fedify",
|
|
1207
|
+
"sig",
|
|
1208
|
+
"http"
|
|
1209
|
+
]).debug("Failed to consume the response from {url}; closing the session: {error}", {
|
|
1210
|
+
url: request.url,
|
|
1211
|
+
error
|
|
1212
|
+
});
|
|
1213
|
+
throw error;
|
|
1214
|
+
} finally {
|
|
1215
|
+
await session.close();
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
/**
|
|
1219
|
+
* A hop session for {@link doubleKnock}: it uses the global `fetch()` without
|
|
1220
|
+
* validating or pinning addresses, and its `close()` does nothing, so that
|
|
1221
|
+
* the final response can be returned to the caller.
|
|
1222
|
+
*/
|
|
1223
|
+
function openGlobalFetchHop(url) {
|
|
1224
|
+
const sessionUrl = new URL(url);
|
|
1225
|
+
return Promise.resolve({
|
|
1226
|
+
get url() {
|
|
1227
|
+
return new URL(sessionUrl);
|
|
1228
|
+
},
|
|
1229
|
+
fetch: (input, init) => fetch(input, init),
|
|
1230
|
+
close: () => Promise.resolve()
|
|
1198
1231
|
});
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1232
|
+
}
|
|
1233
|
+
function isRedirectResponse(response) {
|
|
1234
|
+
return response.status >= 300 && response.status < 400 && response.headers.has("Location");
|
|
1235
|
+
}
|
|
1236
|
+
/**
|
|
1237
|
+
* Starts cancelling the body of a response that is not passed to the caller,
|
|
1238
|
+
* without waiting for it to settle. The cancellation of a branch of a tee
|
|
1239
|
+
* (e.g., a body cloned by a fetch mock) settles only after the other branch
|
|
1240
|
+
* is cancelled too, per the Streams standard, so awaiting it could block
|
|
1241
|
+
* forever. Failures are only logged.
|
|
1242
|
+
*/
|
|
1243
|
+
function cancelResponseBody(response, url) {
|
|
1244
|
+
response.body?.cancel().catch((error) => {
|
|
1245
|
+
getLogger([
|
|
1212
1246
|
"fedify",
|
|
1213
1247
|
"sig",
|
|
1214
1248
|
"http"
|
|
1215
|
-
])
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1249
|
+
]).debug("Failed to cancel the response body from {url}: {error}", {
|
|
1250
|
+
url,
|
|
1251
|
+
error
|
|
1252
|
+
});
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1255
|
+
async function doubleKnockCore(request, identity, options, openHop) {
|
|
1256
|
+
const { specDeterminer, log, tracerProvider, signal } = options;
|
|
1257
|
+
signal?.throwIfAborted();
|
|
1258
|
+
const maximumRedirection = options.maxRedirection ?? DEFAULT_MAX_REDIRECTION;
|
|
1259
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1260
|
+
const body = options.body !== void 0 ? options.body : request.method !== "GET" && request.method !== "HEAD" ? await request.clone().arrayBuffer() : null;
|
|
1261
|
+
let session = await openHop(request.url);
|
|
1262
|
+
try {
|
|
1263
|
+
for (let redirected = 0;; redirected++) {
|
|
1264
|
+
visited.add(request.url);
|
|
1265
|
+
const origin = new URL(request.url).origin;
|
|
1266
|
+
const firstTrySpec = specDeterminer == null ? "rfc9421" : await specDeterminer.determineSpec(origin);
|
|
1267
|
+
signal?.throwIfAborted();
|
|
1268
|
+
let signedRequest = await signRequest(request, identity.privateKey, identity.keyId, {
|
|
1269
|
+
spec: firstTrySpec,
|
|
1270
|
+
tracerProvider,
|
|
1271
|
+
body
|
|
1272
|
+
});
|
|
1273
|
+
signal?.throwIfAborted();
|
|
1274
|
+
log?.(signedRequest);
|
|
1275
|
+
let response = await fetchDoubleKnockRequest(session, request, signedRequest, signal);
|
|
1276
|
+
const firstRedirected = isRedirectResponse(response);
|
|
1277
|
+
if (!firstRedirected && (response.status === 400 || response.status === 401 || response.status > 401)) {
|
|
1278
|
+
const logger = getLogger([
|
|
1279
|
+
"fedify",
|
|
1280
|
+
"sig",
|
|
1281
|
+
"http"
|
|
1282
|
+
]);
|
|
1283
|
+
const acceptSigHeader = response.headers.get("Accept-Signature");
|
|
1284
|
+
if (acceptSigHeader != null) {
|
|
1285
|
+
const entries = validateAcceptSignature(parseAcceptSignature(acceptSigHeader));
|
|
1286
|
+
const localKeyId = identity.keyId.href;
|
|
1287
|
+
const localAlg = "rsa-v1_5-sha256";
|
|
1288
|
+
let fulfilled = false;
|
|
1289
|
+
let challengeRequest;
|
|
1290
|
+
for (const entry of entries) {
|
|
1291
|
+
signal?.throwIfAborted();
|
|
1292
|
+
const rfc9421 = fulfillAcceptSignature(entry, localKeyId, localAlg);
|
|
1293
|
+
if (rfc9421 == null) continue;
|
|
1294
|
+
logger.debug("Received Accept-Signature challenge; accumulating label {label} and components {components}.", {
|
|
1295
|
+
label: rfc9421.label,
|
|
1296
|
+
components: rfc9421.components
|
|
1297
|
+
});
|
|
1298
|
+
try {
|
|
1299
|
+
challengeRequest = await signRequest(challengeRequest ?? request, identity.privateKey, identity.keyId, {
|
|
1300
|
+
spec: "rfc9421",
|
|
1301
|
+
tracerProvider,
|
|
1302
|
+
body,
|
|
1303
|
+
rfc9421
|
|
1304
|
+
});
|
|
1305
|
+
fulfilled = true;
|
|
1306
|
+
} catch (error) {
|
|
1307
|
+
logger.debug("Failed to fulfill Accept-Signature challenge entry {label}: {error}", {
|
|
1308
|
+
label: entry.label,
|
|
1309
|
+
error
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
if (fulfilled && challengeRequest != null) {
|
|
1314
|
+
signal?.throwIfAborted();
|
|
1315
|
+
cancelResponseBody(response, request.url);
|
|
1316
|
+
signedRequest = challengeRequest;
|
|
1317
|
+
log?.(signedRequest);
|
|
1318
|
+
response = await session.fetch(signedRequest, {
|
|
1319
|
+
redirect: "manual",
|
|
1320
|
+
signal
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
if (fulfilled && !isRedirectResponse(response)) {
|
|
1324
|
+
if (response.status < 300) {
|
|
1325
|
+
await specDeterminer?.rememberSpec(origin, "rfc9421");
|
|
1326
|
+
return {
|
|
1327
|
+
response,
|
|
1328
|
+
session
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
1331
|
+
if (response.status !== 400 && response.status !== 401) return {
|
|
1332
|
+
response,
|
|
1333
|
+
session
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
if (!isRedirectResponse(response)) {
|
|
1338
|
+
const spec = firstTrySpec === "draft-cavage-http-signatures-12" ? "rfc9421" : "draft-cavage-http-signatures-12";
|
|
1339
|
+
getLogger([
|
|
1340
|
+
"fedify",
|
|
1341
|
+
"sig",
|
|
1342
|
+
"http"
|
|
1343
|
+
]).debug("Failed to verify with the spec {spec} ({status} {statusText}); retrying with spec {secondSpec}... (double-knocking)", {
|
|
1344
|
+
spec: firstTrySpec,
|
|
1345
|
+
secondSpec: spec,
|
|
1346
|
+
status: response.status,
|
|
1347
|
+
statusText: response.statusText
|
|
1237
1348
|
});
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1349
|
+
cancelResponseBody(response, request.url);
|
|
1350
|
+
signal?.throwIfAborted();
|
|
1351
|
+
signedRequest = await signRequest(request, identity.privateKey, identity.keyId, {
|
|
1352
|
+
spec,
|
|
1353
|
+
tracerProvider,
|
|
1354
|
+
body
|
|
1243
1355
|
});
|
|
1356
|
+
signal?.throwIfAborted();
|
|
1357
|
+
log?.(signedRequest);
|
|
1358
|
+
response = await fetchDoubleKnockRequest(session, request, signedRequest, signal);
|
|
1359
|
+
if (!isRedirectResponse(response) && response.status !== 400 && response.status !== 401) await specDeterminer?.rememberSpec(origin, spec);
|
|
1244
1360
|
}
|
|
1245
|
-
}
|
|
1246
|
-
if (
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
signal
|
|
1253
|
-
});
|
|
1254
|
-
if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) return doubleKnock(await createRedirectRequest(request, response.headers.get("Location"), body, options.validateRedirect), identity, {
|
|
1255
|
-
...options,
|
|
1256
|
-
body
|
|
1257
|
-
});
|
|
1258
|
-
}
|
|
1259
|
-
if (fulfilled && response.status < 300) {
|
|
1260
|
-
await specDeterminer?.rememberSpec(origin, "rfc9421");
|
|
1261
|
-
return response;
|
|
1262
|
-
}
|
|
1263
|
-
if (fulfilled && response.status !== 400 && response.status !== 401) return response;
|
|
1264
|
-
}
|
|
1265
|
-
const spec = firstTrySpec === "draft-cavage-http-signatures-12" ? "rfc9421" : "draft-cavage-http-signatures-12";
|
|
1266
|
-
logger.debug("Failed to verify with the spec {spec} ({status} {statusText}); retrying with spec {secondSpec}... (double-knocking)", {
|
|
1267
|
-
spec: firstTrySpec,
|
|
1268
|
-
secondSpec: spec,
|
|
1269
|
-
status: response.status,
|
|
1270
|
-
statusText: response.statusText
|
|
1271
|
-
});
|
|
1272
|
-
signal?.throwIfAborted();
|
|
1273
|
-
signedRequest = await signRequest(request, identity.privateKey, identity.keyId, {
|
|
1274
|
-
spec,
|
|
1275
|
-
tracerProvider,
|
|
1276
|
-
body
|
|
1277
|
-
});
|
|
1278
|
-
signal?.throwIfAborted();
|
|
1279
|
-
log?.(signedRequest);
|
|
1280
|
-
response = await fetchDoubleKnockRequest(request, signedRequest, signal);
|
|
1281
|
-
if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
|
|
1361
|
+
} else if (!firstRedirected) await specDeterminer?.rememberSpec(origin, firstTrySpec);
|
|
1362
|
+
if (!isRedirectResponse(response)) return {
|
|
1363
|
+
response,
|
|
1364
|
+
session
|
|
1365
|
+
};
|
|
1366
|
+
cancelResponseBody(response, request.url);
|
|
1367
|
+
await session.close();
|
|
1282
1368
|
if (redirected >= maximumRedirection) throw new FetchError(request.url, `Too many redirections (${redirected + 1})`);
|
|
1283
|
-
const
|
|
1369
|
+
const location = response.headers.get("Location");
|
|
1370
|
+
const redirectRequest = await createRedirectRequest(request, location, body, options.validateRedirect);
|
|
1284
1371
|
if (visited.has(redirectRequest.url)) throw new FetchError(request.url, `Redirect loop detected: ${redirectRequest.url}`);
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1372
|
+
request = redirectRequest;
|
|
1373
|
+
session = await openHop(request.url);
|
|
1374
|
+
}
|
|
1375
|
+
} catch (error) {
|
|
1376
|
+
try {
|
|
1377
|
+
await session.close();
|
|
1378
|
+
} catch (closeError) {
|
|
1379
|
+
getLogger([
|
|
1380
|
+
"fedify",
|
|
1381
|
+
"sig",
|
|
1382
|
+
"http"
|
|
1383
|
+
]).debug("Failed to close the session for {url}: {error}", {
|
|
1384
|
+
url: request.url,
|
|
1385
|
+
error: closeError
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
throw error;
|
|
1389
|
+
}
|
|
1292
1390
|
}
|
|
1293
1391
|
/**
|
|
1294
1392
|
* Performs a timing-safe equality comparison between two `Uint8Array` values.
|
|
@@ -1318,4 +1416,4 @@ function timingSafeEqual(a, b) {
|
|
|
1318
1416
|
return result === 0;
|
|
1319
1417
|
}
|
|
1320
1418
|
//#endregion
|
|
1321
|
-
export {
|
|
1419
|
+
export { formatRfc9421SignatureParameters as a, parseRfc9421SignatureInput as c, timingSafeEqual as d, validateMaxSignatures as f, formatRfc9421Signature as i, selectRequestSignature as l, verifyRequestDetailed as m, doubleKnock as n, listRequestSignatures as o, verifyRequest as p, doubleKnockScoped as r, parseRfc9421Signature as s, createRfc9421SignatureBase as t, signRequest as u };
|