admin: Handle team password

This commit is contained in:
nemunaire 2021-09-09 11:20:45 +02:00
commit 5eeb1a6297
11 changed files with 299 additions and 40 deletions

View file

@ -5,38 +5,12 @@ import (
"crypto/elliptic"
"crypto/rand"
"crypto/x509"
"encoding/base64"
"encoding/pem"
"os"
"strings"
)
var PKIDir string
func GeneratePassword() (password string, err error) {
// This will make a 12 chars long password
b := make([]byte, 9)
if _, err = rand.Read(b); err != nil {
return
}
password = base64.StdEncoding.EncodeToString(b)
// Avoid hard to read characters
for _, i := range [][2]string{
{"v", "*"}, {"u", "("},
{"l", "%"}, {"1", "?"},
{"o", "@"}, {"O", "!"}, {"0", ">"},
// This one is to avoid problem with openssl
{"/", "^"},
} {
password = strings.Replace(password, i[0], i[1], -1)
}
return
}
func GeneratePrivKey() (pub *ecdsa.PublicKey, priv *ecdsa.PrivateKey, err error) {
if priv, err = ecdsa.GenerateKey(elliptic.P384(), rand.Reader); err == nil {
pub = &priv.PublicKey