Add support for latest HTTP Signatures spec draft (#14556)
Add support for latest HTTP Signatures spec draft (#14556)

* Add support for latest HTTP Signatures spec draft

https://www.ietf.org/id/draft-ietf-httpbis-message-signatures-00.html

- add support for the “hs2019” signature algorithm (assumed to be equivalent
  to RSA-SHA256, since we do not have a mechanism to specify the algorithm
  within the key metadata yet)
- add support for (created) and (expires) pseudo-headers and related
  signature parameters, when using the hs2019 signature algorithm
- adjust default “headers” parameter while being backwards-compatible with
  previous implementation
- change the acceptable time window logic from 12 hours surrounding the “date”
  header to accepting signatures created up to 1 hour in the future and
  expiring up to 1 hour in the past (but only allowing expiration dates up to
  12 hours after the creation date)
  This doesn't conform with the current draft, as it doesn't permit accounting
  for clock skew.
  This, however, should be addressed in a next version of the draft:
  https://github.com/httpwg/http-extensions/pull/1235

* Add additional signature requirements

* Rewrite signature params parsing using Parslet

* Make apparent which signature algorithm Mastodon on verification failure

Mastodon uses RSASSA-PKCS1-v1_5, which is not recommended for new applications,
and new implementers may thus unknowingly use RSASSA-PSS.

* Add workaround for PeerTube's invalid signature header

The previous parser allowed incorrect Signature headers, such as
those produced by old versions of the `http-signature` node.js package,
and seemingly used by PeerTube.

This commit adds a workaround for that.

* Fix `signature_key_id` raising an exception

Previously, parsing failures would result in `signature_key_id` being nil,
but the parser changes made that result in an exception.

This commit changes the `signature_key_id` method to return `nil` in case
of parsing failures.

* Move extra HTTP signature helper methods to private methods

* Relax (request-target) requirement to (request-target) || digest

This lets requests from Plume work without lowering security significantly.
ikuradon/mastodon,ikuradon/mastodon,yukimochi/mastodon,tootsuite/mastodon,Nyoho/mastodon,tootcafe/mastodon,cobodo/mastodon,pinfort/mastodon,yukimochi/mastodon,imas/mastodon,ykzts/mastodon,gol-cha/mastodon,maa123/mastodon,imas/mastodon,yukimochi/mastodon,danhunsaker/mastodon,koba-lab/mastodon,tootcafe/mastodon,Nyoho/mastodon,pinfort/mastodon,lynlynlynx/mastodon,yi0713/mastodon,koba-lab/mastodon,yukimochi/mastodon,imas/mastodon,primenumber/mastodon,abcang/mastodon,im-in-space/mastodon,Kirishima21/mastodon,masto-donte-com-br/mastodon,koba-lab/mastodon,koba-lab/mastodon,im-in-space/mastodon,danhunsaker/mastodon,musashino205/mastodon,h3zjp/mastodon,primenumber/mastodon,gol-cha/mastodon,glitch-soc/mastodon,tootsuite/mastodon,theoria24/mastodon,yi0713/mastodon,ykzts/mastodon,Kirishima21/mastodon,MitarashiDango/mastodon,imas/mastodon,ikuradon/mastodon,MitarashiDango/mastodon,Nyoho/mastodon,lynlynlynx/mastodon,masto-donte-com-br/mastodon,danhunsaker/mastodon,theoria24/mastodon,h3zjp/mastodon,theoria24/mastodon,danhunsaker/mastodon,Kirishima21/mastodon,lindwurm/mastodon,pinfort/mastodon,lindwurm/mastodon,gol-cha/mastodon,tri-star/mastodon,primenumber/mastodon,masto-donte-com-br/mastodon,glitch-soc/mastodon,MitarashiDango/mastodon,im-in-space/mastodon,lynlynlynx/mastodon,Ryanaka/mastodon,im-in-space/mastodon,glitch-soc/mastodon,maa123/mastodon,ykzts/mastodon,ykzts/mastodon,lindwurm/mastodon,h3zjp/mastodon,ikuradon/mastodon,abcang/mastodon,Ryanaka/mastodon,abcang/mastodon,masto-donte-com-br/mastodon,Ryanaka/mastodon,tri-star/mastodon,tootcafe/mastodon,musashino205/mastodon,tri-star/mastodon,cobodo/mastodon,glitch-soc/mastodon,lindwurm/mastodon,yi0713/mastodon,lynlynlynx/mastodon,pinfort/mastodon,tootcafe/mastodon,tootsuite/mastodon,abcang/mastodon,gol-cha/mastodon,cobodo/mastodon,tri-star/mastodon,cobodo/mastodon,maa123/mastodon,musashino205/mastodon,Nyoho/mastodon,theoria24/mastodon,Kirishima21/mastodon,h3zjp/mastodon,maa123/mastodon,Ryanaka/mastodon,musashino205/mastodon,yi0713/mastodon,tootsuite/mastodon,primenumber/mastodon,MitarashiDango/mastodon