Skip to content

Commit

Permalink
ra/sa: Remove deprecated UpdateRegistration methods (#7911)
Browse files Browse the repository at this point in the history
This is the final stage of #5554: removing the old, combined
`UpdateRegistration` flow, which has been replaced by
`UpdateRegistrationContact` and `UpdateRegistrationKey`. Those new
functions have their own tests.

The RA's `UpdateRegistration` function no longer has any callers (as of
#7827's deployment), so it is safely deployable to remove it from the SA
too, and its request from gRPC.

Fixes #5554

---------

Co-authored-by: Jacob Hoffman-Andrews <[email protected]>
Co-authored-by: Aaron Gable <[email protected]>
  • Loading branch information
3 people authored Jan 14, 2025
1 parent 04dec59 commit 2e1f733
Show file tree
Hide file tree
Showing 10 changed files with 392 additions and 854 deletions.
578 changes: 247 additions & 331 deletions ra/proto/ra.pb.go

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions ra/proto/ra.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import "google/protobuf/empty.proto";

service RegistrationAuthority {
rpc NewRegistration(core.Registration) returns (core.Registration) {}
rpc UpdateRegistration(UpdateRegistrationRequest) returns (core.Registration) {}
rpc UpdateRegistrationContact(UpdateRegistrationContactRequest) returns (core.Registration) {}
rpc UpdateRegistrationKey(UpdateRegistrationKeyRequest) returns (core.Registration) {}
rpc PerformValidation(PerformValidationRequest) returns (core.Authorization) {}
Expand All @@ -30,11 +29,6 @@ message GenerateOCSPRequest {
string serial = 1;
}

message UpdateRegistrationRequest {
core.Registration base = 1;
core.Registration update = 2;
}

message UpdateRegistrationContactRequest {
int64 registrationID = 1;
repeated string contacts = 2;
Expand Down
38 changes: 0 additions & 38 deletions ra/proto/ra_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

118 changes: 0 additions & 118 deletions ra/ra.go
Original file line number Diff line number Diff line change
Expand Up @@ -1243,49 +1243,6 @@ func (ra *RegistrationAuthorityImpl) getSCTs(ctx context.Context, cert []byte, e
return scts, nil
}

// UpdateRegistration updates an existing Registration with new values. Caller
// is responsible for making sure that update.Key is only different from base.Key
// if it is being called from the WFE key change endpoint.
//
// Deprecated: Use UpdateRegistrationContact or UpdateRegistrationKey instead.
func (ra *RegistrationAuthorityImpl) UpdateRegistration(ctx context.Context, req *rapb.UpdateRegistrationRequest) (*corepb.Registration, error) {
// Error if the request is nil, there is no account key or IP address
if req.Base == nil || len(req.Base.Key) == 0 || req.Base.Id == 0 {
return nil, errIncompleteGRPCRequest
}

err := validateContactsPresent(req.Base.Contact, req.Base.ContactsPresent)
if err != nil {
return nil, err
}
err = validateContactsPresent(req.Update.Contact, req.Update.ContactsPresent)
if err != nil {
return nil, err
}
err = ra.validateContacts(req.Update.Contact)
if err != nil {
return nil, err
}

update, changed := mergeUpdate(req.Base, req.Update)
if !changed {
// If merging the update didn't actually change the base then our work is
// done, we can return before calling ra.SA.UpdateRegistration since there's
// nothing for the SA to do
return req.Base, nil
}

_, err = ra.SA.UpdateRegistration(ctx, update)
if err != nil {
// berrors.InternalServerError since the user-data was validated before being
// passed to the SA.
err = berrors.InternalServerError("Could not update registration: %s", err)
return nil, err
}

return update, nil
}

// UpdateRegistrationContact updates an existing Registration's contact.
// The updated contacts field may be empty.
func (ra *RegistrationAuthorityImpl) UpdateRegistrationContact(ctx context.Context, req *rapb.UpdateRegistrationContactRequest) (*corepb.Registration, error) {
Expand Down Expand Up @@ -1326,81 +1283,6 @@ func (ra *RegistrationAuthorityImpl) UpdateRegistrationKey(ctx context.Context,
return update, nil
}

func contactsEqual(a []string, b []string) bool {
if len(a) != len(b) {
return false
}

// If there is an existing contact slice and it has the same length as the
// new contact slice we need to look at each contact to determine if there
// is a change being made. Use `sort.Strings` here to ensure a consistent
// comparison
sort.Strings(a)
sort.Strings(b)
for i := range len(b) {
// If the contact's string representation differs at any index they aren't
// equal
if a[i] != b[i] {
return false
}
}

// They are equal!
return true
}

// MergeUpdate returns a new corepb.Registration with the majority of its fields
// copies from the base Registration, and a subset (Contact, Agreement, and Key)
// copied from the update Registration. It also returns a boolean indicating
// whether or not this operation resulted in a Registration which differs from
// the base.
func mergeUpdate(base *corepb.Registration, update *corepb.Registration) (*corepb.Registration, bool) {
var changed bool

// Start by copying all of the fields.
res := &corepb.Registration{
Id: base.Id,
Key: base.Key,
Contact: base.Contact,
ContactsPresent: base.ContactsPresent,
Agreement: base.Agreement,
CreatedAt: base.CreatedAt,
Status: base.Status,
}

// Note: we allow update.Contact to overwrite base.Contact even if the former
// is empty in order to allow users to remove the contact associated with
// a registration. If the update has ContactsPresent set to false, then we
// know it is not attempting to update the contacts field.
if update.ContactsPresent && !contactsEqual(base.Contact, update.Contact) {
res.Contact = update.Contact
res.ContactsPresent = update.ContactsPresent
changed = true
}

if len(update.Agreement) > 0 && update.Agreement != base.Agreement {
res.Agreement = update.Agreement
changed = true
}

if len(update.Key) > 0 {
if len(update.Key) != len(base.Key) {
res.Key = update.Key
changed = true
} else {
for i := range len(base.Key) {
if update.Key[i] != base.Key[i] {
res.Key = update.Key
changed = true
break
}
}
}
}

return res, changed
}

// recordValidation records an authorization validation event,
// it should only be used on v2 style authorizations.
func (ra *RegistrationAuthorityImpl) recordValidation(ctx context.Context, authID string, authExpires *time.Time, challenge *core.Challenge) error {
Expand Down
Loading

0 comments on commit 2e1f733

Please sign in to comment.