Skip to content
Snippets Groups Projects
Commit 111e5d56 authored by Akihiko Odaki's avatar Akihiko Odaki
Browse files

Make inbox signature verification compatible with Mastodon

parent a3cef6e9
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment