|
| 1 | +[//]: # (-*- coding: utf-8 -*-) |
| 2 | + |
| 3 | + |
| 4 | + |
1 | 5 | # python-keyctl |
| 6 | + |
2 | 7 | Basic management of keys in the Linux kernel keyring in Python. Also comes with a small gui. |
| 8 | + |
| 9 | + |
| 10 | +## Table of contents |
| 11 | + |
| 12 | +[//]: # (AUTO TOC BEGIN) |
| 13 | + |
| 14 | + * [Description](#description) |
| 15 | + * [Requirements](#requirements) |
| 16 | + * [Installation](#installation) |
| 17 | + * [Usage](#usage) |
| 18 | + * [Module](#module) |
| 19 | + * [GUI](#gui) |
| 20 | + * [Development](#development) |
| 21 | + * [Warning](#warning) |
| 22 | + * [Similar projects](#similar-projects) |
| 23 | + * [License](#license) |
| 24 | + |
| 25 | +[//]: # (AUTO TOC END) |
| 26 | + |
| 27 | + |
| 28 | +## Description |
| 29 | + |
| 30 | +This is a small library to make use of some functions of the kernel keyring in Python. You can read, add and delete keys. |
| 31 | + |
| 32 | +It simply uses the keyctl command (invoking it via subprocess), so this util must be installed. |
| 33 | + |
| 34 | +Available functions: |
| 35 | + |
| 36 | + * **list** *(list all keys in keyring)* |
| 37 | + * **describe** *(retrieve key name/description)* |
| 38 | + * **read/pipe/print** *(retrieve key content)* |
| 39 | + * **update** *(modify key content)* |
| 40 | + * **add** *(add key)* |
| 41 | + * **revoke/unlink** *(delete key)* |
| 42 | + * **search/request** *(search for a key by name)* |
| 43 | + * **clear** *(remove all keys from keyring)* |
| 44 | + |
| 45 | +There are many more functions with keys in the kernel keyring (e.g. permissions) that is needed for proper keymanagement. But for my usecase I just needed the given simple functionality. |
| 46 | + |
| 47 | + |
| 48 | +## Requirements |
| 49 | + |
| 50 | +Python 2.7 |
| 51 | +``` |
| 52 | +$ sudo apt-get install python2.7 |
| 53 | +$ python --version |
| 54 | +Python 2.7.3 |
| 55 | +``` |
| 56 | + |
| 57 | +pip |
| 58 | +``` |
| 59 | +$ sudo apt-get install python-pip |
| 60 | +$ pip --version |
| 61 | +pip 9.0.1 from .... (python 2.7) |
| 62 | +``` |
| 63 | + |
| 64 | +The 'keyctl' command |
| 65 | +``` |
| 66 | +$ sudo apt-get install keyutils |
| 67 | +$ dpkg -s keyutils | grep Version |
| 68 | +Version: 1.5.2-2 |
| 69 | +``` |
| 70 | + |
| 71 | +For the GUI you also need: |
| 72 | + |
| 73 | +Qt4 |
| 74 | +``` |
| 75 | +google it for your distribution |
| 76 | +``` |
| 77 | + |
| 78 | +PySide |
| 79 | +``` |
| 80 | +$ pip install pyside |
| 81 | +$ pip show pyside | grep Version |
| 82 | +Version: 1.2.4 |
| 83 | +``` |
| 84 | + |
| 85 | + |
| 86 | +## Installation |
| 87 | + |
| 88 | +``` |
| 89 | +$ pip install keyctl |
| 90 | +``` |
| 91 | + |
| 92 | +Ready to use. |
| 93 | + |
| 94 | + |
| 95 | +## Usage |
| 96 | + |
| 97 | +### Module |
| 98 | +Get all keys: |
| 99 | +```python |
| 100 | +from keyctl import Key |
| 101 | +keylist = Key.list() |
| 102 | +for mykey in keylist: |
| 103 | + print mykey.id |
| 104 | +``` |
| 105 | + |
| 106 | +Read existing key: |
| 107 | +```python |
| 108 | +from keyctl import Key |
| 109 | +mykey = Key(123) |
| 110 | +print mykey.name |
| 111 | +print mykey.data |
| 112 | +print mykey.data_hex |
| 113 | +``` |
| 114 | + |
| 115 | +Find key by name: |
| 116 | +```python |
| 117 | +from keyctl import Key |
| 118 | +mykey = Key.search('test key') |
| 119 | +print mykey.id |
| 120 | +``` |
| 121 | + |
| 122 | +Add key: |
| 123 | +```python |
| 124 | +from keyctl import Key |
| 125 | +mykey = Key.add('test key', 'test content') |
| 126 | +print mykey.id |
| 127 | +``` |
| 128 | + |
| 129 | +Delete key: |
| 130 | +```python |
| 131 | +from keyctl import Key |
| 132 | +mykey = Key(123) |
| 133 | +mykey.delete() |
| 134 | +``` |
| 135 | + |
| 136 | +Update key: |
| 137 | +```python |
| 138 | +from keyctl import Key |
| 139 | +mykey = Key(123) |
| 140 | +mykey.update('new content') |
| 141 | +``` |
| 142 | + |
| 143 | + |
| 144 | +### GUI |
| 145 | +To open the GUI, run the installed command. |
| 146 | +``` |
| 147 | +$ keyctlgui |
| 148 | +``` |
| 149 | + |
| 150 | + |
| 151 | +## Development |
| 152 | + |
| 153 | +### Warning |
| 154 | + |
| 155 | +If you run the integrated tests, your user keyring will be cleared. Don't do this when you have active keys e.g. for encryption. |
| 156 | + |
| 157 | + |
| 158 | +## Similar projects |
| 159 | + |
| 160 | +Similar projects you might want to checkout: |
| 161 | + |
| 162 | + * https://github.com/sassoftware/python-keyutils (more complete, available in debian repo) |
| 163 | + * https://github.com/jdukes/pykeyctl (more complete, direct library wrapper) |
| 164 | + |
| 165 | + |
| 166 | +## License |
| 167 | + |
| 168 | +GPL-3.0 |
| 169 | +see [LICENSE](https://raw.githubusercontent.com/tuxberlin/python-keyctl/master/LICENSE) file |
0 commit comments