Imported Debian patch 4.0.5-6~numeezy
This commit is contained in:
committed by
Mario Fetka
parent
c44de33144
commit
10dfc9587b
@@ -36,29 +36,24 @@ def dump_keys():
|
||||
"""
|
||||
Dump all keys
|
||||
"""
|
||||
result = run(['keyctl', 'list', KEYRING], raiseonerr=False,
|
||||
capture_output=True)
|
||||
return result.output
|
||||
(stdout, stderr, rc) = run(['keyctl', 'list', KEYRING], raiseonerr=False)
|
||||
return stdout
|
||||
|
||||
def get_real_key(key):
|
||||
"""
|
||||
One cannot request a key based on the description it was created with
|
||||
so find the one we're looking for.
|
||||
"""
|
||||
assert isinstance(key, str)
|
||||
result = run(['keyctl', 'search', KEYRING, KEYTYPE, key],
|
||||
raiseonerr=False, capture_output=True)
|
||||
if result.returncode:
|
||||
(stdout, stderr, rc) = run(['keyctl', 'search', KEYRING, KEYTYPE, key], raiseonerr=False)
|
||||
if rc:
|
||||
raise ValueError('key %s not found' % key)
|
||||
return result.raw_output.rstrip()
|
||||
return stdout.rstrip()
|
||||
|
||||
def get_persistent_key(key):
|
||||
assert isinstance(key, str)
|
||||
result = run(['keyctl', 'get_persistent', KEYRING, key],
|
||||
raiseonerr=False, capture_output=True)
|
||||
if result.returncode:
|
||||
(stdout, stderr, rc) = run(['keyctl', 'get_persistent', KEYRING, key], raiseonerr=False)
|
||||
if rc:
|
||||
raise ValueError('persistent key %s not found' % key)
|
||||
return result.raw_output.rstrip()
|
||||
return stdout.rstrip()
|
||||
|
||||
def is_persistent_keyring_supported():
|
||||
uid = os.geteuid()
|
||||
@@ -73,7 +68,6 @@ def has_key(key):
|
||||
"""
|
||||
Returns True/False whether the key exists in the keyring.
|
||||
"""
|
||||
assert isinstance(key, str)
|
||||
try:
|
||||
get_real_key(key)
|
||||
return True
|
||||
@@ -86,27 +80,22 @@ def read_key(key):
|
||||
|
||||
Use pipe instead of print here to ensure we always get the raw data.
|
||||
"""
|
||||
assert isinstance(key, str)
|
||||
real_key = get_real_key(key)
|
||||
result = run(['keyctl', 'pipe', real_key], raiseonerr=False,
|
||||
capture_output=True)
|
||||
if result.returncode:
|
||||
raise ValueError('keyctl pipe failed: %s' % result.error_log)
|
||||
(stdout, stderr, rc) = run(['keyctl', 'pipe', real_key], raiseonerr=False)
|
||||
if rc:
|
||||
raise ValueError('keyctl pipe failed: %s' % stderr)
|
||||
|
||||
return result.raw_output
|
||||
return stdout
|
||||
|
||||
def update_key(key, value):
|
||||
"""
|
||||
Update the keyring data. If they key doesn't exist it is created.
|
||||
"""
|
||||
assert isinstance(key, str)
|
||||
assert isinstance(value, bytes)
|
||||
if has_key(key):
|
||||
real_key = get_real_key(key)
|
||||
result = run(['keyctl', 'pupdate', real_key], stdin=value,
|
||||
raiseonerr=False)
|
||||
if result.returncode:
|
||||
raise ValueError('keyctl pupdate failed: %s' % result.error_log)
|
||||
(stdout, stderr, rc) = run(['keyctl', 'pupdate', real_key], stdin=value, raiseonerr=False)
|
||||
if rc:
|
||||
raise ValueError('keyctl pupdate failed: %s' % stderr)
|
||||
else:
|
||||
add_key(key, value)
|
||||
|
||||
@@ -114,22 +103,17 @@ def add_key(key, value):
|
||||
"""
|
||||
Add a key to the kernel keyring.
|
||||
"""
|
||||
assert isinstance(key, str)
|
||||
assert isinstance(value, bytes)
|
||||
if has_key(key):
|
||||
raise ValueError('key %s already exists' % key)
|
||||
result = run(['keyctl', 'padd', KEYTYPE, key, KEYRING],
|
||||
stdin=value, raiseonerr=False)
|
||||
if result.returncode:
|
||||
raise ValueError('keyctl padd failed: %s' % result.error_log)
|
||||
(stdout, stderr, rc) = run(['keyctl', 'padd', KEYTYPE, key, KEYRING], stdin=value, raiseonerr=False)
|
||||
if rc:
|
||||
raise ValueError('keyctl padd failed: %s' % stderr)
|
||||
|
||||
def del_key(key):
|
||||
"""
|
||||
Remove a key from the keyring
|
||||
"""
|
||||
assert isinstance(key, str)
|
||||
real_key = get_real_key(key)
|
||||
result = run(['keyctl', 'unlink', real_key, KEYRING],
|
||||
raiseonerr=False)
|
||||
if result.returncode:
|
||||
raise ValueError('keyctl unlink failed: %s' % result.error_log)
|
||||
(stdout, stderr, rc) = run(['keyctl', 'unlink', real_key, KEYRING], raiseonerr=False)
|
||||
if rc:
|
||||
raise ValueError('keyctl unlink failed: %s' % stderr)
|
||||
|
||||
Reference in New Issue
Block a user