Skip to content

Commit c6d5c96

Browse files
swagner-defelix-kaestner
authored andcommitted
fix(nxos): Make sure salt does not contain zero bytes
Cisco cannot handle zero bytes in the salt. Those lead to password hash becoming invalid and the credentials being unusable. Closes #172.
1 parent d1e3ae4 commit c6d5c96

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

internal/provider/cisco/nxos/provider.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package nxos
55

66
import (
7+
"bytes"
78
"cmp"
89
"context"
910
"crypto/rand"
@@ -85,8 +86,17 @@ func (p *Provider) Disconnect(_ context.Context, _ *deviceutil.Connection) error
8586

8687
func (p *Provider) HashProvisioningPassword(password string) (hashed, encryptType string, err error) {
8788
s := [10]byte{}
88-
if _, err := rand.Read(s[:]); err != nil {
89-
return "", "", err
89+
for {
90+
// Read cryptographically secure random bytes into the slice.
91+
if _, err := rand.Read(s[:]); err != nil {
92+
return "", "", err
93+
}
94+
// Check if the slice contains a zero byte.
95+
if !bytes.Contains(s[:], []byte{0}) {
96+
// If no zero is found, we're done. Break the loop.
97+
break
98+
}
99+
// If a zero was found, the loop will repeat, overwriting the slice.
90100
}
91101
e := Scrypt{Salt: s}
92102
hashed, pwdEncryptType, err := e.Encode(password)

0 commit comments

Comments
 (0)