f11ff8650d
A new elevate request verifies the web sign-in password (scrypt hash, read-only, rate-limited, constant time) and elevates that connection for 15 minutes. chat_shell_run/input, rename/move/delete, terminal_open/input and POST /files (via a per-connection upload token) are refused with code elevation_required until then.
48 lines
1.8 KiB
Go
48 lines
1.8 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"testing"
|
|
)
|
|
|
|
// RFC 7914 section 12 test vectors (the 1 GiB N=1048576 vector is omitted).
|
|
func TestScryptKeyMatchesRFC7914(t *testing.T) {
|
|
cases := []struct {
|
|
password, salt string
|
|
n, r, p int
|
|
want string
|
|
}{
|
|
{"", "", 16, 1, 1, "77d6576238657b203b19ca42c18a0497f16b4844e3074ae8dfdffa3fede21442fcd0069ded0948f8326a753a0fc81f17e8d3e0fb2e0d3628cf35e20c38d18906"},
|
|
{"password", "NaCl", 1024, 8, 16, "fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b3731622eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640"},
|
|
{"pleaseletmein", "SodiumChloride", 16384, 8, 1, "7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b543f6545da1f2d5432955613f0fcf62d49705242a9af9e61e85dc0d651e40dfcf017b45575887"},
|
|
}
|
|
for _, c := range cases {
|
|
got, err := scryptKey([]byte(c.password), []byte(c.salt), c.n, c.r, c.p, 64)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if hex.EncodeToString(got) != c.want {
|
|
t.Fatalf("scrypt(%q,%q,%d,%d,%d) = %x", c.password, c.salt, c.n, c.r, c.p, got)
|
|
}
|
|
}
|
|
if _, err := scryptKey([]byte("x"), nil, 1000, 8, 1, 32); err == nil {
|
|
t.Fatal("non power-of-two N accepted")
|
|
}
|
|
}
|
|
|
|
// Hashes written by web/src/authStore.js (Node) and scripts/password.py.
|
|
func TestWebAuthVerifiesNodeAndPythonHashes(t *testing.T) {
|
|
for _, hash := range []string{
|
|
"scrypt$1024$8$1$MR3k3NXe_hsd4UA6ipwLCQ$4sbSBzIXD8kVwJxwdg85f7wSvF6yzn3E0V480Z2ktG8",
|
|
"scrypt$1024$8$1$ulLLNZltxuQsW2fYURfjkw$8LptNPQf8ABG7GBih5ZH924wfqf1eDnZOhhdVIA7z2U",
|
|
} {
|
|
verifier := webAuthVerifier{hash: hash}
|
|
if ok, err := verifier.verify("tulip orbit canyon ember"); !ok || err != nil {
|
|
t.Fatalf("%s: %v %v", hash, ok, err)
|
|
}
|
|
if ok, _ := verifier.verify("tulip orbit canyon embers"); ok {
|
|
t.Fatalf("%s accepted a wrong password", hash)
|
|
}
|
|
}
|
|
}
|