Merge pull request #78 from slackhq/sign-fix

Fix impossible error message condition, go fmt
This commit is contained in:
Nathan Brown 2019-12-09 16:55:45 -08:00 committed by GitHub
commit 4e2cdb51aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -11,8 +11,8 @@ import (
"strings" "strings"
"time" "time"
"golang.org/x/crypto/curve25519"
"github.com/slackhq/nebula/cert" "github.com/slackhq/nebula/cert"
"golang.org/x/crypto/curve25519"
) )
type signFlags struct { type signFlags struct {
@ -173,10 +173,6 @@ func signCert(args []string, out io.Writer, errOut io.Writer) error {
*sf.outCertPath = *sf.name + ".crt" *sf.outCertPath = *sf.name + ".crt"
} }
if _, err := os.Stat(*sf.outKeyPath); err == nil {
return fmt.Errorf("refusing to overwrite existing key: %s", *sf.outKeyPath)
}
if _, err := os.Stat(*sf.outCertPath); err == nil { if _, err := os.Stat(*sf.outCertPath); err == nil {
return fmt.Errorf("refusing to overwrite existing cert: %s", *sf.outCertPath) return fmt.Errorf("refusing to overwrite existing cert: %s", *sf.outCertPath)
} }
@ -187,6 +183,10 @@ func signCert(args []string, out io.Writer, errOut io.Writer) error {
} }
if *sf.inPubPath == "" { if *sf.inPubPath == "" {
if _, err := os.Stat(*sf.outKeyPath); err == nil {
return fmt.Errorf("refusing to overwrite existing key: %s", *sf.outKeyPath)
}
err = ioutil.WriteFile(*sf.outKeyPath, cert.MarshalX25519PrivateKey(rawPriv), 0600) err = ioutil.WriteFile(*sf.outKeyPath, cert.MarshalX25519PrivateKey(rawPriv), 0600)
if err != nil { if err != nil {
return fmt.Errorf("error while writing out-key: %s", err) return fmt.Errorf("error while writing out-key: %s", err)