-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
increment hoard version in grant to preserve backwards compatability
Signed-off-by: Gregory Hill <[email protected]>
- Loading branch information
Gregory Hill
committed
Dec 18, 2019
1 parent
effc361
commit da892da
Showing
14 changed files
with
939 additions
and
682 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
### Changed | ||
- [CMD] Secret keys can now be loaded from the environment | ||
|
||
### Fixed | ||
- [ENCRYPTION] Secret keys are no longer derived at runtime due to high scrypt memory overhead | ||
- Symmetric grants are now versioned to preserve backwards compatability | ||
|
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package config | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/BurntSushi/toml" | ||
"github.com/monax/hoard/v7/encryption" | ||
"github.com/stretchr/testify/assert" | ||
yaml "gopkg.in/yaml.v2" | ||
) | ||
|
||
func TestSecretKeyMarshal(t *testing.T) { | ||
salt := make([]byte, encryption.NonceSize) | ||
key, err := encryption.DeriveSecretKey([]byte("hello"), salt) | ||
assert.NoError(t, err) | ||
|
||
secret := SecretKey(key) | ||
data, err := secret.MarshalText() | ||
assert.NoError(t, err) | ||
expected := "bFQ+wRhNaOgC4fNcliGFaZ5Xr3wOywYJZP1eqj6SDCk=" | ||
assert.Equal(t, expected, string(data)) | ||
|
||
inSecret := new(SymmetricSecret) | ||
inSecret.SecretKey = secret | ||
outSecret := new(SymmetricSecret) | ||
|
||
data, err = json.Marshal(inSecret) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "{\"PublicID\":\"\",\"SecretKey\":\"bFQ+wRhNaOgC4fNcliGFaZ5Xr3wOywYJZP1eqj6SDCk=\",\"Passphrase\":\"\"}", string(data)) | ||
err = json.Unmarshal(data, outSecret) | ||
assert.NoError(t, err) | ||
assert.Equal(t, key, []byte(outSecret.SecretKey)) | ||
|
||
data, err = yaml.Marshal(inSecret) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "publicid: \"\"\nsecretkey: bFQ+wRhNaOgC4fNcliGFaZ5Xr3wOywYJZP1eqj6SDCk=\npassphrase: \"\"\n", string(data)) | ||
err = yaml.Unmarshal(data, outSecret) | ||
assert.NoError(t, err) | ||
assert.Equal(t, key, []byte(outSecret.SecretKey)) | ||
|
||
buf := new(bytes.Buffer) | ||
encoder := toml.NewEncoder(buf) | ||
err = encoder.Encode(inSecret) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "PublicID = \"\"\nSecretKey = \"bFQ+wRhNaOgC4fNcliGFaZ5Xr3wOywYJZP1eqj6SDCk=\"\nPassphrase = \"\"\n", buf.String()) | ||
err = toml.Unmarshal(buf.Bytes(), outSecret) | ||
assert.NoError(t, err) | ||
assert.Equal(t, key, []byte(outSecret.SecretKey)) | ||
|
||
err = toml.Unmarshal([]byte("SecretKey = \"bFQ+wRhNaOgC4fNcliGFaZ5Xr3wOywYJZP1eqj6SDCk=\"\n"), outSecret) | ||
assert.NoError(t, err) | ||
assert.Equal(t, key, []byte(outSecret.SecretKey)) | ||
assert.Equal(t, "", outSecret.PublicID) | ||
assert.Equal(t, "", outSecret.Passphrase) | ||
|
||
err = toml.Unmarshal([]byte("PublicID = \"\"\nSecretKey = \"badkey=\"\n"), outSecret) | ||
assert.Error(t, err) | ||
} |
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
Oops, something went wrong.