Skip to content
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ _trash/

# Python
__pycache__/
.pytest_cache/
*.py[cod]
*$py.class
*.so
Expand Down
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

25 changes: 13 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
init:
pip install -r requirements.txt
python3 -m pip install -r requirements.txt
python3 -m pip install -r requirements-dev.txt

test:
pytest tests
python3 -m pytest tests

build:
bash make-readme-toc.sh
python setup.py sdist
python setup.py bdist_wheel
python3 -m build

pypi: clean build
twine upload dist/* -r testpypi
pypi:
python3 -m twine upload --repository testpypi dist/*
python3 -m pip install --index-url https://test.pypi.org/simple/ --no-deps keyctl

pypi-real: clean build
@read -r -p "Are you sure? " INPUT; \
pypi-real:
@read -r -p "Are you sure to upload to real pypi? " INPUT; \
if [ "$$INPUT" != "y" ] ; then exit 1 ; fi
twine upload dist/*
python3 -m twine upload dist/*

clean:
pip freeze | xargs pip uninstall keyctl -y
find . -type f -name '*~' -delete
find . -type f -name '*.o' -delete
find . -type f -name '*.pyc' -delete
rm -rf build dist .cache *.egg-info tests/__pycache__

find . -type d -name '__pycache__' -delete
rm -rf build dist .cache *.egg-info .pytest_cache tests/.pytest_cache
137 changes: 59 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
[//]: # (-*- coding: utf-8 -*-)

[![Travis](https://img.shields.io/travis/tuxberlin/python-keyctl/master.svg)](https://travis-ci.org/tuxberlin/python-keyctl)
[![PyPI Package version](https://img.shields.io/pypi/v/keyctl.svg)](https://pypi.python.org/pypi/keyctl)
[![PyPI Python version](https://img.shields.io/pypi/pyversions/keyctl.svg)](https://pypi.python.org/pypi/keyctl)
[![License](https://img.shields.io/github/license/tuxberlin/python-keyctl.svg)](https://raw.githubusercontent.com/tuxberlin/python-keyctl/master/LICENSE)


# python-keyctl
<h1>python-keyctl</h1>

Basic management of keys in the Linux kernel keyring in Python. Also comes with a small gui.

* [Description](#description)
* [Requirements](#requirements)
* [Installation](#installation)
* [Usage](#usage)
* [Module](#module)
* [GUI](#gui)
* [Development](#development)
* [Warning](#warning)
* [Similar projects](#similar-projects)
* [License](#license)

## Table of contents

[//]: # (AUTO TOC BEGIN)

* [Description](#description)
* [Requirements](#requirements)
* [Installation](#installation)
* [Usage](#usage)
* [Module](#module)
* [GUI](#gui)
* [Development](#development)
* [Warning](#warning)
* [Similar projects](#similar-projects)
* [License](#license)
# Description

[//]: # (AUTO TOC END)


## Description

This is a small library to make use of some functions of the kernel keyring in Python. You can read, add and delete keys.
This is a small library to make use of some functions of the kernel keyring in Python.
You can read, add and delete keys.

It simply uses the keyctl command (invoking it via subprocess), so this util must be installed.

Expand All @@ -46,68 +40,51 @@ Available functions:
* **search/request** *(search for a key by name)*
* **clear** *(remove all keys from keyring)*

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.
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.

:warning: You might need to link your keyrings (e.g. for the testcases using the default keyring)
to have proper permissions.
E.g.:
```sh
$ keyctl link @u @s
```

## Requirements

Python 2.7
```
$ sudo apt-get install python2.7
# Requirements

Python 3.9
```sh
$ sudo apt install python3.9
$ python --version
Python 2.7.3
Python 3.9.18
```

pip
```
$ sudo apt-get install python-pip
```sh
$ sudo apt install python3-pip
$ pip --version
pip 9.0.1 from .... (python 2.7)
pip 23.3.2 from .... (python 3.9)
```

The 'keyctl' command
```
$ sudo apt-get install keyutils
```sh
$ sudo apt install keyutils
$ dpkg -s keyutils | grep Version
Version: 1.5.2-2
```

For the GUI you also need:

Qt4
```
$ sudo apt-get install qt4-qmake libqt4-core libqt4-dev
$ qmake-qt4 --version
QMake version 2.01a
Using Qt version 4.8.1 in /usr/lib/x86_64-linux-gnu
```

PySide
```
$ sudo apt-get install python-qt4 python-pyside
$ python -c "import PySide; print PySide.__version__"
Version: 1.1.0
Version: 1.6.1
```

Virtualenv:
If you want to use this module in a virtualenv you either have to
`(venv)$ pip install pyside` (which takes up to 40min to compile)
or you can link your pyside distro package into your virtualenv like this:
If you want to use the GUI, you also need PySide6
```
$ cd myprojectfolder
$ ln -s /usr/lib/python2.7/dist-packages/PySide/ venv/lib/python2.7/site-packages/
$ pip install pyside6
$ python3 -c "import PySide6; print(PySide6.__version__)"
6.6.1
```

try it:
```
$ cd myprojectfolder
$ source venv/bin/activate
(venv)$ python -c "import PySide; import os; print PySide.__version__, os.path.realpath(PySide.__path__[0])"
1.1.0 /usr/lib/python2.7/dist-packages/PySide
```


## Installation
# Installation

```
$ pip install keyctl
Expand All @@ -116,38 +93,39 @@ $ pip install keyctl
Ready to use.


## Usage

### Module
# Usage

## Module
Get all keys:
```python
from keyctl import Key
keylist = Key.list()
for mykey in keylist:
print mykey.id
print(mykey.id)
```

Read existing key:
```python
from keyctl import Key
mykey = Key(123)
print mykey.name
print mykey.data
print mykey.data_hex
print(mykey.name)
print(mykey.data)
print(mykey.data_hex)
```

Find key by name:
```python
from keyctl import Key
mykey = Key.search('test key')
print mykey.id
print(mykey.id)
```

Add key:
```python
from keyctl import Key
mykey = Key.add('test key', 'test content')
print mykey.id
print(mykey.id)
```

Delete key:
Expand All @@ -165,7 +143,7 @@ mykey.update('new content')
```


### GUI
## GUI
To open the GUI, run the installed command.
```
$ keyctlgui
Expand All @@ -175,22 +153,25 @@ $ keyctlgui



## Development
# Development

### Warning
## Warning

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.
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.


## Similar projects

Similar projects you might want to checkout:
# Similar projects

Similar projects you might want to check out:

* https://github.com/sassoftware/python-keyutils (more complete, available in debian repo)
* https://github.com/jdukes/pykeyctl (more complete, direct library wrapper)


## License

# License

GPL-3.0
see [LICENSE](https://raw.githubusercontent.com/tuxberlin/python-keyctl/master/LICENSE) file
6 changes: 4 additions & 2 deletions keyctl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@
try:
subprocess.check_output(['which', 'keyctl'])
except subprocess.CalledProcessError:
raise OSError('The commandline util \'keyctl\' must be installed to use this module. ' +
'Install it via \'apt-get install keyutils\'.')
raise OSError(
'The commandline util \'keyctl\' must be installed to use this module. ' +
'Install it via \'apt-get install keyutils\'.'
)
9 changes: 5 additions & 4 deletions keyctl/gui/gui.py → keyctl/gui/_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# -*- coding: utf-8 -*-

import os
from PySide.QtUiTools import QUiLoader
from PySide.QtGui import QMainWindow, QDesktopWidget, QTableWidgetItem, QDialog
from PySide6.QtUiTools import QUiLoader
from PySide6.QtWidgets import QMainWindow, QTableWidgetItem, QDialog
from PySide6.QtGui import QGuiApplication

from keyctl import Key

Expand Down Expand Up @@ -42,7 +43,7 @@ def __init__(self):
self._refresh_table()

def center_window(self):
coords = QDesktopWidget().availableGeometry().center()
coords = QGuiApplication.primaryScreen().availableGeometry().center()
fg = self.ui.frameGeometry()
fg.moveCenter(coords)
self.ui.move(fg.topLeft())
Expand All @@ -67,7 +68,7 @@ def _open_add_dialog(self):
name, content = dialog.get_input()
Key.add(name, content)
else:
print 'ERROR'
print('ERROR')

self._refresh_table()

Expand Down
9 changes: 6 additions & 3 deletions keyctl/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@
# -*- coding: utf-8 -*-

import sys
from PySide.QtGui import QApplication
from PySide6.QtCore import Qt, QCoreApplication
from PySide6.QtWidgets import QApplication

from gui import KeyringApp
from keyctl.gui._gui import KeyringApp


# -------------------------------------------------------------------


def main():
QCoreApplication.setAttribute(Qt.AA_ShareOpenGLContexts)

app = QApplication(sys.argv)

window = KeyringApp()
window.ui.show()
window.center_window()
window.activateWindow()

ret = app.exec_()
ret = app.exec()
sys.exit(ret)


Expand Down
Loading