Fix RFC 1123 date format - use zero-padded day

The issue was that Java's DateTimeFormatter.RFC_1123_DATE_TIME produces
dates like 'Tue, 2 Dec 2025' (without zero-padded day) but Mastodon
requires strict RFC 1123 format with zero-padded day: 'Tue, 02 Dec 2025'.

This was causing HTTP Signature validation failures (401 Unauthorized)
because the Date header in the signed string didn't match the actual header.

Changes:
- Fixed date format in HttpSignatureValidator to use custom pattern
- Pattern: 'EEE, dd MMM yyyy HH:mm:ss GMT' with Locale.US
- Added date format test to verify correct output
- Added debug endpoint for key validation
- Explicitly set Host header in FederationService

This should fix the 401 errors when federating with Mastodon.
This commit is contained in:
Tim Zöller 2025-12-02 21:51:52 +01:00
parent cc8e309821
commit 9c745cf07d
3 changed files with 61 additions and 2 deletions

View file

@ -0,0 +1,31 @@
package org.operaton.fitpub.security;
import org.junit.jupiter.api.Test;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
public class DateFormatTest {
@Test
public void testRFC1123DateFormat() {
ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
// Old format (broken)
DateTimeFormatter oldFormatter = DateTimeFormatter.RFC_1123_DATE_TIME;
String oldDate = now.format(oldFormatter);
System.out.println("OLD RFC 1123 Date (broken): " + oldDate);
// New format (correct)
DateTimeFormatter newFormatter = DateTimeFormatter.ofPattern(
"EEE, dd MMM yyyy HH:mm:ss 'GMT'",
java.util.Locale.US
);
String newDate = now.format(newFormatter);
System.out.println("NEW RFC 1123 Date (correct): " + newDate);
// Mastodon expects format like: "Mon, 02 Dec 2024 20:48:33 GMT"
// Note the zero-padded day "02" not "2"
}
}