upd: refetch user keys on signature failure

Reference: https://github.com/misskey-dev/misskey/pull/12051
This commit is contained in:
Mar0xy 2023-10-20 12:50:56 +02:00
parent 4dda43d276
commit 71b7c31958
No known key found for this signature in database
GPG key ID: 56569BBE47D2C828
2 changed files with 28 additions and 3 deletions

View file

@ -104,12 +104,24 @@ export class InboxProcessorService {
}
// HTTP-Signatureの検証
const httpSignatureValidated = httpSignature.verifySignature(signature, authUser.key.keyPem);
let httpSignatureValidated = httpSignature.verifySignature(signature, authUser.key.keyPem);
// また、signatureのsignerは、activity.actorと一致する必要がある
if (!httpSignatureValidated || authUser.user.uri !== activity.actor) {
let renewKeyFailed = false;
if (!httpSignatureValidated) {
authUser.key = await this.apDbResolverService.refetchPublicKeyForApId(authUser.user);
if (authUser.key != null) {
httpSignatureValidated = httpSignature.verifySignature(signature, authUser.key.keyPem);
} else {
renewKeyFailed = true;
}
}
// 一致しなくても、でもLD-Signatureがありそうならそっちも見る
if (activity.signature) {
if (activity.signature && renewKeyFailed) {
if (activity.signature.type !== 'RsaSignature2017') {
throw new Bull.UnrecoverableError(`skip: unsupported LD-signature type ${activity.signature.type}`);
}