Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,11 @@ func Unlink(parent Keyring, child Id) error {
func UnlinkKeyring(kr NamedKeyring) error {
return keyctl_Unlink(keyId(kr.Id()), kr.(*namedKeyring).parent)
}

func Move(source Keyring, dest Keyring, child Id, excl bool) error {
var flags uint
if excl {
flags = keyctlMoveExcl
}
return keyctl_Move(keyId(child.Id()), keyId(source.Id()), keyId(dest.Id()), flags)
}
35 changes: 35 additions & 0 deletions keyring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,38 @@ func TestUnlinkKeyring(t *testing.T) {

t.Logf("unlinked keyring %v [%s]", nring.Id(), nring.Name())
}

func TestMoveKey(t *testing.T) {
ring, err := SessionKeyring()
if err != nil {
t.Fatal(err)
}

nring, err := CreateKeyring(ring, "testring")
if err != nil {
t.Fatal(err)
}
t.Logf("created keyring %v named %q", nring.Id(), nring.Name())
defer UnlinkKeyring(nring)

key, err := ring.Add("move-test", []byte("test"))
if err != nil {
t.Fatal(err)
}
t.Logf("added test key as: %v\n", key.Id())
defer key.Unlink()

err = Move(ring, nring, key, false)
if err != nil {
t.Fatal(err)
}

movedKey, err := nring.Search("move-test")
if err != nil {
t.Fatal(err)
}
t.Logf("found key in keyring: %v\n", movedKey.Id())
if movedKey.Id() != key.Id() {
t.Fatal("IDs don't match\n")
}
}
60 changes: 60 additions & 0 deletions sys_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const (
keySpecReqKeyAuthKey keyId = -7
)

const (
keyctlMoveExcl uint = 1
)

const (
keyctlGetKeyringId keyctlCommand = iota
keyctlJoinSessionKeyring
Expand All @@ -37,6 +41,22 @@ const (
keyctlSetReqKeyKeyring
keyctlSetTimeout
keyctlAssumeAuthority
keyctlGetSecurity
keyctlSessionToParent
keyctlReject
keyctlInstantiateIov
keyctlInvalidate
keyctlGetPersistent
keyctlDhCompute
keyctlPkeyQuery
keyctlPkeyEncrypt
keyctlPkeyDecrypt
keyctlPkeySign
keyctlPkeyVerify
keyctlRestrictKeyring
keyctlMove
keyctlCapabilities
keyctlWatchKey
)

var debugSyscalls bool
Expand Down Expand Up @@ -81,6 +101,38 @@ func (cmd keyctlCommand) String() string {
return "keyctlSetTimeout"
case keyctlAssumeAuthority:
return "keyctlAssumeAuthority"
case keyctlGetSecurity:
return "keyctlGetSecurity"
case keyctlSessionToParent:
return "keyctlSessionToParent"
case keyctlReject:
return "keyctlReject"
case keyctlInstantiateIov:
return "keyctlInstantiateIov"
case keyctlInvalidate:
return "keyctlInvalidate"
case keyctlGetPersistent:
return "keyctlGetPersistent"
case keyctlDhCompute:
return "keyctlDhCompute"
case keyctlPkeyQuery:
return "keyctlPkeyQuery"
case keyctlPkeyEncrypt:
return "keyctlPkeyEncrypt"
case keyctlPkeyDecrypt:
return "keyctlPkeyDecrypt"
case keyctlPkeySign:
return "keyctlPkeySign"
case keyctlPkeyVerify:
return "keyctlPkeyVerify"
case keyctlRestrictKeyring:
return "keyctlRestrictKeyring"
case keyctlMove:
return "keyctlMove"
case keyctlCapabilities:
return "keyctlCapabilities"
case keyctlWatchKey:
return "keyctlWatchKey"
}
panic("bad arg")
}
Expand Down Expand Up @@ -294,3 +346,11 @@ func updateKey(id keyId, payload []byte) error {
}
return nil
}

func keyctl_Move(id, from_ring keyId, to_ring keyId, flags uint) error {
_, _, errno := syscall.Syscall6(syscall_keyctl, uintptr(keyctlMove), uintptr(id), uintptr(from_ring), uintptr(to_ring), uintptr(flags), 0)
if errno != 0 {
return errno
}
return nil
}