mirror of https://github.com/minio/minio.git
Golint cleanup pkg/utils/crypto/keys
This commit is contained in:
parent
b33e2d2f9b
commit
66e31445ff
|
@ -92,7 +92,7 @@ func (web *webUiApi) accessHandler(w http.ResponseWriter, req *http.Request) {
|
|||
var user = config.User{}
|
||||
user.Name = username
|
||||
|
||||
accesskey, err = keys.GetRandomAlphaNumeric(keys.MINIO_ACCESS_ID)
|
||||
accesskey, err = keys.GenerateRandomAlphaNumeric(keys.MinioAccessID)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
|
@ -100,7 +100,7 @@ func (web *webUiApi) accessHandler(w http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
user.AccessKey = string(accesskey)
|
||||
|
||||
secretkey, err = keys.GetRandomBase64(keys.MINIO_SECRET_ID)
|
||||
secretkey, err = keys.GenerateRandomBase64(keys.MinioSecretID)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
|
|
|
@ -46,8 +46,8 @@ func (s *MySuite) TestConfig(c *C) {
|
|||
}
|
||||
conf.configLock = new(sync.RWMutex)
|
||||
|
||||
accesskey, _ := keys.GetRandomAlphaNumeric(keys.MINIO_ACCESS_ID)
|
||||
secretkey, _ := keys.GetRandomBase64(keys.MINIO_SECRET_ID)
|
||||
accesskey, _ := keys.GenerateRandomAlphaNumeric(keys.MINIO_ACCESS_ID)
|
||||
secretkey, _ := keys.GenerateRandomBase64(keys.MINIO_SECRET_ID)
|
||||
|
||||
user := User{
|
||||
Name: "gnubot",
|
||||
|
@ -62,8 +62,8 @@ func (s *MySuite) TestConfig(c *C) {
|
|||
err = conf.ReadConfig()
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
accesskey, _ = keys.GetRandomAlphaNumeric(keys.MINIO_ACCESS_ID)
|
||||
secretkey, _ = keys.GetRandomBase64(keys.MINIO_SECRET_ID)
|
||||
accesskey, _ = keys.GenerateRandomAlphaNumeric(keys.MINIO_ACCESS_ID)
|
||||
secretkey, _ = keys.GenerateRandomBase64(keys.MINIO_SECRET_ID)
|
||||
user = User{
|
||||
Name: "minio",
|
||||
AccessKey: string(accesskey),
|
||||
|
|
|
@ -16,9 +16,10 @@
|
|||
|
||||
package keys
|
||||
|
||||
// AccessID and SecretID length in bytes
|
||||
const (
|
||||
MINIO_ACCESS_ID = 20
|
||||
MINIO_SECRET_ID = 40
|
||||
MinioAccessID = 20
|
||||
MinioSecretID = 40
|
||||
)
|
||||
|
||||
/// helpers
|
||||
|
@ -28,8 +29,8 @@ func isalnum(c byte) bool {
|
|||
return '0' <= c && c <= '9' || 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z'
|
||||
}
|
||||
|
||||
// validate access key for only alphanumeric characters
|
||||
func ValidateAccessKey(key []byte) bool {
|
||||
// IsValidAccessKey - validate access key for only alphanumeric characters
|
||||
func IsValidAccessKey(key []byte) bool {
|
||||
for _, char := range key {
|
||||
if isalnum(char) {
|
||||
continue
|
||||
|
|
|
@ -23,13 +23,10 @@ import (
|
|||
|
||||
// Static alphaNumeric table used for generating unique keys
|
||||
var alphaNumericTable = []byte("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
var alphaNumericTableFull = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
|
||||
|
||||
/// helpers
|
||||
|
||||
// Generate random alpha numeric value using only uppercase characters
|
||||
// GenerateRandomAlphaNumeric - generate random alpha numeric value using only uppercase characters
|
||||
// takes input as size in integer
|
||||
func GetRandomAlphaNumeric(size int) ([]byte, error) {
|
||||
func GenerateRandomAlphaNumeric(size int) ([]byte, error) {
|
||||
alpha := make([]byte, size)
|
||||
_, err := rand.Read(alpha)
|
||||
if err != nil {
|
||||
|
@ -42,22 +39,8 @@ func GetRandomAlphaNumeric(size int) ([]byte, error) {
|
|||
return alpha, nil
|
||||
}
|
||||
|
||||
// Generate random alpha numeric value using all alphanumeric characters
|
||||
// takes input as size in integer
|
||||
func GetRandomAlphaNumericFull(size int) ([]byte, error) {
|
||||
alphaFull := make([]byte, size)
|
||||
_, err := rand.Read(alphaFull)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := 0; i < size; i++ {
|
||||
alphaFull[i] = alphaNumericTableFull[alphaFull[i]%byte(len(alphaNumericTableFull))]
|
||||
}
|
||||
return alphaFull, nil
|
||||
}
|
||||
|
||||
// Generate random base64 numeric value from a random seed.
|
||||
func GetRandomBase64(size int) ([]byte, error) {
|
||||
// GenerateRandomBase64 - generate random base64 numeric value from a random seed.
|
||||
func GenerateRandomBase64(size int) ([]byte, error) {
|
||||
rb := make([]byte, size)
|
||||
_, err := rand.Read(rb)
|
||||
if err != nil {
|
||||
|
|
|
@ -29,10 +29,10 @@ type MySuite struct{}
|
|||
var _ = Suite(&MySuite{})
|
||||
|
||||
func (s *MySuite) Testing(c *C) {
|
||||
value, err := GetRandomBase64(MINIO_SECRET_ID)
|
||||
value, err := GenerateRandomBase64(MinioSecretID)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
alphanum, err := GetRandomAlphaNumeric(MINIO_ACCESS_ID)
|
||||
alphanum, err := GenerateRandomAlphaNumeric(MinioAccessID)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
c.Log(string(value))
|
||||
|
|
|
@ -32,7 +32,7 @@ import (
|
|||
"github.com/minio-io/minio/pkg/utils/config"
|
||||
)
|
||||
|
||||
// Sign a given http request using HMAC style signatures
|
||||
// SignRequest - a given http request using HMAC style signatures
|
||||
func SignRequest(user config.User, req *http.Request) {
|
||||
if date := req.Header.Get("Date"); date == "" {
|
||||
req.Header.Set("Date", time.Now().UTC().Format(http.TimeFormat))
|
||||
|
@ -49,7 +49,7 @@ func SignRequest(user config.User, req *http.Request) {
|
|||
req.Header.Set("Authorization", authHeader.String())
|
||||
}
|
||||
|
||||
// Validate an API request by validating its signature using HMAC signatures
|
||||
// ValidateRequest - an API request by validating its signature using HMAC signatures
|
||||
func ValidateRequest(user config.User, req *http.Request) (bool, error) {
|
||||
// Verify if date headers are set, if not reject the request
|
||||
if req.Header.Get("x-amz-date") == "" {
|
||||
|
@ -117,7 +117,7 @@ func hasPrefixCaseInsensitive(s, pfx string) bool {
|
|||
|
||||
// Canonicalize amazon special headers, headers starting with 'x-amz-'
|
||||
func writeCanonicalizedAmzHeaders(buf *bytes.Buffer, req *http.Request) {
|
||||
amzHeaders := make([]string, 0)
|
||||
var amzHeaders []string
|
||||
vals := make(map[string][]string)
|
||||
for k, vv := range req.Header {
|
||||
if hasPrefixCaseInsensitive(k, "x-amz-") {
|
||||
|
|
Loading…
Reference in New Issue