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

Resolves some linting errors flagged in GitHub actions #512

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ func (c *Client) LoadTLSCertificate(server, certFile string) (cert tls.Certifica
return cert, nil
}

// DefaultLoadPubKey will parse a public key from the provided bytes.
// The function used to load the public key in ScanDir if no LoadPubKey
// argument is provided
func DefaultLoadPubKey(in []byte) (crypto.PublicKey, error) {
block, _ := pem.Decode(in)
if block == nil {
Expand Down
6 changes: 2 additions & 4 deletions client/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,13 @@ func signOpFromSignerOpts(key *PrivateKey, opts crypto.SignerOpts) protocol.Op {
case *rsa.PublicKey:
if value, ok := rsaCrypto[opts.HashFunc()]; ok {
return value
} else {
return protocol.OpError
}
return protocol.OpError
case *ecdsa.PublicKey:
if value, ok := ecdsaCrypto[opts.HashFunc()]; ok {
return value
} else {
return protocol.OpError
}
return protocol.OpError
case ed25519.PublicKey:
return protocol.OpEd25519Sign
default:
Expand Down
14 changes: 7 additions & 7 deletions cmd/gokeyless/gokeyless.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func runMain() error {

return nil
case manualMode && configMode:
return fmt.Errorf("can't specify both --manual-activation and --config-only!")
return fmt.Errorf("can't specify both --manual-activation and --config-only")
case manualMode:
// Allow manual activation (requires the CSR to be manually signed).
// manual activation won't proceed to start the server
Expand Down Expand Up @@ -403,15 +403,15 @@ func validCertExpiry(cert *x509.Certificate) bool {
}

// needNewCertAndKey checks the validity of certificate and key
func (config Config) needNewCertAndKey() bool {
_, err := tls.LoadX509KeyPair(config.CertFile, config.KeyFile)
func (c Config) needNewCertAndKey() bool {
_, err := tls.LoadX509KeyPair(c.CertFile, c.KeyFile)
if err != nil {
log.Errorf("cannot load server cert/key: %v", err)
return true
}

// error is ignore because tls.LoadX509KeyPair already verify the existence of the file
certBytes, _ := os.ReadFile(config.CertFile)
certBytes, _ := os.ReadFile(c.CertFile)
// error is ignore because tls.LoadX509KeyPair already verify the file can be parsed
cert, _ := helpers.ParseCertificatePEM(certBytes)
// verify the leaf certificate
Expand All @@ -424,8 +424,8 @@ func (config Config) needNewCertAndKey() bool {
}

// verifyCSRAndKey checks if csr and key files exist and if they match
func (config Config) verifyCSRAndKey() bool {
csrBytes, err := os.ReadFile(config.CSRFile)
func (c Config) verifyCSRAndKey() bool {
csrBytes, err := os.ReadFile(c.CSRFile)
if err != nil {
log.Errorf("cannot read csr file: %v", err)
return false
Expand All @@ -448,7 +448,7 @@ func (config Config) verifyCSRAndKey() bool {
return false
}

keyBytes, err := os.ReadFile(config.KeyFile)
keyBytes, err := os.ReadFile(c.KeyFile)
if err != nil {
log.Errorf("cannot read private key file: %v", err)
return false
Expand Down
3 changes: 2 additions & 1 deletion internal/test/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// (the size of an MD5 hash) and 20 (the size of a SHA1 hash).

var (
RSAMD5SHA1Params = RSASignParams{Opcode: protocol.OpRSASignMD5SHA1, Opts: crypto.MD5SHA1, PayloadSize: 36}

Check failure on line 25 in internal/test/params/params.go

View workflow job for this annotation

GitHub Actions / lint

exported var RSAMD5SHA1Params should have comment or be unexported

Check failure on line 25 in internal/test/params/params.go

View workflow job for this annotation

GitHub Actions / lint

exported var RSAMD5SHA1Params should have comment or be unexported
RSASHA1Params = RSASignParams{Opcode: protocol.OpRSASignSHA1, Opts: crypto.SHA1, PayloadSize: 20}
RSASHA224Params = RSASignParams{Opcode: protocol.OpRSASignSHA224, Opts: crypto.SHA224, PayloadSize: 28}
RSASHA256Params = RSASignParams{Opcode: protocol.OpRSASignSHA256, Opts: crypto.SHA256, PayloadSize: 32}
Expand All @@ -46,7 +46,7 @@
}

var (
ECDSASHA224Params = ECDSASignParams{Opcode: protocol.OpECDSASignSHA224, Curve: elliptic.P256(), Opts: crypto.SHA224, PayloadSize: 28}

Check failure on line 49 in internal/test/params/params.go

View workflow job for this annotation

GitHub Actions / lint

exported var ECDSASHA224Params should have comment or be unexported

Check failure on line 49 in internal/test/params/params.go

View workflow job for this annotation

GitHub Actions / lint

exported var ECDSASHA224Params should have comment or be unexported
ECDSASHA256Params = ECDSASignParams{Opcode: protocol.OpECDSASignSHA256, Curve: elliptic.P256(), Opts: crypto.SHA256, PayloadSize: 32}
ECDSASHA384Params = ECDSASignParams{Opcode: protocol.OpECDSASignSHA384, Curve: elliptic.P384(), Opts: crypto.SHA384, PayloadSize: 48}
ECDSASHA512Params = ECDSASignParams{Opcode: protocol.OpECDSASignSHA512, Curve: elliptic.P521(), Opts: crypto.SHA512, PayloadSize: 64}
Expand All @@ -65,7 +65,8 @@
// Compatibility. Before running tests, copy the contents of the
// testdata/tokens/ directory to your SoftHSM2 token directory, usually
// located at /var/lib/softhsm/tokens/, and run `make test-softhsm`
RSAURI = "pkcs11:token=SoftHSM2%20Token;id=%03?module-path=" + getSoftHSMModulePath() + "&pin-value=1234"
RSAURI = "pkcs11:token=SoftHSM2%20Token;id=%03?module-path=" + getSoftHSMModulePath() + "&pin-value=1234"
// ECDSAURI is a sample PKCS #11 URIs used for testing HSM Compatibility
ECDSAURI = "pkcs11:token=SoftHSM2%20Token;id=%02?module-path=" + getSoftHSMModulePath() + "&pin-value=1234"
)

Expand All @@ -78,6 +79,6 @@
}

var (
HSMECDSASHA256Params = HSMSignParams{Opcode: protocol.OpECDSASignSHA256, URI: ECDSAURI, Opts: crypto.SHA256, PayloadSize: 32}

Check failure on line 82 in internal/test/params/params.go

View workflow job for this annotation

GitHub Actions / lint

exported var HSMECDSASHA256Params should have comment or be unexported

Check failure on line 82 in internal/test/params/params.go

View workflow job for this annotation

GitHub Actions / lint

exported var HSMECDSASHA256Params should have comment or be unexported
HSMRSASHA512Params = HSMSignParams{Opcode: protocol.OpRSASignSHA512, URI: RSAURI, Opts: crypto.SHA512, PayloadSize: 64}
)
Loading