You've already forked step-ca-cli
mirror of
https://github.com/smallstep/cli.git
synced 2025-08-09 03:22:43 +03:00
Move random utilities to crypto/randutil package.
This commit is contained in:
@@ -9,8 +9,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/smallstep/cli/crypto"
|
|
||||||
"github.com/smallstep/cli/crypto/pem"
|
"github.com/smallstep/cli/crypto/pem"
|
||||||
|
"github.com/smallstep/cli/crypto/randutil"
|
||||||
"github.com/smallstep/cli/errs"
|
"github.com/smallstep/cli/errs"
|
||||||
"github.com/smallstep/cli/jose"
|
"github.com/smallstep/cli/jose"
|
||||||
"github.com/smallstep/cli/utils"
|
"github.com/smallstep/cli/utils"
|
||||||
@@ -562,7 +562,7 @@ func createAction(ctx *cli.Context) error {
|
|||||||
return errors.Wrap(err, "error reading password")
|
return errors.Wrap(err, "error reading password")
|
||||||
}
|
}
|
||||||
|
|
||||||
salt, err := crypto.GetRandomSalt(pbkdf2SaltSize)
|
salt, err := randutil.GetRandomSalt(pbkdf2SaltSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -574,7 +574,7 @@ func createAction(ctx *cli.Context) error {
|
|||||||
P2S: salt,
|
P2S: salt,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
key, err := crypto.RandAlphanumeric(32)
|
key, err := randutil.RandAlphanumeric(32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error generating password")
|
return errors.Wrap(err, "error generating password")
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/smallstep/cli/crypto"
|
"github.com/smallstep/cli/crypto/randutil"
|
||||||
"github.com/smallstep/cli/errs"
|
"github.com/smallstep/cli/errs"
|
||||||
"github.com/smallstep/cli/jose"
|
"github.com/smallstep/cli/jose"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
@@ -283,7 +283,7 @@ func signAction(ctx *cli.Context) error {
|
|||||||
c.IssuedAt = jose.NewNumericDate(now)
|
c.IssuedAt = jose.NewNumericDate(now)
|
||||||
}
|
}
|
||||||
if c.ID == "" && ctx.IsSet("jti") {
|
if c.ID == "" && ctx.IsSet("jti") {
|
||||||
if c.ID, err = crypto.RandHex(40); err != nil {
|
if c.ID, err = randutil.RandHex(40); err != nil {
|
||||||
return errors.Wrap(err, "error creating random jti")
|
return errors.Wrap(err, "error creating random jti")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,7 @@ import (
|
|||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
|
||||||
"github.com/smallstep/cli/command"
|
"github.com/smallstep/cli/command"
|
||||||
"github.com/smallstep/cli/crypto"
|
"github.com/smallstep/cli/crypto/randutil"
|
||||||
"github.com/smallstep/cli/errs"
|
"github.com/smallstep/cli/errs"
|
||||||
"github.com/smallstep/cli/exec"
|
"github.com/smallstep/cli/exec"
|
||||||
jose "gopkg.in/square/go-jose.v2"
|
jose "gopkg.in/square/go-jose.v2"
|
||||||
@@ -282,12 +282,12 @@ type oauth struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newOauth(provider, clientID, clientSecret, authzEp, tokenEp, scope, loginHint string) (*oauth, error) {
|
func newOauth(provider, clientID, clientSecret, authzEp, tokenEp, scope, loginHint string) (*oauth, error) {
|
||||||
state, err := crypto.GenerateRandomRestrictedString(32)
|
state, err := randutil.GenerateRandomRestrictedString(32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
challenge, err := crypto.GenerateRandomRestrictedString(64)
|
challenge, err := randutil.GenerateRandomRestrictedString(64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
package crypto
|
package randutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
@@ -7,8 +7,8 @@ import (
|
|||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/smallstep/cli/crypto"
|
|
||||||
"github.com/smallstep/cli/crypto/pem"
|
"github.com/smallstep/cli/crypto/pem"
|
||||||
|
"github.com/smallstep/cli/crypto/randutil"
|
||||||
"golang.org/x/crypto/ed25519"
|
"golang.org/x/crypto/ed25519"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -160,7 +160,7 @@ func generateOctKey(size int, alg, use, kid string) (*JSONWebKey, error) {
|
|||||||
size = DefaultOctSize
|
size = DefaultOctSize
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := crypto.RandAlphanumeric(size)
|
key, err := randutil.RandAlphanumeric(size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/smallstep/cli/crypto"
|
"github.com/smallstep/cli/crypto/randutil"
|
||||||
"golang.org/x/crypto/ssh/terminal"
|
"golang.org/x/crypto/ssh/terminal"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ func GeneratePasswordOnEmpty(ptr *string, key string) error {
|
|||||||
|
|
||||||
if len(*ptr) == 0 {
|
if len(*ptr) == 0 {
|
||||||
var err error
|
var err error
|
||||||
if *ptr, err = crypto.GenerateRandomRestrictedString(passwordLength); err != nil {
|
if *ptr, err = randutil.GenerateRandomRestrictedString(passwordLength); err != nil {
|
||||||
return errors.Wrapf(err, "Failed to generate %s", key)
|
return errors.Wrapf(err, "Failed to generate %s", key)
|
||||||
}
|
}
|
||||||
fmt.Printf("\n\n%s: %s\n\n", key, *ptr)
|
fmt.Printf("\n\n%s: %s\n\n", key, *ptr)
|
||||||
|
Reference in New Issue
Block a user