aeb3cb34bf
* Added a mode option to the resource specification enabling secrets to set the file permissions * Fixed a bug in the renewal time, when a resource does not have a custom update and the lease time is 0s * Cleaned up some of the vetting issue
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
/*
|
|
Copyright 2015 Home Office All rights reserved.
|
|
|
|
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.
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"io"
|
|
)
|
|
|
|
var stdChars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+,.?/:;{}[]`~")
|
|
|
|
func newPassword(length int) string {
|
|
return randString(length, stdChars)
|
|
}
|
|
|
|
func randString(length int, chars []byte) string {
|
|
pass := make([]byte, length)
|
|
data := make([]byte, length+(length/4)) // storage for random bytes.
|
|
clen := byte(len(chars))
|
|
maxrb := byte(256 - (256 % len(chars)))
|
|
i := 0
|
|
for {
|
|
if _, err := io.ReadFull(rand.Reader, data); err != nil {
|
|
panic(err)
|
|
}
|
|
for _, c := range data {
|
|
if c >= maxrb {
|
|
continue
|
|
}
|
|
pass[i] = chars[c%clen]
|
|
i++
|
|
if i == length {
|
|
return string(pass)
|
|
}
|
|
}
|
|
}
|
|
}
|