-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add delegation option for any user to be able to decrypt
core: Add AnyUser field to DelegateRequest and pass to cache calls keycache: Add AnyUser parameter to AddKeyFromRecord function signature keycache_test: Add tests for AnyUser and update AddKeyFromRecord calls cryptor: Update tests to AddKeyFromRecord to reflect API update cmd/ro: Add bool flag for anyUser parameter
- Loading branch information
Tyler J
committed
Apr 13, 2016
1 parent
577d957
commit 4093134
Showing
5 changed files
with
78 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ func TestUsesFlush(t *testing.T) { | |
// Initialize keycache and delegate the user's key to it. | ||
cache := NewCache() | ||
|
||
err = cache.AddKeyFromRecord(pr, "user", "weakpassword", nil, nil, 2, "", "1h") | ||
err = cache.AddKeyFromRecord(pr, "user", "weakpassword", nil, nil, 2, "", "1h", false) | ||
This comment has been minimized.
Sorry, something went wrong.
kisom
Contributor
|
||
if err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
|
@@ -90,7 +90,7 @@ func TestTimeFlush(t *testing.T) { | |
|
||
cache := NewCache() | ||
|
||
err = cache.AddKeyFromRecord(pr, "user", "weakpassword", nil, nil, 10, "", "1s") | ||
err = cache.AddKeyFromRecord(pr, "user", "weakpassword", nil, nil, 10, "", "1s", false) | ||
if err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
|
@@ -129,7 +129,7 @@ func TestGoodLabel(t *testing.T) { | |
|
||
cache := NewCache() | ||
|
||
err = cache.AddKeyFromRecord(pr, "user", "weakpassword", nil, []string{"red"}, 1, "", "1h") | ||
err = cache.AddKeyFromRecord(pr, "user", "weakpassword", nil, []string{"red"}, 1, "", "1h", false) | ||
if err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
|
@@ -171,7 +171,7 @@ func TestBadLabel(t *testing.T) { | |
|
||
cache := NewCache() | ||
|
||
err = cache.AddKeyFromRecord(pr, "user", "weakpassword", nil, []string{"red"}, 1, "", "1h") | ||
err = cache.AddKeyFromRecord(pr, "user", "weakpassword", nil, []string{"red"}, 1, "", "1h", false) | ||
if err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
|
@@ -217,7 +217,7 @@ func TestGoodUser(t *testing.T) { | |
pr, "user", "weakpassword", | ||
[]string{"ci", "buildeng", "user"}, | ||
[]string{"red", "blue"}, | ||
1, "", "1h", | ||
1, "", "1h", false, | ||
) | ||
if err != nil { | ||
t.Fatalf("%v", err) | ||
|
@@ -264,7 +264,7 @@ func TestBadUser(t *testing.T) { | |
pr, "user", "weakpassword", | ||
[]string{"ci", "buildeng", "user"}, | ||
[]string{"red", "blue"}, | ||
1, "", "1h", | ||
1, "", "1h", false, | ||
) | ||
if err != nil { | ||
t.Fatalf("%v", err) | ||
|
@@ -291,3 +291,50 @@ func TestBadUser(t *testing.T) { | |
t.Fatalf("Error in number of live keys %v", cache.UserKeys) | ||
} | ||
} | ||
|
||
func TestAnyUser(t *testing.T) { | ||
This comment has been minimized.
Sorry, something went wrong.
kisom
Contributor
|
||
// Initialize passvault and keycache. Delegate a key with tag and user | ||
// restrictions and verify that permissible decryption is allowed. | ||
records, err := passvault.InitFrom("memory") | ||
if err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
|
||
pr, err := records.AddNewRecord("user", "weakpassword", true, passvault.DefaultRecordType) | ||
if err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
|
||
cache := NewCache() | ||
|
||
err = cache.AddKeyFromRecord( | ||
pr, "user", "weakpassword", | ||
nil, | ||
[]string{"red", "blue"}, | ||
1, "", "1h", true, | ||
) | ||
if err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
|
||
cache.Refresh() | ||
if len(cache.UserKeys) != 1 { | ||
t.Fatalf("Error in number of live keys") | ||
} | ||
|
||
dummy := make([]byte, 16) | ||
pubEncryptedKey, err := pr.EncryptKey(dummy) | ||
if err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
|
||
_, err = cache.DecryptKey(dummy, "user", "anybody", []string{"red"}, pubEncryptedKey) | ||
if err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
|
||
cache.Refresh() | ||
if len(cache.UserKeys) != 0 { | ||
t.Fatalf("Error in number of live keys %v", cache.UserKeys) | ||
} | ||
} |
It might be useful to clean this up as
and to have the call to
cache.AddKeyFromRecord
in core/core.go:400 use a core.DelegateRequest -> cache.Usage conversion function to build the request.