parent
25cc9e0bf1
commit
eefca034fc
|
@ -15,7 +15,7 @@ import type { Antenna } from '@/server/api/endpoints/i/import-antennas.js';
|
||||||
import type { DbQueue, DeliverQueue, EndedPollNotificationQueue, InboxQueue, ObjectStorageQueue, RelationshipQueue, SystemQueue, WebhookDeliverQueue } from './QueueModule.js';
|
import type { DbQueue, DeliverQueue, EndedPollNotificationQueue, InboxQueue, ObjectStorageQueue, RelationshipQueue, SystemQueue, WebhookDeliverQueue } from './QueueModule.js';
|
||||||
import type { DbJobData, DeliverJobData, RelationshipJobData, ThinUser } from '../queue/types.js';
|
import type { DbJobData, DeliverJobData, RelationshipJobData, ThinUser } from '../queue/types.js';
|
||||||
import type * as Bull from 'bullmq';
|
import type * as Bull from 'bullmq';
|
||||||
import type { ParsedSignature } from '@misskey-dev/node-http-message-signatures';
|
import { genRFC3230DigestHeader, type ParsedSignature } from '@misskey-dev/node-http-message-signatures';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class QueueService {
|
export class QueueService {
|
||||||
|
@ -81,6 +81,7 @@ export class QueueService {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
},
|
},
|
||||||
content: contentBody,
|
content: contentBody,
|
||||||
|
digest: await genRFC3230DigestHeader(contentBody, 'SHA-256'),
|
||||||
to,
|
to,
|
||||||
isSharedInbox,
|
isSharedInbox,
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,7 +28,7 @@ type PrivateKey = {
|
||||||
keyId: string;
|
keyId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function createSignedPost(args: { level: string; key: PrivateKey; url: string; body: string; additionalHeaders: Record<string, string> }) {
|
export async function createSignedPost(args: { level: string; key: PrivateKey; url: string; body: string; digest?: string, additionalHeaders: Record<string, string> }) {
|
||||||
const u = new URL(args.url);
|
const u = new URL(args.url);
|
||||||
const request: RequestLike = {
|
const request: RequestLike = {
|
||||||
url: u.href,
|
url: u.href,
|
||||||
|
@ -40,9 +40,9 @@ export async function createSignedPost(args: { level: string; key: PrivateKey; u
|
||||||
...args.additionalHeaders,
|
...args.additionalHeaders,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
c
|
||||||
// TODO: httpMessageSignaturesImplementationLevelによって新規格で通信をするようにする
|
// TODO: httpMessageSignaturesImplementationLevelによって新規格で通信をするようにする
|
||||||
const digestHeader = await genRFC3230DigestHeader(args.body, 'SHA-256');
|
const digestHeader = args.digest ?? await genRFC3230DigestHeader(args.body, 'SHA-256');
|
||||||
request.headers['Digest'] = digestHeader;
|
request.headers['Digest'] = digestHeader;
|
||||||
|
|
||||||
const result = await signAsDraftToRequest(request, args.key, ['(request-target)', 'date', 'host', 'digest']);
|
const result = await signAsDraftToRequest(request, args.key, ['(request-target)', 'date', 'host', 'digest']);
|
||||||
|
@ -105,7 +105,7 @@ export class ApRequestService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public async signedPost(user: { id: MiUser['id'] }, url: string, object: unknown, level: string): Promise<void> {
|
public async signedPost(user: { id: MiUser['id'] }, url: string, object: unknown, level: string, digest?: string): Promise<void> {
|
||||||
const body = typeof object === 'string' ? object : JSON.stringify(object);
|
const body = typeof object === 'string' ? object : JSON.stringify(object);
|
||||||
const key = await this.getPrivateKey(user.id, level);
|
const key = await this.getPrivateKey(user.id, level);
|
||||||
const req = await createSignedPost({
|
const req = await createSignedPost({
|
||||||
|
@ -116,6 +116,7 @@ export class ApRequestService {
|
||||||
additionalHeaders: {
|
additionalHeaders: {
|
||||||
'User-Agent': this.config.userAgent,
|
'User-Agent': this.config.userAgent,
|
||||||
},
|
},
|
||||||
|
digest,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.logger.debug('create signed post', {
|
this.logger.debug('create signed post', {
|
||||||
|
|
|
@ -76,7 +76,7 @@ export class DeliverProcessorService {
|
||||||
await this.fetchInstanceMetadataService.fetchInstanceMetadata(_server).then(() => {});
|
await this.fetchInstanceMetadataService.fetchInstanceMetadata(_server).then(() => {});
|
||||||
const server = await this.federatedInstanceService.fetch(host);
|
const server = await this.federatedInstanceService.fetch(host);
|
||||||
|
|
||||||
await this.apRequestService.signedPost(job.data.user, job.data.to, job.data.content, server.httpMessageSignaturesImplementationLevel);
|
await this.apRequestService.signedPost(job.data.user, job.data.to, job.data.content, server.httpMessageSignaturesImplementationLevel, job.data.digest);
|
||||||
|
|
||||||
// Update stats
|
// Update stats
|
||||||
if (server.isNotResponding) {
|
if (server.isNotResponding) {
|
||||||
|
|
|
@ -32,6 +32,8 @@ export type DeliverJobData = {
|
||||||
user: ThinUser;
|
user: ThinUser;
|
||||||
/** Activity */
|
/** Activity */
|
||||||
content: string;
|
content: string;
|
||||||
|
/** Digest header */
|
||||||
|
digest: string;
|
||||||
/** inbox URL to deliver */
|
/** inbox URL to deliver */
|
||||||
to: string;
|
to: string;
|
||||||
/** whether it is sharedInbox */
|
/** whether it is sharedInbox */
|
||||||
|
|
Loading…
Reference in New Issue