diff options
| author | Joe Richey <joerichey@google.com> | 2017-03-02 11:47:07 -0800 |
|---|---|---|
| committer | Joe Richey joerichey@google.com <joerichey@google.com> | 2017-05-02 13:39:18 -0700 |
| commit | 53d15f466a665e4e564af3afdcbcfe9ff1c91331 (patch) | |
| tree | f154df351d4a1df8c277015db7acd20517292f01 /crypto/crypto_test.go | |
| parent | 20924ca06efba5a50356bdb5abb1f7b87f34f817 (diff) | |
crypto: insert key into keyring from go
This commit adds in the ability to insert Keys into the kernel keyring
from go code. This is done via a patched version of x/sys/unix. We
also expose the specific requirements for keys that will be placed in
the keyring, namely PolicyKeyLen. The legacy services are also exposed.
Change-Id: I177928c9aa676cae13b749042b9a3996e7490f68
Diffstat (limited to 'crypto/crypto_test.go')
| -rw-r--r-- | crypto/crypto_test.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/crypto/crypto_test.go b/crypto/crypto_test.go index d76381e..025b5b9 100644 --- a/crypto/crypto_test.go +++ b/crypto/crypto_test.go @@ -40,6 +40,12 @@ func makeKey(b byte, n int) (*Key, error) { return NewFixedLengthKeyFromReader(ConstReader(b), n) } +var fakeValidDescriptor = "0123456789abcdef" +var fakeInvalidDescriptor = "123456789abcdef" + +var fakeValidPolicyKey, _ = makeKey(42, PolicyKeyLen) +var fakeInvalidPolicyKey, _ = makeKey(42, PolicyKeyLen-1) + // Tests the two ways of making keys func TestMakeKeys(t *testing.T) { data := []byte("1234\n6789") @@ -111,3 +117,25 @@ func TestLongLength(t *testing.T) { t.Error("Key contained incorrect data") } } + +// Adds a key with and without legacy (check keyctl to see the key identifiers). +func TestAddKeys(t *testing.T) { + for _, service := range []string{ServiceDefault, ServiceExt4, ServiceF2FS} { + if err := InsertPolicyKey(fakeValidPolicyKey, fakeValidDescriptor, service); err != nil { + t.Error(err) + } + } +} + +// Makes sure a key fails with bad descriptor, policy, or service +func TestBadAddKeys(t *testing.T) { + if InsertPolicyKey(fakeInvalidPolicyKey, fakeValidDescriptor, ServiceDefault) == nil { + t.Error("InsertPolicyKey should fail with bad policy key") + } + if InsertPolicyKey(fakeValidPolicyKey, fakeInvalidDescriptor, ServiceDefault) == nil { + t.Error("InsertPolicyKey should fail with bad descriptor") + } + if InsertPolicyKey(fakeValidPolicyKey, fakeValidDescriptor, "ext4") == nil { + t.Error("InsertPolicyKey should fail with bad service") + } +} |