首先,请使用他人现有的XMPP 库,而不要编写自己的XMPP 库。已经有很多了。从SleekXMPP开始。
要回答您的问题,请在要执行Start-TLS时调用ssl.wrap_socket。例如:
import socket
import ssl
sock = socket.create_connection(("example.com", 5222))
sock.write("""<stream:stream
to='example.com'
version='1.0'
xml:lang='en'
xmlns='jabber:client'
xmlns:stream='http://etherx.jabber.org/streams'>""")
sock.recv(1000) # reads the stream:stream and stream:features. Obviously bad code, to get the point accross
sock.write("<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>")
sock.recv(1000) # read the proceed
ssl_sock = ssl.wrap_socket(sock)
ssl_sock.write("""<stream:stream
to='example.com'
version='1.0'
xml:lang='en'
xmlns='jabber:client'
xmlns:stream='http://etherx.jabber.org/streams'>""")
Run Code Online (Sandbox Code Playgroud)
等等。
| 归档时间: |
|
| 查看次数: |
1319 次 |
| 最近记录: |