@fedify/fedify 2.4.0-dev.1964 → 2.4.0-dev.1995
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/{builder-B4zpKIFU.mjs → builder-D0DxgOV5.mjs} +2 -2
- package/dist/{client-CtxvmazV.mjs → client-DpnpgjyX.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 +1 -1
- package/dist/compound-proof-CJnWc6c-.mjs +495 -0
- package/dist/{context-COLwHogJ.d.cts → context-BeDnDuF3.d.cts} +4 -3
- package/dist/{context-DiiCt4S7.d.ts → context-uyRUWoZQ.d.ts} +4 -3
- package/dist/{deno-CtG93ohj.mjs → deno-CABhzCb_.mjs} +1 -1
- package/dist/{docloader-dk_k3S8d.mjs → docloader-BbGSL0Xq.mjs} +2 -2
- package/dist/federation/builder.test.mjs +1 -1
- package/dist/federation/handler-compound-proof.test.d.mts +2 -0
- package/dist/federation/handler-compound-proof.test.mjs +152 -0
- package/dist/federation/handler.test.mjs +122 -4
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/keycache.test.mjs +52 -9
- package/dist/federation/metrics.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +111 -15
- 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/send.test.mjs +139 -4
- package/dist/federation/tasks/enqueue.test.mjs +1 -1
- package/dist/federation/tasks/tasks.test.mjs +2 -2
- package/dist/federation/temporal.test.mjs +1 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{federation-Drjlrrax.cjs → federation-DCEHQk4G.cjs} +632 -57
- package/dist/{http-6TI0tI03.d.cts → http-65PYi9jY.d.ts} +34 -2
- package/dist/{http-Dj4s1UQ0.js → http-9WyuldYh.js} +170 -8
- package/dist/{http-CdrSn2ip.d.ts → http-CP-7OdSq.d.cts} +34 -2
- package/dist/{http-B3skRvGo.cjs → http-CRFns-UE.cjs} +181 -7
- package/dist/{http-D7LX-BL9.mjs → http-D9urSO2D.mjs} +3 -3
- package/dist/{key-BVjgbs_9.mjs → key-Ccs8cnd7.mjs} +169 -7
- package/dist/{keycache-ZLqIfrkL.mjs → keycache-BUDHB5rY.mjs} +12 -4
- package/dist/{kv-cache-DtsjH_bY.cjs → kv-cache-DXT9vmIg.cjs} +2 -2
- package/dist/{kv-cache-tGNbvDCF.js → kv-cache-DtmXhPXG.js} +2 -2
- package/dist/{kv-cache-xRcC_xxP.mjs → kv-cache-lKyFn_Dn.mjs} +1 -1
- package/dist/{ld-OuCeQFny.mjs → ld-qup__MAW.mjs} +3 -3
- package/dist/map-local-context-conflict-DOYEEJ3u.mjs +204 -0
- package/dist/map-local-create-note-B0SeXJms.mjs +214 -0
- package/dist/{metrics-B9N27cCB.mjs → metrics-CISXCvB1.mjs} +1 -1
- package/dist/{middleware-TeLjzoxn.mjs → middleware-CzvJvPHK.mjs} +58 -15
- package/dist/{middleware-Cd_vPqDH.mjs → middleware-DkrU2WhY.mjs} +1 -1
- package/dist/{middleware-CPTDFMmJ.js → middleware-DsfWajaD.js} +593 -18
- package/dist/{mod-DypxPS9H.d.ts → mod-C0BYc0OU.d.ts} +1 -1
- package/dist/{mod-CnGLNoVw.d.cts → mod-CbKDOnCt.d.cts} +1 -1
- package/dist/{mod-CLHkCwLm.d.cts → mod-CyiSjRkk.d.cts} +1 -1
- package/dist/{mod-CSH1Ee-I.d.ts → mod-D882_Xsg.d.ts} +1 -1
- package/dist/{mod-DzRXACM5.d.ts → mod-UDwMjuHM.d.ts} +1 -1
- package/dist/{mod-BZldCEU0.d.cts → mod-x9W0d0Pk.d.cts} +1 -1
- package/dist/mod.cjs +20 -20
- 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 +1 -1
- package/dist/nodeinfo/mod.cjs +1 -1
- package/dist/nodeinfo/mod.js +1 -1
- package/dist/{owner-DGSfntI-.d.ts → owner-BF0L9cMt.d.cts} +12 -1
- package/dist/{proof-BO_esQii.js → owner-BIPEZGiU.js} +1255 -1098
- package/dist/{owner-r_waTiQj.d.cts → owner-BSzr5-I8.d.ts} +12 -1
- package/dist/owner-CRoq8Spb.mjs +175 -0
- package/dist/{proof-Dua0d906.cjs → owner-CVA7L9MA.cjs} +1266 -1097
- package/dist/{proof-D5Ajk4DJ.mjs → proof-BDxNVZ3E.mjs} +186 -83
- package/dist/{send-DVXyUqhO.mjs → send-BzM5GLyn.mjs} +68 -11
- package/dist/sig/compound-proof-discovery.test.d.mts +2 -0
- package/dist/sig/compound-proof-discovery.test.mjs +331 -0
- package/dist/sig/compound-proof-verification.test.d.mts +2 -0
- package/dist/sig/compound-proof-verification.test.mjs +465 -0
- package/dist/sig/compound-proof.test.d.mts +2 -0
- package/dist/sig/compound-proof.test.mjs +324 -0
- package/dist/sig/http.test.mjs +2 -2
- package/dist/sig/key.test.mjs +169 -2
- package/dist/sig/ld.test.mjs +55 -2
- package/dist/sig/mod.cjs +17 -17
- 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 +103 -4
- package/dist/sig/proof.test.mjs +120 -1
- package/dist/{temporal-BoDw51A-.mjs → temporal-Dv6Qv-8k.mjs} +1 -1
- package/dist/testing/kv.test.mjs +1 -1
- package/dist/testing/mod.d.mts +2 -1
- package/dist/{types-RXm5YxpC.cjs → types-Be2zbyeG.cjs} +94 -2
- package/dist/{types-Dtyf8lVj.js → types-C_cNlNVK.js} +78 -4
- package/dist/utils/docloader.test.mjs +27 -3
- 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 +6 -6
- package/dist/owner-DTEqTzSr.mjs +0 -120
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
2
|
import { Activity, Actor, CryptographicKey } from "@fedify/vocab";
|
|
3
|
-
import { DocumentLoader } from "@fedify/vocab-runtime";
|
|
4
3
|
import { TracerProvider } from "@opentelemetry/api";
|
|
4
|
+
import { DocumentLoader } from "@fedify/vocab-runtime";
|
|
5
5
|
|
|
6
6
|
//#region src/sig/owner.d.ts
|
|
7
7
|
/**
|
|
@@ -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 "temporal-polyfill";
|
|
2
|
+
import "urlpattern-polyfill";
|
|
3
|
+
globalThis.addEventListener = () => {};
|
|
4
|
+
import { n as version, t as name } from "./deno-CABhzCb_.mjs";
|
|
5
|
+
import { c as verifyKeyOwnership, n as fetchActorDocument, t as exportJwk } from "./key-Ccs8cnd7.mjs";
|
|
6
|
+
import { getLogger } from "@logtape/logtape";
|
|
7
|
+
import { CryptographicKey, Object as Object$1, isActor } from "@fedify/vocab";
|
|
8
|
+
import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
9
|
+
import { getDocumentLoader } from "@fedify/vocab-runtime";
|
|
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 };
|