-
-
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
f7667b5
commit 88d0184
Showing
13 changed files
with
113 additions
and
114 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
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 ( | ||
"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 comparision") | ||
|
||
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,70 @@ | ||
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) { | ||
const settings = "$y$j9T$AAt9R641xPvCI9nXw1HHW/" | ||
|
||
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, string(test.hash)) | ||
|
||
assert.Equal(tt, test.expected, result) | ||
}) | ||
} | ||
} |