From da31b67d31083b4e54665a0f7e00dbe5ed362ab5 Mon Sep 17 00:00:00 2001 From: Phil Porada Date: Thu, 26 Oct 2023 13:54:48 -0400 Subject: [PATCH 1/2] grpc: Read timestamps from timestamppb fields instead of int64 fields --- grpc/pb-marshalling.go | 24 ++++++++++++------------ grpc/pb-marshalling_test.go | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/grpc/pb-marshalling.go b/grpc/pb-marshalling.go index 8b9014a912d..f9689ea970c 100644 --- a/grpc/pb-marshalling.go +++ b/grpc/pb-marshalling.go @@ -116,8 +116,8 @@ func PBToChallenge(in *corepb.Challenge) (challenge core.Challenge, err error) { return core.Challenge{}, err } var validated *time.Time - if in.ValidatedNS != 0 { - val := time.Unix(0, in.ValidatedNS).UTC() + if !in.Validated.AsTime().IsZero() { + val := in.Validated.AsTime() validated = &val } ch := core.Challenge{ @@ -275,8 +275,8 @@ func PbToRegistration(pb *corepb.Registration) (core.Registration, error) { return core.Registration{}, err } var createdAt *time.Time - if pb.CreatedAtNS != 0 { - c := time.Unix(0, pb.CreatedAtNS).UTC() + if !pb.CreatedAt.AsTime().IsZero() { + c := pb.CreatedAt.AsTime() createdAt = &c } var contacts *[]string @@ -344,8 +344,8 @@ func PBToAuthz(pb *corepb.Authorization) (core.Authorization, error) { challs[i] = chall } var expires *time.Time - if pb.ExpiresNS != 0 { - c := time.Unix(0, pb.ExpiresNS).UTC() + if !pb.Expires.AsTime().IsZero() { + c := pb.Expires.AsTime() expires = &c } authz := core.Authorization{ @@ -396,8 +396,8 @@ func PBToCert(pb *corepb.Certificate) core.Certificate { Serial: pb.Serial, Digest: pb.Digest, DER: pb.Der, - Issued: time.Unix(0, pb.IssuedNS), - Expires: time.Unix(0, pb.ExpiresNS), + Issued: pb.Issued.AsTime(), + Expires: pb.Expires.AsTime(), } } @@ -423,11 +423,11 @@ func PBToCertStatus(pb *corepb.CertificateStatus) core.CertificateStatus { return core.CertificateStatus{ Serial: pb.Serial, Status: core.OCSPStatus(pb.Status), - OCSPLastUpdated: time.Unix(0, pb.OcspLastUpdatedNS), - RevokedDate: time.Unix(0, pb.RevokedDateNS), + OCSPLastUpdated: pb.OcspLastUpdated.AsTime(), + RevokedDate: pb.RevokedDate.AsTime(), RevokedReason: revocation.Reason(pb.RevokedReason), - LastExpirationNagSent: time.Unix(0, pb.LastExpirationNagSentNS), - NotAfter: time.Unix(0, pb.NotAfterNS), + LastExpirationNagSent: pb.LastExpirationNagSent.AsTime(), + NotAfter: pb.NotAfter.AsTime(), IsExpired: pb.IsExpired, IssuerNameID: pb.IssuerID, } diff --git a/grpc/pb-marshalling_test.go b/grpc/pb-marshalling_test.go index 3fcd791307a..863510850cb 100644 --- a/grpc/pb-marshalling_test.go +++ b/grpc/pb-marshalling_test.go @@ -267,7 +267,7 @@ func TestAuthz(t *testing.T) { } func TestCert(t *testing.T) { - now := time.Now().Round(0) + now := time.Now().Round(0).UTC() cert := core.Certificate{ RegistrationID: 1, Serial: "serial", From e83a58e0290488e22821b9587f659147191d9736 Mon Sep 17 00:00:00 2001 From: Phil Porada Date: Fri, 27 Oct 2023 12:00:12 -0400 Subject: [PATCH 2/2] Add non-nil checks --- grpc/pb-marshalling.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grpc/pb-marshalling.go b/grpc/pb-marshalling.go index f9689ea970c..32fa9f4a743 100644 --- a/grpc/pb-marshalling.go +++ b/grpc/pb-marshalling.go @@ -116,7 +116,7 @@ func PBToChallenge(in *corepb.Challenge) (challenge core.Challenge, err error) { return core.Challenge{}, err } var validated *time.Time - if !in.Validated.AsTime().IsZero() { + if in.Validated != nil && !in.Validated.AsTime().IsZero() { val := in.Validated.AsTime() validated = &val } @@ -275,7 +275,7 @@ func PbToRegistration(pb *corepb.Registration) (core.Registration, error) { return core.Registration{}, err } var createdAt *time.Time - if !pb.CreatedAt.AsTime().IsZero() { + if pb.CreatedAt != nil && !pb.CreatedAt.AsTime().IsZero() { c := pb.CreatedAt.AsTime() createdAt = &c } @@ -344,7 +344,7 @@ func PBToAuthz(pb *corepb.Authorization) (core.Authorization, error) { challs[i] = chall } var expires *time.Time - if !pb.Expires.AsTime().IsZero() { + if pb.Expires != nil && !pb.Expires.AsTime().IsZero() { c := pb.Expires.AsTime() expires = &c }