xi-keyring

simple and extensible alternative for gnome-keyring
git clone https://git.ce9e.org/xi-keyring.git

commit
1d2fba14b56e0b1484c7976ea99e7a895b000906
parent
38452867fe097b470d00951fbe0c3ac194ca3322
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2026-05-24 15:36
add socket client

Diffstat

M PKGBUILD 1 +
A scripts/socket_client.py 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++

2 files changed, 58 insertions, 0 deletions


diff --git a/PKGBUILD b/PKGBUILD

@@ -20,4 +20,5 @@ package() {
   20    20 	install -Dm 644 system/systemd.service "$pkgdir/usr/lib/systemd/user/xi-keyring.service"
   21    21 	install -Dm 644 system/systemd.socket "$pkgdir/usr/lib/systemd/user/xi-keyring.socket"
   22    22 	install -Dm 644 system/portal "$pkgdir/usr/share/xdg-desktop-portal/portals/xi-keyring.portal"
   -1    23 	install -Dm 755 scripts/socket_client.py "$pkgdir/usr/bin/xikeyring"
   23    24 }

diff --git a/scripts/socket_client.py b/scripts/socket_client.py

@@ -0,0 +1,57 @@
   -1     1 #!/usr/bin/env python3
   -1     2 
   -1     3 import argparse
   -1     4 import json
   -1     5 import os
   -1     6 import socket
   -1     7 import sys
   -1     8 from getpass import getpass
   -1     9 from pathlib import Path
   -1    10 
   -1    11 
   -1    12 def get_runtime_dir():
   -1    13     return Path(os.environ['XDG_RUNTIME_DIR'])
   -1    14 
   -1    15 
   -1    16 def parse_args():
   -1    17     parser = argparse.ArgumentParser('xikeyring')
   -1    18     parser.add_argument('method', choices=['get', 'set', 'del'])
   -1    19     parser.add_argument('service')
   -1    20     parser.add_argument('username')
   -1    21     parser.add_argument(
   -1    22         '--socket',
   -1    23         type=Path,
   -1    24         default=get_runtime_dir() / 'xi.portal.Secret',
   -1    25     )
   -1    26     return parser.parse_args()
   -1    27 
   -1    28 
   -1    29 def call(sock, msg):
   -1    30     sock.send(json.dumps(msg).encode('utf-8'))
   -1    31     chunk = sock.recv(1024)  # TODO: buffer
   -1    32     reply = json.loads(chunk)
   -1    33     if 'error' in reply:
   -1    34         print(reply['error'], file=sys.stderr)
   -1    35         sys.exit(1)
   -1    36     return reply
   -1    37 
   -1    38 
   -1    39 args = parse_args()
   -1    40 sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
   -1    41 sock.connect(str(args.socket))
   -1    42 query = {
   -1    43     'username': args.username,
   -1    44     'service': args.service,
   -1    45     'application': 'xikeyring',
   -1    46 }
   -1    47 try:
   -1    48     if args.method == 'get':
   -1    49         reply = call(sock, {'method': 'get', 'query': query})
   -1    50         print(reply['secret'])
   -1    51     elif args.method == 'set':
   -1    52         secret = getpass()
   -1    53         call(sock, {'method': 'set', 'query': query, 'secret': secret})
   -1    54     elif args.method == 'del':
   -1    55         call(sock, {'method': 'del', 'query': query})
   -1    56 finally:
   -1    57     sock.close()