@fedify/fedify 2.1.22 → 2.1.24
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/{assert_instance_of-C4Ri6VuN.mjs → assert-BhQd8QHP.mjs} +19 -1
- package/dist/{builder-uOFBJkK3.mjs → builder-BatYe9a2.mjs} +3 -3
- package/dist/{client-CZWLyLmp.mjs → client-DNiBssfx.mjs} +78 -4
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/transformers.test.mjs +3 -4
- package/dist/{context-_l9t359k.d.ts → context-BgU5UWTx.d.ts} +4 -3
- package/dist/{context-o22vjzS2.d.cts → context-D4s0Wk3N.d.cts} +4 -3
- package/dist/{deno-Dq7ws4iI.mjs → deno-BXkm_rws.mjs} +1 -1
- package/dist/{docloader-BC4p0nXc.mjs → docloader-DdEK2tXP.mjs} +2 -2
- package/dist/federation/builder.test.mjs +2 -2
- package/dist/federation/collection.test.mjs +1 -1
- package/dist/federation/handler.test.mjs +127 -9
- package/dist/federation/idempotency.test.mjs +4 -4
- package/dist/federation/inbox.test.mjs +1 -1
- package/dist/federation/keycache.test.mjs +44 -10
- package/dist/federation/kv.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +99 -11
- 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/mq.test.mjs +1 -1
- package/dist/federation/negotiation.test.mjs +2 -2
- package/dist/federation/retry.test.mjs +1 -1
- package/dist/federation/router.test.mjs +1 -1
- package/dist/federation/send.test.mjs +138 -6
- package/dist/federation/temporal.test.mjs +2 -2
- package/dist/federation/webfinger.test.mjs +2 -2
- package/dist/{http-CWMbnDWz.cjs → http-7FmLhLDv.cjs} +166 -6
- package/dist/{http-C5HQIcH6.js → http-Chr54tTL.js} +155 -7
- package/dist/{http-BDZeS5om.d.ts → http-Dl00HXr4.d.ts} +1 -1
- package/dist/{http-C87EWkO0.d.cts → http-DqZhyEso.d.cts} +1 -1
- package/dist/{http-DFOoxt_R.mjs → http-UyebnM2c.mjs} +3 -3
- package/dist/{inbox-B07FmpqX.mjs → inbox-ByQ2iD14.mjs} +1 -1
- package/dist/{key-BhxG-x5D.mjs → key-A8SuFznD.mjs} +154 -6
- package/dist/{keycache-CCSwkQcY.mjs → keycache-CaO7wyQA.mjs} +12 -4
- package/dist/{kv-cache-ByRYF-t6.cjs → kv-cache-DJhBDA9T.cjs} +1 -1
- package/dist/{kv-cache-C4CXZOaq.js → kv-cache-J6hmiAEd.js} +1 -1
- package/dist/{ld-CHqytT_K.mjs → ld-BSvHU-S0.mjs} +2 -2
- package/dist/{middleware-B1736exe.cjs → middleware-Bddj287b.cjs} +1 -1
- package/dist/{middleware-_PzelxB9.cjs → middleware-CCYqHlzn.cjs} +90 -14
- package/dist/{middleware-Dyz-bNVJ.js → middleware-Do50b12a.js} +90 -14
- package/dist/{middleware-DRMVB2Bf.mjs → middleware-DvxNTKpl.mjs} +1 -1
- package/dist/{middleware-CFbSzb-d.mjs → middleware-Dy18K1xP.mjs} +31 -20
- package/dist/{mod-CjiK2zrW.d.ts → mod-BLDHhuW0.d.ts} +1 -1
- package/dist/{mod-0dF0OeGw.d.cts → mod-Bx80LUTA.d.cts} +1 -1
- package/dist/{mod-BTWFtZwa.d.ts → mod-CMK_S-eX.d.ts} +1 -1
- package/dist/{mod-Bv1elC-b.d.ts → mod-DcAiY74j.d.ts} +1 -1
- package/dist/{mod-D5YlzzP3.d.cts → mod-DiuFTYUt.d.cts} +1 -1
- package/dist/{mod-dxOnKp2Y.d.cts → mod-DniKVJ_C.d.cts} +1 -1
- package/dist/mod.cjs +5 -5
- package/dist/mod.d.cts +6 -6
- package/dist/mod.d.ts +6 -6
- package/dist/mod.js +5 -5
- package/dist/nodeinfo/client.test.mjs +28 -1
- package/dist/nodeinfo/handler.test.mjs +2 -2
- package/dist/nodeinfo/mod.cjs +1 -1
- package/dist/nodeinfo/mod.js +1 -1
- package/dist/nodeinfo/types.test.mjs +1 -1
- package/dist/otel/exporter.test.mjs +1 -1
- package/dist/{owner-DEvZuyOE.d.cts → owner-B3hNQCG8.d.cts} +11 -0
- package/dist/owner-CaaCVHsG.mjs +175 -0
- package/dist/{owner-CnngXDNJ.d.ts → owner-CiBPcC6F.d.ts} +11 -0
- package/dist/{proof-DtJrGFAd.js → proof-BrOQrPQf.js} +112 -58
- package/dist/{proof-BLCy90_K.cjs → proof-CaCUMcvk.cjs} +112 -58
- package/dist/{proof-B9xBlvFD.mjs → proof-_AyA4r7z.mjs} +2 -2
- package/dist/{send-TxZWfiOg.mjs → send-B1CRgb14.mjs} +64 -6
- package/dist/sig/accept.test.mjs +1 -1
- package/dist/sig/http.test.mjs +4 -4
- package/dist/sig/key.test.mjs +170 -3
- package/dist/sig/ld.test.mjs +56 -4
- 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 +105 -6
- package/dist/sig/proof.test.mjs +72 -3
- package/dist/{temporal-Q6m8vHyx.mjs → temporal-Pmk5ouB1.mjs} +1 -1
- package/dist/{types-m8u9L86X.cjs → types-DWs-qZaY.cjs} +94 -2
- package/dist/{types-DTONwNqL.js → types-sXITXcWa.js} +78 -4
- package/dist/utils/docloader.test.mjs +28 -4
- package/dist/utils/kv-cache.test.mjs +1 -1
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.d.cts +1 -1
- package/dist/utils/mod.d.ts +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +5 -5
- package/dist/assert-ddO5KLpe.mjs +0 -23
- package/dist/owner-D79Nd_56.mjs +0 -120
- /package/dist/{accept-Dd__NiUL.mjs → accept-BavzedPB.mjs} +0 -0
- /package/dist/{collection-BD6-SZ6O.mjs → collection-ChgDTHLz.mjs} +0 -0
- /package/dist/{keys-BAK-tUlf.mjs → keys-CtZLJq76.mjs} +0 -0
- /package/dist/{kv-tL2TOE9X.mjs → kv-BrZHNugx.mjs} +0 -0
- /package/dist/{kv-cache-FsT1ljhs.mjs → kv-cache-DqEKe5E0.mjs} +0 -0
- /package/dist/{negotiation-DnsfFF8I.mjs → negotiation-BehA2uul.mjs} +0 -0
- /package/dist/{retry-CJL0poaU.mjs → retry-B_E3V_Dx.mjs} +0 -0
- /package/dist/{types-DCP0WLdt.mjs → types-C37hquWI.mjs} +0 -0
package/dist/mod.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
2
|
import { a as InboundService, c as OutboundService, d as Software, f as Usage, i as parseNodeInfo, l as Protocol, n as ParseNodeInfoOptions, o as JsonValue, p as nodeInfoToJson, r as getNodeInfo, s as NodeInfo, t as GetNodeInfoOptions, u as Services } from "./client-CSddvgWN.js";
|
|
3
|
-
import { C as exportJwk, D as importJwk, E as generateCryptoKeyPair, S as KeyCache, T as fetchKeyDetailed, _ as validateAcceptSignature, a as VerifyRequestDetailedResult, b as FetchKeyOptions, c as signRequest, d as AcceptSignatureMember, f as AcceptSignatureParameters, g as parseAcceptSignature, h as fulfillAcceptSignature, i as SignRequestOptions, l as verifyRequest, m as formatAcceptSignature, n as HttpMessageSignaturesSpecDeterminer, o as VerifyRequestFailureReason, p as FulfillAcceptSignatureResult, r as Rfc9421SignRequestOptions, s as VerifyRequestOptions, t as HttpMessageSignaturesSpec, u as verifyRequestDetailed, v as FetchKeyDetailedResult, w as fetchKey, x as FetchKeyResult, y as FetchKeyErrorResult } from "./http-
|
|
4
|
-
import { i as getKeyOwner, n as GetKeyOwnerOptions, r as doesActorOwnKey, t as DoesActorOwnKeyOptions } from "./owner-
|
|
5
|
-
import { $ as ActorKeyPairsDispatcher, A as createFederation, B as RouterRouteResult, C as InboxChallengePolicy, Ct as ActivityTransformer, D as FederationKvPrefixes, E as Rfc6570Expression, F as Message, G as InProcessMessageQueueOptions, H as respondWithObject, I as createFederationBuilder, J as MessageQueueListenOptions, K as MessageQueue, L as Router, M as RetryContext, N as RetryPolicy, O as FederationOrigin, P as createExponentialBackoffPolicy, Q as ActorHandleMapper, R as RouterError, S as IdempotencyStrategy, St as digest, T as ObjectCallbackSetters, U as respondWithObjectIfAcceptable, V as RespondWithObjectOptions, W as InProcessMessageQueue, X as ActorAliasMapper, Y as ParallelMessageQueue, Z as ActorDispatcher, _ as FederationBuilder, _t as WebFingerLinksDispatcher, a as InboxContext, at as CustomCollectionCursor, b as FederationStartQueueOptions, bt as PageItems, c as RouteActivityOptions, ct as InboxListener, d as ActorCallbackSetters, dt as ObjectDispatcher, et as AuthorizePredicate, f as CollectionCallbackSetters, ft as OutboxErrorHandler, g as Federation, gt as UnverifiedActivityReason, h as Federatable, ht as UnverifiedActivityHandler, i as GetSignedKeyOptions, it as CustomCollectionCounter, j as CreateExponentialBackoffPolicyOptions, k as FederationQueueOptions, l as SendActivityOptions, lt as NodeInfoDispatcher, m as CustomCollectionCallbackSetters, mt as SharedInboxKeyDispatcher, n as Context, nt as CollectionCursor, o as ParseUriResult, ot as CustomCollectionDispatcher, p as ConstructorWithTypeId, pt as OutboxPermanentFailureHandler, q as MessageQueueEnqueueOptions, r as ForwardActivityOptions, rt as CollectionDispatcher, s as RequestContext, st as InboxErrorHandler, t as ActorKeyPair, tt as CollectionCounter, u as SendActivityOptionsForCollection, ut as ObjectAuthorizePredicate, v as FederationFetchOptions, vt as SendActivityError, w as InboxListenerSetters, x as IdempotencyKeyCallback, xt as buildCollectionSynchronizationHeader, y as FederationOptions, yt as SenderKeyPair, z as RouterOptions } from "./context-
|
|
3
|
+
import { C as exportJwk, D as importJwk, E as generateCryptoKeyPair, S as KeyCache, T as fetchKeyDetailed, _ as validateAcceptSignature, a as VerifyRequestDetailedResult, b as FetchKeyOptions, c as signRequest, d as AcceptSignatureMember, f as AcceptSignatureParameters, g as parseAcceptSignature, h as fulfillAcceptSignature, i as SignRequestOptions, l as verifyRequest, m as formatAcceptSignature, n as HttpMessageSignaturesSpecDeterminer, o as VerifyRequestFailureReason, p as FulfillAcceptSignatureResult, r as Rfc9421SignRequestOptions, s as VerifyRequestOptions, t as HttpMessageSignaturesSpec, u as verifyRequestDetailed, v as FetchKeyDetailedResult, w as fetchKey, x as FetchKeyResult, y as FetchKeyErrorResult } from "./http-Dl00HXr4.js";
|
|
4
|
+
import { i as getKeyOwner, n as GetKeyOwnerOptions, r as doesActorOwnKey, t as DoesActorOwnKeyOptions } from "./owner-CiBPcC6F.js";
|
|
5
|
+
import { $ as ActorKeyPairsDispatcher, A as createFederation, B as RouterRouteResult, C as InboxChallengePolicy, Ct as ActivityTransformer, D as FederationKvPrefixes, E as Rfc6570Expression, F as Message, G as InProcessMessageQueueOptions, H as respondWithObject, I as createFederationBuilder, J as MessageQueueListenOptions, K as MessageQueue, L as Router, M as RetryContext, N as RetryPolicy, O as FederationOrigin, P as createExponentialBackoffPolicy, Q as ActorHandleMapper, R as RouterError, S as IdempotencyStrategy, St as digest, T as ObjectCallbackSetters, U as respondWithObjectIfAcceptable, V as RespondWithObjectOptions, W as InProcessMessageQueue, X as ActorAliasMapper, Y as ParallelMessageQueue, Z as ActorDispatcher, _ as FederationBuilder, _t as WebFingerLinksDispatcher, a as InboxContext, at as CustomCollectionCursor, b as FederationStartQueueOptions, bt as PageItems, c as RouteActivityOptions, ct as InboxListener, d as ActorCallbackSetters, dt as ObjectDispatcher, et as AuthorizePredicate, f as CollectionCallbackSetters, ft as OutboxErrorHandler, g as Federation, gt as UnverifiedActivityReason, h as Federatable, ht as UnverifiedActivityHandler, i as GetSignedKeyOptions, it as CustomCollectionCounter, j as CreateExponentialBackoffPolicyOptions, k as FederationQueueOptions, l as SendActivityOptions, lt as NodeInfoDispatcher, m as CustomCollectionCallbackSetters, mt as SharedInboxKeyDispatcher, n as Context, nt as CollectionCursor, o as ParseUriResult, ot as CustomCollectionDispatcher, p as ConstructorWithTypeId, pt as OutboxPermanentFailureHandler, q as MessageQueueEnqueueOptions, r as ForwardActivityOptions, rt as CollectionDispatcher, s as RequestContext, st as InboxErrorHandler, t as ActorKeyPair, tt as CollectionCounter, u as SendActivityOptionsForCollection, ut as ObjectAuthorizePredicate, v as FederationFetchOptions, vt as SendActivityError, w as InboxListenerSetters, x as IdempotencyKeyCallback, xt as buildCollectionSynchronizationHeader, y as FederationOptions, yt as SenderKeyPair, z as RouterOptions } from "./context-BgU5UWTx.js";
|
|
6
6
|
import { a as MemoryKvStore, i as KvStoreSetOptions, n as KvStore, r as KvStoreListEntry, t as KvKey } from "./kv-D6hNiMTK.js";
|
|
7
7
|
import { actorDehydrator, autoIdAssigner, getDefaultActivityTransformers } from "./compat/mod.js";
|
|
8
|
-
import { n as handleWebFinger, t as WebFingerHandlerParameters } from "./mod-
|
|
9
|
-
import { _ as verifyJsonLd, a as createProof, c as verifyProof, d as VerifyJsonLdOptions, f as VerifySignatureOptions, g as signJsonLd, h as detachSignature, i as VerifyProofOptions, l as CreateSignatureOptions, m as createSignature, n as SignObjectOptions, o as signObject, p as attachSignature, r as VerifyObjectOptions, s as verifyObject, t as CreateProofOptions, u as SignJsonLdOptions, v as verifySignature } from "./mod-
|
|
10
|
-
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./mod-
|
|
8
|
+
import { n as handleWebFinger, t as WebFingerHandlerParameters } from "./mod-DcAiY74j.js";
|
|
9
|
+
import { _ as verifyJsonLd, a as createProof, c as verifyProof, d as VerifyJsonLdOptions, f as VerifySignatureOptions, g as signJsonLd, h as detachSignature, i as VerifyProofOptions, l as CreateSignatureOptions, m as createSignature, n as SignObjectOptions, o as signObject, p as attachSignature, r as VerifyObjectOptions, s as verifyObject, t as CreateProofOptions, u as SignJsonLdOptions, v as verifySignature } from "./mod-BLDHhuW0.js";
|
|
10
|
+
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./mod-CMK_S-eX.js";
|
|
11
11
|
export * from "@fedify/vocab-runtime";
|
|
12
12
|
|
|
13
13
|
//#region src/mod.d.ts
|
package/dist/mod.js
CHANGED
|
@@ -3,11 +3,11 @@ import { URLPattern } from "urlpattern-polyfill";
|
|
|
3
3
|
import "./chunk-CRNNMoPX.js";
|
|
4
4
|
import { n as autoIdAssigner, r as getDefaultActivityTransformers, t as actorDehydrator } from "./transformers-BGMIq1cs.js";
|
|
5
5
|
import "./compat/mod.js";
|
|
6
|
-
import { a as verifyRequestDetailed, c as
|
|
7
|
-
import { a as createExponentialBackoffPolicy, c as buildCollectionSynchronizationHeader, d as Router, f as RouterError, i as SendActivityError, l as digest, o as respondWithObject, r as handleWebFinger, s as respondWithObjectIfAcceptable, t as createFederation, u as createFederationBuilder } from "./middleware-
|
|
8
|
-
import {
|
|
9
|
-
import { n as
|
|
10
|
-
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./kv-cache-
|
|
6
|
+
import { _ as validateAcceptSignature, a as verifyRequestDetailed, c as fetchKey, d as importJwk, g as parseAcceptSignature, h as fulfillAcceptSignature, i as verifyRequest, l as fetchKeyDetailed, m as formatAcceptSignature, o as exportJwk, r as signRequest, u as generateCryptoKeyPair } from "./http-Chr54tTL.js";
|
|
7
|
+
import { a as createExponentialBackoffPolicy, c as buildCollectionSynchronizationHeader, d as Router, f as RouterError, i as SendActivityError, l as digest, o as respondWithObject, r as handleWebFinger, s as respondWithObjectIfAcceptable, t as createFederation, u as createFederationBuilder } from "./middleware-Do50b12a.js";
|
|
8
|
+
import { n as getNodeInfo, r as parseNodeInfo, t as nodeInfoToJson } from "./types-sXITXcWa.js";
|
|
9
|
+
import { _ as signJsonLd, a as doesActorOwnKey, b as verifySignature, d as createSignature, f as detachSignature, i as verifyProof, l as attachSignature, n as signObject, o as getKeyOwner, r as verifyObject, t as createProof, y as verifyJsonLd } from "./proof-BrOQrPQf.js";
|
|
10
|
+
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./kv-cache-J6hmiAEd.js";
|
|
11
11
|
import { InProcessMessageQueue, MemoryKvStore, ParallelMessageQueue } from "./federation/mod.js";
|
|
12
12
|
import "./nodeinfo/mod.js";
|
|
13
13
|
import "./runtime/mod.js";
|
|
@@ -4,7 +4,7 @@ globalThis.addEventListener = () => {};
|
|
|
4
4
|
import { t as esm_default } from "../esm-DVILvP5e.mjs";
|
|
5
5
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
6
6
|
import "../std__assert-Duiq_YC9.mjs";
|
|
7
|
-
import { a as parseProtocol, c as parseUsage, i as parseOutboundService, n as parseInboundService, o as parseServices, r as parseNodeInfo, s as parseSoftware, t as getNodeInfo } from "../client-
|
|
7
|
+
import { a as parseProtocol, c as parseUsage, i as parseOutboundService, n as parseInboundService, o as parseServices, r as parseNodeInfo, s as parseSoftware, t as getNodeInfo } from "../client-DNiBssfx.mjs";
|
|
8
8
|
import { test } from "@fedify/fixture";
|
|
9
9
|
//#region src/nodeinfo/client.test.ts
|
|
10
10
|
test("getNodeInfo()", async (t) => {
|
|
@@ -967,5 +967,32 @@ test("parseUsage()", () => {
|
|
|
967
967
|
localComments: 456
|
|
968
968
|
});
|
|
969
969
|
});
|
|
970
|
+
test("getNodeInfo() bounds both discovery and document responses", async () => {
|
|
971
|
+
esm_default.mockGlobal();
|
|
972
|
+
const base = "https://8.8.8.8";
|
|
973
|
+
const descriptor = { links: [{
|
|
974
|
+
rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
|
|
975
|
+
href: `${base}/nodeinfo`
|
|
976
|
+
}] };
|
|
977
|
+
let oversizedDescriptor = true;
|
|
978
|
+
let oversizedDocument = true;
|
|
979
|
+
const data = { padding: "a".repeat(256) };
|
|
980
|
+
try {
|
|
981
|
+
esm_default.get(`${base}/.well-known/nodeinfo`, () => new Response(JSON.stringify(descriptor), { headers: oversizedDescriptor ? { "Content-Length": String(16777217) } : {} }));
|
|
982
|
+
esm_default.get(`${base}/nodeinfo`, () => new Response(JSON.stringify(data), { headers: oversizedDocument ? { "Content-Length": String(16777217) } : {} }));
|
|
983
|
+
assertEquals(await getNodeInfo(base), void 0);
|
|
984
|
+
assertEquals(esm_default.callHistory.calls(`${base}/nodeinfo`).length, 0);
|
|
985
|
+
oversizedDescriptor = false;
|
|
986
|
+
assertEquals(await getNodeInfo(base), void 0);
|
|
987
|
+
assertEquals(await getNodeInfo(`${base}/nodeinfo`, {
|
|
988
|
+
direct: true,
|
|
989
|
+
parse: "none"
|
|
990
|
+
}), void 0);
|
|
991
|
+
oversizedDocument = false;
|
|
992
|
+
assertEquals(await getNodeInfo(base, { parse: "none" }), data);
|
|
993
|
+
} finally {
|
|
994
|
+
esm_default.hardReset();
|
|
995
|
+
}
|
|
996
|
+
});
|
|
970
997
|
//#endregion
|
|
971
998
|
export {};
|
|
@@ -4,8 +4,8 @@ globalThis.addEventListener = () => {};
|
|
|
4
4
|
import { n as createRequestContext } from "../context-Juj6bdHC.mjs";
|
|
5
5
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
6
6
|
import "../std__assert-Duiq_YC9.mjs";
|
|
7
|
-
import { t as MemoryKvStore } from "../kv-
|
|
8
|
-
import { a as createFederation, h as handleNodeInfoJrd, m as handleNodeInfo } from "../middleware-
|
|
7
|
+
import { t as MemoryKvStore } from "../kv-BrZHNugx.mjs";
|
|
8
|
+
import { a as createFederation, h as handleNodeInfoJrd, m as handleNodeInfo } from "../middleware-Dy18K1xP.mjs";
|
|
9
9
|
import { test } from "@fedify/fixture";
|
|
10
10
|
//#region src/nodeinfo/handler.test.ts
|
|
11
11
|
test("handleNodeInfo()", async () => {
|
package/dist/nodeinfo/mod.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { Temporal } = require("@js-temporal/polyfill");
|
|
2
2
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
-
const require_types = require("../types-
|
|
4
|
+
const require_types = require("../types-DWs-qZaY.cjs");
|
|
5
5
|
exports.getNodeInfo = require_types.getNodeInfo;
|
|
6
6
|
exports.nodeInfoToJson = require_types.nodeInfoToJson;
|
|
7
7
|
exports.parseNodeInfo = require_types.parseNodeInfo;
|
package/dist/nodeinfo/mod.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
|
-
import { n as getNodeInfo, r as parseNodeInfo, t as nodeInfoToJson } from "../types-
|
|
3
|
+
import { n as getNodeInfo, r as parseNodeInfo, t as nodeInfoToJson } from "../types-sXITXcWa.js";
|
|
4
4
|
export { getNodeInfo, nodeInfoToJson, parseNodeInfo };
|
|
@@ -4,7 +4,7 @@ globalThis.addEventListener = () => {};
|
|
|
4
4
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
5
5
|
import "../std__assert-Duiq_YC9.mjs";
|
|
6
6
|
import { t as assertThrows } from "../assert_throws-4NwKEy2q.mjs";
|
|
7
|
-
import { t as nodeInfoToJson } from "../types-
|
|
7
|
+
import { t as nodeInfoToJson } from "../types-C37hquWI.mjs";
|
|
8
8
|
import { test } from "@fedify/fixture";
|
|
9
9
|
//#region src/nodeinfo/types.test.ts
|
|
10
10
|
test("nodeInfoToJson()", () => {
|
|
@@ -3,7 +3,7 @@ import "urlpattern-polyfill";
|
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
4
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
5
5
|
import "../std__assert-Duiq_YC9.mjs";
|
|
6
|
-
import { t as MemoryKvStore } from "../kv-
|
|
6
|
+
import { t as MemoryKvStore } from "../kv-BrZHNugx.mjs";
|
|
7
7
|
import { test } from "@fedify/fixture";
|
|
8
8
|
import { SpanKind, SpanStatusCode, TraceFlags } from "@opentelemetry/api";
|
|
9
9
|
import { getLogger } from "@logtape/logtape";
|
|
@@ -26,6 +26,13 @@ interface DoesActorOwnKeyOptions {
|
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Checks if the actor of the given activity owns the specified key.
|
|
29
|
+
*
|
|
30
|
+
* Ownership is never taken from what the activity or the key say about
|
|
31
|
+
* themselves, as both are written by whoever sent the activity. It is
|
|
32
|
+
* established from a document that the owner itself serves: either the key's
|
|
33
|
+
* claimed owner links back to the key, or the actor the activity claims lists
|
|
34
|
+
* the key as its own.
|
|
35
|
+
*
|
|
29
36
|
* @param activity The activity to check.
|
|
30
37
|
* @param key The public key to check.
|
|
31
38
|
* @param options Options for checking the key ownership.
|
|
@@ -56,6 +63,10 @@ interface GetKeyOwnerOptions {
|
|
|
56
63
|
* Gets the actor that owns the specified key. Returns `null` if the key has no
|
|
57
64
|
* known owner.
|
|
58
65
|
*
|
|
66
|
+
* The owner is only returned when the key and the owner link to each other:
|
|
67
|
+
* a document that merely claims to own a key is not enough, as the claim and
|
|
68
|
+
* the key can come from the same host.
|
|
69
|
+
*
|
|
59
70
|
* @param keyId The ID of the key to check, or the key itself.
|
|
60
71
|
* @param options Options for getting the key owner.
|
|
61
72
|
* @returns The actor that owns the key, or `null` if the key has no known
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import "@js-temporal/polyfill";
|
|
2
|
+
import "urlpattern-polyfill";
|
|
3
|
+
globalThis.addEventListener = () => {};
|
|
4
|
+
import { n as version, t as name } from "./deno-BXkm_rws.mjs";
|
|
5
|
+
import { c as verifyKeyOwnership, n as fetchActorDocument, t as exportJwk } from "./key-A8SuFznD.mjs";
|
|
6
|
+
import { CryptographicKey, Object as Object$1, isActor } from "@fedify/vocab";
|
|
7
|
+
import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
8
|
+
import { getDocumentLoader } from "@fedify/vocab-runtime";
|
|
9
|
+
import { getLogger } from "@logtape/logtape";
|
|
10
|
+
//#region src/sig/owner.ts
|
|
11
|
+
const logger = getLogger([
|
|
12
|
+
"fedify",
|
|
13
|
+
"sig",
|
|
14
|
+
"owner"
|
|
15
|
+
]);
|
|
16
|
+
/**
|
|
17
|
+
* Checks if the actor of the given activity owns the specified key.
|
|
18
|
+
*
|
|
19
|
+
* Ownership is never taken from what the activity or the key say about
|
|
20
|
+
* themselves, as both are written by whoever sent the activity. It is
|
|
21
|
+
* established from a document that the owner itself serves: either the key's
|
|
22
|
+
* claimed owner links back to the key, or the actor the activity claims lists
|
|
23
|
+
* the key as its own.
|
|
24
|
+
*
|
|
25
|
+
* @param activity The activity to check.
|
|
26
|
+
* @param key The public key to check.
|
|
27
|
+
* @param options Options for checking the key ownership.
|
|
28
|
+
* @returns Whether the actor is the owner of the key.
|
|
29
|
+
*/
|
|
30
|
+
async function doesActorOwnKey(activity, key, options) {
|
|
31
|
+
return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("activitypub.verify_key_ownership", {
|
|
32
|
+
kind: SpanKind.INTERNAL,
|
|
33
|
+
attributes: {
|
|
34
|
+
"activitypub.actor.id": activity.actorId?.href ?? "",
|
|
35
|
+
"activitypub.key.id": key.id?.href ?? ""
|
|
36
|
+
}
|
|
37
|
+
}, async (span) => {
|
|
38
|
+
try {
|
|
39
|
+
const actorId = activity.actorId;
|
|
40
|
+
if (actorId == null) {
|
|
41
|
+
span.setAttribute("activitypub.key_ownership.verified", false);
|
|
42
|
+
span.setAttribute("activitypub.key_ownership.method", "none");
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
if (key.ownerId != null) {
|
|
46
|
+
const owner = await verifyKeyOwnership(key, options);
|
|
47
|
+
if (owner?.id != null && owner.id.href === actorId.href) {
|
|
48
|
+
span.setAttribute("activitypub.key_ownership.verified", true);
|
|
49
|
+
span.setAttribute("activitypub.key_ownership.method", "key_owner");
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const actor = await fetchActorDocument(actorId, options);
|
|
54
|
+
if (actor != null && await doesActorListKey(actor, key, options)) {
|
|
55
|
+
span.setAttribute("activitypub.key_ownership.verified", true);
|
|
56
|
+
span.setAttribute("activitypub.key_ownership.method", "actor_fetch");
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
logger.debug("The actor {actorId} does not own key {keyId}: neither the owner the key claims nor the actor's own document links the two to each other.", {
|
|
60
|
+
actorId: actorId.href,
|
|
61
|
+
keyId: key.id?.href
|
|
62
|
+
});
|
|
63
|
+
span.setAttribute("activitypub.key_ownership.verified", false);
|
|
64
|
+
span.setAttribute("activitypub.key_ownership.method", "actor_fetch");
|
|
65
|
+
return false;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
span.recordException(error);
|
|
68
|
+
span.setStatus({
|
|
69
|
+
code: SpanStatusCode.ERROR,
|
|
70
|
+
message: String(error)
|
|
71
|
+
});
|
|
72
|
+
throw error;
|
|
73
|
+
} finally {
|
|
74
|
+
span.end();
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Determines whether the given actor's own document lists the given key among
|
|
80
|
+
* its public keys.
|
|
81
|
+
*
|
|
82
|
+
* Keys are matched by id, which is what an actor document links to. A key
|
|
83
|
+
* document may leave its id implicit, though, and then there is no id for the
|
|
84
|
+
* actor to link to; the key material itself is the only thing the two can
|
|
85
|
+
* have in common, so that is what gets compared.
|
|
86
|
+
*/
|
|
87
|
+
async function doesActorListKey(actor, key, options) {
|
|
88
|
+
if (key.id != null) {
|
|
89
|
+
for (const publicKeyId of actor.publicKeyIds) if (publicKeyId.href === key.id.href) return true;
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
if (key.publicKey == null) return false;
|
|
93
|
+
const publicKeys = actor.getPublicKeys({
|
|
94
|
+
...options,
|
|
95
|
+
suppressError: true
|
|
96
|
+
});
|
|
97
|
+
for await (const publicKey of publicKeys) {
|
|
98
|
+
if (publicKey.publicKey == null) continue;
|
|
99
|
+
if (await isSamePublicKey(publicKey.publicKey, key.publicKey)) return true;
|
|
100
|
+
}
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Compares two public keys by their key material, ignoring the metadata that
|
|
105
|
+
* surrounds it.
|
|
106
|
+
*/
|
|
107
|
+
async function isSamePublicKey(a, b) {
|
|
108
|
+
const [x, y] = await Promise.all([exportJwk(a), exportJwk(b)]);
|
|
109
|
+
return x.kty === y.kty && x.crv === y.crv && x.n === y.n && x.e === y.e && x.x === y.x && x.y === y.y;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Gets the actor that owns the specified key. Returns `null` if the key has no
|
|
113
|
+
* known owner.
|
|
114
|
+
*
|
|
115
|
+
* The owner is only returned when the key and the owner link to each other:
|
|
116
|
+
* a document that merely claims to own a key is not enough, as the claim and
|
|
117
|
+
* the key can come from the same host.
|
|
118
|
+
*
|
|
119
|
+
* @param keyId The ID of the key to check, or the key itself.
|
|
120
|
+
* @param options Options for getting the key owner.
|
|
121
|
+
* @returns The actor that owns the key, or `null` if the key has no known
|
|
122
|
+
* owner.
|
|
123
|
+
* @since 0.7.0
|
|
124
|
+
*/
|
|
125
|
+
async function getKeyOwner(keyId, options) {
|
|
126
|
+
const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
|
|
127
|
+
const documentLoader = options.documentLoader ?? getDocumentLoader();
|
|
128
|
+
const fetchOptions = {
|
|
129
|
+
documentLoader,
|
|
130
|
+
contextLoader: options.contextLoader ?? getDocumentLoader(),
|
|
131
|
+
tracerProvider
|
|
132
|
+
};
|
|
133
|
+
if (keyId instanceof CryptographicKey) return await verifyKeyOwnership(keyId, fetchOptions);
|
|
134
|
+
let keyDoc;
|
|
135
|
+
let documentUrl = keyId;
|
|
136
|
+
try {
|
|
137
|
+
const remoteDocument = await documentLoader(keyId.href);
|
|
138
|
+
keyDoc = remoteDocument.document;
|
|
139
|
+
documentUrl = new URL(remoteDocument.documentUrl ?? "", keyId);
|
|
140
|
+
} catch (_) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
let object;
|
|
144
|
+
try {
|
|
145
|
+
object = await Object$1.fromJsonLd(keyDoc, {
|
|
146
|
+
...fetchOptions,
|
|
147
|
+
baseUrl: documentUrl
|
|
148
|
+
});
|
|
149
|
+
} catch (e) {
|
|
150
|
+
if (!(e instanceof TypeError)) throw e;
|
|
151
|
+
try {
|
|
152
|
+
object = await CryptographicKey.fromJsonLd(keyDoc, fetchOptions);
|
|
153
|
+
} catch (e) {
|
|
154
|
+
if (e instanceof TypeError) return null;
|
|
155
|
+
throw e;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (object instanceof CryptographicKey) {
|
|
159
|
+
if (object.id != null && object.id.href !== keyId.href) return null;
|
|
160
|
+
return await verifyKeyOwnership(object.id == null ? object.clone({ id: keyId }) : object, fetchOptions);
|
|
161
|
+
}
|
|
162
|
+
if (!isActor(object)) return null;
|
|
163
|
+
if (object.id == null || object.id.origin !== documentUrl.origin) {
|
|
164
|
+
logger.debug("The document served at {documentUrl} claims to be the actor {actorId}, which belongs to another origin; refusing to treat it as the owner of key {keyId}.", {
|
|
165
|
+
documentUrl: documentUrl.href,
|
|
166
|
+
actorId: object.id?.href,
|
|
167
|
+
keyId: keyId.href
|
|
168
|
+
});
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
for (const kid of object.publicKeyIds) if (kid.href === keyId.href) return object;
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
export { getKeyOwner as n, doesActorOwnKey as t };
|
|
@@ -26,6 +26,13 @@ interface DoesActorOwnKeyOptions {
|
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Checks if the actor of the given activity owns the specified key.
|
|
29
|
+
*
|
|
30
|
+
* Ownership is never taken from what the activity or the key say about
|
|
31
|
+
* themselves, as both are written by whoever sent the activity. It is
|
|
32
|
+
* established from a document that the owner itself serves: either the key's
|
|
33
|
+
* claimed owner links back to the key, or the actor the activity claims lists
|
|
34
|
+
* the key as its own.
|
|
35
|
+
*
|
|
29
36
|
* @param activity The activity to check.
|
|
30
37
|
* @param key The public key to check.
|
|
31
38
|
* @param options Options for checking the key ownership.
|
|
@@ -56,6 +63,10 @@ interface GetKeyOwnerOptions {
|
|
|
56
63
|
* Gets the actor that owns the specified key. Returns `null` if the key has no
|
|
57
64
|
* known owner.
|
|
58
65
|
*
|
|
66
|
+
* The owner is only returned when the key and the owner link to each other:
|
|
67
|
+
* a document that merely claims to own a key is not enough, as the claim and
|
|
68
|
+
* the key can come from the same host.
|
|
69
|
+
*
|
|
59
70
|
* @param keyId The ID of the key to check, or the key itself.
|
|
60
71
|
* @param options Options for getting the key owner.
|
|
61
72
|
* @returns The actor that owns the key, or `null` if the key has no known
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
|
-
import {
|
|
3
|
+
import { c as fetchKey, f as validateCryptoKey, o as exportJwk, p as verifyKeyOwnership, s as fetchActorDocument, v as name, y as version } from "./http-Chr54tTL.js";
|
|
4
4
|
import { getLogger } from "@logtape/logtape";
|
|
5
5
|
import { Activity, CryptographicKey, DataIntegrityProof, Multikey, Object as Object$1, getTypeId, isActor } from "@fedify/vocab";
|
|
6
6
|
import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
@@ -10,7 +10,7 @@ import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
|
|
|
10
10
|
import jsonld from "@fedify/vocab-runtime/jsonld";
|
|
11
11
|
import serialize from "json-canon";
|
|
12
12
|
//#region src/sig/ld.ts
|
|
13
|
-
const logger$
|
|
13
|
+
const logger$2 = getLogger([
|
|
14
14
|
"fedify",
|
|
15
15
|
"sig",
|
|
16
16
|
"ld"
|
|
@@ -417,7 +417,7 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
417
417
|
try {
|
|
418
418
|
signature = decodeBase64(sig.signatureValue);
|
|
419
419
|
} catch (error) {
|
|
420
|
-
logger$
|
|
420
|
+
logger$2.debug("Failed to verify; invalid base64 signatureValue: {signatureValue}", {
|
|
421
421
|
...sig,
|
|
422
422
|
error
|
|
423
423
|
});
|
|
@@ -436,7 +436,7 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
436
436
|
try {
|
|
437
437
|
sigOptsHash = await hashJsonLd(sigOpts, options.contextLoader);
|
|
438
438
|
} catch (error) {
|
|
439
|
-
logger$
|
|
439
|
+
logger$2.warn("Failed to verify; failed to hash the signature options: {signatureOptions}\n{error}", {
|
|
440
440
|
signatureOptions: sigOpts,
|
|
441
441
|
error
|
|
442
442
|
});
|
|
@@ -448,7 +448,7 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
448
448
|
try {
|
|
449
449
|
docHash = await hashJsonLd(document, options.contextLoader);
|
|
450
450
|
} catch (error) {
|
|
451
|
-
logger$
|
|
451
|
+
logger$2.warn("Failed to verify; failed to hash the document: {document}\n{error}", {
|
|
452
452
|
document,
|
|
453
453
|
error
|
|
454
454
|
});
|
|
@@ -459,7 +459,7 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
459
459
|
const messageBytes = encoder.encode(message);
|
|
460
460
|
if (await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key.publicKey, signature.slice(), messageBytes)) return key;
|
|
461
461
|
if (cached) {
|
|
462
|
-
logger$
|
|
462
|
+
logger$2.debug("Failed to verify with the cached key {keyId}; signature {signatureValue} is invalid. Retrying with the freshly fetched key...", {
|
|
463
463
|
keyId: sig.creator,
|
|
464
464
|
...sig
|
|
465
465
|
});
|
|
@@ -473,7 +473,7 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
473
473
|
if (key == null) return null;
|
|
474
474
|
return await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key.publicKey, signature.slice(), messageBytes) ? key : null;
|
|
475
475
|
}
|
|
476
|
-
logger$
|
|
476
|
+
logger$2.debug("Failed to verify with the fetched key {keyId}; signature {signatureValue} is invalid. Check if the key is correct or if the signed message is correct. The message to sign is:\n{message}", {
|
|
477
477
|
keyId: sig.creator,
|
|
478
478
|
...sig,
|
|
479
479
|
message
|
|
@@ -517,12 +517,12 @@ async function verifyJsonLdInternal(jsonLd, options, compact) {
|
|
|
517
517
|
const key = await verifySignature(compacted, verificationOptions);
|
|
518
518
|
if (key == null) return false;
|
|
519
519
|
if (key.ownerId == null) {
|
|
520
|
-
logger$
|
|
520
|
+
logger$2.debug("Key {keyId} has no owner.", { keyId: key.id?.href });
|
|
521
521
|
return false;
|
|
522
522
|
}
|
|
523
523
|
attributions.delete(key.ownerId.href);
|
|
524
524
|
if (attributions.size > 0) {
|
|
525
|
-
logger$
|
|
525
|
+
logger$2.debug("Some attributions are not authenticated by the Linked Data Signatures: {attributions}.", { attributions: [...attributions] });
|
|
526
526
|
return false;
|
|
527
527
|
}
|
|
528
528
|
return true;
|
|
@@ -547,8 +547,20 @@ async function hashJsonLd(jsonLd, contextLoader) {
|
|
|
547
547
|
}
|
|
548
548
|
//#endregion
|
|
549
549
|
//#region src/sig/owner.ts
|
|
550
|
+
const logger$1 = getLogger([
|
|
551
|
+
"fedify",
|
|
552
|
+
"sig",
|
|
553
|
+
"owner"
|
|
554
|
+
]);
|
|
550
555
|
/**
|
|
551
556
|
* Checks if the actor of the given activity owns the specified key.
|
|
557
|
+
*
|
|
558
|
+
* Ownership is never taken from what the activity or the key say about
|
|
559
|
+
* themselves, as both are written by whoever sent the activity. It is
|
|
560
|
+
* established from a document that the owner itself serves: either the key's
|
|
561
|
+
* claimed owner links back to the key, or the actor the activity claims lists
|
|
562
|
+
* the key as its own.
|
|
563
|
+
*
|
|
552
564
|
* @param activity The activity to check.
|
|
553
565
|
* @param key The public key to check.
|
|
554
566
|
* @param options Options for checking the key ownership.
|
|
@@ -563,23 +575,30 @@ async function doesActorOwnKey(activity, key, options) {
|
|
|
563
575
|
}
|
|
564
576
|
}, async (span) => {
|
|
565
577
|
try {
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
span.setAttribute("activitypub.key_ownership.verified", owns);
|
|
569
|
-
span.setAttribute("activitypub.key_ownership.method", "owner_id");
|
|
570
|
-
return owns;
|
|
571
|
-
}
|
|
572
|
-
const actor = await activity.getActor(options);
|
|
573
|
-
if (actor == null || !isActor(actor)) {
|
|
578
|
+
const actorId = activity.actorId;
|
|
579
|
+
if (actorId == null) {
|
|
574
580
|
span.setAttribute("activitypub.key_ownership.verified", false);
|
|
575
|
-
span.setAttribute("activitypub.key_ownership.method", "
|
|
581
|
+
span.setAttribute("activitypub.key_ownership.method", "none");
|
|
576
582
|
return false;
|
|
577
583
|
}
|
|
578
|
-
|
|
584
|
+
if (key.ownerId != null) {
|
|
585
|
+
const owner = await verifyKeyOwnership(key, options);
|
|
586
|
+
if (owner?.id != null && owner.id.href === actorId.href) {
|
|
587
|
+
span.setAttribute("activitypub.key_ownership.verified", true);
|
|
588
|
+
span.setAttribute("activitypub.key_ownership.method", "key_owner");
|
|
589
|
+
return true;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
const actor = await fetchActorDocument(actorId, options);
|
|
593
|
+
if (actor != null && await doesActorListKey(actor, key, options)) {
|
|
579
594
|
span.setAttribute("activitypub.key_ownership.verified", true);
|
|
580
595
|
span.setAttribute("activitypub.key_ownership.method", "actor_fetch");
|
|
581
596
|
return true;
|
|
582
597
|
}
|
|
598
|
+
logger$1.debug("The actor {actorId} does not own key {keyId}: neither the owner the key claims nor the actor's own document links the two to each other.", {
|
|
599
|
+
actorId: actorId.href,
|
|
600
|
+
keyId: key.id?.href
|
|
601
|
+
});
|
|
583
602
|
span.setAttribute("activitypub.key_ownership.verified", false);
|
|
584
603
|
span.setAttribute("activitypub.key_ownership.method", "actor_fetch");
|
|
585
604
|
return false;
|
|
@@ -596,9 +615,46 @@ async function doesActorOwnKey(activity, key, options) {
|
|
|
596
615
|
});
|
|
597
616
|
}
|
|
598
617
|
/**
|
|
618
|
+
* Determines whether the given actor's own document lists the given key among
|
|
619
|
+
* its public keys.
|
|
620
|
+
*
|
|
621
|
+
* Keys are matched by id, which is what an actor document links to. A key
|
|
622
|
+
* document may leave its id implicit, though, and then there is no id for the
|
|
623
|
+
* actor to link to; the key material itself is the only thing the two can
|
|
624
|
+
* have in common, so that is what gets compared.
|
|
625
|
+
*/
|
|
626
|
+
async function doesActorListKey(actor, key, options) {
|
|
627
|
+
if (key.id != null) {
|
|
628
|
+
for (const publicKeyId of actor.publicKeyIds) if (publicKeyId.href === key.id.href) return true;
|
|
629
|
+
return false;
|
|
630
|
+
}
|
|
631
|
+
if (key.publicKey == null) return false;
|
|
632
|
+
const publicKeys = actor.getPublicKeys({
|
|
633
|
+
...options,
|
|
634
|
+
suppressError: true
|
|
635
|
+
});
|
|
636
|
+
for await (const publicKey of publicKeys) {
|
|
637
|
+
if (publicKey.publicKey == null) continue;
|
|
638
|
+
if (await isSamePublicKey(publicKey.publicKey, key.publicKey)) return true;
|
|
639
|
+
}
|
|
640
|
+
return false;
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Compares two public keys by their key material, ignoring the metadata that
|
|
644
|
+
* surrounds it.
|
|
645
|
+
*/
|
|
646
|
+
async function isSamePublicKey(a, b) {
|
|
647
|
+
const [x, y] = await Promise.all([exportJwk(a), exportJwk(b)]);
|
|
648
|
+
return x.kty === y.kty && x.crv === y.crv && x.n === y.n && x.e === y.e && x.x === y.x && x.y === y.y;
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
599
651
|
* Gets the actor that owns the specified key. Returns `null` if the key has no
|
|
600
652
|
* known owner.
|
|
601
653
|
*
|
|
654
|
+
* The owner is only returned when the key and the owner link to each other:
|
|
655
|
+
* a document that merely claims to own a key is not enough, as the claim and
|
|
656
|
+
* the key can come from the same host.
|
|
657
|
+
*
|
|
602
658
|
* @param keyId The ID of the key to check, or the key itself.
|
|
603
659
|
* @param options Options for getting the key owner.
|
|
604
660
|
* @returns The actor that owns the key, or `null` if the key has no known
|
|
@@ -608,52 +664,50 @@ async function doesActorOwnKey(activity, key, options) {
|
|
|
608
664
|
async function getKeyOwner(keyId, options) {
|
|
609
665
|
const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
|
|
610
666
|
const documentLoader = options.documentLoader ?? getDocumentLoader();
|
|
611
|
-
const
|
|
667
|
+
const fetchOptions = {
|
|
668
|
+
documentLoader,
|
|
669
|
+
contextLoader: options.contextLoader ?? getDocumentLoader(),
|
|
670
|
+
tracerProvider
|
|
671
|
+
};
|
|
672
|
+
if (keyId instanceof CryptographicKey) return await verifyKeyOwnership(keyId, fetchOptions);
|
|
673
|
+
let keyDoc;
|
|
674
|
+
let documentUrl = keyId;
|
|
675
|
+
try {
|
|
676
|
+
const remoteDocument = await documentLoader(keyId.href);
|
|
677
|
+
keyDoc = remoteDocument.document;
|
|
678
|
+
documentUrl = new URL(remoteDocument.documentUrl ?? "", keyId);
|
|
679
|
+
} catch (_) {
|
|
680
|
+
return null;
|
|
681
|
+
}
|
|
612
682
|
let object;
|
|
613
|
-
|
|
614
|
-
object =
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
const { document } = await documentLoader(keyId.href);
|
|
621
|
-
keyDoc = document;
|
|
622
|
-
} catch (_) {
|
|
623
|
-
return null;
|
|
624
|
-
}
|
|
683
|
+
try {
|
|
684
|
+
object = await Object$1.fromJsonLd(keyDoc, {
|
|
685
|
+
...fetchOptions,
|
|
686
|
+
baseUrl: documentUrl
|
|
687
|
+
});
|
|
688
|
+
} catch (e) {
|
|
689
|
+
if (!(e instanceof TypeError)) throw e;
|
|
625
690
|
try {
|
|
626
|
-
object = await
|
|
627
|
-
documentLoader,
|
|
628
|
-
contextLoader,
|
|
629
|
-
tracerProvider
|
|
630
|
-
});
|
|
691
|
+
object = await CryptographicKey.fromJsonLd(keyDoc, fetchOptions);
|
|
631
692
|
} catch (e) {
|
|
632
|
-
if (
|
|
633
|
-
|
|
634
|
-
object = await CryptographicKey.fromJsonLd(keyDoc, {
|
|
635
|
-
documentLoader,
|
|
636
|
-
contextLoader,
|
|
637
|
-
tracerProvider
|
|
638
|
-
});
|
|
639
|
-
} catch (e) {
|
|
640
|
-
if (e instanceof TypeError) return null;
|
|
641
|
-
throw e;
|
|
642
|
-
}
|
|
693
|
+
if (e instanceof TypeError) return null;
|
|
694
|
+
throw e;
|
|
643
695
|
}
|
|
644
696
|
}
|
|
645
|
-
let owner = null;
|
|
646
697
|
if (object instanceof CryptographicKey) {
|
|
647
|
-
if (object.
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
698
|
+
if (object.id != null && object.id.href !== keyId.href) return null;
|
|
699
|
+
return await verifyKeyOwnership(object.id == null ? object.clone({ id: keyId }) : object, fetchOptions);
|
|
700
|
+
}
|
|
701
|
+
if (!isActor(object)) return null;
|
|
702
|
+
if (object.id == null || object.id.origin !== documentUrl.origin) {
|
|
703
|
+
logger$1.debug("The document served at {documentUrl} claims to be the actor {actorId}, which belongs to another origin; refusing to treat it as the owner of key {keyId}.", {
|
|
704
|
+
documentUrl: documentUrl.href,
|
|
705
|
+
actorId: object.id?.href,
|
|
706
|
+
keyId: keyId.href
|
|
652
707
|
});
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
if (
|
|
656
|
-
for (const kid of owner.publicKeyIds) if (kid.href === keyId.href) return owner;
|
|
708
|
+
return null;
|
|
709
|
+
}
|
|
710
|
+
for (const kid of object.publicKeyIds) if (kid.href === keyId.href) return object;
|
|
657
711
|
return null;
|
|
658
712
|
}
|
|
659
713
|
//#endregion
|