@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
|
@@ -7,11 +7,12 @@ let _opentelemetry_api = require("@opentelemetry/api");
|
|
|
7
7
|
let byte_encodings_hex = require("byte-encodings/hex");
|
|
8
8
|
let _fedify_vocab_runtime = require("@fedify/vocab-runtime");
|
|
9
9
|
let structured_field_values = require("structured-field-values");
|
|
10
|
+
let _fedify_vocab_runtime_internal = require("@fedify/vocab-runtime/internal");
|
|
10
11
|
let _opentelemetry_semantic_conventions = require("@opentelemetry/semantic-conventions");
|
|
11
12
|
let byte_encodings_base64 = require("byte-encodings/base64");
|
|
12
13
|
//#region deno.json
|
|
13
14
|
var name = "@fedify/fedify";
|
|
14
|
-
var version = "2.1.
|
|
15
|
+
var version = "2.1.32";
|
|
15
16
|
//#endregion
|
|
16
17
|
//#region src/sig/accept.ts
|
|
17
18
|
/**
|
|
@@ -262,7 +263,7 @@ function generateCryptoKeyPair(algorithm) {
|
|
|
262
263
|
*/
|
|
263
264
|
async function exportJwk(key) {
|
|
264
265
|
validateCryptoKey(key);
|
|
265
|
-
const jwk = await crypto.subtle.exportKey("jwk", key);
|
|
266
|
+
const jwk = await crypto.subtle.exportKey("jwk", (0, _fedify_vocab_runtime_internal.asCryptoKey)(key));
|
|
266
267
|
if (jwk.crv === "Ed25519") jwk.alg = "Ed25519";
|
|
267
268
|
return jwk;
|
|
268
269
|
}
|
|
@@ -775,12 +776,13 @@ const DOUBLE_KNOCK_TRANSPORT_RETRY_DELAY_MS = 100;
|
|
|
775
776
|
*/
|
|
776
777
|
async function signRequest(request, privateKey, keyId, options = {}) {
|
|
777
778
|
validateCryptoKey(privateKey, "private");
|
|
779
|
+
const signingKey = (0, _fedify_vocab_runtime_internal.asCryptoKey)(privateKey);
|
|
778
780
|
return await (options.tracerProvider ?? _opentelemetry_api.trace.getTracerProvider()).getTracer(name, version).startActiveSpan("http_signatures.sign", async (span) => {
|
|
779
781
|
try {
|
|
780
782
|
const spec = options.spec ?? "draft-cavage-http-signatures-12";
|
|
781
783
|
let signed;
|
|
782
|
-
if (spec === "rfc9421") signed = await signRequestRfc9421(request,
|
|
783
|
-
else signed = await signRequestDraft(request,
|
|
784
|
+
if (spec === "rfc9421") signed = await signRequestRfc9421(request, signingKey, keyId, span, options.currentTime, options.body, options.rfc9421);
|
|
785
|
+
else signed = await signRequestDraft(request, signingKey, keyId, span, options.currentTime, options.body);
|
|
784
786
|
if (span.isRecording()) {
|
|
785
787
|
span.setAttribute(_opentelemetry_semantic_conventions.ATTR_HTTP_REQUEST_METHOD, signed.method);
|
|
786
788
|
span.setAttribute(_opentelemetry_semantic_conventions.ATTR_URL_FULL, signed.url);
|
|
@@ -1598,10 +1600,10 @@ async function createRedirectRequest(request, location, body, validateRedirect)
|
|
|
1598
1600
|
cache: request.cache
|
|
1599
1601
|
});
|
|
1600
1602
|
}
|
|
1601
|
-
async function fetchDoubleKnockRequest(request, signedRequest, signal) {
|
|
1603
|
+
async function fetchDoubleKnockRequest(session, request, signedRequest, signal) {
|
|
1602
1604
|
const maxAttempts = request.method === "GET" || request.method === "HEAD" ? 2 : 1;
|
|
1603
1605
|
for (let attempt = 1;; attempt++) try {
|
|
1604
|
-
return await fetch(signedRequest, {
|
|
1606
|
+
return await session.fetch(signedRequest, {
|
|
1605
1607
|
redirect: "manual",
|
|
1606
1608
|
signal
|
|
1607
1609
|
});
|
|
@@ -1652,117 +1654,186 @@ function getAbortReason(signal) {
|
|
|
1652
1654
|
return signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
|
|
1653
1655
|
}
|
|
1654
1656
|
/**
|
|
1655
|
-
* Performs a double-knock request
|
|
1656
|
-
*
|
|
1657
|
-
*
|
|
1657
|
+
* Performs a double-knock request like {@link doubleKnock}, opening a session
|
|
1658
|
+
* for every hop with the given function, and passes the final response to
|
|
1659
|
+
* the given function. The final session is closed after `consume` settles,
|
|
1660
|
+
* so `consume` must read or cancel the response body before it returns.
|
|
1661
|
+
* This is not exported from any entry point.
|
|
1658
1662
|
* @param request The request to send.
|
|
1659
1663
|
* @param identity The identity to use for signing the request.
|
|
1660
1664
|
* @param options The options for double-knock requests.
|
|
1661
|
-
* @
|
|
1662
|
-
*
|
|
1665
|
+
* @param openHop The function to open a session for each hop. The session of
|
|
1666
|
+
* a hop is closed before the next hop is opened.
|
|
1667
|
+
* @param consume The function to consume the final response.
|
|
1668
|
+
* @returns The value returned by `consume`.
|
|
1663
1669
|
*/
|
|
1664
|
-
async function
|
|
1665
|
-
|
|
1670
|
+
async function doubleKnockScoped(request, identity, options, openHop, consume) {
|
|
1671
|
+
const { response, session } = await doubleKnockCore(request, identity, options, openHop);
|
|
1672
|
+
try {
|
|
1673
|
+
return await consume(response);
|
|
1674
|
+
} catch (error) {
|
|
1675
|
+
(0, _logtape_logtape.getLogger)([
|
|
1676
|
+
"fedify",
|
|
1677
|
+
"sig",
|
|
1678
|
+
"http"
|
|
1679
|
+
]).debug("Failed to consume the response from {url}; closing the session: {error}", {
|
|
1680
|
+
url: request.url,
|
|
1681
|
+
error
|
|
1682
|
+
});
|
|
1683
|
+
throw error;
|
|
1684
|
+
} finally {
|
|
1685
|
+
await session.close();
|
|
1686
|
+
}
|
|
1666
1687
|
}
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
|
|
1681
|
-
if (redirected >= DEFAULT_MAX_REDIRECTION) throw new _fedify_vocab_runtime.FetchError(request.url, `Too many redirections (${redirected + 1})`);
|
|
1682
|
-
const redirectRequest = await createRedirectRequest(request, response.headers.get("Location"), body, options.validateRedirect);
|
|
1683
|
-
if (visited.has(redirectRequest.url)) throw new _fedify_vocab_runtime.FetchError(request.url, `Redirect loop detected: ${redirectRequest.url}`);
|
|
1684
|
-
return doubleKnockInternal(redirectRequest, identity, {
|
|
1685
|
-
...options,
|
|
1686
|
-
body
|
|
1687
|
-
}, redirected + 1, visited);
|
|
1688
|
-
} else if (response.status === 400 || response.status === 401 || response.status > 401) {
|
|
1689
|
-
const logger = (0, _logtape_logtape.getLogger)([
|
|
1688
|
+
function isRedirectResponse(response) {
|
|
1689
|
+
return response.status >= 300 && response.status < 400 && response.headers.has("Location");
|
|
1690
|
+
}
|
|
1691
|
+
/**
|
|
1692
|
+
* Starts cancelling the body of a response that is not passed to the caller,
|
|
1693
|
+
* without waiting for it to settle. The cancellation of a branch of a tee
|
|
1694
|
+
* (e.g., a body cloned by a fetch mock) settles only after the other branch
|
|
1695
|
+
* is cancelled too, per the Streams standard, so awaiting it could block
|
|
1696
|
+
* forever. Failures are only logged.
|
|
1697
|
+
*/
|
|
1698
|
+
function cancelResponseBody(response, url) {
|
|
1699
|
+
response.body?.cancel().catch((error) => {
|
|
1700
|
+
(0, _logtape_logtape.getLogger)([
|
|
1690
1701
|
"fedify",
|
|
1691
1702
|
"sig",
|
|
1692
1703
|
"http"
|
|
1693
|
-
])
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1704
|
+
]).debug("Failed to cancel the response body from {url}: {error}", {
|
|
1705
|
+
url,
|
|
1706
|
+
error
|
|
1707
|
+
});
|
|
1708
|
+
});
|
|
1709
|
+
}
|
|
1710
|
+
async function doubleKnockCore(request, identity, options, openHop) {
|
|
1711
|
+
const { specDeterminer, log, tracerProvider, signal } = options;
|
|
1712
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1713
|
+
const body = options.body !== void 0 ? options.body : request.method !== "GET" && request.method !== "HEAD" ? await request.clone().arrayBuffer() : null;
|
|
1714
|
+
let session = await openHop(request.url);
|
|
1715
|
+
try {
|
|
1716
|
+
for (let redirected = 0;; redirected++) {
|
|
1717
|
+
visited.add(request.url);
|
|
1718
|
+
const origin = new URL(request.url).origin;
|
|
1719
|
+
const firstTrySpec = specDeterminer == null ? "rfc9421" : await specDeterminer.determineSpec(origin);
|
|
1720
|
+
let signedRequest = await signRequest(request, identity.privateKey, identity.keyId, {
|
|
1721
|
+
spec: firstTrySpec,
|
|
1722
|
+
tracerProvider,
|
|
1723
|
+
body
|
|
1724
|
+
});
|
|
1725
|
+
log?.(signedRequest);
|
|
1726
|
+
let response = await fetchDoubleKnockRequest(session, request, signedRequest, signal);
|
|
1727
|
+
const firstRedirected = isRedirectResponse(response);
|
|
1728
|
+
if (!firstRedirected && (response.status === 400 || response.status === 401 || response.status > 401)) {
|
|
1729
|
+
const logger = (0, _logtape_logtape.getLogger)([
|
|
1730
|
+
"fedify",
|
|
1731
|
+
"sig",
|
|
1732
|
+
"http"
|
|
1733
|
+
]);
|
|
1734
|
+
const acceptSigHeader = response.headers.get("Accept-Signature");
|
|
1735
|
+
if (acceptSigHeader != null) {
|
|
1736
|
+
const entries = validateAcceptSignature(parseAcceptSignature(acceptSigHeader));
|
|
1737
|
+
const localKeyId = identity.keyId.href;
|
|
1738
|
+
const localAlg = "rsa-v1_5-sha256";
|
|
1739
|
+
let fulfilled = false;
|
|
1740
|
+
let challengeRequest;
|
|
1741
|
+
for (const entry of entries) {
|
|
1742
|
+
const rfc9421 = fulfillAcceptSignature(entry, localKeyId, localAlg);
|
|
1743
|
+
if (rfc9421 == null) continue;
|
|
1744
|
+
logger.debug("Received Accept-Signature challenge; accumulating label {label} and components {components}.", {
|
|
1745
|
+
label: rfc9421.label,
|
|
1746
|
+
components: rfc9421.components
|
|
1747
|
+
});
|
|
1748
|
+
try {
|
|
1749
|
+
challengeRequest = await signRequest(challengeRequest ?? request, identity.privateKey, identity.keyId, {
|
|
1750
|
+
spec: "rfc9421",
|
|
1751
|
+
tracerProvider,
|
|
1752
|
+
body,
|
|
1753
|
+
rfc9421
|
|
1754
|
+
});
|
|
1755
|
+
fulfilled = true;
|
|
1756
|
+
} catch (error) {
|
|
1757
|
+
logger.debug("Failed to fulfill Accept-Signature challenge entry {label}: {error}", {
|
|
1758
|
+
label: entry.label,
|
|
1759
|
+
error
|
|
1760
|
+
});
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
if (fulfilled && challengeRequest != null) {
|
|
1764
|
+
cancelResponseBody(response, request.url);
|
|
1765
|
+
signedRequest = challengeRequest;
|
|
1766
|
+
log?.(signedRequest);
|
|
1767
|
+
response = await session.fetch(signedRequest, {
|
|
1768
|
+
redirect: "manual",
|
|
1769
|
+
signal
|
|
1770
|
+
});
|
|
1771
|
+
}
|
|
1772
|
+
if (fulfilled && !isRedirectResponse(response)) {
|
|
1773
|
+
if (response.status < 300) {
|
|
1774
|
+
await specDeterminer?.rememberSpec(origin, "rfc9421");
|
|
1775
|
+
return {
|
|
1776
|
+
response,
|
|
1777
|
+
session
|
|
1778
|
+
};
|
|
1779
|
+
}
|
|
1780
|
+
if (response.status !== 400 && response.status !== 401) return {
|
|
1781
|
+
response,
|
|
1782
|
+
session
|
|
1783
|
+
};
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
if (!isRedirectResponse(response)) {
|
|
1787
|
+
const spec = firstTrySpec === "draft-cavage-http-signatures-12" ? "rfc9421" : "draft-cavage-http-signatures-12";
|
|
1788
|
+
(0, _logtape_logtape.getLogger)([
|
|
1789
|
+
"fedify",
|
|
1790
|
+
"sig",
|
|
1791
|
+
"http"
|
|
1792
|
+
]).debug("Failed to verify with the spec {spec} ({status} {statusText}); retrying with spec {secondSpec}... (double-knocking)", {
|
|
1793
|
+
spec: firstTrySpec,
|
|
1794
|
+
secondSpec: spec,
|
|
1795
|
+
status: response.status,
|
|
1796
|
+
statusText: response.statusText
|
|
1714
1797
|
});
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1798
|
+
cancelResponseBody(response, request.url);
|
|
1799
|
+
signedRequest = await signRequest(request, identity.privateKey, identity.keyId, {
|
|
1800
|
+
spec,
|
|
1801
|
+
tracerProvider,
|
|
1802
|
+
body
|
|
1720
1803
|
});
|
|
1804
|
+
log?.(signedRequest);
|
|
1805
|
+
response = await fetchDoubleKnockRequest(session, request, signedRequest, signal);
|
|
1806
|
+
if (!isRedirectResponse(response) && response.status !== 400 && response.status !== 401) await specDeterminer?.rememberSpec(origin, spec);
|
|
1721
1807
|
}
|
|
1722
|
-
}
|
|
1723
|
-
if (
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
});
|
|
1730
|
-
if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) return doubleKnock(await createRedirectRequest(request, response.headers.get("Location"), body, options.validateRedirect), identity, {
|
|
1731
|
-
...options,
|
|
1732
|
-
body
|
|
1733
|
-
});
|
|
1734
|
-
}
|
|
1735
|
-
if (fulfilled && response.status < 300) {
|
|
1736
|
-
await specDeterminer?.rememberSpec(origin, "rfc9421");
|
|
1737
|
-
return response;
|
|
1738
|
-
}
|
|
1739
|
-
if (fulfilled && response.status !== 400 && response.status !== 401) return response;
|
|
1740
|
-
}
|
|
1741
|
-
const spec = firstTrySpec === "draft-cavage-http-signatures-12" ? "rfc9421" : "draft-cavage-http-signatures-12";
|
|
1742
|
-
logger.debug("Failed to verify with the spec {spec} ({status} {statusText}); retrying with spec {secondSpec}... (double-knocking)", {
|
|
1743
|
-
spec: firstTrySpec,
|
|
1744
|
-
secondSpec: spec,
|
|
1745
|
-
status: response.status,
|
|
1746
|
-
statusText: response.statusText
|
|
1747
|
-
});
|
|
1748
|
-
signedRequest = await signRequest(request, identity.privateKey, identity.keyId, {
|
|
1749
|
-
spec,
|
|
1750
|
-
tracerProvider,
|
|
1751
|
-
body
|
|
1752
|
-
});
|
|
1753
|
-
log?.(signedRequest);
|
|
1754
|
-
response = await fetchDoubleKnockRequest(request, signedRequest, signal);
|
|
1755
|
-
if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
|
|
1808
|
+
} else if (!firstRedirected) await specDeterminer?.rememberSpec(origin, firstTrySpec);
|
|
1809
|
+
if (!isRedirectResponse(response)) return {
|
|
1810
|
+
response,
|
|
1811
|
+
session
|
|
1812
|
+
};
|
|
1813
|
+
cancelResponseBody(response, request.url);
|
|
1814
|
+
await session.close();
|
|
1756
1815
|
if (redirected >= DEFAULT_MAX_REDIRECTION) throw new _fedify_vocab_runtime.FetchError(request.url, `Too many redirections (${redirected + 1})`);
|
|
1757
|
-
const
|
|
1816
|
+
const location = response.headers.get("Location");
|
|
1817
|
+
const redirectRequest = await createRedirectRequest(request, location, body, options.validateRedirect);
|
|
1758
1818
|
if (visited.has(redirectRequest.url)) throw new _fedify_vocab_runtime.FetchError(request.url, `Redirect loop detected: ${redirectRequest.url}`);
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1819
|
+
request = redirectRequest;
|
|
1820
|
+
session = await openHop(request.url);
|
|
1821
|
+
}
|
|
1822
|
+
} catch (error) {
|
|
1823
|
+
try {
|
|
1824
|
+
await session.close();
|
|
1825
|
+
} catch (closeError) {
|
|
1826
|
+
(0, _logtape_logtape.getLogger)([
|
|
1827
|
+
"fedify",
|
|
1828
|
+
"sig",
|
|
1829
|
+
"http"
|
|
1830
|
+
]).debug("Failed to close the session for {url}: {error}", {
|
|
1831
|
+
url: request.url,
|
|
1832
|
+
error: closeError
|
|
1833
|
+
});
|
|
1834
|
+
}
|
|
1835
|
+
throw error;
|
|
1836
|
+
}
|
|
1766
1837
|
}
|
|
1767
1838
|
/**
|
|
1768
1839
|
* Performs a timing-safe equality comparison between two `Uint8Array` values.
|
|
@@ -1792,10 +1863,10 @@ function timingSafeEqual(a, b) {
|
|
|
1792
1863
|
return result === 0;
|
|
1793
1864
|
}
|
|
1794
1865
|
//#endregion
|
|
1795
|
-
Object.defineProperty(exports, "
|
|
1866
|
+
Object.defineProperty(exports, "doubleKnockScoped", {
|
|
1796
1867
|
enumerable: true,
|
|
1797
1868
|
get: function() {
|
|
1798
|
-
return
|
|
1869
|
+
return doubleKnockScoped;
|
|
1799
1870
|
}
|
|
1800
1871
|
});
|
|
1801
1872
|
Object.defineProperty(exports, "exportJwk", {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
2
|
import { Actor, CryptographicKey, Multikey } from "@fedify/vocab";
|
|
3
|
-
import { DocumentLoader } from "@fedify/vocab-runtime";
|
|
4
3
|
import { TracerProvider } from "@opentelemetry/api";
|
|
5
|
-
|
|
4
|
+
import { CryptoKeyLike, DocumentLoader } from "@fedify/vocab-runtime";
|
|
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
|
*/
|