Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ra/sa: Remove deprecated UpdateRegistration methods #7911

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
588 changes: 252 additions & 336 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 @@ -1584,49 +1584,6 @@ func (ra *RegistrationAuthorityImpl) checkNewOrderLimits(ctx context.Context, na
return 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 @@ -1667,81 +1624,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
Loading