mirror of
https://github.com/minio/minio.git
synced 2025-11-07 04:42:56 -05:00
Authorization validation in accordance with S3 signer AWSv2
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package keys
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
)
|
||||
@@ -41,28 +39,6 @@ func GetRandomBase64(size int) ([]byte, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var bytesBuffer bytes.Buffer
|
||||
writer := bufio.NewWriter(&bytesBuffer)
|
||||
encoder := base64.NewEncoder(base64.StdEncoding, writer)
|
||||
encoder.Write(rb)
|
||||
encoder.Close()
|
||||
return bytesBuffer.Bytes(), nil
|
||||
}
|
||||
|
||||
func ValidateAccessKey(key []byte) bool {
|
||||
for _, char := range key {
|
||||
if isalnum(char) {
|
||||
continue
|
||||
}
|
||||
switch char {
|
||||
case '-':
|
||||
case '.':
|
||||
case '_':
|
||||
case '~':
|
||||
continue
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
dest := base64.StdEncoding.EncodeToString(rb)
|
||||
return []byte(dest), nil
|
||||
}
|
||||
|
||||
24
pkg/utils/crypto/keys/keys_test.go
Normal file
24
pkg/utils/crypto/keys/keys_test.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package keys
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
func Test(t *testing.T) { TestingT(t) }
|
||||
|
||||
type MySuite struct{}
|
||||
|
||||
var _ = Suite(&MySuite{})
|
||||
|
||||
func (s *MySuite) Testing(c *C) {
|
||||
value, err := GetRandomBase64(MINIO_SECRET_ID)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
alphanum, err := GetRandomAlphaNumeric(MINIO_ACCESS_ID)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
c.Log(string(value))
|
||||
c.Log(string(alphanum))
|
||||
}
|
||||
Reference in New Issue
Block a user