@fedify/fedify 2.1.30 → 2.1.32
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-DZ4JHJD8.mjs +111 -0
- package/dist/{builder-CTpfuuVp.mjs → builder--sc-rozj.mjs} +3 -3
- package/dist/callback-BARPujV7.d.mts +2388 -0
- package/dist/{client-CAM_bQXx.d.cts → client-9DPcy_Yx.d.ts} +16 -1
- package/dist/{client-CSddvgWN.d.ts → client-B3ruDgWg.d.cts} +16 -1
- package/dist/{client-CjDMsn4a.mjs → client-cpPaW7Ww.mjs} +189 -65
- package/dist/compat/attachment-arrays.test.d.mts +2 -0
- package/dist/compat/attachment-arrays.test.mjs +254 -0
- 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/{context-DLLaDau8.d.ts → context-DE2YrQwM.d.ts} +56 -13
- package/dist/{context-BNwv9Q1v.d.cts → context-y6ZUQCMf.d.cts} +56 -13
- package/dist/{deno-BATJ1hq6.mjs → deno-L23b3Hba.mjs} +1 -1
- package/dist/docloader-DUXr9k_O.mjs +124 -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 +280 -0
- package/dist/federation/handler.test.mjs +208 -16
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +1559 -26
- 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-CK3efjgM.js → http-BtbMAgTA.js} +176 -105
- package/dist/{http-Dl00HXr4.d.ts → http-C8qLHs_Z.d.cts} +3 -4
- package/dist/{http-BoR1M3W7.cjs → http-D5woFKA_.cjs} +177 -106
- package/dist/{http-DqZhyEso.d.cts → http-D8WmcRAF.d.ts} +3 -4
- package/dist/{http-Bjd6I92u.mjs → http-HX6wVyJh.mjs} +198 -98
- package/dist/{inbox-9MlBGgs9.mjs → inbox-CL7A0HXT.mjs} +1 -1
- package/dist/{key-ClQh9Qqh.mjs → key-Dai3f5yI.mjs} +3 -2
- package/dist/{kv-cache-BxSx_Iyp.cjs → kv-cache-B0V_e231.cjs} +59 -17
- package/dist/{kv-cache-ImApO425.js → kv-cache-BsDg-cT8.js} +60 -18
- package/dist/{ld-Crg0Xmwr.mjs → ld-DN6x1iZ8.mjs} +153 -21
- package/dist/ld-signature-DoZcbsZR.mjs +23 -0
- package/dist/{middleware-jL9p9V9G.cjs → middleware-Cl6k5Hrm.cjs} +1 -1
- package/dist/{middleware-CmD3lpy4.cjs → middleware-CrfRuKCf.cjs} +728 -143
- package/dist/{middleware-CE0b69gj.mjs → middleware-DiquMgtt.mjs} +444 -115
- package/dist/{middleware-C2AJFk8W.js → middleware-DunNtbo9.js} +727 -143
- package/dist/{middleware-Bi5D6DBT.mjs → middleware-SnQS8eIb.mjs} +1 -1
- package/dist/{mod-DiuFTYUt.d.cts → mod-CehHJOV4.d.cts} +30 -13
- package/dist/{mod-CWJNbyju.d.ts → mod-DLJpnqdw.d.ts} +1 -1
- package/dist/{mod-BLDHhuW0.d.ts → mod-Mh3oIuRK.d.ts} +30 -13
- package/dist/{mod-DNEgTI8M.d.ts → mod-REfljt0T.d.ts} +4 -9
- package/dist/{mod-Cn9GJ5ex.d.cts → mod-UvIGUHqW.d.cts} +4 -9
- package/dist/{mod-BmlfRBmU.d.cts → mod-sTa1Zzxk.d.cts} +1 -1
- 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 -19
- 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/{owner-BRoKojK1.mjs → owner-DwyDorZI.mjs} +2 -2
- package/dist/{proof-CHXVlsH_.cjs → proof-Be-4K4jn.cjs} +193 -46
- package/dist/{proof-DMIAezxz.mjs → proof-DYjmyrHh.mjs} +38 -13
- package/dist/{proof-7R4s10TJ.js → proof-Du4-5SHY.js} +187 -46
- package/dist/send-BGSfQkIK.mjs +416 -0
- package/dist/sig/http.test.mjs +506 -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 +95 -3
- package/dist/{temporal-DR0JahMu.mjs → temporal-CNCchWly.mjs} +3 -5
- package/dist/testing/mod.d.mts +1 -2177
- package/dist/{types-DRPjmHVV.cjs → types-B5wRhemi.cjs} +187 -63
- package/dist/{types-miAYfiGO.js → types-CXy2lRVU.js} +188 -64
- package/dist/utils/docloader.test.mjs +316 -32
- 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-OLWc7P2D.mjs +0 -82
- package/dist/send-BHIt_8ia.mjs +0 -260
- /package/dist/{collection-BD6-SZ6O.mjs → collection-DnoYNwBC.mjs} +0 -0
- /package/dist/{negotiation-BehA2uul.mjs → negotiation-xb0QR3u_.mjs} +0 -0
- /package/dist/{retry-B_E3V_Dx.mjs → retry-CI1flGDD.mjs} +0 -0
- /package/dist/{types-DCP0WLdt.mjs → types-s4mCTGkT.mjs} +0 -0
|
@@ -4,7 +4,7 @@ globalThis.addEventListener = () => {};
|
|
|
4
4
|
import "../std__assert-DflMZha5.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-CNCchWly.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 { n as createRequestContext } from "../context-Juj6bdHC.mjs";
|
|
|
5
5
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
6
6
|
import "../std__assert-DflMZha5.mjs";
|
|
7
7
|
import { t as MemoryKvStore } from "../kv-HvthQAHr.mjs";
|
|
8
|
-
import { a as createFederation, o as handleWebFinger } from "../middleware-
|
|
8
|
+
import { a as createFederation, o as handleWebFinger } from "../middleware-DiquMgtt.mjs";
|
|
9
9
|
import { test } from "@fedify/fixture";
|
|
10
10
|
import { Image, Link, Person } from "@fedify/vocab";
|
|
11
11
|
//#region src/federation/webfinger.test.ts
|
|
@@ -6,11 +6,12 @@ import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
|
6
6
|
import { encodeHex } from "byte-encodings/hex";
|
|
7
7
|
import { FetchError, UrlError, getDocumentLoader } from "@fedify/vocab-runtime";
|
|
8
8
|
import { Item, decodeDict, encodeDict, encodeItem } from "structured-field-values";
|
|
9
|
+
import { asCryptoKey } from "@fedify/vocab-runtime/internal";
|
|
9
10
|
import { ATTR_HTTP_REQUEST_HEADER, ATTR_HTTP_REQUEST_METHOD, ATTR_URL_FULL } from "@opentelemetry/semantic-conventions";
|
|
10
11
|
import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
|
|
11
12
|
//#region deno.json
|
|
12
13
|
var name = "@fedify/fedify";
|
|
13
|
-
var version = "2.1.
|
|
14
|
+
var version = "2.1.32";
|
|
14
15
|
//#endregion
|
|
15
16
|
//#region src/sig/accept.ts
|
|
16
17
|
/**
|
|
@@ -261,7 +262,7 @@ function generateCryptoKeyPair(algorithm) {
|
|
|
261
262
|
*/
|
|
262
263
|
async function exportJwk(key) {
|
|
263
264
|
validateCryptoKey(key);
|
|
264
|
-
const jwk = await crypto.subtle.exportKey("jwk", key);
|
|
265
|
+
const jwk = await crypto.subtle.exportKey("jwk", asCryptoKey(key));
|
|
265
266
|
if (jwk.crv === "Ed25519") jwk.alg = "Ed25519";
|
|
266
267
|
return jwk;
|
|
267
268
|
}
|
|
@@ -774,12 +775,13 @@ const DOUBLE_KNOCK_TRANSPORT_RETRY_DELAY_MS = 100;
|
|
|
774
775
|
*/
|
|
775
776
|
async function signRequest(request, privateKey, keyId, options = {}) {
|
|
776
777
|
validateCryptoKey(privateKey, "private");
|
|
778
|
+
const signingKey = asCryptoKey(privateKey);
|
|
777
779
|
return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("http_signatures.sign", async (span) => {
|
|
778
780
|
try {
|
|
779
781
|
const spec = options.spec ?? "draft-cavage-http-signatures-12";
|
|
780
782
|
let signed;
|
|
781
|
-
if (spec === "rfc9421") signed = await signRequestRfc9421(request,
|
|
782
|
-
else signed = await signRequestDraft(request,
|
|
783
|
+
if (spec === "rfc9421") signed = await signRequestRfc9421(request, signingKey, keyId, span, options.currentTime, options.body, options.rfc9421);
|
|
784
|
+
else signed = await signRequestDraft(request, signingKey, keyId, span, options.currentTime, options.body);
|
|
783
785
|
if (span.isRecording()) {
|
|
784
786
|
span.setAttribute(ATTR_HTTP_REQUEST_METHOD, signed.method);
|
|
785
787
|
span.setAttribute(ATTR_URL_FULL, signed.url);
|
|
@@ -1597,10 +1599,10 @@ async function createRedirectRequest(request, location, body, validateRedirect)
|
|
|
1597
1599
|
cache: request.cache
|
|
1598
1600
|
});
|
|
1599
1601
|
}
|
|
1600
|
-
async function fetchDoubleKnockRequest(request, signedRequest, signal) {
|
|
1602
|
+
async function fetchDoubleKnockRequest(session, request, signedRequest, signal) {
|
|
1601
1603
|
const maxAttempts = request.method === "GET" || request.method === "HEAD" ? 2 : 1;
|
|
1602
1604
|
for (let attempt = 1;; attempt++) try {
|
|
1603
|
-
return await fetch(signedRequest, {
|
|
1605
|
+
return await session.fetch(signedRequest, {
|
|
1604
1606
|
redirect: "manual",
|
|
1605
1607
|
signal
|
|
1606
1608
|
});
|
|
@@ -1651,117 +1653,186 @@ function getAbortReason(signal) {
|
|
|
1651
1653
|
return signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
|
|
1652
1654
|
}
|
|
1653
1655
|
/**
|
|
1654
|
-
* Performs a double-knock request
|
|
1655
|
-
*
|
|
1656
|
-
*
|
|
1656
|
+
* Performs a double-knock request like {@link doubleKnock}, opening a session
|
|
1657
|
+
* for every hop with the given function, and passes the final response to
|
|
1658
|
+
* the given function. The final session is closed after `consume` settles,
|
|
1659
|
+
* so `consume` must read or cancel the response body before it returns.
|
|
1660
|
+
* This is not exported from any entry point.
|
|
1657
1661
|
* @param request The request to send.
|
|
1658
1662
|
* @param identity The identity to use for signing the request.
|
|
1659
1663
|
* @param options The options for double-knock requests.
|
|
1660
|
-
* @
|
|
1661
|
-
*
|
|
1664
|
+
* @param openHop The function to open a session for each hop. The session of
|
|
1665
|
+
* a hop is closed before the next hop is opened.
|
|
1666
|
+
* @param consume The function to consume the final response.
|
|
1667
|
+
* @returns The value returned by `consume`.
|
|
1662
1668
|
*/
|
|
1663
|
-
async function
|
|
1664
|
-
|
|
1669
|
+
async function doubleKnockScoped(request, identity, options, openHop, consume) {
|
|
1670
|
+
const { response, session } = await doubleKnockCore(request, identity, options, openHop);
|
|
1671
|
+
try {
|
|
1672
|
+
return await consume(response);
|
|
1673
|
+
} catch (error) {
|
|
1674
|
+
getLogger([
|
|
1675
|
+
"fedify",
|
|
1676
|
+
"sig",
|
|
1677
|
+
"http"
|
|
1678
|
+
]).debug("Failed to consume the response from {url}; closing the session: {error}", {
|
|
1679
|
+
url: request.url,
|
|
1680
|
+
error
|
|
1681
|
+
});
|
|
1682
|
+
throw error;
|
|
1683
|
+
} finally {
|
|
1684
|
+
await session.close();
|
|
1685
|
+
}
|
|
1665
1686
|
}
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
|
|
1680
|
-
if (redirected >= DEFAULT_MAX_REDIRECTION) throw new FetchError(request.url, `Too many redirections (${redirected + 1})`);
|
|
1681
|
-
const redirectRequest = await createRedirectRequest(request, response.headers.get("Location"), body, options.validateRedirect);
|
|
1682
|
-
if (visited.has(redirectRequest.url)) throw new FetchError(request.url, `Redirect loop detected: ${redirectRequest.url}`);
|
|
1683
|
-
return doubleKnockInternal(redirectRequest, identity, {
|
|
1684
|
-
...options,
|
|
1685
|
-
body
|
|
1686
|
-
}, redirected + 1, visited);
|
|
1687
|
-
} else if (response.status === 400 || response.status === 401 || response.status > 401) {
|
|
1688
|
-
const logger = getLogger([
|
|
1687
|
+
function isRedirectResponse(response) {
|
|
1688
|
+
return response.status >= 300 && response.status < 400 && response.headers.has("Location");
|
|
1689
|
+
}
|
|
1690
|
+
/**
|
|
1691
|
+
* Starts cancelling the body of a response that is not passed to the caller,
|
|
1692
|
+
* without waiting for it to settle. The cancellation of a branch of a tee
|
|
1693
|
+
* (e.g., a body cloned by a fetch mock) settles only after the other branch
|
|
1694
|
+
* is cancelled too, per the Streams standard, so awaiting it could block
|
|
1695
|
+
* forever. Failures are only logged.
|
|
1696
|
+
*/
|
|
1697
|
+
function cancelResponseBody(response, url) {
|
|
1698
|
+
response.body?.cancel().catch((error) => {
|
|
1699
|
+
getLogger([
|
|
1689
1700
|
"fedify",
|
|
1690
1701
|
"sig",
|
|
1691
1702
|
"http"
|
|
1692
|
-
])
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1703
|
+
]).debug("Failed to cancel the response body from {url}: {error}", {
|
|
1704
|
+
url,
|
|
1705
|
+
error
|
|
1706
|
+
});
|
|
1707
|
+
});
|
|
1708
|
+
}
|
|
1709
|
+
async function doubleKnockCore(request, identity, options, openHop) {
|
|
1710
|
+
const { specDeterminer, log, tracerProvider, signal } = options;
|
|
1711
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1712
|
+
const body = options.body !== void 0 ? options.body : request.method !== "GET" && request.method !== "HEAD" ? await request.clone().arrayBuffer() : null;
|
|
1713
|
+
let session = await openHop(request.url);
|
|
1714
|
+
try {
|
|
1715
|
+
for (let redirected = 0;; redirected++) {
|
|
1716
|
+
visited.add(request.url);
|
|
1717
|
+
const origin = new URL(request.url).origin;
|
|
1718
|
+
const firstTrySpec = specDeterminer == null ? "rfc9421" : await specDeterminer.determineSpec(origin);
|
|
1719
|
+
let signedRequest = await signRequest(request, identity.privateKey, identity.keyId, {
|
|
1720
|
+
spec: firstTrySpec,
|
|
1721
|
+
tracerProvider,
|
|
1722
|
+
body
|
|
1723
|
+
});
|
|
1724
|
+
log?.(signedRequest);
|
|
1725
|
+
let response = await fetchDoubleKnockRequest(session, request, signedRequest, signal);
|
|
1726
|
+
const firstRedirected = isRedirectResponse(response);
|
|
1727
|
+
if (!firstRedirected && (response.status === 400 || response.status === 401 || response.status > 401)) {
|
|
1728
|
+
const logger = getLogger([
|
|
1729
|
+
"fedify",
|
|
1730
|
+
"sig",
|
|
1731
|
+
"http"
|
|
1732
|
+
]);
|
|
1733
|
+
const acceptSigHeader = response.headers.get("Accept-Signature");
|
|
1734
|
+
if (acceptSigHeader != null) {
|
|
1735
|
+
const entries = validateAcceptSignature(parseAcceptSignature(acceptSigHeader));
|
|
1736
|
+
const localKeyId = identity.keyId.href;
|
|
1737
|
+
const localAlg = "rsa-v1_5-sha256";
|
|
1738
|
+
let fulfilled = false;
|
|
1739
|
+
let challengeRequest;
|
|
1740
|
+
for (const entry of entries) {
|
|
1741
|
+
const rfc9421 = fulfillAcceptSignature(entry, localKeyId, localAlg);
|
|
1742
|
+
if (rfc9421 == null) continue;
|
|
1743
|
+
logger.debug("Received Accept-Signature challenge; accumulating label {label} and components {components}.", {
|
|
1744
|
+
label: rfc9421.label,
|
|
1745
|
+
components: rfc9421.components
|
|
1746
|
+
});
|
|
1747
|
+
try {
|
|
1748
|
+
challengeRequest = await signRequest(challengeRequest ?? request, identity.privateKey, identity.keyId, {
|
|
1749
|
+
spec: "rfc9421",
|
|
1750
|
+
tracerProvider,
|
|
1751
|
+
body,
|
|
1752
|
+
rfc9421
|
|
1753
|
+
});
|
|
1754
|
+
fulfilled = true;
|
|
1755
|
+
} catch (error) {
|
|
1756
|
+
logger.debug("Failed to fulfill Accept-Signature challenge entry {label}: {error}", {
|
|
1757
|
+
label: entry.label,
|
|
1758
|
+
error
|
|
1759
|
+
});
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
if (fulfilled && challengeRequest != null) {
|
|
1763
|
+
cancelResponseBody(response, request.url);
|
|
1764
|
+
signedRequest = challengeRequest;
|
|
1765
|
+
log?.(signedRequest);
|
|
1766
|
+
response = await session.fetch(signedRequest, {
|
|
1767
|
+
redirect: "manual",
|
|
1768
|
+
signal
|
|
1769
|
+
});
|
|
1770
|
+
}
|
|
1771
|
+
if (fulfilled && !isRedirectResponse(response)) {
|
|
1772
|
+
if (response.status < 300) {
|
|
1773
|
+
await specDeterminer?.rememberSpec(origin, "rfc9421");
|
|
1774
|
+
return {
|
|
1775
|
+
response,
|
|
1776
|
+
session
|
|
1777
|
+
};
|
|
1778
|
+
}
|
|
1779
|
+
if (response.status !== 400 && response.status !== 401) return {
|
|
1780
|
+
response,
|
|
1781
|
+
session
|
|
1782
|
+
};
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
if (!isRedirectResponse(response)) {
|
|
1786
|
+
const spec = firstTrySpec === "draft-cavage-http-signatures-12" ? "rfc9421" : "draft-cavage-http-signatures-12";
|
|
1787
|
+
getLogger([
|
|
1788
|
+
"fedify",
|
|
1789
|
+
"sig",
|
|
1790
|
+
"http"
|
|
1791
|
+
]).debug("Failed to verify with the spec {spec} ({status} {statusText}); retrying with spec {secondSpec}... (double-knocking)", {
|
|
1792
|
+
spec: firstTrySpec,
|
|
1793
|
+
secondSpec: spec,
|
|
1794
|
+
status: response.status,
|
|
1795
|
+
statusText: response.statusText
|
|
1713
1796
|
});
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1797
|
+
cancelResponseBody(response, request.url);
|
|
1798
|
+
signedRequest = await signRequest(request, identity.privateKey, identity.keyId, {
|
|
1799
|
+
spec,
|
|
1800
|
+
tracerProvider,
|
|
1801
|
+
body
|
|
1719
1802
|
});
|
|
1803
|
+
log?.(signedRequest);
|
|
1804
|
+
response = await fetchDoubleKnockRequest(session, request, signedRequest, signal);
|
|
1805
|
+
if (!isRedirectResponse(response) && response.status !== 400 && response.status !== 401) await specDeterminer?.rememberSpec(origin, spec);
|
|
1720
1806
|
}
|
|
1721
|
-
}
|
|
1722
|
-
if (
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
});
|
|
1729
|
-
if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) return doubleKnock(await createRedirectRequest(request, response.headers.get("Location"), body, options.validateRedirect), identity, {
|
|
1730
|
-
...options,
|
|
1731
|
-
body
|
|
1732
|
-
});
|
|
1733
|
-
}
|
|
1734
|
-
if (fulfilled && response.status < 300) {
|
|
1735
|
-
await specDeterminer?.rememberSpec(origin, "rfc9421");
|
|
1736
|
-
return response;
|
|
1737
|
-
}
|
|
1738
|
-
if (fulfilled && response.status !== 400 && response.status !== 401) return response;
|
|
1739
|
-
}
|
|
1740
|
-
const spec = firstTrySpec === "draft-cavage-http-signatures-12" ? "rfc9421" : "draft-cavage-http-signatures-12";
|
|
1741
|
-
logger.debug("Failed to verify with the spec {spec} ({status} {statusText}); retrying with spec {secondSpec}... (double-knocking)", {
|
|
1742
|
-
spec: firstTrySpec,
|
|
1743
|
-
secondSpec: spec,
|
|
1744
|
-
status: response.status,
|
|
1745
|
-
statusText: response.statusText
|
|
1746
|
-
});
|
|
1747
|
-
signedRequest = await signRequest(request, identity.privateKey, identity.keyId, {
|
|
1748
|
-
spec,
|
|
1749
|
-
tracerProvider,
|
|
1750
|
-
body
|
|
1751
|
-
});
|
|
1752
|
-
log?.(signedRequest);
|
|
1753
|
-
response = await fetchDoubleKnockRequest(request, signedRequest, signal);
|
|
1754
|
-
if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
|
|
1807
|
+
} else if (!firstRedirected) await specDeterminer?.rememberSpec(origin, firstTrySpec);
|
|
1808
|
+
if (!isRedirectResponse(response)) return {
|
|
1809
|
+
response,
|
|
1810
|
+
session
|
|
1811
|
+
};
|
|
1812
|
+
cancelResponseBody(response, request.url);
|
|
1813
|
+
await session.close();
|
|
1755
1814
|
if (redirected >= DEFAULT_MAX_REDIRECTION) throw new FetchError(request.url, `Too many redirections (${redirected + 1})`);
|
|
1756
|
-
const
|
|
1815
|
+
const location = response.headers.get("Location");
|
|
1816
|
+
const redirectRequest = await createRedirectRequest(request, location, body, options.validateRedirect);
|
|
1757
1817
|
if (visited.has(redirectRequest.url)) throw new FetchError(request.url, `Redirect loop detected: ${redirectRequest.url}`);
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1818
|
+
request = redirectRequest;
|
|
1819
|
+
session = await openHop(request.url);
|
|
1820
|
+
}
|
|
1821
|
+
} catch (error) {
|
|
1822
|
+
try {
|
|
1823
|
+
await session.close();
|
|
1824
|
+
} catch (closeError) {
|
|
1825
|
+
getLogger([
|
|
1826
|
+
"fedify",
|
|
1827
|
+
"sig",
|
|
1828
|
+
"http"
|
|
1829
|
+
]).debug("Failed to close the session for {url}: {error}", {
|
|
1830
|
+
url: request.url,
|
|
1831
|
+
error: closeError
|
|
1832
|
+
});
|
|
1833
|
+
}
|
|
1834
|
+
throw error;
|
|
1835
|
+
}
|
|
1765
1836
|
}
|
|
1766
1837
|
/**
|
|
1767
1838
|
* Performs a timing-safe equality comparison between two `Uint8Array` values.
|
|
@@ -1791,4 +1862,4 @@ function timingSafeEqual(a, b) {
|
|
|
1791
1862
|
return result === 0;
|
|
1792
1863
|
}
|
|
1793
1864
|
//#endregion
|
|
1794
|
-
export { validateAcceptSignature as _, verifyRequestDetailed as a, fetchKey as c, importJwk as d, validateCryptoKey as f, parseAcceptSignature as g, fulfillAcceptSignature as h, verifyRequest as i, fetchKeyDetailed as l, formatAcceptSignature as m, parseRfc9421SignatureInput as n, exportJwk as o, verifyKeyOwnership as p, signRequest as r, fetchActorDocument as s,
|
|
1865
|
+
export { validateAcceptSignature as _, verifyRequestDetailed as a, fetchKey as c, importJwk as d, validateCryptoKey as f, parseAcceptSignature as g, fulfillAcceptSignature as h, verifyRequest as i, fetchKeyDetailed as l, formatAcceptSignature as m, parseRfc9421SignatureInput as n, exportJwk as o, verifyKeyOwnership as p, signRequest as r, fetchActorDocument as s, doubleKnockScoped as t, generateCryptoKeyPair as u, name as v, version as y };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
2
|
import { Actor, CryptographicKey, Multikey } from "@fedify/vocab";
|
|
3
|
+
import { CryptoKeyLike, DocumentLoader } from "@fedify/vocab-runtime";
|
|
3
4
|
import { TracerProvider } from "@opentelemetry/api";
|
|
4
|
-
import { DocumentLoader } from "@fedify/vocab-runtime";
|
|
5
|
-
|
|
6
5
|
//#region src/sig/key.d.ts
|
|
7
6
|
/**
|
|
8
7
|
* Generates a key pair which is appropriate for Fedify.
|
|
@@ -19,7 +18,7 @@ declare function generateCryptoKeyPair(algorithm?: "RSASSA-PKCS1-v1_5" | "Ed2551
|
|
|
19
18
|
* serialization and storage.
|
|
20
19
|
* @throws {TypeError} If the key is invalid or unsupported.
|
|
21
20
|
*/
|
|
22
|
-
declare function exportJwk(key:
|
|
21
|
+
declare function exportJwk(key: CryptoKeyLike): Promise<JsonWebKey>;
|
|
23
22
|
/**
|
|
24
23
|
* Imports a key from JWK format.
|
|
25
24
|
* @param jwk The key in JWK format.
|
|
@@ -421,7 +420,7 @@ interface Rfc9421SignRequestOptions {
|
|
|
421
420
|
* @returns The signed request.
|
|
422
421
|
* @throws {TypeError} If the private key is invalid or unsupported.
|
|
423
422
|
*/
|
|
424
|
-
declare function signRequest(request: Request, privateKey:
|
|
423
|
+
declare function signRequest(request: Request, privateKey: CryptoKeyLike, keyId: URL, options?: SignRequestOptions): Promise<Request>;
|
|
425
424
|
/**
|
|
426
425
|
* Options for {@link verifyRequest}.
|
|
427
426
|
*/
|