fermi-ad / acsys-python

Python module to access the Fermilab Control System
MIT License
8 stars 2 forks source link

Add SSL support #42

Open beauremus opened 2 years ago

beauremus commented 2 years ago

Here's an HTTPS implementation that seems like it could be useful for our socket communications. https://chaobin.github.io/2015/07/22/a-working-understanding-on-SSL-and-HTTPS-using-python/

beauremus commented 2 years ago

If this post can be believed this is a one-line change after importing the SSL module. This would be a good first issue. https://stackoverflow.com/questions/26851034/opening-a-ssl-socket-connection-in-python

potap75 commented 2 years ago

I'll take it, please!

rneswold commented 2 years ago

Thanks for volunteering, @potap75 !

potap75 commented 2 years ago

What should I use as an upstream master? v1.0.0rc6 ?

beauremus commented 2 years ago

Yes. That's correct.

potap75 commented 2 years ago

thank you!

potap75 commented 2 years ago

I keep getting: "fatal: branch 'master' does not exist"

potap75 commented 2 years ago

When I'm trying to setup a branch in PyCharm: git branch --set-upstream-to=upstream/v1.0.0rc6

beauremus commented 2 years ago

Yes. Branch master doesn't exist. The branches are labeled by major version so you want v1.x.

rneswold commented 2 years ago

Strange. We set v1.x to be the default branch so, when you check it out, I would have thought you would get that branch.

potap75 commented 2 years ago

This is what I get when I try to set a branch:

Screen Shot 2021-10-07 at 5 04 56 PM
potap75 commented 2 years ago

Anyways. Maybe I can contribute directly here:

import socket
import ssl

hostname = ''
context = ssl.create_default_context()

with socket.create_connection((hostname, 443)) as sock:
    with context.wrap_socket(sock, server_hostname=hostname) as ssock:
        print(ssock.version())

EDIT: Code highlighting

rneswold commented 2 years ago

Thank you for the contribution, @potap75.

We're using the async features of Python3 so our TCP socket is hidden in the Transport class. Looking at the 3.10 documentation, I see there's a chance that the asyncio library supports SSL sockets, if we choose the proper set-up options. Hopefully this also works for 3.6.

UPDATE: It looks like we can do something like this:

con_fut = loop.create_connection(lambda: self,
                                 host='acsys-proxy.fnal.gov',
                                 port=self.port,
                                 ssl=True)
rneswold commented 2 years ago

e56b8d6d2e3aaf96223fc13b6b034c0e7b0af1bb is the proposed change.

We're getting sslv3 handshake errors but, when I point the Python script to a non-DPM SSL server, this code connects. So @charlieking65 and I think it's a config issue on the proxy.