XMPPPY with Openfire - python

I'm trying to simply connect XMPPPY to Openfire, send a message, then close. The problem is that I keep getting
(Python 2.6)
import xmpp
pwd = "password"
jid=xmpp.protocol.JID("testuser#localhost")
cl=xmpp.Client(jid.getDomain()) #which translates to 'localhost'
cl.connect()
DEBUG: socket start Plugging <xmpp.transports.TCPsocket instance at 0x190ea1b8> into <xmpp.client.Client instance at 0x190e5320>
DEBUG: socket start Successfully connected to remote host ('localhost', 5222)
DEBUG: dispatcher start Plugging <xmpp.dispatcher.Dispatcher instance at 0x190ea2d8> into <xmpp.client.Client instance at 0x190e5320>
cl.auth(jid.getNode(),pwd) #translates to 'testuser' / 'password'
DEBUG: sasl error Failed SASL authentification: <not-authorized />
DEBUG: sasl stop Plugging <xmpp.auth.SASL instance at 0x190f0320> out of <xmpp.client.Client instance at 0x190e5320>.
I'm 100% sure that the username and password are correct as I've tried many times and can connect via Spark.
Is there a setting somewhere that I'm missing / has anyone has success with this?

lookup your jid format
jid=xmpp.protocol.JID("testuser#localhost")
the xmpp server name should same as name after '#'
check the xmpp server name at http://localhost:9090/index.jsp

Related

Connect to a host that doesn't answer to ping

I am trying to connect to a smtp port to automatically send emails through it. The problem is that when trying to connect to it with python smtplib it gives an error that it can't connect to the host. When trying to run nmap with the command
nmap -T4 -p 25,587,465
I get the following output:
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 2.12 seconds
When I add the -Pn option I get the following output:
Host is up.
PORT STATE SERVICE
25/tcp filtered smtp
465/tcp filtered smtps
587/tcp filtered submission
The python script that I have used is:
import smtplib, ssl
port = 465
password = "password"
email = "my#mail"
hostname = "hostname"
context = ssl.create_default_context()
with smtplib.SMTP_SSL(hostname, port, context=context) as server:
server.login(email, password)
And this is the error I get:
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
I am running the code on a Windows 10 machine and using Python 3.7.5.
Is there any way for me to connect to one of the email ports and send emails through it through python or c/c++?

Errno 10060 A connection attempt failed

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST='smtp.gmail.com'
EMAIL_PORT=465
EMAIL_HOST_USER = 'yogi'
EMAIL_HOST_PASSWORD = '###'
DEFAULT_EMAIL_FROM = 'yogi#gmail.com'
above are the settings for django core mail module. I am using its send_mail to send mails to users. When i try to build the program with the gmail smtp it throws the following error
'Errno 10060 A connection attempt failed because the connected party
did not properly respond after a period of time, or established
connection failed because connected host has failed to respond'.
I am doing this in my company and so it has proxy settings. I have given the proxy credentials in .condarc settings file. But still the connection timeout error. Do i need to set the proxy settings somewhere else or let me know where i am going wrong. ?
As far as I know django does not detect any SMTP proxy settings from anaconda configuration files. You can overcome this by manually building a connection.
Notice that send_mail , has an option parameter for a connection. You get one by calling mail.get_connection now you need to wrap it around sockspi
see Python smtplib proxy support and Python send email behind a proxy server for further details.

How do I access pyftpdlib FTPS server on Amazon EC2?

