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

Use output to save client cert file locally #79

Merged
merged 8 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ var signCmd = &cobra.Command{
return err
}
fmt.Println("Rekor entry successful. URL: ", tlogEntry)

if viper.IsSet("output") {
err = ioutil.WriteFile(viper.GetString("output"), signingCertPEM, 0600)
if err != nil {
return err
}
}
return nil
},
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/cryptoutils/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ func MarshalCertificateToPEM(cert *x509.Certificate) ([]byte, error) {
func UnmarshalCertificatesFromPEM(pemBytes []byte) ([]*x509.Certificate, error) {
result := []*x509.Certificate{}
remaining := pemBytes

for {
if remaining == nil {
if len(remaining) == 0 {
break
}
certDer, restBytes := pem.Decode(remaining)

Copy link
Member

Choose a reason for hiding this comment

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

nit: maybe the extra line should be in line 53

if len(remaining) == 0 {
	break
}

certDer, restBytes := pem.Decode(remaining)
if certDer == nil {
	return nil, errors.New("error during PEM decoding")
}

if certDer == nil {
return nil, errors.New("error during PEM decoding")
}

cert, err := x509.ParseCertificate(certDer.Bytes)
if err != nil {
return nil, err
Expand Down