diff options
author | Chocobozzz <me@florianbigard.com> | 2022-05-06 15:11:54 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-05-06 15:13:59 +0200 |
commit | e08ec7a723724c247d9bbcdbf157da08d3ba31a7 (patch) | |
tree | bfa3fdc9b3a57a9ac40b8cf900f396c1ccde0215 /server/helpers/peertube-crypto.ts | |
parent | 822f50fa814e945d136b8bb5a7e14e3c84889d42 (diff) | |
download | PeerTube-e08ec7a723724c247d9bbcdbf157da08d3ba31a7.tar.gz PeerTube-e08ec7a723724c247d9bbcdbf157da08d3ba31a7.tar.zst PeerTube-e08ec7a723724c247d9bbcdbf157da08d3ba31a7.zip |
Handle HTTP signature draft 11
Diffstat (limited to 'server/helpers/peertube-crypto.ts')
-rw-r--r-- | server/helpers/peertube-crypto.ts | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts index b8f7c782a..1a7ee24a7 100644 --- a/server/helpers/peertube-crypto.ts +++ b/server/helpers/peertube-crypto.ts | |||
@@ -51,11 +51,18 @@ function isHTTPSignatureVerified (httpSignatureParsed: any, actor: MActor): bool | |||
51 | } | 51 | } |
52 | 52 | ||
53 | function parseHTTPSignature (req: Request, clockSkew?: number) { | 53 | function parseHTTPSignature (req: Request, clockSkew?: number) { |
54 | const headers = req.method === 'POST' | 54 | const requiredHeaders = req.method === 'POST' |
55 | ? HTTP_SIGNATURE.REQUIRED_HEADERS.POST | 55 | ? [ '(request-target)', 'host', 'digest' ] |
56 | : HTTP_SIGNATURE.REQUIRED_HEADERS.ALL | 56 | : [ '(request-target)', 'host' ] |
57 | 57 | ||
58 | return httpSignature.parse(req, { clockSkew, headers }) | 58 | const parsed = httpSignature.parse(req, { clockSkew, headers: requiredHeaders }) |
59 | |||
60 | const parsedHeaders = parsed.params.headers | ||
61 | if (!parsedHeaders.includes('date') && !parsedHeaders.includes('(created)')) { | ||
62 | throw new Error(`date or (created) must be included in signature`) | ||
63 | } | ||
64 | |||
65 | return parsed | ||
59 | } | 66 | } |
60 | 67 | ||
61 | // JSONLD | 68 | // JSONLD |