Skip to content

Commit

Permalink
nest: Add nonce to token filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
unkaktus committed Oct 4, 2024
1 parent fa63e50 commit 8d72a7b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions nest/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import (
)

const (
tokenLength int = 24
fallbackPort uint64 = 2222
tokenLength int = 24
tokenNonceLength int = 8
fallbackPort uint64 = 2222
)

func UserPort() uint64 {
Expand All @@ -49,8 +50,8 @@ func UserPort() uint64 {
return number
}

func generateToken() string {
rb := make([]byte, tokenLength)
func generateRandomString(length int) string {
rb := make([]byte, length)
_, err := rand.Read(rb)

if err != nil {
Expand All @@ -66,8 +67,8 @@ func writeTokenFile() (token, filename string, err error) {
if err != nil {
return "", "", fmt.Errorf("get current working directory: %w", err)
}
filename = filepath.Join(cwd, ".robin-token")
token = generateToken()
filename = filepath.Join(cwd, ".robin-token.", generateRandomString(tokenNonceLength))
token = generateRandomString(tokenLength)
err = os.WriteFile(filename, []byte(token), 0600)
if err != nil {
return "", "", fmt.Errorf("writing token file: %w", err)
Expand Down

0 comments on commit 8d72a7b

Please sign in to comment.