This commit is contained in:
Samuel Lorch 2021-09-06 15:55:55 +02:00
parent 0538e86ddd
commit 28e2ccf7e4
2 changed files with 9 additions and 22 deletions

View file

@ -146,10 +146,7 @@ func (c *Client) Login(ctx context.Context) error {
}
// Validate that this Publickey that the Server gave us actually Matches our Privatekey
randomString, err := randStringBytesRmndr(50)
if err != nil {
return fmt.Errorf("Generating Random String as PublicKey Validation Message: %w", err)
}
randomString := randStringBytesRmndr(50)
armor, err := helper.EncryptMessageArmored(user.GPGKey.ArmoredKey, randomString)
if err != nil {
return fmt.Errorf("Encryping PublicKey Validation Message: %w", err)

View file

@ -1,25 +1,15 @@
package api
import (
"crypto/rand"
"math/big"
"math/rand"
)
func randStringBytesRmndr(length int) (string, error) {
result := ""
for {
if len(result) >= length {
return result, nil
}
num, err := rand.Int(rand.Reader, big.NewInt(int64(127)))
if err != nil {
return "", err
}
n := num.Int64()
// Make sure that the number/byte/letter is inside
// the range of printable ASCII characters (excluding space and DEL)
if n > 32 && n < 127 {
result += string(n)
}
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
func randStringBytesRmndr(length int) string {
b := make([]byte, length)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return string(b)
}