Home/Support/Support Forum/How to use SSL with the digi.xbee.xsocket module?
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

How to use SSL with the digi.xbee.xsocket module?

0 votes
TL;DR: I am following the example at https://github.com/digidotcom/xbee-python/blob/master/examples/communication/socket/SocketTCPClientSample/SocketTCPClientSample.py to POST data to our server but cannot figure out how to use SSL with it.

I have an XBIB-U-DEV board with an embedded LTE Cat 1 cellular modem. This modem is currently connected through USB to a Raspberry Pi 3 running Kali Linux. I want to be able to run a python script on the Kali OS that will Try a `requests.post` to our server with a fallback from ethernet to wifi to cellular.

I was provided Digi's SocketTCPClientSample.py example (link in TL;DR) by a colleague and have been able to adapt that to our needs with one exception: making the call over SSL. I cannot simply `ssl.wrap_socket` as I am using `xsocket.socket` per the example. Attempting to do so just reveals that an `xsocket.socket` is not a `socket` with the error of "AttributeError: 'socket' object has no attribute 'getsockopt'".

- I do not have a static IP which limits options a bit.
- Yes, the cellular contract is active; I can run the original example without ssl just fine.
- When I make the POST with cellular and thus no SSL, I receive a response of 400 Bad Request with "The plain HTTP request was sent to HTTPS port" but using wifi with with the same exact payload succeeds with 200 OK.
asked May 8, 2020 in Other/Legacy by cory.schooley New to the Community (4 points)

Please log in or register to answer this question.

2 Answers

0 votes
Best answer
For anyone wanting to know what was needed for this...

Can't believe I missed this in the docs as well (facepalm moment)...

In the SocketTCPClientSample.py, I just needed to add the protocol to the socket creation.

Instead of simply `with xsocket.socket(device) as sock:`...
Change to `with xsocket.socket(device, IPProtocol.TCP_SSL) as sock:`.
answered May 11, 2020 by cory.schooley New to the Community (4 points)
selected May 12, 2020 by cory.schooley
0 votes
I don't know of a Python example but there is a Micro Python example at http://cms.digi.com/resources/documentation/digidocs/90002219/#reference/r_ussl.htm?Highlight=SSL
answered May 8, 2020 by mvut Veteran of the Digi Community (13,684 points)
Unfortunately, that does not help me much as the socket I am creating is  on the host system using `xsocket` and `CellularDevice` from the `digi.xbee` package.

Unless there is a way on the modem to upload the certs and tell it to always use `ussl` for all socket connections but I am not seeing how that is practical as the sockets are being created on the host system.
Yes, you can upload certificates to the radio and set the radio to use SSL.  That is part of what that section of the document shows.