external auth: allow to inspect and preserve an existing user

This commit is contained in:
Nicola Murino
2021-03-26 15:19:01 +01:00
parent d5f092284a
commit 5f49af1780
8 changed files with 209 additions and 64 deletions

View File

@@ -2,6 +2,7 @@
package utils
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"crypto/ecdsa"
@@ -489,3 +490,29 @@ func CheckTCP4Port(port int) {
}
listener.Close()
}
// IsByteArrayEmpty return true if the byte array is empty or a new line
func IsByteArrayEmpty(b []byte) bool {
if len(b) == 0 {
return true
}
if bytes.Equal(b, []byte("\n")) {
return true
}
if bytes.Equal(b, []byte("\r\n")) {
return true
}
return false
}
// GetSSHPublicKeyAsString returns an SSH public key serialized as string
func GetSSHPublicKeyAsString(pubKey []byte) (string, error) {
if len(pubKey) == 0 {
return "", nil
}
k, err := ssh.ParsePublicKey(pubKey)
if err != nil {
return "", err
}
return string(ssh.MarshalAuthorizedKey(k)), nil
}