-
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(agent,pkg): migrate from libxcrypt to yescrypt-go
- Loading branch information
1 parent
a930b11
commit e4af915
Showing
17 changed files
with
103 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/shellhub-io/shellhub/api | ||
|
||
go 1.22 | ||
go 1.22.4 | ||
|
||
toolchain go1.22.5 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/shellhub-io/shellhub/cli | ||
|
||
go 1.22 | ||
go 1.22.4 | ||
|
||
toolchain go1.22.8 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package yescrypt | ||
|
||
import ( | ||
yescrypt "github.com/openwall/yescrypt-go" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// Verify verifies a yescrypt hash against a given key. | ||
func Verify(password, hash string) bool { | ||
hashed, err := yescrypt.Hash([]byte(password), []byte(hash)) | ||
if err != nil { | ||
log.WithError(err).Debug("failed to hash the password for comparison") | ||
|
||
return false | ||
} | ||
|
||
return hash == string(hashed) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package yescrypt | ||
|
||
import ( | ||
"crypto/rand" | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/openwall/yescrypt-go" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func FuzzVerify(f *testing.F) { | ||
const settings = "$y$j9T$AAt9R641xPvCI9nXw1HHW/" | ||
|
||
for i := 0; i < 100; i++ { | ||
v, err := rand.Int(rand.Reader, big.NewInt(64)) | ||
assert.NoError(f, err) | ||
|
||
password := make([]byte, v.Int64()) | ||
_, err = rand.Read(password) | ||
assert.NoError(f, err) | ||
|
||
hash, err := yescrypt.Hash(password, []byte(settings)) | ||
assert.NoError(f, err) | ||
|
||
f.Add(string(password), string(hash)) | ||
} | ||
|
||
f.Fuzz(func(t *testing.T, a string, b string) { | ||
assert.True(f, Verify(a, b)) | ||
}) | ||
} | ||
|
||
func TestVeirfy(t *testing.T) { | ||
cases := []struct { | ||
description string | ||
password string | ||
hash string | ||
expected bool | ||
}{ | ||
{ | ||
description: "invalid password", | ||
password: "invalid", | ||
hash: "$y$j9T$AAt9R641xPvCI9nXw1HHW/$nCv3bckjDEC9Q5ahIEpyXVNGZhySye/ZdjxNxTY5ttB", | ||
expected: false, | ||
}, | ||
{ | ||
description: "invalid hash", | ||
password: "password", | ||
hash: "invalid", | ||
expected: false, | ||
}, | ||
{ | ||
description: "valid", | ||
password: "password", | ||
hash: "$y$j9T$AAt9R641xPvCI9nXw1HHW/$nCv3bckjDEC9Q5ahIEpyXVNGZhySye/ZdjxNxTY5ttB", | ||
expected: true, | ||
}, | ||
} | ||
|
||
for _, test := range cases { | ||
t.Run(test.description, func(tt *testing.T) { | ||
result := Verify(test.password, test.hash) | ||
|
||
assert.Equal(tt, test.expected, result) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/shellhub-io/shellhub/ssh | ||
|
||
go 1.21 | ||
go 1.22.4 | ||
|
||
require ( | ||
github.com/Masterminds/semver v1.5.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters