Resolve account by signature in inbox
This commit is contained in:
parent
ce7efc4dbb
commit
69763ac32b
7 changed files with 72 additions and 56 deletions
|
|
@ -1,10 +1,12 @@
|
|||
import follow from './follow';
|
||||
import performActivityPub from './perform-activitypub';
|
||||
import processInbox from './process-inbox';
|
||||
import reportGitHubFailure from './report-github-failure';
|
||||
|
||||
const handlers = {
|
||||
follow,
|
||||
performActivityPub,
|
||||
processInbox,
|
||||
reportGitHubFailure,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,5 +2,5 @@ import User from '../../models/user';
|
|||
import act from '../../remote/activitypub/act';
|
||||
|
||||
export default ({ data }, done) => User.findOne({ _id: data.actor })
|
||||
.then(actor => act(actor, data.outbox, data.distribute))
|
||||
.then(actor => act(actor, data.outbox, false))
|
||||
.then(() => done(), done);
|
||||
|
|
|
|||
38
src/processor/http/process-inbox.ts
Normal file
38
src/processor/http/process-inbox.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { verifySignature } from 'http-signature';
|
||||
import parseAcct from '../../acct/parse';
|
||||
import User, { IRemoteUser } from '../../models/user';
|
||||
import act from '../../remote/activitypub/act';
|
||||
import resolvePerson from '../../remote/activitypub/resolve-person';
|
||||
|
||||
export default ({ data }, done) => (async () => {
|
||||
const keyIdLower = data.signature.keyId.toLowerCase();
|
||||
let user;
|
||||
|
||||
if (keyIdLower.startsWith('acct:')) {
|
||||
const { username, host } = parseAcct(keyIdLower.slice('acct:'.length));
|
||||
if (host === null) {
|
||||
throw 'request was made by local user';
|
||||
}
|
||||
|
||||
user = await User.findOne({ usernameLower: username, hostLower: host }) as IRemoteUser;
|
||||
} else {
|
||||
user = await User.findOne({
|
||||
host: { $ne: null },
|
||||
'account.publicKey.id': data.signature.keyId
|
||||
}) as IRemoteUser;
|
||||
|
||||
if (user === null) {
|
||||
user = await resolvePerson(data.signature.keyId);
|
||||
}
|
||||
}
|
||||
|
||||
if (user === null) {
|
||||
throw 'failed to resolve user';
|
||||
}
|
||||
|
||||
if (!verifySignature(data.signature, user.account.publicKey.publicKeyPem)) {
|
||||
throw 'signature verification failed';
|
||||
}
|
||||
|
||||
await act(user, data.inbox, true);
|
||||
})().then(done, done);
|
||||
Loading…
Add table
Add a link
Reference in a new issue