Edent,
@Edent@mastodon.social avatar

🆕 blog! “I made a mistake in verifying HTTP Message Signatures”

It's never great to find out you're wrong, but that's how learning and personal growth happens. HTTP Message Signatures are hard1. There are lots of complex parts and getting any aspect wrong means certain death2. In a previous post, I wrote A simple(ish) guide to verifying …

👀 Read more: https://shkspr.mobi/blog/2024/03/i-made-a-mistake-in-verifying-http-message-signatures/

#ActivityPub #CyberSecurity #http #security

Edent,
@Edent@mastodon.social avatar

Part of the problem with verifying HTTP Message Signatures is that you kinda have to wait for a duff one to come along before you know whether your code works.

(Yes, I'm aware I could build a test-suite, but it's much more fun to telnet into prod and YOLO.)

Edent, (edited )
@Edent@mastodon.social avatar

Aha! I now have a number of failed HTTP Message Signatures from #ActivityPub servers.

The most common cause seems to be Date failures. The message was created with over 30 seconds of difference to when it was signed.

For example

Signature: 2024-03-17 19:46:07  
Published: 2024-03-17 19:44:45  

I don't know if 30 seconds is too stringent. Mastodon uses one hour https://github.com/mastodon/mastodon/blob/82c2af0356ff888e9665b5b08fda58c7722be637/app/controllers/concerns/signature_verification.rb#L183

Should I reply with a specific HTTP code?

julian,
@julian@fietkau.social avatar

@Edent Wait, you're comparing the Date header to the activity's "published" property? Is that recommended? I don't think there are restrictions on that duration, I've received hours old messages from congested servers.

What I compare (and what I believe Mastodon compares) is the difference between the signed message's Date header and my own server's time. The goal is to ensure the signature itself is current. There's less room for valid time differences there.

Edent,
@Edent@mastodon.social avatar

@julian
7.2.4 of https://datatracker.ietf.org/doc/rfc9421/ says:

> An application could also put limits on how much skew there is between the Date field and the created signature parameter, in order to limit the application of a generated signature to different HTTP messages.

julian,
@julian@fietkau.social avatar

@Edent Okay, but Mastodon's signatures don't have a "created" signature parameter, right? I don't remember ever seeing one. Is this one of those things where Mastodon's signatures differ from the RFC?

Looking at your code now, I see you're checking both differences: between signature date and current local time, as well as between signature date and "published" property. I think the latter will keep causing problems. Multi-hour differences are not especially rare in my experience.

Edent,
@Edent@mastodon.social avatar

@julian
Ah, I see what you mean. I read that as date it was created, rather than an explicit header.
I'm not sure why a server would sign a message hours after publishing it though?

django,
@django@social.coop avatar

@Edent not sure when those logs are from, but daylight savings changes can create some larger skews!

Edent,
@Edent@mastodon.social avatar

@django
Not really. All the times are in a standardised format (GMT / Zulu) and are then converted to Epoch seconds for comparison.
Biggest drift I've seen is in the order a of a couple of minutes - nothing DST related that I've seen.

mikedev,

First time I had a communication failure because of inaccurate timestamps was 1987. And thousands of times over the years. It became an epidemic around 2005 because of the rise of VMs. They have emulated hardware clocks in software and when they're loaded, they lose ticks. There have always been issues with Linux because they can't always decide if the hardware clock is GMT or localtime. You can be a stickler about it if you want, it's your legitimate communications you're dropping from people who have no idea there's a problem and many won't know what to do about if they did.

Edent,
@Edent@mastodon.social avatar

@mikedev if a site can't run a clock correctly in the age of NTP, I'm not sure I trust it to do anything else of minor complexity.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • fediverse
  • DreamBathrooms
  • mdbf
  • ethstaker
  • magazineikmin
  • cubers
  • rosin
  • thenastyranch
  • Youngstown
  • osvaldo12
  • slotface
  • khanakhh
  • kavyap
  • InstantRegret
  • Durango
  • JUstTest
  • everett
  • tacticalgear
  • modclub
  • anitta
  • cisconetworking
  • tester
  • ngwrru68w68
  • GTA5RPClips
  • normalnudes
  • megavids
  • Leos
  • provamag3
  • lostlight
  • All magazines