-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new tool to support copying/filtering certs
CHANGES The new `cpcert` prototype tool supports copying certificate chains from a server or input file and optionally filtering to specific certificate types before saving to an output file (PEM format). Config validation logic has been refactored to help the new tool fit within the project without duplicating existing work. Overall, this is a "MVP" build and while usable, it should be considered to be of "alpha" level quality. Please report issues that you encounter. Many of the exposed flags, help text and summary output are subject to change significantly in later releases. Feedback on the new `cpcert` tool is welcome: - #963 REFERENCES - refs GH-171 - refs GH-956
- Loading branch information
Showing
20 changed files
with
1,411 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2020 Adam Chalkley | ||
// | ||
// https://github.com/atc0005/check-cert | ||
// | ||
// Licensed under the MIT License. See LICENSE file in the project root for | ||
// full license information. | ||
|
||
// CLI app used to copy and manipulate certificates. | ||
// | ||
// See our [GitHub repo]: | ||
// | ||
// - to review documentation (including examples) | ||
// - for the latest code | ||
// - to file an issue or submit improvements for review and potential | ||
// inclusion into the project | ||
// | ||
// [GitHub repo]: https://github.com/atc0005/check-cert | ||
package main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2024 Adam Chalkley | ||
// | ||
// https://github.com/atc0005/check-cert | ||
// | ||
// Licensed under the MIT License. See LICENSE file in the project root for | ||
// full license information. | ||
|
||
package main | ||
|
||
import ( | ||
"crypto/x509" | ||
|
||
"github.com/atc0005/check-cert/internal/certs" | ||
"github.com/atc0005/check-cert/internal/config" | ||
"github.com/atc0005/check-cert/internal/textutils" | ||
) | ||
|
||
// filterCertChain filters the given certificate chain to the specified list | ||
// of certificate types. | ||
func filterCertChain(filterKeywords []string, certChain []*x509.Certificate) []*x509.Certificate { | ||
filteredCertChain := make([]*x509.Certificate, 0, len(certChain)) | ||
|
||
// Validation prevents other keywords from being specified alongside this | ||
// one. | ||
if textutils.InList(config.CertTypeAll, filterKeywords, true) { | ||
filteredCertChain = append(filteredCertChain, certChain...) | ||
} | ||
|
||
if textutils.InList(config.CertTypeLeaf, filterKeywords, true) { | ||
for _, cert := range certChain { | ||
if certs.IsLeafCert(cert, certChain) { | ||
filteredCertChain = append(filteredCertChain, cert) | ||
} | ||
} | ||
} | ||
|
||
if textutils.InList(config.CertTypeIntermediate, filterKeywords, true) { | ||
for _, cert := range certChain { | ||
if certs.IsIntermediateCert(cert, certChain) { | ||
filteredCertChain = append(filteredCertChain, cert) | ||
} | ||
} | ||
} | ||
|
||
if textutils.InList(config.CertTypeRoot, filterKeywords, true) { | ||
for _, cert := range certChain { | ||
if certs.IsRootCert(cert, certChain) { | ||
filteredCertChain = append(filteredCertChain, cert) | ||
} | ||
} | ||
} | ||
|
||
return filteredCertChain | ||
} |
Oops, something went wrong.