You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I made a fork/branch to get the library working with Python 3.10. It works but as there is no documentation, I think I'm doing something wrong in my usage.
importpotrfrompotr.compatcryptoimportDSAKey# Custom Context classclassMyContext(potr.context.Context):
def__init__(self, account, peername):
super(MyContext, self).__init__(account, peername)
defgetPolicy(self, key):
returnself.user.getPolicy(key)
definject(self, msg, appdata=None):
print(f"{self.user.name} -> {self.peer}: {msg}")
ifappdata:
try:
decrypted_msg, tlvs=appdata.receiveMessage(msg)
ifdecrypted_msg:
print(f"{appdata.user.name} received decrypted message: {decrypted_msg}")
exceptpotr.context.NotEncryptedError:
passexceptpotr.context.NotOTRMessage:
passdefhandleQuery(self, message, appdata=None):
if2inmessage.versionsandself.getPolicy('ALLOW_V2'):
self.authStartV2(appdata=appdata)
elif1inmessage.versionsandself.getPolicy('ALLOW_V1'):
self.authStartV1(appdata=appdata)
else:
print(f"{self.user.name} received a non-OTR message: {message.msg.decode('utf-8')}")
# Custom Account class with required methodsclassMyAccount(potr.context.Account):
contextclass=MyContextdef__init__(self, *args, **kwargs):
super(MyAccount, self).__init__(*args, **kwargs)
self.policy= {
'ALLOW_V2': True,
'ALLOW_V1': False,
'REQUIRE_ENCRYPTION': True,
'SEND_TAG': True,
}
defloadPrivkey(self):
returnDSAKey.generate()
defsavePrivkey(self):
passdefsaveTrusts(self):
passdefgetPolicy(self, key):
returnself.policy.get(key, False)
# Initialize accounts for Alice and Bobalice_account=MyAccount('alice@example.com', 'XMPP', maxMessageSize=1024)
bob_account=MyAccount('bob@example.com', 'XMPP', maxMessageSize=1024)
# Initialize contexts for Alice and Bobalice_context=alice_account.getContext('bob@example.com')
bob_context=bob_account.getContext('alice@example.com')
# Alice sends an OTR query message to Bobalice_query=alice_account.getDefaultQueryMessage(alice_context.getPolicy)
alice_context.inject(alice_query, appdata=bob_context)
# Wait for the AKE to completeimporttimetime.sleep(5)
# Alice and Bob can now send encrypted messages to each otherencrypted_msg=alice_context.sendMessage(potr.context.FRAGMENT_SEND_ALL, b"Hello, Bob!", appdata=bob_context)
decrypted_msg, tlvs=bob_context.receiveMessage(encrypted_msg)
ifdecrypted_msg:
print(f"Bob received decrypted message: {decrypted_msg}")
encrypted_msg=bob_context.sendMessage(potr.context.FRAGMENT_SEND_ALL, b"Hello, Alice!", appdata=alice_context)
decrypted_msg, tlvs=alice_context.receiveMessage(encrypted_msg)
ifdecrypted_msg:
print(f"Alice received decrypted message: {decrypted_msg}")
# Alice and Bob can disconnect the OTR sessionalice_context.disconnect()
bob_context.disconnect()
which prints:
alice@example.com -> bob@example.com: b'?OTRv2?\nI would like to start an Off-the-Record private conversation. However, you do not have a plugin to support that.\nSee https://otr.cypherpunks.ca/ for more information.'
bob@example.com -> alice@example.com: b'?OTR:AAICAAAAxKgjXJiCdN3p76/REwybuA3kWoZa5QOxuYsaZbLqO+pIfEDSkD1gUWGerdyj6ikELK0QArEcrhfQhvuw7OsfrCFujruX9AoNCglTIG5LLcU5skElWOk+DZQ1dunSMwn0E9BVGFCFfCtvXkjyESMwS2rU0LIR4topbdp9HLRNnJizNKWlpwO4Q1AxNqlF8OY9i265tqHj29EetAtcR2zx3P3dEdM3+aiJcZxoJ8h4YyKASmtD1QDHWR3D6JmPK3JQSN90DlkAAAAg1E8Re3oNsmtK6WRQtl3AMd6nPmi24q/F84ktgmIP90M=.'
bob@example.com -> alice@example.com: b'?OTR:AAICAAAAxIr+WZ5U1YFXf5KZ/IF+Exw5S0ENvJYEEq22rh2iQNldbB3QFWHmwr2PiymJ5kWeuj4XXDFwRM9Y08dzrGqq238aDeCMkGP1dIZ3O9s7Q/k3Pt9+pN9Csb3wbu9xUVFt3blSI5VoR4nVcAJrwlFcX4QpH6OWhmqqm6DDt/SoqXBeVGoddbhTGVQLEMcsjelXwmYeKjqxb3kR3ihgCli8b4/69rnK1/UiX8V5Wqp2FKd80uYH+XSH2vtFC9/4qWbdcjYBkC8AAAAgEagK0yJzkHwg7DQKF3nSL8IPGzD7YkZ5NwcIn+qk2oI=.'
alice@example.com -> bob@example.com: b'?OTR:AAICAAAAxGvDVCQvO9BDPzt916H400KtSjrFvic8qhkMyykSkCMHMNJL9yVUEsuqQqxSqu4CsqKmrwQekfGYMxmQF+u+ssuJJnJ4omXUGk1tjFvOgrG2677/rYSY4t7Cco96Ram9j3/DtKWrpc9V+jn7f0R8Gnf+LIrQtxnSOXAvTCD4BEGX25f72d5RGlGJZkb1ZsmV8j7Ov662P+G9PpEg+4VZhGXN1Y/YFmDAwuk4Sw4CK74Ge9Q9KEy+KWRKu3lowSEi96iBYrkAAAAgFnqzNfHwNx5UmHSXx7Fm0H6cNEUTKoZ9ioLLjKUIask=.'
Why is decrypted_msg always None? I must be missing something.
The text was updated successfully, but these errors were encountered:
I made a fork/branch to get the library working with Python 3.10. It works but as there is no documentation, I think I'm doing something wrong in my usage.
Installing my fork/branch:
pip install "git+https://github.com/bitnom/pure-python-otr.git@python3"
My example:
which prints:
Why is
decrypted_msg
alwaysNone
? I must be missing something.The text was updated successfully, but these errors were encountered: