From 55a31ad052a542536fc702e8748685a9e47e053c Mon Sep 17 00:00:00 2001 From: dm Date: Mon, 7 Oct 2024 15:15:03 +0200 Subject: [PATCH] Fixes #846 (#847) * Fix #846 Signed-off-by: Alexis * Fix linter Signed-off-by: Alexis --------- Signed-off-by: Alexis --- pkg/api/timestamp.go | 14 +++++++++----- pkg/tests/api_test.go | 3 +++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/api/timestamp.go b/pkg/api/timestamp.go index b17a538f..2dc911f4 100644 --- a/pkg/api/timestamp.go +++ b/pkg/api/timestamp.go @@ -162,11 +162,15 @@ func TimestampResponseHandler(params ts.GetTimestampResponseParams) middleware.R tsStruct := timestamp.Timestamp{ HashAlgorithm: req.HashAlgorithm, HashedMessage: req.HashedMessage, - Time: time.Now(), - Nonce: req.Nonce, - Policy: policyID, - Ordering: false, - Accuracy: duration, + // The field here is going to be serialized as a GeneralizedTime, and RFC5280 + // states that the GeneralizedTime values MUST be expressed in Greenwich Mean Time. + // However, go asn1/marshal will happily accept other formats. So we force it directly here. + // https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.5.2 + Time: time.Now().UTC(), + Nonce: req.Nonce, + Policy: policyID, + Ordering: false, + Accuracy: duration, // Not qualified for the european directive Qualified: false, AddTSACertificate: req.Certificates, diff --git a/pkg/tests/api_test.go b/pkg/tests/api_test.go index 758f173a..0de40e12 100644 --- a/pkg/tests/api_test.go +++ b/pkg/tests/api_test.go @@ -166,6 +166,9 @@ func TestGetTimestampResponse(t *testing.T) { if tsr.Time.After(time.Now()) { t.Fatalf("test '%s': expected time to be set to a previous time", tc.name) } + if tsr.Time.Location() != time.UTC { + t.Fatalf("test '%s': expected time to be in UTC, got %v", tc.name, tsr.Time.Location()) + } duration, _ := time.ParseDuration("1s") if tsr.Accuracy != duration { t.Fatalf("test '%s': expected 1s accuracy, got %v", tc.name, tsr.Accuracy)