aboutsummaryrefslogtreecommitdiff
path: root/gpg_websocket.py
diff options
context:
space:
mode:
authorPasha <pasha@member.fsf.org>2023-12-17 19:37:05 +0000
committerPasha <pasha@member.fsf.org>2023-12-17 19:37:05 +0000
commit551f957d57cb930bfcfd46e763a6556b2e50ec72 (patch)
treec6c96c79994bf9be8cb78d2997098f9c5ab034c5 /gpg_websocket.py
downloadgnupg_over_web-551f957d57cb930bfcfd46e763a6556b2e50ec72.tar.gz
gnupg_over_web-551f957d57cb930bfcfd46e763a6556b2e50ec72.tar.bz2
initial commit
Diffstat (limited to 'gpg_websocket.py')
-rw-r--r--gpg_websocket.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/gpg_websocket.py b/gpg_websocket.py
new file mode 100644
index 0000000..2a18eb1
--- /dev/null
+++ b/gpg_websocket.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+
+# gpg_websocket - websocket server for gpg_over_web
+#
+# Copyright (C) 2023 Salahuddin <salahuddin@member.fsf.org>
+#
+# This program is free software: you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with this
+# program. If not, see <https://www.gnu.org/licenses/>.
+
+#
+# There are two different gnupg bindings. This script is using python3-gpg
+#
+# python3-gpg - Python interface to the GPGME GnuPG encryption library (Python 3)
+# python3-gnupg - Python wrapper for the GNU Privacy Guard (Python 3.x)
+
+
+import gpg
+import asyncio
+from websockets.server import serve
+
+async def gpg_over_web(websocket):
+ ctx = gpg.Context()
+ async for message in websocket:
+ if len(message) == 0:
+ return ""
+ try:
+ plaintext, result, verify_result = ctx.decrypt(message.encode())
+ except gpg.errors.GPGMEError as e:
+ plaintext = "--- gpg error ---".encode()
+ print(e)
+ await websocket.send(plaintext.decode("utf-8"))
+
+async def main():
+ async with serve(gpg_over_web, "localhost", 8765):
+ await asyncio.Future()
+
+asyncio.run(main())