@evanp/activitypub-bot 0.39.1 → 0.39.3
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/lib/activitypubclient.js +24 -6
- package/package.json +1 -1
package/lib/activitypubclient.js
CHANGED
|
@@ -160,15 +160,17 @@ export class ActivityPubClient {
|
|
|
160
160
|
}
|
|
161
161
|
this.#logger.debug({ headers }, 'Sending headers')
|
|
162
162
|
const method = 'GET'
|
|
163
|
-
this.#logger.debug({ url: baseUrl }, 'Signing GET request')
|
|
164
163
|
let storedPolicy, lastPolicy
|
|
165
164
|
if (sign) {
|
|
165
|
+
this.#logger.debug({ url: baseUrl }, 'Signing GET request')
|
|
166
166
|
storedPolicy = await this.#policyStorage.get(parsed.origin)
|
|
167
167
|
if (!storedPolicy || storedPolicy === SignaturePolicyStorage.RFC9421) {
|
|
168
|
+
this.#logger.debug({ origin: parsed.origin, storedPolicy }, 'Signing with RFC 9421')
|
|
168
169
|
lastPolicy = SignaturePolicyStorage.RFC9421
|
|
169
170
|
const sigHeaders = await this.#messageSign({ username, url: baseUrl, method, headers })
|
|
170
171
|
Object.assign(headers, sigHeaders || {})
|
|
171
172
|
} else if (storedPolicy === SignaturePolicyStorage.DRAFT_CAVAGE_12) {
|
|
173
|
+
this.#logger.debug({ origin: parsed.origin, storedPolicy }, 'Signing with draft-cavage-12')
|
|
172
174
|
lastPolicy = SignaturePolicyStorage.DRAFT_CAVAGE_12
|
|
173
175
|
headers.signature =
|
|
174
176
|
await this.#sign({ username, url: baseUrl, method, headers })
|
|
@@ -190,6 +192,10 @@ export class ActivityPubClient {
|
|
|
190
192
|
if ([401, 403].includes(res.status) &&
|
|
191
193
|
sign &&
|
|
192
194
|
!storedPolicy) {
|
|
195
|
+
const body = await res.text()
|
|
196
|
+
this.#logger.debug(
|
|
197
|
+
{ url, status: res.status, body, headers: res.headers },
|
|
198
|
+
'Authentication error; retrying with draft-cavage-12 signature')
|
|
193
199
|
lastPolicy = SignaturePolicyStorage.DRAFT_CAVAGE_12
|
|
194
200
|
delete headers['signature-input']
|
|
195
201
|
headers.signature =
|
|
@@ -272,23 +278,32 @@ export class ActivityPubClient {
|
|
|
272
278
|
const json = await obj.export()
|
|
273
279
|
this.#fixupJson(json)
|
|
274
280
|
const body = JSON.stringify(json)
|
|
275
|
-
const
|
|
281
|
+
const digest = await this.#digester.digest(body)
|
|
282
|
+
const contentDigest = await this.#digester.contentDigest(body)
|
|
283
|
+
const baseHeaders = {
|
|
276
284
|
date: new Date().toUTCString(),
|
|
277
285
|
'user-agent': ActivityPubClient.#userAgent,
|
|
278
|
-
'content-type': 'application/activity+json'
|
|
279
|
-
digest: await this.#digester.digest(body)
|
|
286
|
+
'content-type': 'application/activity+json'
|
|
280
287
|
}
|
|
281
288
|
const method = 'POST'
|
|
282
|
-
|
|
289
|
+
let headers
|
|
283
290
|
this.#logger.debug({ url }, 'Signing POST')
|
|
284
291
|
let lastPolicy
|
|
285
292
|
const storedPolicy = await this.#policyStorage.get(parsed.origin)
|
|
286
293
|
if (!storedPolicy || storedPolicy === SignaturePolicyStorage.RFC9421) {
|
|
287
294
|
lastPolicy = SignaturePolicyStorage.RFC9421
|
|
295
|
+
headers = {
|
|
296
|
+
...baseHeaders,
|
|
297
|
+
'content-digest': contentDigest
|
|
298
|
+
}
|
|
288
299
|
const sigHeaders = await this.#messageSign({ username, url, method, headers })
|
|
289
300
|
Object.assign(headers, sigHeaders || {})
|
|
290
301
|
} else if (storedPolicy === SignaturePolicyStorage.DRAFT_CAVAGE_12) {
|
|
291
302
|
lastPolicy = SignaturePolicyStorage.DRAFT_CAVAGE_12
|
|
303
|
+
headers = {
|
|
304
|
+
...baseHeaders,
|
|
305
|
+
digest
|
|
306
|
+
}
|
|
292
307
|
headers.signature =
|
|
293
308
|
await this.#sign({ username, url, method, headers })
|
|
294
309
|
} else {
|
|
@@ -307,7 +322,10 @@ export class ActivityPubClient {
|
|
|
307
322
|
)
|
|
308
323
|
if ([401, 403].includes(res.status) && !storedPolicy) {
|
|
309
324
|
lastPolicy = SignaturePolicyStorage.DRAFT_CAVAGE_12
|
|
310
|
-
|
|
325
|
+
headers = {
|
|
326
|
+
...baseHeaders,
|
|
327
|
+
digest
|
|
328
|
+
}
|
|
311
329
|
headers.signature =
|
|
312
330
|
await this.#sign({ username, url, method, headers })
|
|
313
331
|
res = await fetch(url,
|