I am trying to create a simple FTPS server on my Ubuntu Amazon EC2 instance using the Python library pyftpdlib.
Here is the code straight from the documentation:
#!/usr/bin/env python
"""
An RFC-4217 asynchronous FTPS server supporting both SSL and TLS.
Requires PyOpenSSL module (http://pypi.python.org/pypi/pyOpenSSL).
"""
from pyftpdlib.servers import FTPServer
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.contrib.handlers import TLS_FTPHandler
import os
def main():
authorizer = DummyAuthorizer()
authorizer.add_user('ubuntu', '*****', os.getcwd(), perm='elradfmw')
authorizer.add_anonymous('.')
handler = TLS_FTPHandler
handler.certfile = 'keycert.pem'
handler.authorizer = authorizer
handler.masquerade_address = '52.23.244.142'
# requires SSL for both control and data channel
handler.tls_control_required = True
handler.tls_data_required = True
handler.passive_ports = range(60000, 60099)
server = FTPServer(('', 21), handler)
server.serve_forever()
if __name__ == '__main__':
main()
When I run the script on my Amazon EC2 instance and when I try to connect remotely using FileZilla, I get:
Status: Connecting to 52.23.244.142:21...
Status: Connection established, waiting for welcome message...
Response: 220 pyftpdlib 1.4.0 ready.
Command: AUTH TLS
Response: 234 AUTH TLS successful.
Status: Initializing TLS...
Status: Verifying certificate...
Command: USER ubuntu
Status: TLS/SSL connection established.
Response: 331 Username ok, send password.
Command: PASS *****
Response: 230 Login successful.
Command: OPTS UTF8 ON
Response: 501 Invalid argument.
Command: PBSZ 0
Response: 200 PBSZ=0 successful.
Command: PROT P
Response: 200 Protection set to Private
Command: OPTS MLST type;perm;size;modify;unix.mode;unix.uid;unix.gid;
Response: 200 MLST OPTS type;perm;size;modify;unix.mode;unix.uid;unix.gid;
Status: Connected
Status: Retrieving directory listing...
Command: PWD
Response: 257 "/" is the current directory.
Command: TYPE I
Response: 200 Type set to: Binary.
Command: PASV
Response: 227 Entering passive mode (52,23,244,142,174,172).
Command: MLSD
Response: 150 File status okay. About to open data connection.
Error: Connection timed out
Error: Failed to retrieve directory listing
I think I am missing something. Can I get some help?
Your server must present its external IP address in the response to the PASV command. You instead present an internal IP address within the EC2 private network, to which the FileZilla obviously cannot connect to.
While FileZilla can workaround that:
Server sent passive reply with unroutable address. Using server address instead.
other FTP clients (like the Windows command-line ftp.exe) cannot.
Use the handler.masquerade_address to configure the external IP address:
handler.masquerade_address = '52.23.244.142'
FileZilla cannot connect to the port 50048 (195 << 8 + 128). You have probably not opened ports in an FTP passive mode port range in the EC2 firewall.
See Setting up FTP on Amazon Cloud Server (particularly section "Step #2: Open up the FTP ports on your EC2 instance" in the best answer).
To avoid opening whole unprivileged port range, limit the FTP server to use a smaller port range using handler.passive_ports:
handler.passive_ports = range(60000, 60099)
For a general information see my article about the network setup in respect to FTP passive (and active) connection modes.

Tornado WebSocketHandler won't respond to SSL request

I have a Tornado HTTPServer initialized like so:
ssl_options = {
"certfile": "mycert.crt",
"keyfile": "mykey.key"
}
server = tornado.httpserver.HTTPServer(application, xheaders=True,
ssl_options=ssl_options)
It has a WebSocketHandler with an open() method.
When I attempt to open a secure websocket connection via Javascript from the Chrome 30 console, like
var sock = new WebSocket("wss://localhost:9001/mywebsocket");
the connection does not open successfully, there is no log output, and the WebSocketHandler's open() is not called.
How can I open and maintain a secure (SSL) WebSocket connection to a Javascript client in Tornado?
Attempting an insecure connection, like
var sock = new WebSocket("ws://localhost:9001/mywebsocket");
results in the following error output in the Tornado log:
2013-10-08 13:59:55,305 tornado.general 820 : SSL Error on 8 ('192.168.149.27', 62851): [Errno 1] _ssl.c:490: error:1407609C:SSL routines:SSL23_GET_CLIENT_HELLO:http request
Also in this case, the connection is not opened successfully and open() isn't called.
Additional info: The number after the IP in the error message (62851 in the above example) increases with every request, secure or otherwise. I don't know what that number is but it does indicate that the request is at least getting to the server.
Also, removing ssl_options from the constructor and making insecure (ws://) requests to the server fixes the issue.
The certificate being used is self-signed. To communicate with an HTTP endpoint of the server via curl, I had to use the --insecure flag.
If you're starting the connection from the javascript console, the browser doesn't have a chance to show you the self-signed certificate warning and give you a chance to accept it. If you go to https://localhost:9001 first and accept the certificate there, does it work?

xmpp with python: xmpp.protocol.InvalidFrom: (u'invalid-from', '')

cl = xmpp.Client('myserver.com')
if not cl.connect(server=('mysefver.com',5223)):
raise IOError('cannot connect to server')
cl.RegisterHandler('message',messageHandler)
cl.auth('myemail#myserver.com', 'mypassword', 'statusbot')
cl.sendInitPresence()
msgtext = formatToDo(cal, 'text')
message = xmpp.Message('anotheremail#myserver.com', msgtext)
message.setAttr('type', 'chat')
cl.send(message)
I get the following error message when I try to run it:
xmpp.protocol.InvalidFrom: (u'invalid-from', '')
Why is this happening :(
From the XMPP protocol specification:
If the value of the 'from'
address does not match the hostname represented by the Receiving
Server when opening the TCP connection (or any validated domain
thereof, such as a validated subdomain of the Receiving Server's
hostname or another validated domain hosted by the Receiving Server),
then the Authoritative Server MUST generate an stream
error condition and terminate both the XML stream and the underlying
TCP connection.
which basically means, that if the sender is not recognized by the xmpp-server, it'll reply with this message. XMPP supplies a registration mechanism: xmpp.features.register

Categories