@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
|
@@ -2,10 +2,10 @@ const { Temporal } = require("@js-temporal/polyfill");
|
|
|
2
2
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
3
3
|
const require_chunk = require("./chunk-DDcVe30Y.cjs");
|
|
4
4
|
const require_transformers = require("./transformers-NeAONrAq.cjs");
|
|
5
|
-
const require_http = require("./http-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const require_kv_cache = require("./kv-cache-
|
|
5
|
+
const require_http = require("./http-BNaPJVnF.cjs");
|
|
6
|
+
const require_proof = require("./proof-Dbz6ApNP.cjs");
|
|
7
|
+
const require_types = require("./types-BWx7zw3Y.cjs");
|
|
8
|
+
const require_kv_cache = require("./kv-cache-Bj3CY9Jo.cjs");
|
|
9
9
|
let _logtape_logtape = require("@logtape/logtape");
|
|
10
10
|
let _fedify_vocab = require("@fedify/vocab");
|
|
11
11
|
let _opentelemetry_api = require("@opentelemetry/api");
|
|
@@ -14,9 +14,13 @@ let uri_template_router = require("uri-template-router");
|
|
|
14
14
|
let url_template = require("url-template");
|
|
15
15
|
let byte_encodings_hex = require("byte-encodings/hex");
|
|
16
16
|
let _fedify_vocab_runtime = require("@fedify/vocab-runtime");
|
|
17
|
-
let _opentelemetry_semantic_conventions = require("@opentelemetry/semantic-conventions");
|
|
18
17
|
let _fedify_vocab_runtime_jsonld = require("@fedify/vocab-runtime/jsonld");
|
|
19
18
|
_fedify_vocab_runtime_jsonld = require_chunk.__toESM(_fedify_vocab_runtime_jsonld);
|
|
19
|
+
let _fedify_vocab_runtime_internal = require("@fedify/vocab-runtime/internal");
|
|
20
|
+
let _opentelemetry_semantic_conventions = require("@opentelemetry/semantic-conventions");
|
|
21
|
+
let json_canon = require("json-canon");
|
|
22
|
+
json_canon = require_chunk.__toESM(json_canon);
|
|
23
|
+
let _fedify_vocab_runtime_temporal = require("@fedify/vocab-runtime/temporal");
|
|
20
24
|
let _fedify_webfinger = require("@fedify/webfinger");
|
|
21
25
|
let node_url = require("node:url");
|
|
22
26
|
//#region src/federation/activity-listener.ts
|
|
@@ -213,7 +217,7 @@ var FederationBuilderImpl = class {
|
|
|
213
217
|
this.collectionTypeIds = {};
|
|
214
218
|
}
|
|
215
219
|
async build(options) {
|
|
216
|
-
const { FederationImpl } = await Promise.resolve().then(() => require("./middleware-
|
|
220
|
+
const { FederationImpl } = await Promise.resolve().then(() => require("./middleware-CWOzxb3o.cjs"));
|
|
217
221
|
const f = new FederationImpl(options);
|
|
218
222
|
const trailingSlashInsensitiveValue = f.router.trailingSlashInsensitive;
|
|
219
223
|
f.router = this.router.clone();
|
|
@@ -781,6 +785,17 @@ async function buildCollectionSynchronizationHeader(collectionId, actorIds) {
|
|
|
781
785
|
return `collectionId="${collectionId}", url="${url}", digest="${(0, byte_encodings_hex.encodeHex)(await digest(actorIds))}"`;
|
|
782
786
|
}
|
|
783
787
|
//#endregion
|
|
788
|
+
//#region src/compat/attachment-arrays.ts
|
|
789
|
+
/**
|
|
790
|
+
* Applies the shared attachment workaround to served documents without
|
|
791
|
+
* rewriting any document that contains a semantic proof or LD signature.
|
|
792
|
+
* RDF equivalence alone cannot preserve JCS signatures.
|
|
793
|
+
* @internal
|
|
794
|
+
*/
|
|
795
|
+
function normalizeAttachmentArrays(document, contextLoader) {
|
|
796
|
+
return require_proof.normalizeAttachmentArrays(document, contextLoader, true);
|
|
797
|
+
}
|
|
798
|
+
//#endregion
|
|
784
799
|
//#region src/federation/inbox.ts
|
|
785
800
|
/**
|
|
786
801
|
* Checks whether an activity's ID and all of its actor IDs have the same
|
|
@@ -1122,13 +1137,10 @@ function acceptsJsonLd(request) {
|
|
|
1122
1137
|
function isPlainObject(value) {
|
|
1123
1138
|
return typeof value === "object" && value != null && !Array.isArray(value);
|
|
1124
1139
|
}
|
|
1125
|
-
function normalizeDateTimeLiteral(value) {
|
|
1126
|
-
return value.substring(19).match(/[Z+-]/) ? value : value + "Z";
|
|
1127
|
-
}
|
|
1128
1140
|
function isMalformedDateTimeLiteral(value) {
|
|
1129
1141
|
if (typeof value !== "string") return false;
|
|
1130
1142
|
try {
|
|
1131
|
-
Temporal.Instant.from(normalizeDateTimeLiteral(value));
|
|
1143
|
+
Temporal.Instant.from((0, _fedify_vocab_runtime_temporal.normalizeDateTimeLiteral)(value));
|
|
1132
1144
|
return false;
|
|
1133
1145
|
} catch {
|
|
1134
1146
|
return true;
|
|
@@ -1166,7 +1178,7 @@ function hasMalformedExpandedQuestionClosedLiteral(value) {
|
|
|
1166
1178
|
if (typeof literal === "boolean") return false;
|
|
1167
1179
|
if (typeof literal !== "string") return false;
|
|
1168
1180
|
if (value["@type"] !== XSD_DATE_TIME_IRI) return false;
|
|
1169
|
-
if (new Date(literal).toString() === "Invalid Date") return false;
|
|
1181
|
+
if (new Date(literal).toString() === "Invalid Date" && new Date((0, _fedify_vocab_runtime_temporal.normalizeDateTimeLiteral)(literal)).toString() === "Invalid Date") return false;
|
|
1170
1182
|
return isMalformedDateTimeLiteral(literal);
|
|
1171
1183
|
}
|
|
1172
1184
|
function hasMalformedExpandedDurationLiteral(value) {
|
|
@@ -1261,7 +1273,7 @@ async function handleActor(request, { identifier, context, actorDispatcher, auth
|
|
|
1261
1273
|
if (!await authorizePredicate(context, identifier)) return await onUnauthorized(request);
|
|
1262
1274
|
}
|
|
1263
1275
|
if (actor instanceof _fedify_vocab.Tombstone) {
|
|
1264
|
-
const jsonLd = await actor
|
|
1276
|
+
const jsonLd = await serializeForResponse(actor, context);
|
|
1265
1277
|
return new Response(JSON.stringify(jsonLd), {
|
|
1266
1278
|
status: 410,
|
|
1267
1279
|
headers: {
|
|
@@ -1270,7 +1282,7 @@ async function handleActor(request, { identifier, context, actorDispatcher, auth
|
|
|
1270
1282
|
}
|
|
1271
1283
|
});
|
|
1272
1284
|
}
|
|
1273
|
-
const jsonLd = await actor
|
|
1285
|
+
const jsonLd = await serializeForResponse(actor, context);
|
|
1274
1286
|
return new Response(JSON.stringify(jsonLd), { headers: {
|
|
1275
1287
|
"Content-Type": "application/activity+json",
|
|
1276
1288
|
Vary: "Accept"
|
|
@@ -1290,7 +1302,7 @@ async function handleObject(request, { values, context, objectDispatcher, author
|
|
|
1290
1302
|
if (authorizePredicate != null) {
|
|
1291
1303
|
if (!await authorizePredicate(context, values)) return await onUnauthorized(request);
|
|
1292
1304
|
}
|
|
1293
|
-
const jsonLd = await object
|
|
1305
|
+
const jsonLd = await serializeForResponse(object, context);
|
|
1294
1306
|
return new Response(JSON.stringify(jsonLd), { headers: {
|
|
1295
1307
|
"Content-Type": "application/activity+json",
|
|
1296
1308
|
Vary: "Accept"
|
|
@@ -1421,7 +1433,7 @@ async function handleCollection(request, { name: name$1, identifier, uriGetter,
|
|
|
1421
1433
|
if (collectionCallbacks.authorizePredicate != null) {
|
|
1422
1434
|
if (!await collectionCallbacks.authorizePredicate(context, identifier)) return await onUnauthorized(request);
|
|
1423
1435
|
}
|
|
1424
|
-
const jsonLd = await collection
|
|
1436
|
+
const jsonLd = await serializeForResponse(collection, context);
|
|
1425
1437
|
return new Response(JSON.stringify(jsonLd), { headers: {
|
|
1426
1438
|
"Content-Type": "application/activity+json",
|
|
1427
1439
|
Vary: "Accept"
|
|
@@ -1770,7 +1782,11 @@ async function handleInboxInternal(request, parameters, span) {
|
|
|
1770
1782
|
}
|
|
1771
1783
|
const keyCache = new KvKeyCache(kv, kvPrefixes.publicKey, ctx);
|
|
1772
1784
|
const jsonWithoutSig = require_proof.detachSignature(json);
|
|
1773
|
-
const hasLdSignature = require_proof.
|
|
1785
|
+
const hasLdSignature = require_proof.hasVerifiableSignature(json);
|
|
1786
|
+
if (!hasLdSignature) {
|
|
1787
|
+
const shape = require_proof.describeSignatureShape(json);
|
|
1788
|
+
if (shape != null) logger.debug("Linked Data Signature has an unsupported shape: {signatureKind}; properties: {signatureProperties}.", shape);
|
|
1789
|
+
}
|
|
1774
1790
|
const canAttemptAlternateAuthAfterLdSignatureFailure = skipSignatureVerification || hasHttpSignatureHeaders(request) || hasObjectIntegrityProof(jsonWithoutSig);
|
|
1775
1791
|
let deferredLdSignatureError = void 0;
|
|
1776
1792
|
const respondInvalidActivity = async (error) => {
|
|
@@ -2249,7 +2265,7 @@ var CustomCollectionHandler = class {
|
|
|
2249
2265
|
* @returns A promise that resolves to the JSON-LD representation.
|
|
2250
2266
|
*/
|
|
2251
2267
|
async toJsonLd() {
|
|
2252
|
-
return (await this.collection
|
|
2268
|
+
return serializeForResponse(await this.collection, this.context);
|
|
2253
2269
|
}
|
|
2254
2270
|
/**
|
|
2255
2271
|
* Fetches the collection with optional cursor for pagination.
|
|
@@ -2552,7 +2568,7 @@ var UnauthorizedError = class extends HandlerError {
|
|
|
2552
2568
|
* @since 0.3.0
|
|
2553
2569
|
*/
|
|
2554
2570
|
async function respondWithObject(object, options) {
|
|
2555
|
-
const jsonLd = await object
|
|
2571
|
+
const jsonLd = await serializeForResponse(object, options);
|
|
2556
2572
|
return new Response(JSON.stringify(jsonLd), { headers: { "Content-Type": "application/activity+json" } });
|
|
2557
2573
|
}
|
|
2558
2574
|
/**
|
|
@@ -2640,6 +2656,106 @@ const MIN_COMPONENTS = [
|
|
|
2640
2656
|
"@target-uri",
|
|
2641
2657
|
"@authority"
|
|
2642
2658
|
];
|
|
2659
|
+
/** Applies compatibility changes only after ordinary vocabulary serialization. */
|
|
2660
|
+
async function serializeForResponse(object, options) {
|
|
2661
|
+
return await normalizeAttachmentArrays(await object.toJsonLd(options), options?.contextLoader);
|
|
2662
|
+
}
|
|
2663
|
+
//#endregion
|
|
2664
|
+
//#region src/sig/proof-creation.ts
|
|
2665
|
+
/** Signs the exact serialized message supplied by an internal producer. */
|
|
2666
|
+
async function createProofForJsonLd(jsonLd, privateKey, keyId, created) {
|
|
2667
|
+
require_http.validateCryptoKey(privateKey, "private");
|
|
2668
|
+
if (privateKey.algorithm.name !== "Ed25519") throw new TypeError("Unsupported algorithm: " + privateKey.algorithm.name);
|
|
2669
|
+
const encoder = new TextEncoder();
|
|
2670
|
+
const msgDigest = await crypto.subtle.digest("SHA-256", encoder.encode((0, json_canon.default)(jsonLd)));
|
|
2671
|
+
created ??= Temporal.Now.instant();
|
|
2672
|
+
const proofConfig = {
|
|
2673
|
+
"@context": jsonLd["@context"],
|
|
2674
|
+
type: "DataIntegrityProof",
|
|
2675
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
2676
|
+
verificationMethod: keyId.href,
|
|
2677
|
+
proofPurpose: "assertionMethod",
|
|
2678
|
+
created: created.toString()
|
|
2679
|
+
};
|
|
2680
|
+
const proofDigest = await crypto.subtle.digest("SHA-256", encoder.encode((0, json_canon.default)(proofConfig)));
|
|
2681
|
+
const digest = new Uint8Array(proofDigest.byteLength + msgDigest.byteLength);
|
|
2682
|
+
digest.set(new Uint8Array(proofDigest), 0);
|
|
2683
|
+
digest.set(new Uint8Array(msgDigest), proofDigest.byteLength);
|
|
2684
|
+
const sig = await crypto.subtle.sign("Ed25519", (0, _fedify_vocab_runtime_internal.asCryptoKey)(privateKey), digest);
|
|
2685
|
+
return new _fedify_vocab.DataIntegrityProof({
|
|
2686
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
2687
|
+
verificationMethod: keyId,
|
|
2688
|
+
proofPurpose: "assertionMethod",
|
|
2689
|
+
created,
|
|
2690
|
+
proofValue: new Uint8Array(sig)
|
|
2691
|
+
});
|
|
2692
|
+
}
|
|
2693
|
+
//#endregion
|
|
2694
|
+
//#region src/compat/delivery-jsonld.ts
|
|
2695
|
+
/**
|
|
2696
|
+
* Returns changed wire JSON only; unchanged documents keep the existing
|
|
2697
|
+
* delivery signing path. This uses ordinary vocabulary serialization, without
|
|
2698
|
+
* retaining or repairing independently signed child representations.
|
|
2699
|
+
*/
|
|
2700
|
+
async function prepareActivityJsonLd(activity, contextLoader) {
|
|
2701
|
+
if (activity.proofIds.length > 0) return void 0;
|
|
2702
|
+
for await (const _ of activity.getProofs({ contextLoader })) return void 0;
|
|
2703
|
+
const source = await activity.clone().toJsonLd({
|
|
2704
|
+
format: "compact",
|
|
2705
|
+
contextLoader
|
|
2706
|
+
});
|
|
2707
|
+
const prepared = await require_proof.normalizeOutgoingActivityJsonLd(source, contextLoader, true);
|
|
2708
|
+
return prepared !== source && typeof prepared === "object" && prepared != null && !Array.isArray(prepared) ? prepared : void 0;
|
|
2709
|
+
}
|
|
2710
|
+
/** Signs a changed, proof-free delivery map without serializing it again. */
|
|
2711
|
+
async function signActivityJsonLd(activity, unsigned, keys, options) {
|
|
2712
|
+
const proofs = [];
|
|
2713
|
+
const serializedProofs = [];
|
|
2714
|
+
const tracer = (options.tracerProvider ?? _opentelemetry_api.trace.getTracerProvider()).getTracer(require_http.name, require_http.version);
|
|
2715
|
+
for (const { privateKey, keyId } of keys) {
|
|
2716
|
+
const proof = await tracer.startActiveSpan("object_integrity_proofs.sign", { attributes: { "activitypub.object.type": (0, _fedify_vocab.getTypeId)(activity).href } }, async (span) => {
|
|
2717
|
+
try {
|
|
2718
|
+
if (activity.id != null) span.setAttribute("activitypub.object.id", activity.id.href);
|
|
2719
|
+
const proof = await createProofForJsonLd(unsigned, privateKey, keyId);
|
|
2720
|
+
if (span.isRecording()) {
|
|
2721
|
+
span.setAttribute("object_integrity_proofs.cryptosuite", "eddsa-jcs-2022");
|
|
2722
|
+
span.setAttribute("object_integrity_proofs.key_id", keyId.href);
|
|
2723
|
+
span.setAttribute("object_integrity_proofs.signature", (0, byte_encodings_hex.encodeHex)(proof.proofValue));
|
|
2724
|
+
}
|
|
2725
|
+
return proof;
|
|
2726
|
+
} catch (error) {
|
|
2727
|
+
span.setStatus({
|
|
2728
|
+
code: _opentelemetry_api.SpanStatusCode.ERROR,
|
|
2729
|
+
message: String(error)
|
|
2730
|
+
});
|
|
2731
|
+
throw error;
|
|
2732
|
+
} finally {
|
|
2733
|
+
span.end();
|
|
2734
|
+
}
|
|
2735
|
+
});
|
|
2736
|
+
proofs.push(proof);
|
|
2737
|
+
serializedProofs.push({
|
|
2738
|
+
"@context": unsigned["@context"],
|
|
2739
|
+
type: "DataIntegrityProof",
|
|
2740
|
+
cryptosuite: proof.cryptosuite,
|
|
2741
|
+
verificationMethod: keyId.href,
|
|
2742
|
+
proofPurpose: "assertionMethod",
|
|
2743
|
+
created: proof.created.toString(),
|
|
2744
|
+
proofValue: new TextDecoder().decode((0, _fedify_vocab_runtime.encodeMultibase)("base58btc", proof.proofValue))
|
|
2745
|
+
});
|
|
2746
|
+
}
|
|
2747
|
+
if (proofs.length === 0) return {
|
|
2748
|
+
activity,
|
|
2749
|
+
jsonLd: unsigned
|
|
2750
|
+
};
|
|
2751
|
+
return {
|
|
2752
|
+
activity: activity.clone({ proofs }),
|
|
2753
|
+
jsonLd: {
|
|
2754
|
+
...unsigned,
|
|
2755
|
+
proof: serializedProofs.length === 1 ? serializedProofs[0] : serializedProofs
|
|
2756
|
+
}
|
|
2757
|
+
};
|
|
2758
|
+
}
|
|
2643
2759
|
//#endregion
|
|
2644
2760
|
//#region src/nodeinfo/handler.ts
|
|
2645
2761
|
/**
|
|
@@ -2738,9 +2854,11 @@ function extractInboxes({ recipients, preferSharedInbox, excludeBaseUris }) {
|
|
|
2738
2854
|
*
|
|
2739
2855
|
* @param parameters The parameters for sending the activity.
|
|
2740
2856
|
* See also {@link SendActivityParameters}.
|
|
2741
|
-
* @
|
|
2857
|
+
* @param deps The dependencies, for tests.
|
|
2858
|
+
* @throws {FetchError} If the delivery times out before receiving a response.
|
|
2859
|
+
* @throws {SendActivityError} If the inbox returns an unsuccessful response.
|
|
2742
2860
|
*/
|
|
2743
|
-
function sendActivity(options) {
|
|
2861
|
+
function sendActivity(options, deps = {}) {
|
|
2744
2862
|
const tracerProvider = options.tracerProvider ?? _opentelemetry_api.trace.getTracerProvider();
|
|
2745
2863
|
return tracerProvider.getTracer(require_http.name, require_http.version).startActiveSpan("activitypub.send_activity", {
|
|
2746
2864
|
kind: _opentelemetry_api.SpanKind.CLIENT,
|
|
@@ -2752,7 +2870,7 @@ function sendActivity(options) {
|
|
|
2752
2870
|
await sendActivityInternal({
|
|
2753
2871
|
...options,
|
|
2754
2872
|
tracerProvider
|
|
2755
|
-
}, span);
|
|
2873
|
+
}, span, deps);
|
|
2756
2874
|
} catch (e) {
|
|
2757
2875
|
span.setStatus({
|
|
2758
2876
|
code: _opentelemetry_api.SpanStatusCode.ERROR,
|
|
@@ -2765,7 +2883,25 @@ function sendActivity(options) {
|
|
|
2765
2883
|
});
|
|
2766
2884
|
}
|
|
2767
2885
|
const MAX_ERROR_RESPONSE_BODY_BYTES = 1024;
|
|
2768
|
-
|
|
2886
|
+
const SEND_ACTIVITY_TIMEOUT_MS = 3e4;
|
|
2887
|
+
function raceWithAbort(promise, signal) {
|
|
2888
|
+
if (signal.aborted) return Promise.reject(signal.reason);
|
|
2889
|
+
return new Promise((resolve, reject) => {
|
|
2890
|
+
const onAbort = () => {
|
|
2891
|
+
signal.removeEventListener("abort", onAbort);
|
|
2892
|
+
reject(signal.reason);
|
|
2893
|
+
};
|
|
2894
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
2895
|
+
promise.then((value) => {
|
|
2896
|
+
signal.removeEventListener("abort", onAbort);
|
|
2897
|
+
resolve(value);
|
|
2898
|
+
}, (error) => {
|
|
2899
|
+
signal.removeEventListener("abort", onAbort);
|
|
2900
|
+
reject(error);
|
|
2901
|
+
});
|
|
2902
|
+
});
|
|
2903
|
+
}
|
|
2904
|
+
async function readLimitedResponseBody(response, maxBytes, signal) {
|
|
2769
2905
|
if (response.body == null) return "";
|
|
2770
2906
|
const reader = response.body.getReader();
|
|
2771
2907
|
const decoder = new TextDecoder();
|
|
@@ -2774,7 +2910,8 @@ async function readLimitedResponseBody(response, maxBytes) {
|
|
|
2774
2910
|
let truncated = false;
|
|
2775
2911
|
try {
|
|
2776
2912
|
while (true) {
|
|
2777
|
-
|
|
2913
|
+
signal.throwIfAborted();
|
|
2914
|
+
const { done, value } = await raceWithAbort(reader.read(), signal);
|
|
2778
2915
|
if (done) break;
|
|
2779
2916
|
if (totalBytes + value.length > maxBytes) {
|
|
2780
2917
|
const remaining = maxBytes - totalBytes;
|
|
@@ -2786,21 +2923,39 @@ async function readLimitedResponseBody(response, maxBytes) {
|
|
|
2786
2923
|
totalBytes += value.length;
|
|
2787
2924
|
}
|
|
2788
2925
|
} finally {
|
|
2789
|
-
reader.
|
|
2926
|
+
if (truncated || signal.aborted) reader.cancel().catch(() => {});
|
|
2927
|
+
try {
|
|
2928
|
+
reader.releaseLock();
|
|
2929
|
+
} catch (_) {}
|
|
2790
2930
|
}
|
|
2791
2931
|
let result = chunks.join("");
|
|
2792
2932
|
if (truncated) result += "… (truncated)";
|
|
2793
2933
|
return result;
|
|
2794
2934
|
}
|
|
2795
|
-
async function sendActivityInternal({ activity, activityId, keys, inbox, allowPrivateAddress, headers, specDeterminer, tracerProvider }, span) {
|
|
2935
|
+
async function sendActivityInternal({ activity, activityId, keys, inbox, allowPrivateAddress, headers, specDeterminer, tracerProvider }, span, deps) {
|
|
2796
2936
|
const logger = (0, _logtape_logtape.getLogger)([
|
|
2797
2937
|
"fedify",
|
|
2798
2938
|
"federation",
|
|
2799
2939
|
"outbox"
|
|
2800
2940
|
]);
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2941
|
+
const timeoutMs = deps.timeoutMs ?? SEND_ACTIVITY_TIMEOUT_MS;
|
|
2942
|
+
const controller = new AbortController();
|
|
2943
|
+
const { signal } = controller;
|
|
2944
|
+
const openUnvalidatedHop = deps.openHop ?? (allowPrivateAddress ? _fedify_vocab_runtime_internal.openDirectFetch : (url) => (0, _fedify_vocab_runtime_internal.openPublicFetch)(url, { signal }));
|
|
2945
|
+
let opened = false;
|
|
2946
|
+
async function openHop(url) {
|
|
2947
|
+
let session;
|
|
2948
|
+
try {
|
|
2949
|
+
signal.throwIfAborted();
|
|
2950
|
+
const opening = openUnvalidatedHop(url);
|
|
2951
|
+
opening.then((lateSession) => {
|
|
2952
|
+
if (signal.aborted) closeAfterError(lateSession, logger);
|
|
2953
|
+
}, () => {});
|
|
2954
|
+
session = await raceWithAbort(opening, signal);
|
|
2955
|
+
if (signal.aborted) {
|
|
2956
|
+
closeAfterError(session, logger);
|
|
2957
|
+
signal.throwIfAborted();
|
|
2958
|
+
}
|
|
2804
2959
|
} catch (error) {
|
|
2805
2960
|
if (error instanceof _fedify_vocab_runtime.UrlError && error.reason === "dns") {
|
|
2806
2961
|
logger.error("DNS resolution failed for URL: {url}", {
|
|
@@ -2817,15 +2972,17 @@ async function sendActivityInternal({ activity, activityId, keys, inbox, allowPr
|
|
|
2817
2972
|
});
|
|
2818
2973
|
throw error;
|
|
2819
2974
|
}
|
|
2975
|
+
opened = true;
|
|
2976
|
+
return session;
|
|
2820
2977
|
}
|
|
2821
|
-
await validateUrl(inbox.href);
|
|
2822
2978
|
headers = new Headers(headers);
|
|
2823
2979
|
headers.set("Content-Type", "application/activity+json");
|
|
2824
2980
|
const request = new Request(inbox, {
|
|
2825
2981
|
method: "POST",
|
|
2826
2982
|
headers,
|
|
2827
2983
|
body: JSON.stringify(activity),
|
|
2828
|
-
redirect: "manual"
|
|
2984
|
+
redirect: "manual",
|
|
2985
|
+
signal
|
|
2829
2986
|
});
|
|
2830
2987
|
let rsaKey = null;
|
|
2831
2988
|
for (const key of keys) if (key.privateKey.algorithm.name === "RSASSA-PKCS1-v1_5") {
|
|
@@ -2839,36 +2996,60 @@ async function sendActivityInternal({ activity, activityId, keys, inbox, allowPr
|
|
|
2839
2996
|
privateKey: pair.privateKey
|
|
2840
2997
|
}))
|
|
2841
2998
|
});
|
|
2842
|
-
let
|
|
2999
|
+
let outcome;
|
|
3000
|
+
const boundedSpecDeterminer = specDeterminer == null ? void 0 : {
|
|
3001
|
+
determineSpec(origin) {
|
|
3002
|
+
signal.throwIfAborted();
|
|
3003
|
+
return raceWithAbort(Promise.resolve(specDeterminer.determineSpec(origin)), signal);
|
|
3004
|
+
},
|
|
3005
|
+
rememberSpec(origin, spec) {
|
|
3006
|
+
if (signal.aborted) return;
|
|
3007
|
+
try {
|
|
3008
|
+
Promise.resolve(specDeterminer.rememberSpec(origin, spec)).catch((error) => logger.debug("Failed to remember the signature spec for {origin}: {error}", {
|
|
3009
|
+
origin,
|
|
3010
|
+
error
|
|
3011
|
+
}));
|
|
3012
|
+
} catch (error) {
|
|
3013
|
+
logger.debug("Failed to remember the signature spec for {origin}: {error}", {
|
|
3014
|
+
origin,
|
|
3015
|
+
error
|
|
3016
|
+
});
|
|
3017
|
+
}
|
|
3018
|
+
}
|
|
3019
|
+
};
|
|
3020
|
+
const timer = setTimeout(() => controller.abort(new DOMException("The delivery timed out.", "TimeoutError")), timeoutMs);
|
|
2843
3021
|
try {
|
|
2844
|
-
|
|
3022
|
+
outcome = rsaKey == null ? await fetchWithValidatedRedirects(request, openHop, (response) => consumeSendActivityResponse(response, inbox, signal), signal) : await require_http.doubleKnockScoped(request, rsaKey, {
|
|
2845
3023
|
tracerProvider,
|
|
2846
|
-
specDeterminer,
|
|
2847
|
-
|
|
2848
|
-
});
|
|
3024
|
+
specDeterminer: boundedSpecDeterminer,
|
|
3025
|
+
signal
|
|
3026
|
+
}, openHop, (response) => consumeSendActivityResponse(response, inbox, signal));
|
|
2849
3027
|
} catch (error) {
|
|
2850
|
-
|
|
3028
|
+
let failureError = error;
|
|
3029
|
+
if (signal.aborted && !(error instanceof SendActivityError)) {
|
|
3030
|
+
const failure = new _fedify_vocab_runtime.FetchError(inbox.href, `Timed out after ${timeoutMs} ms`);
|
|
3031
|
+
failure.cause = signal.reason;
|
|
3032
|
+
failureError = failure;
|
|
3033
|
+
}
|
|
3034
|
+
if (opened || signal.aborted) logger.error("Failed to send activity {activityId} to {inbox}:\n{error}", {
|
|
2851
3035
|
activityId,
|
|
2852
3036
|
inbox: inbox.href,
|
|
2853
|
-
error
|
|
3037
|
+
error: failureError
|
|
2854
3038
|
});
|
|
2855
|
-
throw
|
|
3039
|
+
throw failureError;
|
|
3040
|
+
} finally {
|
|
3041
|
+
clearTimeout(timer);
|
|
2856
3042
|
}
|
|
2857
|
-
if (!
|
|
2858
|
-
|
|
2859
|
-
try {
|
|
2860
|
-
error = await readLimitedResponseBody(response, MAX_ERROR_RESPONSE_BODY_BYTES);
|
|
2861
|
-
} catch (_) {
|
|
2862
|
-
error = "";
|
|
2863
|
-
}
|
|
3043
|
+
if (!outcome.ok) {
|
|
3044
|
+
const { status, statusText, error } = outcome;
|
|
2864
3045
|
logger.error("Failed to send activity {activityId} to {inbox} ({status} {statusText}):\n{error}", {
|
|
2865
3046
|
activityId,
|
|
2866
3047
|
inbox: inbox.href,
|
|
2867
|
-
status
|
|
2868
|
-
statusText
|
|
3048
|
+
status,
|
|
3049
|
+
statusText,
|
|
2869
3050
|
error
|
|
2870
3051
|
});
|
|
2871
|
-
throw new SendActivityError(inbox,
|
|
3052
|
+
throw new SendActivityError(inbox, status, `Failed to send activity ${activityId} to ${inbox.href} (${status} ${statusText}):\n${error}`, error);
|
|
2872
3053
|
}
|
|
2873
3054
|
span.addEvent("activitypub.activity.sent", {
|
|
2874
3055
|
"activitypub.activity.json": JSON.stringify(activity),
|
|
@@ -2876,10 +3057,79 @@ async function sendActivityInternal({ activity, activityId, keys, inbox, allowPr
|
|
|
2876
3057
|
"activitypub.activity.id": activityId ?? ""
|
|
2877
3058
|
});
|
|
2878
3059
|
}
|
|
2879
|
-
|
|
3060
|
+
/**
|
|
3061
|
+
* Starts cancelling the body of a response without waiting for it to settle.
|
|
3062
|
+
* The cancellation of a branch of a tee (e.g., a body cloned by a fetch mock)
|
|
3063
|
+
* settles only after the other branch is cancelled too, per the Streams
|
|
3064
|
+
* standard, so awaiting it could block forever. Failures are only logged.
|
|
3065
|
+
*/
|
|
3066
|
+
function cancelResponseBody(response, url) {
|
|
3067
|
+
response.body?.cancel().catch((error) => {
|
|
3068
|
+
(0, _logtape_logtape.getLogger)([
|
|
3069
|
+
"fedify",
|
|
3070
|
+
"federation",
|
|
3071
|
+
"outbox"
|
|
3072
|
+
]).debug("Failed to cancel the response body from {url}: {error}", {
|
|
3073
|
+
url,
|
|
3074
|
+
error
|
|
3075
|
+
});
|
|
3076
|
+
});
|
|
3077
|
+
}
|
|
3078
|
+
/**
|
|
3079
|
+
* Reads what is needed from the final response of a delivery while its
|
|
3080
|
+
* session is open: the body of a successful response is cancelled, and at
|
|
3081
|
+
* most 1 KiB of an error response body is read.
|
|
3082
|
+
*/
|
|
3083
|
+
async function consumeSendActivityResponse(response, inbox, signal) {
|
|
3084
|
+
if (response.ok) {
|
|
3085
|
+
cancelResponseBody(response, response.url || inbox.href);
|
|
3086
|
+
return { ok: true };
|
|
3087
|
+
}
|
|
3088
|
+
let error;
|
|
3089
|
+
try {
|
|
3090
|
+
error = await readLimitedResponseBody(response, MAX_ERROR_RESPONSE_BODY_BYTES, signal);
|
|
3091
|
+
} catch (_) {
|
|
3092
|
+
error = "";
|
|
3093
|
+
}
|
|
3094
|
+
if (signal.aborted) error = "(timed out reading response body)";
|
|
3095
|
+
return {
|
|
3096
|
+
ok: false,
|
|
3097
|
+
status: response.status,
|
|
3098
|
+
statusText: response.statusText,
|
|
3099
|
+
error
|
|
3100
|
+
};
|
|
3101
|
+
}
|
|
3102
|
+
/**
|
|
3103
|
+
* Sends a request without signing it, following redirects manually like the
|
|
3104
|
+
* Fetch standard does. Every hop is opened with `openHop()`, which validates
|
|
3105
|
+
* the destination, after the previous hop is closed. The final response is
|
|
3106
|
+
* passed to `consume()`, and its session is closed after that.
|
|
3107
|
+
* This is exported only for tests; it is not exported from any entry point.
|
|
3108
|
+
* @param request The request to send.
|
|
3109
|
+
* @param openHop The function to open a session for each hop.
|
|
3110
|
+
* @param consume The function to consume the final response.
|
|
3111
|
+
* @returns The value returned by `consume`.
|
|
3112
|
+
*/
|
|
3113
|
+
async function fetchWithValidatedRedirects(request, openHop, consume, signal) {
|
|
3114
|
+
const logger = (0, _logtape_logtape.getLogger)([
|
|
3115
|
+
"fedify",
|
|
3116
|
+
"federation",
|
|
3117
|
+
"outbox"
|
|
3118
|
+
]);
|
|
2880
3119
|
let body = await request.clone().text();
|
|
2881
3120
|
for (let redirects = 0;; redirects++) {
|
|
2882
|
-
|
|
3121
|
+
signal?.throwIfAborted();
|
|
3122
|
+
const session = await openHop(request.url);
|
|
3123
|
+
let response;
|
|
3124
|
+
try {
|
|
3125
|
+
response = await session.fetch(request, {
|
|
3126
|
+
redirect: "manual",
|
|
3127
|
+
signal
|
|
3128
|
+
});
|
|
3129
|
+
} catch (error) {
|
|
3130
|
+
await closeAfterError(session, logger);
|
|
3131
|
+
throw error;
|
|
3132
|
+
}
|
|
2883
3133
|
const location = response.headers.get("Location");
|
|
2884
3134
|
if (![
|
|
2885
3135
|
301,
|
|
@@ -2887,11 +3137,21 @@ async function fetchWithValidatedRedirects(request, validateUrl) {
|
|
|
2887
3137
|
303,
|
|
2888
3138
|
307,
|
|
2889
3139
|
308
|
|
2890
|
-
].includes(response.status) || location == null)
|
|
2891
|
-
|
|
3140
|
+
].includes(response.status) || location == null) try {
|
|
3141
|
+
return await consume(response);
|
|
3142
|
+
} catch (error) {
|
|
3143
|
+
logger.debug("Failed to consume the response from {url}; closing the session: {error}", {
|
|
3144
|
+
url: request.url,
|
|
3145
|
+
error
|
|
3146
|
+
});
|
|
3147
|
+
throw error;
|
|
3148
|
+
} finally {
|
|
3149
|
+
await session.close();
|
|
3150
|
+
}
|
|
3151
|
+
cancelResponseBody(response, request.url);
|
|
3152
|
+
await session.close();
|
|
2892
3153
|
if (redirects >= 20) throw new TypeError("Too many redirects");
|
|
2893
3154
|
const url = new URL(location, request.url);
|
|
2894
|
-
await validateUrl(url.href);
|
|
2895
3155
|
const headers = new Headers(request.headers);
|
|
2896
3156
|
if (url.origin !== new URL(request.url).origin) {
|
|
2897
3157
|
headers.delete("Authorization");
|
|
@@ -2915,7 +3175,18 @@ async function fetchWithValidatedRedirects(request, validateUrl) {
|
|
|
2915
3175
|
method,
|
|
2916
3176
|
headers,
|
|
2917
3177
|
body,
|
|
2918
|
-
redirect: "manual"
|
|
3178
|
+
redirect: "manual",
|
|
3179
|
+
signal: signal ?? request.signal
|
|
3180
|
+
});
|
|
3181
|
+
}
|
|
3182
|
+
}
|
|
3183
|
+
async function closeAfterError(session, logger) {
|
|
3184
|
+
try {
|
|
3185
|
+
await session.close();
|
|
3186
|
+
} catch (error) {
|
|
3187
|
+
logger.debug("Failed to close the session for {url}: {error}", {
|
|
3188
|
+
url: session.url.href,
|
|
3189
|
+
error
|
|
2919
3190
|
});
|
|
2920
3191
|
}
|
|
2921
3192
|
}
|
|
@@ -3262,8 +3533,25 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
3262
3533
|
_getTracer() {
|
|
3263
3534
|
return this.tracerProvider.getTracer(require_http.name, require_http.version);
|
|
3264
3535
|
}
|
|
3536
|
+
/**
|
|
3537
|
+
* Starts listening on a queue, converting a synchronous throw into
|
|
3538
|
+
* a rejected promise.
|
|
3539
|
+
*
|
|
3540
|
+
* `MessageQueue.listen()` is documented to never reject, but some
|
|
3541
|
+
* implementations (e.g., `WorkersMessageQueue`) throw synchronously. Without
|
|
3542
|
+
* this normalization, one such throw aborts {@link _startQueueInternal} while
|
|
3543
|
+
* it is still collecting listener promises, so listeners started earlier are
|
|
3544
|
+
* never awaited and later queues are never started.
|
|
3545
|
+
*/
|
|
3546
|
+
#listenQueue(queue, ctxData, signal) {
|
|
3547
|
+
try {
|
|
3548
|
+
return queue.listen((msg) => this.processQueuedTask(ctxData, msg), { signal });
|
|
3549
|
+
} catch (error) {
|
|
3550
|
+
return Promise.reject(error);
|
|
3551
|
+
}
|
|
3552
|
+
}
|
|
3265
3553
|
async _startQueueInternal(ctxData, signal, queue) {
|
|
3266
|
-
if (this.inboxQueue == null && this.outboxQueue == null) return;
|
|
3554
|
+
if (this.inboxQueue == null && this.outboxQueue == null && this.fanoutQueue == null) return;
|
|
3267
3555
|
const logger = (0, _logtape_logtape.getLogger)([
|
|
3268
3556
|
"fedify",
|
|
3269
3557
|
"federation",
|
|
@@ -3273,20 +3561,38 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
3273
3561
|
if (this.inboxQueue != null && (queue == null || queue === "inbox") && !this.inboxQueueStarted) {
|
|
3274
3562
|
logger.debug("Starting an inbox task worker.");
|
|
3275
3563
|
this.inboxQueueStarted = true;
|
|
3276
|
-
promises.push(this
|
|
3564
|
+
promises.push(this.#listenQueue(this.inboxQueue, ctxData, signal));
|
|
3277
3565
|
}
|
|
3278
3566
|
if (this.outboxQueue != null && this.outboxQueue !== this.inboxQueue && (queue == null || queue === "outbox") && !this.outboxQueueStarted) {
|
|
3279
3567
|
logger.debug("Starting an outbox task worker.");
|
|
3280
3568
|
this.outboxQueueStarted = true;
|
|
3281
|
-
promises.push(this
|
|
3569
|
+
promises.push(this.#listenQueue(this.outboxQueue, ctxData, signal));
|
|
3282
3570
|
}
|
|
3283
3571
|
if (this.fanoutQueue != null && this.fanoutQueue !== this.inboxQueue && this.fanoutQueue !== this.outboxQueue && (queue == null || queue === "fanout") && !this.fanoutQueueStarted) {
|
|
3284
3572
|
logger.debug("Starting a fanout task worker.");
|
|
3285
3573
|
this.fanoutQueueStarted = true;
|
|
3286
|
-
promises.push(this
|
|
3574
|
+
promises.push(this.#listenQueue(this.fanoutQueue, ctxData, signal));
|
|
3287
3575
|
}
|
|
3288
3576
|
await Promise.all(promises);
|
|
3289
3577
|
}
|
|
3578
|
+
/**
|
|
3579
|
+
* Starts the queue workers automatically, reporting a failure instead of
|
|
3580
|
+
* leaving the returned promise unobserved.
|
|
3581
|
+
*
|
|
3582
|
+
* Automatic startup is best-effort: call sites cannot await it, so a failing
|
|
3583
|
+
* listener (e.g., `WorkersMessageQueue`, whose `listen()` throws) must not
|
|
3584
|
+
* become an unhandled rejection. {@link startQueue} keeps rejecting for
|
|
3585
|
+
* callers that start workers deliberately.
|
|
3586
|
+
*/
|
|
3587
|
+
_startQueueAutomatically(ctxData) {
|
|
3588
|
+
this._startQueueInternal(ctxData).catch((error) => {
|
|
3589
|
+
(0, _logtape_logtape.getLogger)([
|
|
3590
|
+
"fedify",
|
|
3591
|
+
"federation",
|
|
3592
|
+
"queue"
|
|
3593
|
+
]).warn("Failed to start queue workers automatically: {error}", { error });
|
|
3594
|
+
});
|
|
3595
|
+
}
|
|
3290
3596
|
processQueuedTask(contextData, message) {
|
|
3291
3597
|
const tracer = this._getTracer();
|
|
3292
3598
|
const extractedContext = _opentelemetry_api.propagation.extract(_opentelemetry_api.context.active(), message.traceContext);
|
|
@@ -3396,7 +3702,8 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
3396
3702
|
collectionSync: message.collectionSync,
|
|
3397
3703
|
orderingKey: message.orderingKey,
|
|
3398
3704
|
normalizeExistingProofs: message.normalizeExistingProofs,
|
|
3399
|
-
context
|
|
3705
|
+
context,
|
|
3706
|
+
activityJsonLd: hasTopLevelProof(message.activity) ? message.activity : void 0
|
|
3400
3707
|
});
|
|
3401
3708
|
}
|
|
3402
3709
|
async #listenOutboxMessage(_, message, span) {
|
|
@@ -3599,7 +3906,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
3599
3906
|
let parseInput = void 0;
|
|
3600
3907
|
let parseContextLoader = context.contextLoader;
|
|
3601
3908
|
try {
|
|
3602
|
-
const hasSignatureField = require_proof.
|
|
3909
|
+
const hasSignatureField = require_proof.hasVerifiableSignature(message.activity);
|
|
3603
3910
|
const shouldParseFromNormalizedSignedPayload = message.ldSignatureVerified === true || message.normalizedActivity != null || message.ldSignatureVerified == null && hasSignatureField;
|
|
3604
3911
|
const parseContext = hasSignatureField ? {
|
|
3605
3912
|
...context,
|
|
@@ -3795,21 +4102,31 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
3795
4102
|
hasProof = true;
|
|
3796
4103
|
break;
|
|
3797
4104
|
}
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
4105
|
+
const prepared = !hasProof && options.activityJsonLd == null ? await prepareActivityJsonLd(activity, contextLoader) : void 0;
|
|
4106
|
+
let jsonLd;
|
|
4107
|
+
if (prepared != null) {
|
|
4108
|
+
const signingKeys = keys.filter(({ privateKey }) => privateKey.algorithm.name === "Ed25519");
|
|
4109
|
+
const signed = await signActivityJsonLd(activity, prepared, signingKeys, { tracerProvider: this.tracerProvider });
|
|
4110
|
+
activity = signed.activity;
|
|
4111
|
+
jsonLd = signed.jsonLd;
|
|
4112
|
+
proofCreated = signingKeys.length > 0;
|
|
4113
|
+
} else {
|
|
4114
|
+
if (!hasProof) {
|
|
4115
|
+
for (const { keyId, privateKey } of keys) if (privateKey.algorithm.name === "Ed25519") {
|
|
4116
|
+
activity = await require_proof.signObject(activity, privateKey, keyId, {
|
|
4117
|
+
contextLoader,
|
|
4118
|
+
tracerProvider: this.tracerProvider
|
|
4119
|
+
});
|
|
4120
|
+
proofCreated = true;
|
|
4121
|
+
}
|
|
3806
4122
|
}
|
|
4123
|
+
jsonLd = options.activityJsonLd != null ? require_proof.detachSignature(options.activityJsonLd) : await activity.toJsonLd({
|
|
4124
|
+
format: "compact",
|
|
4125
|
+
contextLoader
|
|
4126
|
+
});
|
|
3807
4127
|
}
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
contextLoader
|
|
3811
|
-
});
|
|
3812
|
-
if (proofCreated || !hasProof || options.normalizeExistingProofs) jsonLd = await require_proof.normalizeOutgoingActivityJsonLd(jsonLd, contextLoader);
|
|
4128
|
+
if (prepared == null && (proofCreated || !hasProof || options.normalizeExistingProofs)) jsonLd = await require_proof.normalizeOutgoingActivityJsonLd(jsonLd, contextLoader);
|
|
4129
|
+
hasProof ||= proofCreated;
|
|
3813
4130
|
if (rsaKey == null) logger.warn("No supported key found to create a Linked Data signature for the activity {activityId}. The activity will be sent without a Linked Data signature. In order to create a Linked Data signature, at least one RSASSA-PKCS1-v1_5 key must be provided.", {
|
|
3814
4131
|
activityId,
|
|
3815
4132
|
keys: keys.map((pair) => ({
|
|
@@ -3846,19 +4163,27 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
3846
4163
|
activity: jsonLd
|
|
3847
4164
|
});
|
|
3848
4165
|
const promises = [];
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
4166
|
+
try {
|
|
4167
|
+
for (const inbox in inboxes) {
|
|
4168
|
+
const promise = sendActivity({
|
|
4169
|
+
allowPrivateAddress: this.allowPrivateAddress,
|
|
4170
|
+
keys,
|
|
4171
|
+
activity: jsonLd,
|
|
4172
|
+
activityId: activity.id?.href,
|
|
4173
|
+
activityType: (0, _fedify_vocab.getTypeId)(activity).href,
|
|
4174
|
+
inbox: new URL(inbox),
|
|
4175
|
+
sharedInbox: inboxes[inbox].sharedInbox,
|
|
4176
|
+
headers: collectionSync == null ? void 0 : new Headers({ "Collection-Synchronization": await buildCollectionSynchronizationHeader(collectionSync, inboxes[inbox].actorIds) }),
|
|
4177
|
+
specDeterminer: new KvSpecDeterminer(this.kv, this.kvPrefixes.httpMessageSignaturesSpec, this.firstKnock),
|
|
4178
|
+
tracerProvider: this.tracerProvider
|
|
4179
|
+
});
|
|
4180
|
+
promise.catch(() => {});
|
|
4181
|
+
promises.push(promise);
|
|
4182
|
+
}
|
|
4183
|
+
await Promise.all(promises);
|
|
4184
|
+
} finally {
|
|
4185
|
+
await Promise.allSettled(promises);
|
|
4186
|
+
}
|
|
3862
4187
|
return;
|
|
3863
4188
|
}
|
|
3864
4189
|
logger.debug("Enqueuing activity {activityId} to send later.", {
|
|
@@ -3873,7 +4198,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
3873
4198
|
privateKey: privateKeyJwk
|
|
3874
4199
|
});
|
|
3875
4200
|
}
|
|
3876
|
-
if (!this.manuallyStartQueue) this.
|
|
4201
|
+
if (!this.manuallyStartQueue) this._startQueueAutomatically(ctx.data);
|
|
3877
4202
|
const carrier = {};
|
|
3878
4203
|
_opentelemetry_api.propagation.inject(_opentelemetry_api.context.active(), carrier);
|
|
3879
4204
|
const messages = [];
|
|
@@ -4106,7 +4431,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
4106
4431
|
const identity = await this.sharedInboxKeyDispatcher(context);
|
|
4107
4432
|
if (identity != null) context = this.#createContext(request, contextData, { documentLoader: "identifier" in identity || "username" in identity ? await context.getDocumentLoader(identity) : context.getDocumentLoader(identity) });
|
|
4108
4433
|
}
|
|
4109
|
-
if (!this.manuallyStartQueue) this.
|
|
4434
|
+
if (!this.manuallyStartQueue) this._startQueueAutomatically(contextData);
|
|
4110
4435
|
const inboxContextFactory = context.toInboxContext.bind(context);
|
|
4111
4436
|
inboxContextFactory[rawInboxContextFactorySymbol] = context.toInboxContext.bind(context);
|
|
4112
4437
|
return await handleInbox(request, {
|
|
@@ -4439,6 +4764,8 @@ var ContextImpl = class ContextImpl {
|
|
|
4439
4764
|
for (const keyPair of keyPairs) {
|
|
4440
4765
|
const newPair = {
|
|
4441
4766
|
...keyPair,
|
|
4767
|
+
privateKey: (0, _fedify_vocab_runtime_internal.asCryptoKey)(keyPair.privateKey),
|
|
4768
|
+
publicKey: (0, _fedify_vocab_runtime_internal.asCryptoKey)(keyPair.publicKey),
|
|
4442
4769
|
cryptographicKey: new _fedify_vocab.CryptographicKey({
|
|
4443
4770
|
id: keyPair.keyId,
|
|
4444
4771
|
owner,
|
|
@@ -4515,10 +4842,16 @@ var ContextImpl = class ContextImpl {
|
|
|
4515
4842
|
} else identifierPromise = Promise.resolve(identity.identifier);
|
|
4516
4843
|
return identifierPromise.then((identifier) => {
|
|
4517
4844
|
if (identifier == null) return this.documentLoader;
|
|
4518
|
-
return this.getRsaKeyPairFromIdentifier(identifier).then((pair) => pair == null ? this.documentLoader : this.federation.authenticatedDocumentLoaderFactory(
|
|
4845
|
+
return this.getRsaKeyPairFromIdentifier(identifier).then((pair) => pair == null ? this.documentLoader : this.federation.authenticatedDocumentLoaderFactory({
|
|
4846
|
+
keyId: pair.keyId,
|
|
4847
|
+
privateKey: (0, _fedify_vocab_runtime_internal.asCryptoKey)(pair.privateKey)
|
|
4848
|
+
}));
|
|
4519
4849
|
});
|
|
4520
4850
|
}
|
|
4521
|
-
return this.federation.authenticatedDocumentLoaderFactory(
|
|
4851
|
+
return this.federation.authenticatedDocumentLoaderFactory({
|
|
4852
|
+
keyId: identity.keyId,
|
|
4853
|
+
privateKey: (0, _fedify_vocab_runtime_internal.asCryptoKey)(identity.privateKey)
|
|
4854
|
+
});
|
|
4522
4855
|
}
|
|
4523
4856
|
lookupObject(identifier, options = {}) {
|
|
4524
4857
|
return (0, _fedify_vocab.lookupObject)(identifier, {
|
|
@@ -4541,10 +4874,14 @@ var ContextImpl = class ContextImpl {
|
|
|
4541
4874
|
return options.parse === "none" ? require_types.getNodeInfo(url, {
|
|
4542
4875
|
parse: "none",
|
|
4543
4876
|
direct: options.direct,
|
|
4877
|
+
timeout: options.timeout,
|
|
4878
|
+
signal: options.signal,
|
|
4544
4879
|
userAgent: options?.userAgent ?? this.federation.userAgent
|
|
4545
4880
|
}) : require_types.getNodeInfo(url, {
|
|
4546
4881
|
parse: options.parse,
|
|
4547
4882
|
direct: options.direct,
|
|
4883
|
+
timeout: options.timeout,
|
|
4884
|
+
signal: options.signal,
|
|
4548
4885
|
userAgent: options?.userAgent ?? this.federation.userAgent
|
|
4549
4886
|
});
|
|
4550
4887
|
}
|
|
@@ -4556,7 +4893,17 @@ var ContextImpl = class ContextImpl {
|
|
|
4556
4893
|
allowPrivateAddress: this.federation.allowPrivateAddress
|
|
4557
4894
|
});
|
|
4558
4895
|
}
|
|
4559
|
-
sendActivity(sender, recipients, activity, options = {}) {
|
|
4896
|
+
async sendActivity(sender, recipients, activity, options = {}) {
|
|
4897
|
+
let activityJsonLd = void 0;
|
|
4898
|
+
let hasProof = activity.proofIds.length > 0;
|
|
4899
|
+
if (!hasProof) for await (const _ of activity.getProofs({ contextLoader: this.contextLoader })) {
|
|
4900
|
+
hasProof = true;
|
|
4901
|
+
break;
|
|
4902
|
+
}
|
|
4903
|
+
if (hasProof) {
|
|
4904
|
+
activityJsonLd = await activity.toJsonLd({ contextLoader: this.contextLoader });
|
|
4905
|
+
if (!hasTopLevelProof(activityJsonLd)) activityJsonLd = void 0;
|
|
4906
|
+
}
|
|
4560
4907
|
return this.tracerProvider.getTracer(require_http.name, require_http.version).startActiveSpan(this.federation.outboxQueue == null || options.immediate ? "activitypub.outbox" : "activitypub.fanout", {
|
|
4561
4908
|
kind: this.federation.outboxQueue == null || options.immediate ? _opentelemetry_api.SpanKind.CLIENT : _opentelemetry_api.SpanKind.PRODUCER,
|
|
4562
4909
|
attributes: {
|
|
@@ -4569,7 +4916,7 @@ var ContextImpl = class ContextImpl {
|
|
|
4569
4916
|
}, async (span) => {
|
|
4570
4917
|
try {
|
|
4571
4918
|
if (activity.id != null) span.setAttribute("activitypub.activity.id", activity.id.href);
|
|
4572
|
-
await this.sendActivityInternal(sender, recipients, activity, options, span);
|
|
4919
|
+
await this.sendActivityInternal(sender, recipients, activity, options, span, activityJsonLd);
|
|
4573
4920
|
} catch (e) {
|
|
4574
4921
|
span.setStatus({
|
|
4575
4922
|
code: _opentelemetry_api.SpanStatusCode.ERROR,
|
|
@@ -4581,7 +4928,7 @@ var ContextImpl = class ContextImpl {
|
|
|
4581
4928
|
}
|
|
4582
4929
|
});
|
|
4583
4930
|
}
|
|
4584
|
-
async sendActivityInternal(sender, recipients, activity, options, span) {
|
|
4931
|
+
async sendActivityInternal(sender, recipients, activity, options, span, activityJsonLd) {
|
|
4585
4932
|
const logger = (0, _logtape_logtape.getLogger)([
|
|
4586
4933
|
"fedify",
|
|
4587
4934
|
"federation",
|
|
@@ -4628,15 +4975,23 @@ var ContextImpl = class ContextImpl {
|
|
|
4628
4975
|
if (!(error instanceof RouterError)) throw error;
|
|
4629
4976
|
}
|
|
4630
4977
|
} else expandedRecipients = [recipients];
|
|
4631
|
-
const opts = {
|
|
4632
|
-
context: this,
|
|
4633
|
-
orderingKey: options.orderingKey,
|
|
4634
|
-
collectionSync,
|
|
4635
|
-
immediate: options.immediate,
|
|
4636
|
-
normalizeExistingProofs: options.normalizeExistingProofs
|
|
4637
|
-
};
|
|
4638
4978
|
span.setAttribute("activitypub.inboxes", expandedRecipients.length);
|
|
4639
4979
|
for (const activityTransformer of this.federation.activityTransformers) activity = activityTransformer(activity, this);
|
|
4980
|
+
let contextMatches = false;
|
|
4981
|
+
if (activityJsonLd != null) {
|
|
4982
|
+
const capturedJsonLd = activityJsonLd;
|
|
4983
|
+
const transformedJsonLd = await activity.toJsonLd({
|
|
4984
|
+
format: "compact",
|
|
4985
|
+
contextLoader: this.contextLoader
|
|
4986
|
+
});
|
|
4987
|
+
const contentChanged = getContentFields(transformedJsonLd) !== getContentFields(capturedJsonLd);
|
|
4988
|
+
contextMatches = getContextFields(transformedJsonLd) === getContextFields(capturedJsonLd);
|
|
4989
|
+
const proofsChanged = getProofFields(transformedJsonLd) !== getProofFields(capturedJsonLd);
|
|
4990
|
+
if (contentChanged || !contextMatches && proofsChanged) {
|
|
4991
|
+
activity = activity.clone({ proofs: await getUncapturedProofs(activity, capturedJsonLd, this.contextLoader) });
|
|
4992
|
+
activityJsonLd = void 0;
|
|
4993
|
+
} else if (proofsChanged) activityJsonLd = void 0;
|
|
4994
|
+
}
|
|
4640
4995
|
span?.setAttribute("activitypub.activity.id", activity?.id?.href ?? "");
|
|
4641
4996
|
if (activity.actorId == null) {
|
|
4642
4997
|
logger.error("Activity {activityId} to send does not have an actor.", {
|
|
@@ -4648,15 +5003,42 @@ var ContextImpl = class ContextImpl {
|
|
|
4648
5003
|
let proofCreated = false;
|
|
4649
5004
|
if (actorKeyPairs != null) {
|
|
4650
5005
|
const contextLoader = this.contextLoader;
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
activity =
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
5006
|
+
const willSign = actorKeyPairs.some((kp) => kp.privateKey.algorithm.name === "Ed25519" && kp.multikey.id != null);
|
|
5007
|
+
if (willSign) {
|
|
5008
|
+
if (activityJsonLd != null && !contextMatches) activity = activity.clone({ proofs: [] });
|
|
5009
|
+
}
|
|
5010
|
+
const prepared = willSign ? await prepareActivityJsonLd(activity, contextLoader) : void 0;
|
|
5011
|
+
if (prepared != null) {
|
|
5012
|
+
const signingKeys = actorKeyPairs.flatMap((kp) => kp.privateKey.algorithm.name === "Ed25519" && kp.multikey.id != null ? [{
|
|
5013
|
+
privateKey: kp.privateKey,
|
|
5014
|
+
keyId: kp.multikey.id
|
|
5015
|
+
}] : []);
|
|
5016
|
+
const signed = await signActivityJsonLd(activity, prepared, signingKeys, { tracerProvider: this.tracerProvider });
|
|
5017
|
+
activity = signed.activity;
|
|
5018
|
+
activityJsonLd = signed.jsonLd;
|
|
5019
|
+
proofCreated = signingKeys.length > 0;
|
|
5020
|
+
} else {
|
|
5021
|
+
let proofAdded = false;
|
|
5022
|
+
for (const kp of actorKeyPairs) {
|
|
5023
|
+
if (kp.privateKey.algorithm.name !== "Ed25519" || kp.multikey.id == null) continue;
|
|
5024
|
+
activity = await require_proof.signObject(activity, kp.privateKey, kp.multikey.id, {
|
|
5025
|
+
contextLoader,
|
|
5026
|
+
tracerProvider: this.tracerProvider
|
|
5027
|
+
});
|
|
5028
|
+
proofAdded = true;
|
|
5029
|
+
}
|
|
5030
|
+
if (proofAdded) activityJsonLd = void 0;
|
|
5031
|
+
proofCreated = proofAdded;
|
|
4658
5032
|
}
|
|
4659
5033
|
}
|
|
5034
|
+
const opts = {
|
|
5035
|
+
context: this,
|
|
5036
|
+
orderingKey: options.orderingKey,
|
|
5037
|
+
collectionSync,
|
|
5038
|
+
immediate: options.immediate,
|
|
5039
|
+
activityJsonLd,
|
|
5040
|
+
normalizeExistingProofs: options.normalizeExistingProofs
|
|
5041
|
+
};
|
|
4660
5042
|
const inboxes = extractInboxes({
|
|
4661
5043
|
recipients: expandedRecipients,
|
|
4662
5044
|
preferSharedInbox: options.preferSharedInbox,
|
|
@@ -4696,7 +5078,7 @@ var ContextImpl = class ContextImpl {
|
|
|
4696
5078
|
actorIds: [...actorIds],
|
|
4697
5079
|
sharedInbox
|
|
4698
5080
|
}])),
|
|
4699
|
-
activity: await activity.toJsonLd({
|
|
5081
|
+
activity: activityJsonLd != null ? require_proof.detachSignature(activityJsonLd) : await activity.toJsonLd({
|
|
4700
5082
|
format: "compact",
|
|
4701
5083
|
contextLoader: this.contextLoader
|
|
4702
5084
|
}),
|
|
@@ -4707,7 +5089,7 @@ var ContextImpl = class ContextImpl {
|
|
|
4707
5089
|
normalizeExistingProofs: proofCreated || options.normalizeExistingProofs,
|
|
4708
5090
|
traceContext: carrier
|
|
4709
5091
|
};
|
|
4710
|
-
if (!this.federation.manuallyStartQueue) this.federation.
|
|
5092
|
+
if (!this.federation.manuallyStartQueue) this.federation._startQueueAutomatically(this.data);
|
|
4711
5093
|
await this.federation.fanoutQueue.enqueue(message, { orderingKey: options.orderingKey });
|
|
4712
5094
|
return true;
|
|
4713
5095
|
}
|
|
@@ -4907,43 +5289,83 @@ var RequestContextImpl = class RequestContextImpl extends ContextImpl {
|
|
|
4907
5289
|
}
|
|
4908
5290
|
}), values);
|
|
4909
5291
|
}
|
|
4910
|
-
#signedKey =
|
|
5292
|
+
#signedKey = null;
|
|
5293
|
+
#signedKeyOwner = null;
|
|
5294
|
+
#signatureChecks = /* @__PURE__ */ new WeakMap();
|
|
5295
|
+
#getSignatureCheck(documentLoader, contextLoader) {
|
|
5296
|
+
let checks = this.#signatureChecks.get(documentLoader);
|
|
5297
|
+
if (checks == null) {
|
|
5298
|
+
checks = /* @__PURE__ */ new WeakMap();
|
|
5299
|
+
this.#signatureChecks.set(documentLoader, checks);
|
|
5300
|
+
}
|
|
5301
|
+
let check = checks.get(contextLoader);
|
|
5302
|
+
if (check == null) {
|
|
5303
|
+
check = {};
|
|
5304
|
+
checks.set(contextLoader, check);
|
|
5305
|
+
}
|
|
5306
|
+
return check;
|
|
5307
|
+
}
|
|
4911
5308
|
async getSignedKey(options = {}) {
|
|
4912
5309
|
if (this.#signedKey != null) return this.#signedKey;
|
|
4913
|
-
|
|
5310
|
+
const documentLoader = options.documentLoader ?? this.documentLoader;
|
|
5311
|
+
const contextLoader = options.contextLoader ?? this.contextLoader;
|
|
5312
|
+
const check = this.#getSignatureCheck(documentLoader, contextLoader);
|
|
5313
|
+
if (check.key != null) return check.key;
|
|
5314
|
+
const promise = require_http.verifyRequest(this.request, {
|
|
4914
5315
|
...this,
|
|
4915
|
-
contextLoader
|
|
4916
|
-
documentLoader
|
|
5316
|
+
contextLoader,
|
|
5317
|
+
documentLoader,
|
|
4917
5318
|
timeWindow: this.federation.signatureTimeWindow,
|
|
4918
5319
|
tracerProvider: options.tracerProvider ?? this.tracerProvider
|
|
5320
|
+
}).then((key) => {
|
|
5321
|
+
if (key != null) this.#signedKey ??= key;
|
|
5322
|
+
return key;
|
|
5323
|
+
}).catch((error) => {
|
|
5324
|
+
if (check.key === promise) check.key = void 0;
|
|
5325
|
+
throw error;
|
|
4919
5326
|
});
|
|
5327
|
+
check.key = promise;
|
|
5328
|
+
return await promise;
|
|
4920
5329
|
}
|
|
4921
|
-
#signedKeyOwner = void 0;
|
|
4922
5330
|
async getSignedKeyOwner(options = {}) {
|
|
4923
5331
|
if (this.#signedKeyOwner != null) return this.#signedKeyOwner;
|
|
4924
|
-
const
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
5332
|
+
const normalizedOptions = {
|
|
5333
|
+
documentLoader: options.documentLoader ?? this.documentLoader,
|
|
5334
|
+
contextLoader: options.contextLoader ?? this.contextLoader,
|
|
5335
|
+
tracerProvider: options.tracerProvider ?? this.tracerProvider
|
|
5336
|
+
};
|
|
5337
|
+
const check = this.#getSignatureCheck(normalizedOptions.documentLoader, normalizedOptions.contextLoader);
|
|
5338
|
+
if (check.owner != null) return check.owner;
|
|
5339
|
+
const promise = this.getSignedKey(normalizedOptions).then(async (key) => {
|
|
5340
|
+
if (key == null) {
|
|
5341
|
+
if (check.owner === promise) check.owner = void 0;
|
|
5342
|
+
return null;
|
|
5343
|
+
}
|
|
5344
|
+
try {
|
|
5345
|
+
const owner = await require_proof.getKeyOwner(key, normalizedOptions);
|
|
5346
|
+
if (owner != null) this.#signedKeyOwner ??= owner;
|
|
5347
|
+
return owner;
|
|
5348
|
+
} catch (error) {
|
|
5349
|
+
if (error instanceof _fedify_vocab_runtime.FetchError) {
|
|
5350
|
+
(0, _logtape_logtape.getLogger)([
|
|
5351
|
+
"fedify",
|
|
5352
|
+
"federation",
|
|
5353
|
+
"actor"
|
|
5354
|
+
]).warn("Failed to fetch the key owner {keyOwner} of {keyId} while verifying the request signature; treating the request as unauthenticated: {error}", {
|
|
5355
|
+
keyId: key.id?.href,
|
|
5356
|
+
keyOwner: error.url.href,
|
|
5357
|
+
error
|
|
5358
|
+
});
|
|
5359
|
+
return null;
|
|
5360
|
+
}
|
|
5361
|
+
throw error;
|
|
4944
5362
|
}
|
|
5363
|
+
}).catch((error) => {
|
|
5364
|
+
if (check.owner === promise) check.owner = void 0;
|
|
4945
5365
|
throw error;
|
|
4946
|
-
}
|
|
5366
|
+
});
|
|
5367
|
+
check.owner = promise;
|
|
5368
|
+
return await promise;
|
|
4947
5369
|
}
|
|
4948
5370
|
};
|
|
4949
5371
|
function forwardActivity(ctx, loggerCategory, forwarder, recipients, options) {
|
|
@@ -4994,7 +5416,7 @@ async function forwardActivityInternal(ctx, loggerCategory, forwarder, recipient
|
|
|
4994
5416
|
if (forwarder.length < 1) throw new Error("The forwarder's key pairs are empty.");
|
|
4995
5417
|
keys = forwarder;
|
|
4996
5418
|
} else keys = [forwarder];
|
|
4997
|
-
if (!require_proof.hasSignatureLike(ctx.activity)) {
|
|
5419
|
+
if (!require_proof.hasVerifiableSignature(ctx.activity) && !require_proof.hasSignatureLike(ctx.activity)) {
|
|
4998
5420
|
if (!require_proof.hasProofLike(ctx.activity)) {
|
|
4999
5421
|
if (options?.skipIfUnsigned) return false;
|
|
5000
5422
|
logger.warn("The activity {activityId} is not signed; even if it is forwarded to other servers as is, it may not be accepted by them due to the lack of a signature/proof.", {
|
|
@@ -5032,25 +5454,33 @@ async function forwardActivityInternal(ctx, loggerCategory, forwarder, recipient
|
|
|
5032
5454
|
if (options?.immediate) logger.debug("Forwarding activity immediately without queue since immediate option is set.");
|
|
5033
5455
|
else logger.debug("Forwarding activity immediately without queue since queue is not set.");
|
|
5034
5456
|
const promises = [];
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5457
|
+
try {
|
|
5458
|
+
for (const inbox in inboxes) {
|
|
5459
|
+
const promise = sendActivity({
|
|
5460
|
+
allowPrivateAddress: ctx.federation.allowPrivateAddress,
|
|
5461
|
+
keys,
|
|
5462
|
+
activity: ctx.activity,
|
|
5463
|
+
activityId: ctx.activityId,
|
|
5464
|
+
activityType: ctx.activityType,
|
|
5465
|
+
inbox: new URL(inbox),
|
|
5466
|
+
sharedInbox: inboxes[inbox].sharedInbox,
|
|
5467
|
+
tracerProvider: ctx.tracerProvider,
|
|
5468
|
+
specDeterminer: new KvSpecDeterminer(ctx.federation.kv, ctx.federation.kvPrefixes.httpMessageSignaturesSpec, ctx.federation.firstKnock)
|
|
5469
|
+
});
|
|
5470
|
+
promise.catch(() => {});
|
|
5471
|
+
promises.push(promise);
|
|
5472
|
+
}
|
|
5473
|
+
await Promise.all(promises);
|
|
5474
|
+
} finally {
|
|
5475
|
+
await Promise.allSettled(promises);
|
|
5476
|
+
}
|
|
5047
5477
|
return true;
|
|
5048
5478
|
}
|
|
5049
5479
|
logger.debug("Enqueuing activity {activityId} to forward later.", {
|
|
5050
5480
|
activityId: ctx.activityId,
|
|
5051
5481
|
activity: ctx.activity
|
|
5052
5482
|
});
|
|
5053
|
-
if (!ctx.federation.manuallyStartQueue) ctx.federation.
|
|
5483
|
+
if (!ctx.federation.manuallyStartQueue) ctx.federation._startQueueAutomatically(ctx.data);
|
|
5054
5484
|
const keyJwkPairs = [];
|
|
5055
5485
|
for (const { keyId, privateKey } of keys) {
|
|
5056
5486
|
const privateKeyJwk = await require_http.exportJwk(privateKey);
|
|
@@ -5222,6 +5652,69 @@ var KvSpecDeterminer = class {
|
|
|
5222
5652
|
function notFound(_request) {
|
|
5223
5653
|
return new Response("Not Found", { status: 404 });
|
|
5224
5654
|
}
|
|
5655
|
+
function hasTopLevelProof(value) {
|
|
5656
|
+
return typeof value === "object" && value != null && !Array.isArray(value) && globalThis.Object.prototype.hasOwnProperty.call(value, "proof");
|
|
5657
|
+
}
|
|
5658
|
+
function getContentFields(value) {
|
|
5659
|
+
if (typeof value !== "object" || value == null || Array.isArray(value)) return JSON.stringify(sortJsonKeys(value));
|
|
5660
|
+
const record = { ...value };
|
|
5661
|
+
delete record["@context"];
|
|
5662
|
+
delete record.proof;
|
|
5663
|
+
delete record.signature;
|
|
5664
|
+
return JSON.stringify(sortJsonKeys(record));
|
|
5665
|
+
}
|
|
5666
|
+
function getContextFields(value) {
|
|
5667
|
+
if (typeof value !== "object" || value == null || Array.isArray(value)) return JSON.stringify(sortJsonKeys(value));
|
|
5668
|
+
const context = value["@context"];
|
|
5669
|
+
return JSON.stringify(sortJsonKeys(context ?? null));
|
|
5670
|
+
}
|
|
5671
|
+
function getProofEntries(value) {
|
|
5672
|
+
if (typeof value !== "object" || value == null || Array.isArray(value)) return [];
|
|
5673
|
+
const proof = value.proof;
|
|
5674
|
+
if (proof == null) return [];
|
|
5675
|
+
return Array.isArray(proof) ? proof : [proof];
|
|
5676
|
+
}
|
|
5677
|
+
function normalizeProofEntry(proof) {
|
|
5678
|
+
const stripped = stripContexts(proof);
|
|
5679
|
+
if (typeof stripped !== "object" || stripped == null || Array.isArray(stripped)) return stripped;
|
|
5680
|
+
const record = { ...stripped };
|
|
5681
|
+
if (typeof record.created === "string") try {
|
|
5682
|
+
record.created = Temporal.Instant.from(record.created).toString();
|
|
5683
|
+
} catch {}
|
|
5684
|
+
return record;
|
|
5685
|
+
}
|
|
5686
|
+
function getProofEntryFields(proof) {
|
|
5687
|
+
return JSON.stringify(sortJsonKeys(normalizeProofEntry(proof)));
|
|
5688
|
+
}
|
|
5689
|
+
function getProofFields(value) {
|
|
5690
|
+
return JSON.stringify(getProofEntries(value).map(getProofEntryFields).sort());
|
|
5691
|
+
}
|
|
5692
|
+
async function getUncapturedProofs(activity, capturedJsonLd, contextLoader) {
|
|
5693
|
+
const capturedProofs = new Set(getProofEntries(capturedJsonLd).map(getProofEntryFields));
|
|
5694
|
+
const retainedProofs = [];
|
|
5695
|
+
for await (const proof of activity.getProofs({ contextLoader })) {
|
|
5696
|
+
const proofJsonLd = await proof.toJsonLd({
|
|
5697
|
+
format: "compact",
|
|
5698
|
+
contextLoader
|
|
5699
|
+
});
|
|
5700
|
+
if (!capturedProofs.has(getProofEntryFields(proofJsonLd))) retainedProofs.push(proof);
|
|
5701
|
+
}
|
|
5702
|
+
return retainedProofs;
|
|
5703
|
+
}
|
|
5704
|
+
function stripContexts(value) {
|
|
5705
|
+
if (Array.isArray(value)) return value.map(stripContexts);
|
|
5706
|
+
if (typeof value !== "object" || value == null) return value;
|
|
5707
|
+
const record = { ...value };
|
|
5708
|
+
delete record["@context"];
|
|
5709
|
+
delete record.signature;
|
|
5710
|
+
for (const key of globalThis.Object.keys(record)) record[key] = stripContexts(record[key]);
|
|
5711
|
+
return record;
|
|
5712
|
+
}
|
|
5713
|
+
function sortJsonKeys(value) {
|
|
5714
|
+
if (Array.isArray(value)) return value.map(sortJsonKeys);
|
|
5715
|
+
if (typeof value !== "object" || value == null) return value;
|
|
5716
|
+
return globalThis.Object.fromEntries(globalThis.Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, item]) => [key, sortJsonKeys(item)]));
|
|
5717
|
+
}
|
|
5225
5718
|
function notAcceptable(_request) {
|
|
5226
5719
|
return new Response("Not Acceptable", {
|
|
5227
5720
|
status: 406,
|