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

Sc-8652: Handle Expired Certificates in Certman #972

Merged
merged 9 commits into from
Jan 6, 2023
Merged

Conversation

DanielSollis
Copy link
Contributor

Scope of changes

Updates the Certman reissuance loop to handle the case where the certificate has expired.

Type of change

  • bug fix
  • new feature
  • documentation
  • other (describe)

Acceptance criteria

Describe how reviewers can test this change to be sure that it works correctly. Add a checklist if possible

Author checklist

  • I have manually tested the change and/or added automation in the form of unit tests or integration tests
  • I have updated the dependencies list
  • I have recompiled and included new protocol buffers to reflect changes I made
  • I have added new test fixtures as needed to support added tests
  • Check this box if a reviewer can merge this pull request after approval (leave it unchecked if you want to do it yourself)
  • I have moved the associated Shortcut story to "Ready for Review"

Reviewer(s) checklist

  • Any new user-facing content that has been added for this PR has been QA'ed to ensure correct grammar, spelling, and understandability.

@DanielSollis DanielSollis requested a review from pdeziel December 29, 2022 02:29
Copy link
Collaborator

@pdeziel pdeziel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, I did have a few suggestions before merging but they should be fairly straightforward.

@@ -824,6 +835,10 @@ vaspsLoop:
}
}

func RetrieveCertID(identityCert *pb.Certificate) string {
return fmt.Sprintf("%X", identityCert.SerialNumber)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do like this helper, however I think we can make it a bit more useful by moving it to the models package (pkg/models/v1) so other packages can use it. Then, let's replace all instances where we are encoding the serial number with this helper method so that we can standardize that a bit more (basically just search the repo for fmt.Sprintf("%X).

Also since we're moving it to a different package can we change the name of the method to GetCertID or something along those lines to better match the naming conventions there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea!

continue vaspsLoop
}
cert.Status = models.CertificateState_EXPIRED
c.db.UpdateCert(cert)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to handle any errors returned by UpdateCert here, my first instinct is that we don't need to bail out of the loop or anything but I think we should at least log the error. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed! I hadn't notice UpdateCert returning an error, my bad!

s.updateVaspIdentityCert(charlieVASP, 6)
s.updateVaspIdentityCert(hotelVASP, 1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this test failing? I don't understand why this line is necessary now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, hotelVASP's cert is expired so it was triggering the <= 7 days before expiration case by default, but now since we have a <= 0 days before expiration case it was triggering that and throwing off the expected emails and causing the test to fail, so I added this line to update it's cert expiration.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes complete sense, thanks.

defer s.fixtures.LoadReferenceFixtures()
require := s.Require()

// setup the datastore to contain the modified charlieVASP
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// setup the datastore to contain the modified charlieVASP
// Setup the datastore to contain the modified hotelVASP

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!


cert, err = s.db.RetrieveCert(certID)
require.NoError(err)
require.Equal(cert.Status, models.CertificateState_EXPIRED)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So hotelVASP has an expired certificate by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, see the above comment.

Copy link
Collaborator

@pdeziel pdeziel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the changes, I had an additional suggestion to add a docstring but other than that feel free to merge when you're ready.

pkg/models/v1/models.go Outdated Show resolved Hide resolved
@DanielSollis DanielSollis merged commit 817bc8e into main Jan 6, 2023
@DanielSollis DanielSollis deleted the sc-8652 branch January 6, 2023 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants