summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMaxime “pep” Buquet <pep@bouah.net>2022-03-18 15:22:52 +0100
committerMaxime “pep” Buquet <pep@bouah.net>2022-03-19 10:31:34 +0100
commitbde5aaaf3e197f1fb71bbdabbeb597d8e8f9b4a7 (patch)
tree5105c76c5025aa4b7432ef29a77736217a807664 /examples
parent7222ade0dd252380fb158bb9b1ca1fefec3899a5 (diff)
downloadslixmpp-bde5aaaf3e197f1fb71bbdabbeb597d8e8f9b4a7.tar.gz
slixmpp-bde5aaaf3e197f1fb71bbdabbeb597d8e8f9b4a7.tar.bz2
slixmpp-bde5aaaf3e197f1fb71bbdabbeb597d8e8f9b4a7.tar.xz
slixmpp-bde5aaaf3e197f1fb71bbdabbeb597d8e8f9b4a7.zip
examples/http_upload.py: Add --encrypt parameter to send encrypted files
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/http_upload.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/examples/http_upload.py b/examples/http_upload.py
index cac8fc7e..7f1c44bc 100755
--- a/examples/http_upload.py
+++ b/examples/http_upload.py
@@ -7,6 +7,7 @@
from typing import Optional
+import sys
import logging
from pathlib import Path
from getpass import getpass
@@ -32,20 +33,25 @@ class HttpUpload(slixmpp.ClientXMPP):
recipient: JID,
filename: Path,
domain: Optional[JID] = None,
+ encrypted: bool = False,
):
slixmpp.ClientXMPP.__init__(self, jid, password)
self.recipient = recipient
self.filename = filename
self.domain = domain
+ self.encrypted = encrypted
self.add_event_handler("session_start", self.start)
async def start(self, event):
log.info('Uploading file %s...', self.filename)
try:
- url = await self['xep_0363'].upload_file(
- self.filename, domain=self.domain, timeout=10
+ upload_file = self['xep_0363'].upload_file
+ if self.encrypted:
+ upload_file = self['xep_0454'].upload_file
+ url = await upload_file(
+ self.filename, domain=self.domain, timeout=10,
)
except IqTimeout:
raise TimeoutError('Could not send message in time')
@@ -90,6 +96,10 @@ if __name__ == '__main__':
parser.add_argument("--domain",
help="Domain to use for HTTP File Upload (leave out for your own server’s)")
+ parser.add_argument("-e", "--encrypt", dest="encrypted",
+ help="Whether to encrypt", action="store_true",
+ default=False)
+
args = parser.parse_args()
# Setup logging.
@@ -105,17 +115,27 @@ if __name__ == '__main__':
if domain is not None:
domain = JID(domain)
+ if args.encrypted:
+ print(
+ 'You are using the --encrypt flag. '
+ 'Be aware that the transport being used is NOT end-to-end '
+ 'encrypted. The server will be able to decrypt the file.',
+ file=sys.stderr,
+ )
+
xmpp = HttpUpload(
jid=args.jid,
password=args.password,
recipient=JID(args.recipient),
filename=Path(args.file),
domain=domain,
+ encrypted=args.encrypted,
)
xmpp.register_plugin('xep_0066')
xmpp.register_plugin('xep_0071')
xmpp.register_plugin('xep_0128')
xmpp.register_plugin('xep_0363')
+ xmpp.register_plugin('xep_0454')
# Connect to the XMPP server and start processing XMPP stanzas.
xmpp.connect()