diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bb25b191..b61bfe4c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - go: [ '1.15', '1.16', '1.17' ] + go: [ '1.16', '1.17' ] steps: - name: Checkout @@ -26,26 +26,8 @@ jobs: name: golangci-lint uses: golangci/golangci-lint-action@v2 with: - # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: 'latest' - - # Optional: working directory, useful for monorepos - # working-directory: somedir - - # Optional: golangci-lint command line arguments. + version: 'v1.43.0' args: --timeout=30m - - # Optional: show only new issues if it's a pull request. The default value is `false`. - # only-new-issues: true - - # Optional: if set to true then the action will use pre-installed Go. - # skip-go-installation: true - - # Optional: if set to true then the action don't cache or restore ~/go/pkg. - # skip-pkg-cache: true - - # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. - # skip-build-cache: true - name: Test, Build id: lintTestBuild @@ -251,7 +233,7 @@ jobs: name: Update Reference id: update_refrence run: | - ./bin/step help --markdown ./docs/step-cli/reference + ./bin/step help --markdown ./docs/src/pages/docs/step-cli/reference cd ./docs git config user.email "eng@smallstep.com" git config user.name "Github Action CI" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 14e1c93d..d6fe1344 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - go: [ '1.15', '1.16', '1.17' ] + go: [ '1.16', '1.17' ] steps: - name: Checkout @@ -28,26 +28,8 @@ jobs: name: golangci-lint uses: golangci/golangci-lint-action@v2 with: - # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: 'latest' - - # Optional: working directory, useful for monorepos - # working-directory: somedir - - # Optional: golangci-lint command line arguments. + version: 'v1.43.0' args: --timeout=30m - - # Optional: show only new issues if it's a pull request. The default value is `false`. - # only-new-issues: true - - # Optional: if set to true then the action will use pre-installed Go. - # skip-go-installation: true - - # Optional: if set to true then the action don't cache or restore ~/go/pkg. - # skip-pkg-cache: true - - # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. - # skip-build-cache: true - name: Test, Build id: lintTestBuild @@ -55,7 +37,8 @@ jobs: - name: Codecov uses: codecov/codecov-action@v1.2.1 + if: matrix.go == '1.17' with: - file: ./coverage.out # optional - name: codecov-umbrella # optional - fail_ci_if_error: true # optional (default = false) + file: ./coverage.out + name: codecov-umbrella + fail_ci_if_error: true diff --git a/.golangci.yml b/.golangci.yml index 277bcd19..5c6faefb 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -71,9 +71,3 @@ issues: - should have a package comment, unless it's in another file for this package - func `CLICommand. - error strings should not be capitalized or end with punctuation or a newline -# golangci.com configuration -# https://github.com/golangci/golangci/wiki/Configuration -service: - golangci-lint-version: 1.19.x # use the fixed version to not introduce new linters unexpectedly - prepare: - - echo "here I can run custom commands, but no preparation needed for this repo" diff --git a/README.md b/README.md index fa1c880a..bdf013a8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # Step CLI [](https://github.com/smallstep/cli/releases) -[](https://microbadger.com/images/smallstep/step-cli) [](https://goreportcard.com/report/github.com/smallstep/cli) [](https://travis-ci.com/smallstep/cli) [](https://opensource.org/licenses/Apache-2.0) @@ -10,27 +9,26 @@ [](https://github.com/smallstep/cli/stargazers) [](https://twitter.com/intent/follow?screen_name=smallsteplabs) -`step` is a toolkit for working with your *public key infrastructure* (PKI). -It's also the client counterpart to the [`step-ca`](https://github.com/smallstep/certificates) online Certificate Authority (CA). - -Here's a quick example, combining `step oauth` and `step crypto` to get and verify the signature of a Google OAuth OIDC token: - - +`step` is an easy-to-use CLI tool for building, operating, and automating Public Key Infrastructure (PKI) systems and workflows. +It's the client counterpart to the [`step-ca` online Certificate Authority (CA)](https://github.com/smallstep/certificates). +You can use it for many common crypto and X.509 operations—independently, or with a CA. **Questions? Ask us on [GitHub Discussions](https://github.com/smallstep/certificates/discussions) or [Discord](https://bit.ly/step-discord).** [Website](https://smallstep.com) | [Documentation](https://smallstep.com/docs/step-cli) | [Installation](https://smallstep.com/docs/step-cli/installation) | -[Getting Started](https://smallstep.com/docs/step-cli/basic-crypto-operations) | +[Basic Crypto Operations](https://smallstep.com/docs/step-cli/basic-crypto-operations) | [Contributor's Guide](./docs/CONTRIBUTING.md) ## Features -Step CLI's command groups illustrate some of its uses: +Step CLI's command groups illustrate its wide-ranging uses: + - [`step certificate`](https://smallstep.com/docs/step-cli/reference/certificate/): Work with X.509 (TLS/HTTPS) certificates. - Create, revoke, validate, lint, and bundle X.509 certificates. - Install (and remove) X.509 certificates into your system's (and brower's) trust store. + - Validate certificate deployment and renewal status for automation - Create key pairs (RSA, ECDSA, EdDSA) and certificate signing requests (CSRs) - [Sign CSRs](https://smallstep.com/docs/step-cli/reference/certificate/sign/) - Create [RFC5280](https://tools.ietf.org/html/rfc5280) and [CA/Browser Forum](https://cabforum.org/baseline-requirements-documents/)-compliant certificates that work for TLS and HTTPS @@ -45,6 +43,7 @@ Step CLI's command groups illustrate some of its uses: - Securely [distribute root certificates](https://smallstep.com/docs/step-cli/reference/ca/root/) and [bootstrap](https://smallstep.com/docs/step-cli/reference/ca/bootstrap/) PKI relying parties - [Renew](https://smallstep.com/docs/step-cli/reference/ca/renew/) and [revoke](https://smallstep.com/docs/step-cli/reference/ca/revoke/) certificates issued by [`step-ca`](https://github.com/smallstep/certificates) - [Submit CSRs](https://smallstep.com/docs/step-cli/reference/ca/sign/) to be signed by [`step-ca`](https://github.com/smallstep/certificates) + - With an ACME CA, `step` supports the `http-01` challenge type - [`step crypto`](https://smallstep.com/docs/step-cli/reference/crypto/): A general-purpose crypto toolkit - Work with [JWTs](https://jwt.io) ([RFC7519](https://tools.ietf.org/html/rfc7519)) and [other JOSE constructs](https://datatracker.ietf.org/wg/jose/documents/) @@ -57,10 +56,12 @@ Step CLI's command groups illustrate some of its uses: signing - [Apply key derivation functions](https://smallstep.com/docs/step-cli/reference/crypto/kdf/) (KDFs) and [verify passwords](https://smallstep.com/docs/step-cli/reference/crypto/kdf/compare/) using `scrypt`, `bcrypt`, and `argo2` - Generate and check [file hashes](https://smallstep.com/docs/step-cli/reference/crypto/hash/) + - [`step oauth`](https://smallstep.com/docs/step-cli/reference/oauth/): Add an OAuth 2.0 single sign-on flow to any CLI application. - Supports OAuth authorization code, out-of-band (OOB), JWT bearer, and refresh token flows - Get OAuth access tokens and OIDC identity tokens at the command line from any provider. - Verify OIDC identity tokens (`step crypto jwt verify`) + - [`step ssh`](https://smallstep.com/docs/step-cli/reference/ssh/): Create and manage SSH certificates (requires an online or offline [`step-ca`](https://github.com/smallstep/certificates) instance) - Generate SSH user and host key pairs and short-lived certificates - Add and remove certificates to the SSH agent @@ -71,6 +72,12 @@ Step CLI's command groups illustrate some of its uses: See our installation docs [here](https://smallstep.com/docs/step-cli/installation). +## Example + +Here's a quick example, combining `step oauth` and `step crypto` to get and verify the signature of a Google OAuth OIDC token: + + + ## Community * Connect with `step` users on [GitHub Discussions](https://github.com/smallstep/certificates/discussions) or [Discord](https://bit.ly/step-discord) diff --git a/command/ca/init.go b/command/ca/init.go index 0e237f37..c5d98be8 100644 --- a/command/ca/init.go +++ b/command/ca/init.go @@ -724,7 +724,7 @@ func promptDeploymentType(ctx *cli.Context, isRA bool) (pki.DeploymentType, erro ui.WithSelectTemplates(&promptui.SelectTemplates{ Active: fmt.Sprintf("%s {{ printf \"%%s - %%s\" .Name .Description | underline }}", ui.IconSelect), Inactive: " {{ .Name }} - {{ .Description }}", - Selected: fmt.Sprintf(`{{ "%s" | green }} {{ "Deployment Type:" | bold }} {{ .Name }}`, ui.IconGood), + Selected: fmt.Sprintf(`{{ %q | green }} {{ "Deployment Type:" | bold }} {{ .Name }}`, ui.IconGood), })) if err != nil { return 0, err diff --git a/command/ca/provisioner/add.go b/command/ca/provisioner/add.go index 2d463fe2..898b3ddf 100644 --- a/command/ca/provisioner/add.go +++ b/command/ca/provisioner/add.go @@ -6,8 +6,8 @@ import ( "crypto/rsa" "crypto/x509" "encoding/pem" - "io/ioutil" "net/url" + "os" "strings" "github.com/pkg/errors" @@ -662,7 +662,7 @@ func addK8sSAProvisioner(ctx *cli.Context, name string, provMap map[string]bool) return nil, errs.RequiredWithFlagValue(ctx, "type", "k8sSA", "pem-keys") } - pemKeysB, err := ioutil.ReadFile(pemKeysF) + pemKeysB, err := os.ReadFile(pemKeysF) if err != nil { return nil, errors.Wrap(err, "error reading pem keys") } diff --git a/command/ca/provisionerbeta/add.go b/command/ca/provisionerbeta/add.go index 1dfad8b5..0b7f1c4c 100644 --- a/command/ca/provisionerbeta/add.go +++ b/command/ca/provisionerbeta/add.go @@ -9,8 +9,8 @@ import ( "encoding/json" "encoding/pem" "fmt" - "io/ioutil" "net/url" + "os" "github.com/pkg/errors" "github.com/smallstep/certificates/authority/provisioner" @@ -473,7 +473,7 @@ func createJWKDetails(ctx *cli.Context) (*linkedca.ProvisionerDetails, error) { if ctx.IsSet("private-key") { jwkFile = ctx.String("private-key") - b, err := ioutil.ReadFile(jwkFile) + b, err := os.ReadFile(jwkFile) if err != nil { return nil, errors.Wrapf(err, "error reading %s", jwkFile) } @@ -587,7 +587,7 @@ func createK8SSADetails(ctx *cli.Context) (*linkedca.ProvisionerDetails, error) return nil, errs.RequiredWithFlagValue(ctx, "type", "k8sSA", "public-key") } - pemKeysB, err := ioutil.ReadFile(pemKeysF) + pemKeysB, err := os.ReadFile(pemKeysF) if err != nil { return nil, errors.Wrap(err, "error reading pem keys") } diff --git a/command/ca/provisionerbeta/update.go b/command/ca/provisionerbeta/update.go index 26f9d11a..76f02df8 100644 --- a/command/ca/provisionerbeta/update.go +++ b/command/ca/provisionerbeta/update.go @@ -9,8 +9,8 @@ import ( "encoding/json" "encoding/pem" "fmt" - "io/ioutil" "net/url" + "os" "github.com/pkg/errors" "github.com/smallstep/certificates/ca" @@ -511,7 +511,7 @@ func updateJWKDetails(ctx *cli.Context, p *linkedca.Provisioner) error { if ctx.IsSet("private-key") { jwkFile := ctx.String("private-key") - b, err := ioutil.ReadFile(jwkFile) + b, err := os.ReadFile(jwkFile) if err != nil { return errors.Wrapf(err, "error reading %s", jwkFile) } @@ -619,7 +619,7 @@ func updateK8SSADetails(ctx *cli.Context, p *linkedca.Provisioner) error { details := data.K8SSA if ctx.IsSet("public-key") { pemKeysF := ctx.String("public-key") - pemKeysB, err := ioutil.ReadFile(pemKeysF) + pemKeysB, err := os.ReadFile(pemKeysF) if err != nil { return errors.Wrap(err, "error reading pem keys") } diff --git a/command/ca/rekey.go b/command/ca/rekey.go index 08fd4ad8..35b07fa7 100644 --- a/command/ca/rekey.go +++ b/command/ca/rekey.go @@ -2,8 +2,8 @@ package ca import ( "crypto" - "io/ioutil" "math/rand" + "os" "strconv" "strings" "syscall" @@ -267,7 +267,7 @@ func rekeyCertificateAction(ctx *cli.Context) error { pidFile := ctx.String("pid-file") if len(pidFile) > 0 { - pidB, err := ioutil.ReadFile(pidFile) + pidB, err := os.ReadFile(pidFile) if err != nil { return errs.FileError(err, pidFile) } diff --git a/command/ca/renew.go b/command/ca/renew.go index e8674294..1c612580 100644 --- a/command/ca/renew.go +++ b/command/ca/renew.go @@ -6,7 +6,6 @@ import ( "crypto/tls" "crypto/x509" "encoding/pem" - "io/ioutil" "log" "math/rand" "net/http" @@ -248,7 +247,7 @@ func renewCertificateAction(ctx *cli.Context) error { pidFile := ctx.String("pid-file") if len(pidFile) > 0 { - pidB, err := ioutil.ReadFile(pidFile) + pidB, err := os.ReadFile(pidFile) if err != nil { return errs.FileError(err, pidFile) } diff --git a/command/ca/revoke.go b/command/ca/revoke.go index 395a371f..21aafbbb 100644 --- a/command/ca/revoke.go +++ b/command/ca/revoke.go @@ -4,7 +4,6 @@ import ( "crypto/tls" "crypto/x509" "encoding/pem" - "io/ioutil" "net/http" "os" "strconv" @@ -405,7 +404,7 @@ func (f *revokeFlow) Revoke(ctx *cli.Context, serial, token string) error { if token == "" { certFile, keyFile := ctx.String("cert"), ctx.String("key") - certPEMBytes, err := ioutil.ReadFile(certFile) + certPEMBytes, err := os.ReadFile(certFile) if err != nil { return errors.Wrap(err, "error reading certificate") } diff --git a/command/certificate/bundle.go b/command/certificate/bundle.go index 676d6c37..878312e0 100644 --- a/command/certificate/bundle.go +++ b/command/certificate/bundle.go @@ -2,7 +2,7 @@ package certificate import ( "encoding/pem" - "io/ioutil" + "os" "github.com/pkg/errors" "github.com/smallstep/cli/flags" @@ -55,7 +55,7 @@ func bundleAction(ctx *cli.Context) error { } crtFile := ctx.Args().Get(0) - crtBytes, err := ioutil.ReadFile(crtFile) + crtBytes, err := os.ReadFile(crtFile) if err != nil { return errs.FileError(err, crtFile) } @@ -65,7 +65,7 @@ func bundleAction(ctx *cli.Context) error { } caFile := ctx.Args().Get(1) - caBytes, err := ioutil.ReadFile(caFile) + caBytes, err := os.ReadFile(caFile) if err != nil { return errs.FileError(err, caFile) } diff --git a/command/certificate/lint.go b/command/certificate/lint.go index 57440dea..c95820a8 100644 --- a/command/certificate/lint.go +++ b/command/certificate/lint.go @@ -3,7 +3,6 @@ package certificate import ( "encoding/json" "encoding/pem" - "io/ioutil" "os" "github.com/pkg/errors" @@ -117,7 +116,7 @@ func lintAction(ctx *cli.Context) error { Bytes: crt.Raw, } default: // is not URL - crtBytes, err := ioutil.ReadFile(crtFile) + crtBytes, err := os.ReadFile(crtFile) if err != nil { return errs.FileError(err, crtFile) } diff --git a/command/certificate/verify.go b/command/certificate/verify.go index 08918bf3..94424c43 100644 --- a/command/certificate/verify.go +++ b/command/certificate/verify.go @@ -3,7 +3,7 @@ package certificate import ( "crypto/x509" "encoding/pem" - "io/ioutil" + "os" "github.com/pkg/errors" "github.com/smallstep/cli/crypto/x509util" @@ -120,7 +120,7 @@ func verifyAction(ctx *cli.Context) error { intermediatePool.AddCert(pc) } default: - crtBytes, err := ioutil.ReadFile(crtFile) + crtBytes, err := os.ReadFile(crtFile) if err != nil { return errs.FileError(err, crtFile) } diff --git a/command/command.go b/command/command.go index 03e6f0a1..7d249572 100644 --- a/command/command.go +++ b/command/command.go @@ -3,7 +3,6 @@ package command import ( "encoding/json" "fmt" - "io/ioutil" "os" "reflect" "strings" @@ -63,7 +62,7 @@ func getConfigVars(ctx *cli.Context) error { configFile = step.DefaultsFile() } - b, err := ioutil.ReadFile(configFile) + b, err := os.ReadFile(configFile) if err != nil { return nil } diff --git a/command/crypto/change-pass.go b/command/crypto/change-pass.go index eeacc15c..d56adf16 100644 --- a/command/crypto/change-pass.go +++ b/command/crypto/change-pass.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "os" "github.com/pkg/errors" "github.com/urfave/cli" @@ -109,7 +109,7 @@ func changePassAction(ctx *cli.Context) error { newKeyPath = keyPath } - b, err := ioutil.ReadFile(keyPath) + b, err := os.ReadFile(keyPath) if err != nil { return errs.FileError(err, keyPath) } diff --git a/command/crypto/hash/hash.go b/command/crypto/hash/hash.go index 9e7f9d58..cc13d63f 100644 --- a/command/crypto/hash/hash.go +++ b/command/crypto/hash/hash.go @@ -11,7 +11,6 @@ import ( "fmt" "hash" "io" - "io/ioutil" "os" "path" "strings" @@ -320,7 +319,7 @@ func hashFile(h hash.Hash, filename string) ([]byte, error) { // 3. return sum func hashDir(hc hashConstructor, dirname string) ([]byte, error) { // ReadDir returns the entries sorted by filename - files, err := ioutil.ReadDir(dirname) + dirEntries, err := os.ReadDir(dirname) if err != nil { return nil, errs.FileError(err, dirname) } @@ -336,7 +335,11 @@ func hashDir(hc hashConstructor, dirname string) ([]byte, error) { h := hc() binary.LittleEndian.PutUint32(mode, uint32(st.Mode())) h.Write(mode) - for _, fi := range files { + for _, dirEntry := range dirEntries { + fi, err := dirEntry.Info() + if err != nil { + return nil, errs.FileError(err, dirEntry.Name()) + } name := path.Join(dirname, fi.Name()) switch { case fi.IsDir(): diff --git a/command/crypto/jose/jose.go b/command/crypto/jose/jose.go index 2d870981..d968a0fd 100644 --- a/command/crypto/jose/jose.go +++ b/command/crypto/jose/jose.go @@ -2,7 +2,7 @@ package jose import ( "fmt" - "io/ioutil" + "io" "os" "regexp" "strings" @@ -65,7 +65,7 @@ $ step crypto jwt sign --key p256.priv.json --iss "joe" --aud "bob" \ } func formatAction(ctx *cli.Context) error { - input, err := ioutil.ReadAll(os.Stdin) + input, err := io.ReadAll(os.Stdin) if err != nil { return errors.Wrap(err, "error reading input") } diff --git a/command/crypto/jwk/keyset.go b/command/crypto/jwk/keyset.go index e7773d3e..94f015bd 100644 --- a/command/crypto/jwk/keyset.go +++ b/command/crypto/jwk/keyset.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "syscall" @@ -124,7 +123,7 @@ func keysetAddAction(ctx *cli.Context) error { return err } - b, err := ioutil.ReadAll(os.Stdin) + b, err := io.ReadAll(os.Stdin) if err != nil { return errors.Wrap(err, "error reading STDIN") } @@ -256,7 +255,7 @@ func rwLockKeySet(filename string) (jwks *jose.JSONWebKeySet, writeFunc func(boo // Read key set var b []byte - b, err = ioutil.ReadAll(f) + b, err = io.ReadAll(f) if err != nil { err = errors.Wrapf(err, "error reading %s", filename) return diff --git a/command/crypto/jwk/public.go b/command/crypto/jwk/public.go index 8417f913..bfd588b3 100644 --- a/command/crypto/jwk/public.go +++ b/command/crypto/jwk/public.go @@ -3,7 +3,7 @@ package jwk import ( "encoding/json" "fmt" - "io/ioutil" + "io" "os" "github.com/pkg/errors" @@ -25,7 +25,7 @@ For examples, see **step help crypto jwk**.`, } func publicAction(ctx *cli.Context) error { - b, err := ioutil.ReadAll(os.Stdin) + b, err := io.ReadAll(os.Stdin) if err != nil { return errors.Wrap(err, "error reading from STDIN") } diff --git a/command/crypto/jwk/thumbprint.go b/command/crypto/jwk/thumbprint.go index e7d6d931..5103f0cb 100644 --- a/command/crypto/jwk/thumbprint.go +++ b/command/crypto/jwk/thumbprint.go @@ -5,7 +5,7 @@ import ( "encoding/base64" "encoding/json" "fmt" - "io/ioutil" + "io" "os" "github.com/pkg/errors" @@ -28,7 +28,7 @@ For examples, see **step help crypto jwk**.`, } func thumbprintAction(ctx *cli.Context) error { - b, err := ioutil.ReadAll(os.Stdin) + b, err := io.ReadAll(os.Stdin) if err != nil { return errors.Wrap(err, "error reading from STDIN") } diff --git a/command/crypto/jws/sign.go b/command/crypto/jws/sign.go index a4e11085..07bcafe6 100644 --- a/command/crypto/jws/sign.go +++ b/command/crypto/jws/sign.go @@ -2,7 +2,6 @@ package jws import ( "fmt" - "io/ioutil" "os" "strings" @@ -361,7 +360,7 @@ func readPayload(filename string) ([]byte, error) { case "-": return utils.ReadAll(os.Stdin) default: - b, err := ioutil.ReadFile(filename) + b, err := os.ReadFile(filename) if err != nil { return nil, errs.FileError(err, filename) } diff --git a/command/crypto/jwt/sign.go b/command/crypto/jwt/sign.go index a26d85f5..2ab64d0c 100644 --- a/command/crypto/jwt/sign.go +++ b/command/crypto/jwt/sign.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "strings" "time" @@ -467,7 +466,7 @@ func readPayload(filename string) (interface{}, error) { case "-": r = os.Stdin default: - b, err := ioutil.ReadFile(filename) + b, err := os.ReadFile(filename) if err != nil { return nil, errs.FileError(err, filename) } diff --git a/command/crypto/nacl/auth.go b/command/crypto/nacl/auth.go index cd37ffa8..4507d757 100644 --- a/command/crypto/nacl/auth.go +++ b/command/crypto/nacl/auth.go @@ -3,7 +3,7 @@ package nacl import ( "encoding/hex" "fmt" - "io/ioutil" + "os" "github.com/pkg/errors" "github.com/smallstep/cli/utils" @@ -107,7 +107,7 @@ func authDigestAction(ctx *cli.Context) error { keyFile := ctx.Args().Get(0) - key, err := ioutil.ReadFile(keyFile) + key, err := os.ReadFile(keyFile) if err != nil { return errs.FileError(err, keyFile) } else if len(key) != auth.KeySize { @@ -135,7 +135,7 @@ func authVerifyAction(ctx *cli.Context) error { args := ctx.Args() keyFile, digest := args[0], args[1] - key, err := ioutil.ReadFile(keyFile) + key, err := os.ReadFile(keyFile) if err != nil { return errs.FileError(err, keyFile) } else if len(key) != auth.KeySize { diff --git a/command/crypto/nacl/box.go b/command/crypto/nacl/box.go index c082a894..3f191040 100644 --- a/command/crypto/nacl/box.go +++ b/command/crypto/nacl/box.go @@ -3,7 +3,6 @@ package nacl import ( "crypto/rand" "fmt" - "io/ioutil" "os" "github.com/pkg/errors" @@ -248,14 +247,14 @@ func boxOpenAction(ctx *cli.Context) error { return errors.New("nonce cannot be longer than 24 bytes") } - pub, err := ioutil.ReadFile(pubFile) + pub, err := os.ReadFile(pubFile) if err != nil { return errs.FileError(err, pubFile) } else if len(pub) != 32 { return errors.New("invalid public key: key size is not 32 bytes") } - priv, err := ioutil.ReadFile(privFile) + priv, err := os.ReadFile(privFile) if err != nil { return errs.FileError(err, privFile) } else if len(priv) != 32 { @@ -314,14 +313,14 @@ func boxSealAction(ctx *cli.Context) error { return errors.New("nonce cannot be longer than 24 bytes") } - pub, err := ioutil.ReadFile(pubFile) + pub, err := os.ReadFile(pubFile) if err != nil { return errs.FileError(err, pubFile) } else if len(pub) != 32 { return errors.New("invalid public key: key size is not 32 bytes") } - priv, err := ioutil.ReadFile(privFile) + priv, err := os.ReadFile(privFile) if err != nil { return errs.FileError(err, privFile) } else if len(priv) != 32 { diff --git a/command/crypto/nacl/secretbox.go b/command/crypto/nacl/secretbox.go index fdf37a99..ff8fc853 100644 --- a/command/crypto/nacl/secretbox.go +++ b/command/crypto/nacl/secretbox.go @@ -2,7 +2,6 @@ package nacl import ( "fmt" - "io/ioutil" "os" "github.com/pkg/errors" @@ -158,7 +157,7 @@ func secretboxOpenAction(ctx *cli.Context) error { return errors.New("nonce cannot be longer than 24 bytes") } - key, err := ioutil.ReadFile(keyFile) + key, err := os.ReadFile(keyFile) if err != nil { return errs.FileError(err, keyFile) } else if len(key) != 32 { @@ -216,7 +215,7 @@ func secretboxSealAction(ctx *cli.Context) error { return errors.New("nonce cannot be longer than 24 bytes") } - key, err := ioutil.ReadFile(keyFile) + key, err := os.ReadFile(keyFile) if err != nil { return errs.FileError(err, keyFile) } else if len(key) != 32 { diff --git a/command/crypto/nacl/sign.go b/command/crypto/nacl/sign.go index d49a812d..9bc0c51a 100644 --- a/command/crypto/nacl/sign.go +++ b/command/crypto/nacl/sign.go @@ -3,7 +3,6 @@ package nacl import ( "crypto/rand" "fmt" - "io/ioutil" "os" "github.com/pkg/errors" @@ -155,7 +154,7 @@ func signOpenAction(ctx *cli.Context) error { } pubFile := ctx.Args().Get(0) - pub, err := ioutil.ReadFile(pubFile) + pub, err := os.ReadFile(pubFile) if err != nil { return errs.FileError(err, pubFile) } else if len(pub) != 32 { @@ -199,7 +198,7 @@ func signSignAction(ctx *cli.Context) error { } privFile := ctx.Args().Get(0) - priv, err := ioutil.ReadFile(privFile) + priv, err := os.ReadFile(privFile) if err != nil { return errs.FileError(err, privFile) } else if len(priv) != 64 { diff --git a/command/crypto/otp/verify.go b/command/crypto/otp/verify.go index fee11a6e..864e44fe 100644 --- a/command/crypto/otp/verify.go +++ b/command/crypto/otp/verify.go @@ -2,7 +2,6 @@ package otp import ( "fmt" - "io/ioutil" "net/url" "os" "strconv" @@ -89,7 +88,7 @@ func verifyAction(ctx *cli.Context) error { } secretFile = args[0] } - b, err := ioutil.ReadFile(secretFile) + b, err := os.ReadFile(secretFile) if err != nil { return errs.FileError(err, secretFile) } diff --git a/command/crypto/winpe/winpe_test.go b/command/crypto/winpe/winpe_test.go index ddf0cea5..9e382635 100644 --- a/command/crypto/winpe/winpe_test.go +++ b/command/crypto/winpe/winpe_test.go @@ -3,17 +3,17 @@ package winpe import ( "bytes" "encoding/base64" - "github.com/smallstep/assert" "io" - "io/ioutil" "os" "testing" + + "github.com/smallstep/assert" ) // This test will write the chrome.exe installer into a temporary file // Then it will just run the extractPE function. func TestExtract(t *testing.T) { - tmpfile, err := ioutil.TempFile("", "step-crypto-winpe-extract-chrome.*.exe") + tmpfile, err := os.CreateTemp("", "step-crypto-winpe-extract-chrome.*.exe") assert.NoError(t, err) defer os.Remove(tmpfile.Name()) defer tmpfile.Close() diff --git a/command/oauth/cmd.go b/command/oauth/cmd.go index b7e55fe1..cb00a340 100644 --- a/command/oauth/cmd.go +++ b/command/oauth/cmd.go @@ -7,7 +7,7 @@ import ( "encoding/json" "encoding/pem" "fmt" - "io/ioutil" + "io" "net" "net/http" "net/http/httptest" @@ -300,7 +300,7 @@ func oauthCmd(c *cli.Context) error { if c.IsSet("account") { opts.Provider = "" filename := c.String("account") - b, err := ioutil.ReadFile(filename) + b, err := os.ReadFile(filename) if err != nil { return errors.Wrapf(err, "error reading account from %s", filename) } @@ -541,7 +541,7 @@ func disco(provider string) (map[string]interface{}, error) { return nil, errors.Wrapf(err, "error retrieving %s", u.String()) } defer resp.Body.Close() - b, err := ioutil.ReadAll(resp.Body) + b, err := io.ReadAll(resp.Body) if err != nil { return nil, errors.Wrapf(err, "error retrieving %s", u.String()) } @@ -866,7 +866,7 @@ func (o *oauth) implicitHandler(w http.ResponseWriter, req *http.Request) { w.Write([]byte(`
`))
diff --git a/command/ssh/certificate.go b/command/ssh/certificate.go
index 284ea49c..68e50ccc 100644
--- a/command/ssh/certificate.go
+++ b/command/ssh/certificate.go
@@ -5,8 +5,8 @@ import (
"crypto"
"crypto/rand"
"crypto/x509"
- "io/ioutil"
"net/url"
+ "os"
"strings"
"github.com/google/uuid"
@@ -492,7 +492,7 @@ func marshalPublicKey(key ssh.PublicKey, subject string) []byte {
func deriveMachineID() (uuid.UUID, error) {
// use /etc/machine-id
- machineID, err := ioutil.ReadFile("/etc/machine-id")
+ machineID, err := os.ReadFile("/etc/machine-id")
if err != nil {
return uuid.Nil, err
}
diff --git a/command/ssh/rekey.go b/command/ssh/rekey.go
index 73174049..42d4fcb5 100644
--- a/command/ssh/rekey.go
+++ b/command/ssh/rekey.go
@@ -1,7 +1,7 @@
package ssh
import (
- "io/ioutil"
+ "os"
"strconv"
"github.com/pkg/errors"
@@ -106,7 +106,7 @@ func rekeyAction(ctx *cli.Context) error {
}
// Load the cert, because we need the serial number.
- certBytes, err := ioutil.ReadFile(certFile)
+ certBytes, err := os.ReadFile(certFile)
if err != nil {
return errors.Wrapf(err, "error reading ssh certificate from %s", certFile)
}
diff --git a/command/ssh/renew.go b/command/ssh/renew.go
index d2e173ac..6e1c262a 100644
--- a/command/ssh/renew.go
+++ b/command/ssh/renew.go
@@ -1,7 +1,7 @@
package ssh
import (
- "io/ioutil"
+ "os"
"strconv"
"github.com/smallstep/certificates/ca/identity"
@@ -28,10 +28,11 @@ func renewCommand() cli.Command {
[**--issuer**=