pythonautobahn

Does Autobahn|Python[asyncio] support secure websockets?


Does the asyncio variant of Autobahn|Python support secure WebSockets? The docs on secure WebSockets with AutoBahn|Python only give a Twisted example: https://autobahn.readthedocs.io/en/latest/websocket/examples.html#secure-websocket


Solution

  • It does work. Here is an example of an asyncio component with secure websocket :

    import ssl
    from autobahn.asyncio.component import Component
    
    
    ssl_c = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
    ssl_c.load_verify_locations(cafile='my_ssl_key.pem')
    
    Component(
        transports={
                'type': 'websocket',
                'url': u'wss://127.0.0.1:8081/',
                'endpoint': {
                    'type': 'tcp',
                    'host': host,
                    'port': 8081,
                    'tls': ssl_c
                }
        },
        realm=u'realm1'
    )