Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b1a2039c7d | |||
| 46c9976e73 | |||
| 5a5dd5e6ea | |||
| 3317b8c33b |
@@ -1,5 +1,11 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
|
|
||||||
|
v1.15.6 - 2025-11-19
|
||||||
|
certlib: add FileKind function to determine file type.
|
||||||
|
|
||||||
|
v1.15.5 - 2025-11-19
|
||||||
|
certlib/bundler: add support for crt files that are pem-encoded.
|
||||||
|
|
||||||
v1.15.4 - 2025-11-19
|
v1.15.4 - 2025-11-19
|
||||||
Quality of life fixes for CSR generation.
|
Quality of life fixes for CSR generation.
|
||||||
|
|
||||||
|
|||||||
@@ -422,6 +422,24 @@ func encodeCertsToFiles(
|
|||||||
name: baseName + ".pem",
|
name: baseName + ".pem",
|
||||||
content: pemContent,
|
content: pemContent,
|
||||||
})
|
})
|
||||||
|
case "crt":
|
||||||
|
pemContent := encodeCertsToPEM(certs)
|
||||||
|
files = append(files, fileEntry{
|
||||||
|
name: baseName + ".crt",
|
||||||
|
content: pemContent,
|
||||||
|
})
|
||||||
|
case "pemcrt":
|
||||||
|
pemContent := encodeCertsToPEM(certs)
|
||||||
|
files = append(files, fileEntry{
|
||||||
|
name: baseName + ".pem",
|
||||||
|
content: pemContent,
|
||||||
|
})
|
||||||
|
|
||||||
|
pemContent = encodeCertsToPEM(certs)
|
||||||
|
files = append(files, fileEntry{
|
||||||
|
name: baseName + ".crt",
|
||||||
|
content: pemContent,
|
||||||
|
})
|
||||||
case "der":
|
case "der":
|
||||||
if isSingle {
|
if isSingle {
|
||||||
// For single file in DER, concatenate all cert DER bytes
|
// For single file in DER, concatenate all cert DER bytes
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.wntrmute.dev/kyle/goutils/certlib/certerr"
|
"git.wntrmute.dev/kyle/goutils/certlib/certerr"
|
||||||
)
|
)
|
||||||
@@ -135,3 +136,75 @@ func LoadCSR(path string) (*x509.CertificateRequest, error) {
|
|||||||
func ExportCSRAsPEM(req *x509.CertificateRequest) []byte {
|
func ExportCSRAsPEM(req *x509.CertificateRequest) []byte {
|
||||||
return pem.EncodeToMemory(&pem.Block{Type: pemTypeCertificateRequest, Bytes: req.Raw})
|
return pem.EncodeToMemory(&pem.Block{Type: pemTypeCertificateRequest, Bytes: req.Raw})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FileFormat uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
FormatPEM FileFormat = iota + 1
|
||||||
|
FormatDER
|
||||||
|
)
|
||||||
|
|
||||||
|
func (f FileFormat) String() string {
|
||||||
|
switch f {
|
||||||
|
case FormatPEM:
|
||||||
|
return "PEM"
|
||||||
|
case FormatDER:
|
||||||
|
return "DER"
|
||||||
|
default:
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type FileType struct {
|
||||||
|
Format FileFormat
|
||||||
|
Type string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ft FileType) String() string {
|
||||||
|
if ft.Type == "" {
|
||||||
|
return ft.Format.String()
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s (%s)", ft.Type, ft.Format)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FileKind returns the file type of the given file.
|
||||||
|
func FileKind(path string) (*FileType, error) {
|
||||||
|
data, err := os.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
block, _ := pem.Decode(data)
|
||||||
|
if block != nil {
|
||||||
|
return &FileType{
|
||||||
|
Format: FormatPEM,
|
||||||
|
Type: strings.ToLower(strings.TrimSpace(block.Type)),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = x509.ParseCertificate(data)
|
||||||
|
if err == nil {
|
||||||
|
return &FileType{
|
||||||
|
Format: FormatDER,
|
||||||
|
Type: strings.ToLower(pemTypeCertificate),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = x509.ParseCertificateRequest(data)
|
||||||
|
if err == nil {
|
||||||
|
return &FileType{
|
||||||
|
Format: FormatDER,
|
||||||
|
Type: strings.ToLower(pemTypeCertificateRequest),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = x509.ParsePKCS8PrivateKey(data)
|
||||||
|
if err == nil {
|
||||||
|
return &FileType{
|
||||||
|
Format: FormatDER,
|
||||||
|
Type: strings.ToLower(pemTypePrivateKey),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, errors.New("certlib; unknown file type")
|
||||||
|
}
|
||||||
|
|||||||
1
cmd/cert-bundler/testdata/bundle.yaml
vendored
1
cmd/cert-bundler/testdata/bundle.yaml
vendored
@@ -12,6 +12,7 @@ chains:
|
|||||||
include_single: true
|
include_single: true
|
||||||
include_individual: true
|
include_individual: true
|
||||||
manifest: true
|
manifest: true
|
||||||
|
encoding: pemcrt
|
||||||
formats:
|
formats:
|
||||||
- zip
|
- zip
|
||||||
- tgz
|
- tgz
|
||||||
|
|||||||
Reference in New Issue
Block a user