Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem/Solution: JSONRPC over HTTPS with self-signed certs #6

Closed
davidmcnabnz opened this issue Nov 25, 2020 · 2 comments
Closed

Problem/Solution: JSONRPC over HTTPS with self-signed certs #6

davidmcnabnz opened this issue Nov 25, 2020 · 2 comments

Comments

@davidmcnabnz
Copy link

aiohttp-rpc framework is great, but doesn't seem to provide easy way to support self-signed certs and sessions (or user-provided SSLContext objects, or user provided CA bundle files).

To do this, I've needed to subclass off JsonRpcClient, to:

  • accept a constructor arg to provide custom SSL info
  • override .connect() to use a subclass of aiohttp.ClientSession
  • override .call() to capture session key after successful login

Also, subclass aiohttp.ClientSession to:

  • override .post() to inject ssl keyword (for user-provided custom SSL info), plus session key header

With these mods, I can now use self-signed certs on the server and validate them in the client with an SSLContext based on the server's CA public key

This is working, but it took me a fair effort to get it solid. I'd recommend allowing for a constructor arg for aiohttp_rpc.JsonRpcServer to allow users to provide their own SSL objects, to cover for cases of private connections with self-signed certs.

I'm happy to rework the company-proprietary code I did for this and send in proof of concept if needed.

Cheers
David

@expert-m
Copy link
Owner

Hi, David! Thanks for the comment.

JsonRpcClient can take arguments for requests in the constructor.

class JsonRpcClient(BaseJsonRpcClient):
    def __init__(self,
                 url: str, *,
                 session: typing.Optional[aiohttp.ClientSession] = None,
                 **request_kwargs) -> None:
       ...

And you can provide additional arguments. For example:

sslcontext = ssl.create_default_context(cafile='/path/to/ca-bundle.crt')
sslcontext.load_cert_chain('/path/to/client/public/device.pem', '/path/to/client/private/device.key')

async with aiohttp_rpc.JsonRpcClient('http://0.0.0.0:8080/rpc', ssl=sslcontext) as rpc:
   ...

Unfortunately, this is not described in the documentation.

@expert-m
Copy link
Owner

expert-m commented Dec 4, 2020

I close this issue. You can write questions here or create a new issue if you have any.

@expert-m expert-m closed this as completed Dec 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants