diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2018-04-02 00:37:41 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-04-02 00:37:41 +0900 |
| commit | d166dbd01e19b27143bee0b3d99eba4b820a9053 (patch) | |
| tree | 533665ad93d929139f15ea3c858e2b7cbeb5a69e /src/server/activitypub | |
| parent | Merge pull request #1357 from akihikodaki/publickey (diff) | |
| parent | Make inbox signature verification compatible with Mastodon (diff) | |
| download | sharkey-d166dbd01e19b27143bee0b3d99eba4b820a9053.tar.gz sharkey-d166dbd01e19b27143bee0b3d99eba4b820a9053.tar.bz2 sharkey-d166dbd01e19b27143bee0b3d99eba4b820a9053.zip | |
Merge pull request #1358 from akihikodaki/inbox
Make inbox signature verification compatible with Mastodon
Diffstat (limited to 'src/server/activitypub')
| -rw-r--r-- | src/server/activitypub/inbox.ts | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/server/activitypub/inbox.ts b/src/server/activitypub/inbox.ts index 9151297487..6d092e66bf 100644 --- a/src/server/activitypub/inbox.ts +++ b/src/server/activitypub/inbox.ts @@ -11,16 +11,32 @@ app.use(bodyParser.json()); app.post('/@:user/inbox', async (req, res) => { let parsed; + req.headers.authorization = 'Signature ' + req.headers.signature; + try { parsed = parseRequest(req); } catch (exception) { return res.sendStatus(401); } - const user = await User.findOne({ - host: { $ne: null }, - 'account.publicKey.id': parsed.keyId - }); + const keyIdLower = parsed.keyId.toLowerCase(); + let query; + + if (keyIdLower.startsWith('acct:')) { + const { username, host } = parseAcct(keyIdLower.slice('acct:'.length)); + if (host === null) { + return res.sendStatus(401); + } + + query = { usernameLower: username, hostLower: host }; + } else { + query = { + host: { $ne: null }, + 'account.publicKey.id': parsed.keyId + }; + } + + const user = await User.findOne(query); if (user === null) { return res.sendStatus(401); |