Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions grpc/pb-marshalling.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ var ErrInvalidParameters = CodedError(codes.InvalidArgument, "RPC parameter was
// This file defines functions to translate between the protobuf types and the
// code types.

func ProblemDetailsToPB(prob *probs.ProblemDetails) (*corepb.ProblemDetails, error) {
func ProblemDetailsToPB(prob *probs.ProblemDetails) *corepb.ProblemDetails {
if prob == nil {
// nil problemDetails is valid
return nil, nil
return nil
}
return &corepb.ProblemDetails{
ProblemType: string(prob.Type),
Detail: prob.Detail,
HttpStatus: int32(prob.HTTPStatus), //nolint: gosec // HTTP status codes are guaranteed to be small, no risk of overflow.
}, nil
}
}

func PBToProblemDetails(in *corepb.ProblemDetails) (*probs.ProblemDetails, error) {
Expand All @@ -59,12 +59,10 @@ func PBToProblemDetails(in *corepb.ProblemDetails) (*probs.ProblemDetails, error
}

func ChallengeToPB(challenge core.Challenge) (*corepb.Challenge, error) {
prob, err := ProblemDetailsToPB(challenge.Error)
if err != nil {
return nil, err
}
prob := ProblemDetailsToPB(challenge.Error)
recordAry := make([]*corepb.ValidationRecord, len(challenge.ValidationRecord))
for i, v := range challenge.ValidationRecord {
var err error
recordAry[i], err = ValidationRecordToPB(v)
if err != nil {
return nil, err
Expand Down Expand Up @@ -196,10 +194,7 @@ func ValidationResultToPB(records []core.ValidationRecord, prob *probs.ProblemDe
return nil, err
}
}
marshalledProb, err := ProblemDetailsToPB(prob)
if err != nil {
return nil, err
}
marshalledProb := ProblemDetailsToPB(prob)
return &vapb.ValidationResult{
Records: recordAry,
Problem: marshalledProb,
Expand Down Expand Up @@ -228,10 +223,7 @@ func pbToValidationResult(in *vapb.ValidationResult) ([]core.ValidationRecord, *
}

func CAAResultToPB(prob *probs.ProblemDetails, perspective, rir string) (*vapb.IsCAAValidResponse, error) {
marshalledProb, err := ProblemDetailsToPB(prob)
if err != nil {
return nil, err
}
marshalledProb := ProblemDetailsToPB(prob)
return &vapb.IsCAAValidResponse{
Problem: marshalledProb,
Perspective: perspective,
Expand Down
6 changes: 2 additions & 4 deletions grpc/pb-marshalling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ import (
const JWK1JSON = `{"kty":"RSA","n":"vuc785P8lBj3fUxyZchF_uZw6WtbxcorqgTyq-qapF5lrO1U82Tp93rpXlmctj6fyFHBVVB5aXnUHJ7LZeVPod7Wnfl8p5OyhlHQHC8BnzdzCqCMKmWZNX5DtETDId0qzU7dPzh0LP0idt5buU7L9QNaabChw3nnaL47iu_1Di5Wp264p2TwACeedv2hfRDjDlJmaQXuS8Rtv9GnRWyC9JBu7XmGvGDziumnJH7Hyzh3VNu-kSPQD3vuAFgMZS6uUzOztCkT0fpOalZI6hqxtWLvXUMj-crXrn-Maavz8qRhpAyp5kcYk3jiHGgQIi7QSK2JIdRJ8APyX9HlmTN5AQ","e":"AQAB"}`

func TestProblemDetails(t *testing.T) {
pb, err := ProblemDetailsToPB(nil)
test.AssertNotEquals(t, err, "problemDetailToPB failed")
pb := ProblemDetailsToPB(nil)
test.Assert(t, pb == nil, "Returned corepb.ProblemDetails is not nil")

prob := &probs.ProblemDetails{Type: probs.TLSProblem, Detail: "asd", HTTPStatus: 200}
pb, err = ProblemDetailsToPB(prob)
test.AssertNotError(t, err, "problemDetailToPB failed")
pb = ProblemDetailsToPB(prob)
test.Assert(t, pb != nil, "return corepb.ProblemDetails is nill")
test.AssertDeepEquals(t, pb.ProblemType, string(prob.Type))
test.AssertEquals(t, pb.Detail, prob.Detail)
Expand Down
15 changes: 3 additions & 12 deletions ra/ra.go
Original file line number Diff line number Diff line change
Expand Up @@ -903,19 +903,11 @@ func (ra *RegistrationAuthorityImpl) failOrder(
defer cancel()

// Convert the problem to a protobuf problem for the *corepb.Order field
pbProb, err := bgrpc.ProblemDetailsToPB(prob)
if err != nil {
ra.log.AuditErr("Converting order problem to PB", err, map[string]any{
"requester": order.RegistrationID,
"order": order.Id,
"prob": prob.String(),
})
return
}
pbProb := bgrpc.ProblemDetailsToPB(prob)

// Assign the protobuf problem to the field and save it via the SA
order.Error = pbProb
_, err = ra.SA.SetOrderError(ctx, &sapb.SetOrderErrorRequest{
_, err := ra.SA.SetOrderError(ctx, &sapb.SetOrderErrorRequest{
Id: order.Id,
Error: order.Error,
})
Expand Down Expand Up @@ -1559,8 +1551,7 @@ func (ra *RegistrationAuthorityImpl) PerformValidation(
},
)
if err != nil {
// ProblemDetailsToPB never returns an error.
prob, _ = bgrpc.ProblemDetailsToPB(probs.ServerInternal("Could not communicate with VA"))
prob = bgrpc.ProblemDetailsToPB(probs.ServerInternal("Could not communicate with VA"))
ra.log.Errf("Failed to communicate with VA: %s", err)
}

Expand Down
5 changes: 1 addition & 4 deletions sa/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,10 +733,7 @@ func populateAttemptedFields(am authzModel, challenge *corepb.Challenge) error {
am.ValidationError,
err)
}
challenge.Error, err = grpc.ProblemDetailsToPB(&prob)
if err != nil {
return err
}
challenge.Error = grpc.ProblemDetailsToPB(&prob)
} else {
// If the error is empty the challenge must be valid.
challenge.Status = string(core.StatusValid)
Expand Down
3 changes: 1 addition & 2 deletions sa/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ func TestAuthzModel(t *testing.T) {
validationErr := probs.Connection("weewoo")

authzPB.Challenges[0].Status = string(core.StatusInvalid)
authzPB.Challenges[0].Error, err = grpc.ProblemDetailsToPB(validationErr)
test.AssertNotError(t, err, "grpc.ProblemDetailsToPB failed")
authzPB.Challenges[0].Error = grpc.ProblemDetailsToPB(validationErr)
model, err = authzPBToModel(authzPB)
test.AssertNotError(t, err, "authzPBToModel failed")

Expand Down
2 changes: 1 addition & 1 deletion sa/sa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2158,7 +2158,7 @@ func TestFinalizeAuthorization2(t *testing.T) {
test.AssertEquals(t, dbVer.Challenges[0].Validated.AsTime(), attemptedAt)

authzID = createPendingAuthorization(t, sa, reg.Id, identifier.NewDNS("aaa"), fc.Now().Add(time.Hour))
prob, _ := bgrpc.ProblemDetailsToPB(probs.Connection("it went bad captain"))
prob := bgrpc.ProblemDetailsToPB(probs.Connection("it went bad captain"))

_, err = sa.FinalizeAuthorization2(context.Background(), &sapb.FinalizeAuthorizationRequest{
Id: authzID,
Expand Down
Loading