import * as bcrypt from 'bcrypt'
import * as createTorrent from 'create-torrent'
-import { createHash, pseudoRandomBytes } from 'crypto'
+import { createHash, HexBase64Latin1Encoding, pseudoRandomBytes } from 'crypto'
import { isAbsolute, join } from 'path'
import * as pem from 'pem'
import { URL } from 'url'
return truncate(str, options)
}
-function sha256 (str: string) {
- return createHash('sha256').update(str).digest('hex')
+function sha256 (str: string, encoding: HexBase64Latin1Encoding = 'hex') {
+ return createHash('sha256').update(str).digest(encoding)
}
function promisify0<A> (func: (cb: (err: any, result: A) => void) => void): () => Promise<A> {
import { logger } from '../../../helpers/logger'
import { doRequest } from '../../../helpers/requests'
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
-import { buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils'
+import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils'
import { BROADCAST_CONCURRENCY, JOB_REQUEST_TIMEOUT } from '../../../initializers'
export type ActivitypubHttpBroadcastPayload = {
uri: '',
json: body,
httpSignature: httpSignatureOptions,
- timeout: JOB_REQUEST_TIMEOUT
+ timeout: JOB_REQUEST_TIMEOUT,
+ headers: buildGlobalHeaders(body)
}
const badUrls: string[] = []
import { logger } from '../../../helpers/logger'
import { doRequest } from '../../../helpers/requests'
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
-import { buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils'
+import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils'
import { JOB_REQUEST_TIMEOUT } from '../../../initializers'
export type ActivitypubHttpUnicastPayload = {
uri,
json: body,
httpSignature: httpSignatureOptions,
- timeout: JOB_REQUEST_TIMEOUT
+ timeout: JOB_REQUEST_TIMEOUT,
+ headers: buildGlobalHeaders(body)
}
try {
import { buildSignedActivity } from '../../../../helpers/activitypub'
import { getServerActor } from '../../../../helpers/utils'
import { ActorModel } from '../../../../models/activitypub/actor'
+import { sha256 } from '../../../../helpers/core-utils'
-async function computeBody (payload: { body: any, signatureActorId?: number }) {
+type Payload = { body: any, signatureActorId?: number }
+
+async function computeBody (payload: Payload) {
let body = payload.body
if (payload.signatureActorId) {
return body
}
-async function buildSignedRequestOptions (payload: { signatureActorId?: number }) {
+async function buildSignedRequestOptions (payload: Payload) {
let actor: ActorModel | null
if (payload.signatureActorId) {
actor = await ActorModel.load(payload.signatureActorId)
algorithm: 'rsa-sha256',
authorizationHeaderName: 'Signature',
keyId,
- key: actor.privateKey
+ key: actor.privateKey,
+ headers: [ 'date', 'host', 'digest', '(request-target)' ]
+ }
+}
+
+function buildGlobalHeaders (body: object) {
+ const digest = 'SHA-256=' + sha256(JSON.stringify(body), 'base64')
+
+ return {
+ 'Digest': digest
}
}
export {
+ buildGlobalHeaders,
computeBody,
buildSignedRequestOptions
}