From 26efd8e1a734d4760c0ba6899b67b7f2f86f24c5 Mon Sep 17 00:00:00 2001 From: ptrcnull Date: Fri, 16 Jun 2023 20:59:10 +0200 Subject: [PATCH] wip: initial commit --- .gitignore | 4 ++ LICENCE | 9 +++ README.md | 8 +++ kakushi/himitsu.py | 42 ++++++++++++++ kakushi/main.py | 133 +++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 23 ++++++++ setup.py | 3 + 7 files changed, 222 insertions(+) create mode 100644 .gitignore create mode 100644 LICENCE create mode 100644 README.md create mode 100644 kakushi/himitsu.py create mode 100644 kakushi/main.py create mode 100644 pyproject.toml create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2e60e3e --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +build/ +dist/ +*.egg-info +__pycache__/ diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..5f662b3 --- /dev/null +++ b/LICENCE @@ -0,0 +1,9 @@ +Copyright (c) + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..6056f3f --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# kakushi + +> an implementation of [Freedesktop's Secrets API][1] for [himitsu][2] +> [kakushi (隠し) - being hidden; being concealed​][3] + +[1]: https://freedesktop.org/wiki/Specifications/secret-storage-spec/secrets-api-0.1.html +[2]: https://himitsustore.org/ +[3]: https://jisho.org/word/%E9%9A%A0%E3%81%97 diff --git a/kakushi/himitsu.py b/kakushi/himitsu.py new file mode 100644 index 0000000..e18d537 --- /dev/null +++ b/kakushi/himitsu.py @@ -0,0 +1,42 @@ +import socket +import os +import os.path +import typing + +class Client: + def __init__(self, addr = None): + if not addr: + addr = os.path.join(os.getenv('XDG_RUNTIME_DIR'), 'himitsu') + + self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + self.sock.connect(addr) + + def query(self, **kwargs): + return self._query(kwargs) + + def query_decrypt(self, **kwargs): + return self._query(kwargs, True) + + def _query(self, query: typing.Dict[str, str], decrypt: bool = False): + params = ['query'] + + if decrypt: + params.append('-d') + + for arg in query: + params.append(f'{arg}={query[arg]}') + + qs = ' '.join(params) + '\n' + + self.sock.send(qs.encode('utf-8')) + raw_res = self._read_raw_response() + return raw_res + + def _read_raw_response(self): + res = '' + while not '\nend\n' in res: + res += self.sock.recv(4096).decode('utf-8') + res = res.strip() + res_lines = res.splitlines() + res_lines.pop() + return res_lines diff --git a/kakushi/main.py b/kakushi/main.py new file mode 100644 index 0000000..bfeb7d1 --- /dev/null +++ b/kakushi/main.py @@ -0,0 +1,133 @@ +from pydbus import SessionBus +from pydbus.generic import signal +from gi.repository import GLib +import himitsu + +loop = GLib.MainLoop() +bus = SessionBus() +hiq = himitsu.Client() + + +class Collection(object): + ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ''' + + @property + def Items(self): + return [] + + Label = 'default' + Private = 'yes?' + Locked = False + Created = 0 + Modified = 0 + + ItemCreated = signal() + ItemDeleted = signal() + +class Service(object): + ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ''' + sessions = [] + + def OpenSession(self): + print('OpenSession') + pass + + def LockService(self): + pass + + def SearchCollections(self, fields): + print('SearchCollections', fields) + return ([], []) + + @property + def Collections(self): + return ['/org/freedesktop/secrets/collection/default'] + + DefaultCollection = '/org/freedesktop/secrets/collection/default' + + CollectionCreated = signal() + CollectionDeleted = signal() + CollectionChanged = signal() + +def entrypoint(): + bus.publish( + "org.freedesktop.secrets", Service(), + ('collection/default', Collection()) + ) + loop.run() + +if __name__ == '__main__': + entrypoint() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..f9b7418 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,23 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "kakushi" +version = "0.1.0" +authors = [ + {name = "Patrycja Rosa", email = "foss@ptrcnull.me"}, +] +description = "an implementation of Secrets API for himitsu" +readme = "README.md" +requires-python = ">=3.7" +license = {text = "BSD-2-Clause"} +classifiers = [ + "Programming Language :: Python :: 3", +] +dependencies = [ + "pydbus >= 0.6" +] + +[project.scripts] +kakushi = "kakushi.main:entrypoint" diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..6068493 --- /dev/null +++ b/setup.py @@ -0,0 +1,3 @@ +from setuptools import setup + +setup()