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

Add pemutil.UnbundleCertificate #352

Merged
merged 3 commits into from
Oct 26, 2023
Merged

Add pemutil.UnbundleCertificate #352

merged 3 commits into from
Oct 26, 2023

Conversation

areed
Copy link
Contributor

@areed areed commented Oct 25, 2023

Removes a certificate from a bundle.

Name of feature:

pemutil.UnbundleCertificate.

Pain or issue this feature alleviates:

BundleCertificate lets you create a new bundle with additional certificates but there was no way to remove certificates from a bundle.

Why is this important to the project (if not answered above):

Is there documentation on how to use this feature? If so, where?

In what environments or workflows is this feature supported?

In what environments or workflows is this feature explicitly NOT supported (if any)?

Supporting links/other PRs/issues:

💔Thank you!

Removes a certificate from a bundle.
pemutil/pem.go Outdated
Comment on lines 769 to 773
block, err := Serialize(cert)
if err != nil {
return nil, false, err
}
keep = append(keep, pem.EncodeToMemory(block)...)
Copy link
Contributor

Choose a reason for hiding this comment

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

Simplify these lines with:

Suggested change
block, err := Serialize(cert)
if err != nil {
return nil, false, err
}
keep = append(keep, pem.EncodeToMemory(block)...)
keep = append(keep, pem.EncodeToMemory(&pem.Block{
Type: "CERTIFICATE",
Bytes: cert.Raw,
})...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pemutil/pem.go Outdated
func UnbundleCertificate(bundlePEM []byte, certsPEM ...[]byte) ([]byte, bool, error) {
drop := make(map[[sha256.Size224]byte]bool, len(certsPEM))
for i := range certsPEM {
cert, err := ParseCertificate(certsPEM[i])
Copy link
Contributor

Choose a reason for hiding this comment

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

I can see using this function but having certsPEM[i] as a certificate bundle. If a read a bundle and want to remove one cert, I don't want to split the bundle in multiple certs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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


// UnbundleCertificate removes PEM-encoded certificates from a PEM-encoded
// certificate bundle.
func UnbundleCertificate(bundlePEM []byte, certsPEM ...[]byte) ([]byte, bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Optionally, return the original bundle if len(certsPEM) == 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@areed areed requested a review from maraino October 26, 2023 15:32
Copy link
Contributor

@maraino maraino left a comment

Choose a reason for hiding this comment

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

lgtm

@areed areed merged commit 3c54615 into master Oct 26, 2023
12 checks passed
@areed areed deleted the areed/remove-from-bundle branch October 26, 2023 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants