Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Cert expired checker #4

Open
wants to merge 3 commits into
base: volt-certificate-provider
Choose a base branch
from

Conversation

orbitalturtle
Copy link

Pull Request Checklist

  • If this is your first time contributing, we recommend you read the Code
    Contribution Guidelines
  • All changes are Go version 1.12 compliant
  • The code being submitted is commented according to Code Documentation and Commenting
  • For new code: Code is accompanied by tests which exercise both
    the positive and negative (error paths) conditions (if applicable)
  • For bug fixes: Code is accompanied by new tests which trigger
    the bug being fixed to prevent regressions
  • Any new logging statements use an appropriate subsystem and
    logging level
  • Code has been formatted with go fmt
  • Protobuf files (lnrpc/**/*.proto) have been formatted with
    make rpc-format and compiled with make rpc
  • New configuration flags have been added to sample-lnd.conf
  • For code and documentation: lines are wrapped at 80 characters
    (the tab character should be counted as 8 characters, not 4, as some IDEs do
    per default)
  • Running make check does not fail any tests
  • Running go vet does not report any issues
  • Running make lint does not report any new issues that did not
    already exist
  • All commits build properly and pass tests. Only in exceptional
    cases it can be justifiable to violate this condition. In that case, the
    reason should be stated in the commit message.
  • Commits have a logical structure according to Ideal Git Commit Structure

Copy link
Member

@gkrizek gkrizek left a comment

Choose a reason for hiding this comment

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

@orbitalturtle This looks awesome and I love how you reformatted the ZeroSSL service. Few comments for the initial review. I can start testing once we straighten those out.

Also looks like it could use a make fmt

lnd.go Outdated
func CheckForExpiredCert(certprovider certprovider.CertProvider, certId string) bool {
cert, err := certprovider.GetCert(certId)
if err != nil {
fmt.Errorf("error retrieving ZeroSSL certificate: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need a return here? Maybe if there's an error return false

lnd.go Outdated

// CheckForExpiredCert finds whether the TLS certificate is expiring soon.
func CheckForExpiredCert(certprovider certprovider.CertProvider, certId string) bool {
cert, err := certprovider.GetCert(certId)
Copy link
Member

Choose a reason for hiding this comment

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

Interesting choice calling to ZeroSSL to check the expiration date. I actually didn't even think about that. My approach would have been to read the tls.cert from disk and check it's expiration date from that. What's your opinion on one versus the other? I think I'm slightly worried that this could get out of step with what the API returns and what the certificate actually is. That might be a super rare case, but could be a crazy happening nonetheless.

Copy link
Author

Choose a reason for hiding this comment

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

Ohh that's a good point. Let's read from disk to be safe. Also just in terms of the API potentially going down sometimes and whatnot

lnd.go Outdated
keyBytes, err = lnencrypt.DecryptPayloadFromReader(reader, activeChainControl.KeyRing)
if err != nil {
ltndLog.Error(err)
// return err
Copy link
Member

Choose a reason for hiding this comment

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

I see you commented out the error, should we return errors from this function?

lnd.go Outdated
if err != nil {
ltndLog.Error("Failed to revoke temporary certifiate:")
ltndLog.Error(err)
}
// Switch the server's TLS certificate to the persisntent one
// Switch the server's TLS certificate to the persistent one
err = tlsReloader.AttemptReload(certBytes, keyBytes)
Copy link
Member

Choose a reason for hiding this comment

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

Should this bit of code be replaced by the new DeleteAndRegenerateCert function? I'm not exactly sure but looks like maybe it can?

@orbitalturtle
Copy link
Author

@gkrizek Thanks for the review! I'll fix those things up.

Are you able to give me an example output of the full JSON that the download endpoint gives (https://zerossl.com/documentation/api/download-certificate-inline/)? That'll actually help with one of these changes

@gkrizek
Copy link
Member

gkrizek commented Apr 5, 2021

Sorry! Forgot about this part. Here's an example response:

{
    "certificate.crt": "-----BEGIN CERTIFICATE-----\nMIIGjzCCBHegAwIBAgIRAK8ncTZjqzI7SXhMESi0i5AwDQYJKoZIhvcNAQEMBQAw\nSzELMAkGA1UEBhMCQVQxEDAOBgNVBAoTB1plcm9TU0wxKjAoBgNVBAMTIVplcm9T\nU0wgUlNBIERvbWFpbiBTZWN1cmUgU2l0ZSBDQTAeFw0yMTA0MDQwMDAwMDBaFw0y\nMTA3MDMyMzU5NTlaMCsxKTAnBgNVBAMTIHRvZGVsZXRlLm0uc3RhZ2luZy52b2x0\nY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jeiV9lRdAM9fSJvsB3svUuu1coIG1xxI1yegoGM4r5QP4\nRGIVvYaiI76C0djoSbQ/dkIUUXQuB8AL5jyH34g3BZaaXyvpmnV4ilppMXVAnAYG\nON51WhJ6W0xNdNJwzYASZYH+tmCWI+N60Gv2NNMGHwMZ7e9bXgzUCZH5FaBFDGR5\nS9VWqHB73Q+OyIVvIbKYcSc2w/aSuFKGSA==\n-----END CERTIFICATE-----\n"
}

@orbitalturtle
Copy link
Author

@gkrizek Here's a refreshed version! I believe most of the new code is test-related

@gkrizek
Copy link
Member

gkrizek commented Apr 8, 2021

Looking over it again I think this look good. I'll test this soon too. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants