omemo-signatures/sign.py

54 lines
1.3 KiB
Python
Executable File

#! /usr/bin/env python3
# Run without arguments for help message
def help():
print("Sign a message with your OMEMO key")
print(" sign.py OMEMO.db \"MESSAGE\"")
import sys
# Gajim plugins have garbage debug output, remove it
prev_output = sys.stderr
sys.stderr = open("/dev/null", 'w')
# omemo module is copied from gajim-plugins, assuming axolotl is already installed on system
from omemo.backend.liteaxolotlstore import LiteAxolotlStore, _convert_identity_key as convert
from axolotl.ecc.curve import Curve
# Reestablish STDERR output so we don't eat errors
sys.stderr = prev_output
# Feed me a private key
def sign(key, message):
return Curve.calculateSignature(key, bytes(message, "utf-8")).hex()
# Feed me a public key
def verify(key, message, sig):
return Curve.verifySignature(key, bytes(message, "utf-8"), bytes.fromhex(sig))
args = len(sys.argv)
if args == 1:
help()
exit(0)
elif args < 3:
help()
exit(2)
try:
db = LiteAxolotlStore(sys.argv[1], None)
except:
print("Failed to load database from " + sys.argv[1])
exit(1)
keypair = db.getIdentityKeyPair()
# Now let's check message from CLI args and sign it
mymessage = sys.argv[2]
try:
sig = sign(keypair.getPrivateKey(), mymessage)
except:
print("Failed to sign message with OMEMO key!")
exit(3)
print(sig)