You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.3 KiB
79 lines
2.3 KiB
10 years ago
|
/*
|
||
9 years ago
|
* Minio Cloud Storage, (C) 2015 Minio, Inc.
|
||
10 years ago
|
*
|
||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
* you may not use this file except in compliance with the License.
|
||
|
* You may obtain a copy of the License at
|
||
|
*
|
||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||
|
*
|
||
|
* Unless required by applicable law or agreed to in writing, software
|
||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
* See the License for the specific language governing permissions and
|
||
|
* limitations under the License.
|
||
|
*/
|
||
|
|
||
9 years ago
|
package main
|
||
10 years ago
|
|
||
|
import (
|
||
|
"crypto/rand"
|
||
10 years ago
|
"encoding/base64"
|
||
9 years ago
|
"regexp"
|
||
9 years ago
|
|
||
9 years ago
|
"github.com/minio/minio-xl/pkg/probe"
|
||
10 years ago
|
)
|
||
|
|
||
9 years ago
|
const (
|
||
|
minioAccessID = 20
|
||
|
minioSecretID = 40
|
||
|
)
|
||
|
|
||
|
// isValidAccessKey - validate access key
|
||
|
func isValidAccessKey(accessKeyID string) bool {
|
||
|
if accessKeyID == "" {
|
||
|
return true
|
||
|
}
|
||
|
regex := regexp.MustCompile("^[A-Z0-9\\-\\.\\_\\~]{20}$")
|
||
|
return regex.MatchString(accessKeyID)
|
||
|
}
|
||
|
|
||
9 years ago
|
// generateAccessKeyID - generate random alpha numeric value using only uppercase characters
|
||
10 years ago
|
// takes input as size in integer
|
||
9 years ago
|
func generateAccessKeyID() ([]byte, *probe.Error) {
|
||
9 years ago
|
alpha := make([]byte, minioAccessID)
|
||
10 years ago
|
_, err := rand.Read(alpha)
|
||
|
if err != nil {
|
||
9 years ago
|
return nil, probe.NewError(err)
|
||
10 years ago
|
}
|
||
9 years ago
|
for i := 0; i < minioAccessID; i++ {
|
||
10 years ago
|
alpha[i] = alphaNumericTable[alpha[i]%byte(len(alphaNumericTable))]
|
||
|
}
|
||
|
return alpha, nil
|
||
|
}
|
||
|
|
||
9 years ago
|
// generateSecretAccessKey - generate random base64 numeric value from a random seed.
|
||
|
func generateSecretAccessKey() ([]byte, *probe.Error) {
|
||
9 years ago
|
rb := make([]byte, minioSecretID)
|
||
10 years ago
|
_, err := rand.Read(rb)
|
||
10 years ago
|
if err != nil {
|
||
9 years ago
|
return nil, probe.NewError(err)
|
||
10 years ago
|
}
|
||
9 years ago
|
return []byte(base64.StdEncoding.EncodeToString(rb))[:minioSecretID], nil
|
||
10 years ago
|
}
|
||
9 years ago
|
|
||
|
// mustGenerateAccessKeyID - must generate random alpha numeric value using only uppercase characters
|
||
|
// takes input as size in integer
|
||
|
func mustGenerateAccessKeyID() []byte {
|
||
9 years ago
|
alpha, err := generateAccessKeyID()
|
||
|
fatalIf(err.Trace(), "Unable to generate accessKeyID.", nil)
|
||
9 years ago
|
return alpha
|
||
|
}
|
||
|
|
||
|
// mustGenerateSecretAccessKey - generate random base64 numeric value from a random seed.
|
||
|
func mustGenerateSecretAccessKey() []byte {
|
||
9 years ago
|
secretKey, err := generateSecretAccessKey()
|
||
|
fatalIf(err.Trace(), "Unable to generate secretAccessKey.", nil)
|
||
|
return secretKey
|
||
9 years ago
|
}
|