mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-11-21 21:45:11 +00:00
normalize re-fetch logic between InboxProcessorService and ActivityPubServerService
This commit is contained in:
parent
c0a5955e0a
commit
27b502fab5
3 changed files with 10 additions and 6 deletions
|
@ -176,10 +176,17 @@ export class ApDbResolverService implements OnApplicationShutdown {
|
||||||
*/
|
*/
|
||||||
@bindThis
|
@bindThis
|
||||||
public async refetchPublicKeyForApId(user: MiRemoteUser): Promise<MiUserPublickey | null> {
|
public async refetchPublicKeyForApId(user: MiRemoteUser): Promise<MiUserPublickey | null> {
|
||||||
this.apLoggerService.logger.info('Re-fetching public key for user', { userId: user.id });
|
this.apLoggerService.logger.debug('Re-fetching public key for user', { userId: user.id, uri: user.uri });
|
||||||
await this.apPersonService.updatePerson(user.uri);
|
await this.apPersonService.updatePerson(user.uri);
|
||||||
|
|
||||||
const key = await this.userPublickeysRepository.findOneBy({ userId: user.id });
|
const key = await this.userPublickeysRepository.findOneBy({ userId: user.id });
|
||||||
this.publicKeyByUserIdCache.set(user.id, key);
|
this.publicKeyByUserIdCache.set(user.id, key);
|
||||||
|
|
||||||
|
if (key) {
|
||||||
|
this.apLoggerService.logger.info('Re-fetched public key for user', { userId: user.id, uri: user.uri });
|
||||||
|
} else {
|
||||||
|
this.apLoggerService.logger.warn('Failed to re-fetch key for user', { userId: user.id, uri: user.uri });
|
||||||
|
}
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,6 +118,7 @@ export class InboxProcessorService implements OnApplicationShutdown {
|
||||||
// HTTP-Signatureの検証
|
// HTTP-Signatureの検証
|
||||||
let httpSignatureValidated = httpSignature.verifySignature(signature, authUser.key.keyPem);
|
let httpSignatureValidated = httpSignature.verifySignature(signature, authUser.key.keyPem);
|
||||||
|
|
||||||
|
// maybe they changed their key? refetch it
|
||||||
if (!httpSignatureValidated) {
|
if (!httpSignatureValidated) {
|
||||||
authUser.key = await this.apDbResolverService.refetchPublicKeyForApId(authUser.user);
|
authUser.key = await this.apDbResolverService.refetchPublicKeyForApId(authUser.user);
|
||||||
if (authUser.key != null) {
|
if (authUser.key != null) {
|
||||||
|
|
|
@ -205,15 +205,11 @@ export class ActivityPubServerService {
|
||||||
|
|
||||||
let httpSignatureValidated = httpSignature.verifySignature(signature, authUser.key.keyPem);
|
let httpSignatureValidated = httpSignature.verifySignature(signature, authUser.key.keyPem);
|
||||||
|
|
||||||
|
// maybe they changed their key? refetch it
|
||||||
if (!httpSignatureValidated) {
|
if (!httpSignatureValidated) {
|
||||||
this.authlogger.info(`${logPrefix} failed to validate signature, re-fetching the key for ${authUser.user.uri}`);
|
|
||||||
// maybe they changed their key? refetch it
|
|
||||||
authUser.key = await this.apDbResolverService.refetchPublicKeyForApId(authUser.user);
|
authUser.key = await this.apDbResolverService.refetchPublicKeyForApId(authUser.user);
|
||||||
|
|
||||||
if (authUser.key != null) {
|
if (authUser.key != null) {
|
||||||
httpSignatureValidated = httpSignature.verifySignature(signature, authUser.key.keyPem);
|
httpSignatureValidated = httpSignature.verifySignature(signature, authUser.key.keyPem);
|
||||||
} else {
|
|
||||||
this.authlogger.warn(`${logPrefix} failed to re-fetch key for ${authUser.user}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue