Coverage for aiocoap/transports/tls.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

15 statements  

1# This file is part of the Python aiocoap library project. 

2# 

3# Copyright (c) 2012-2014 Maciej Wasilak <http://sixpinetrees.blogspot.com/>, 

4# 2013-2014 Christian Amsüss <c.amsuess@energyharvesting.at> 

5# 

6# aiocoap is free software, this file is published under the MIT license as 

7# described in the accompanying LICENSE file. 

8 

9""" 

10CoAP-over-TLS transport (early work in progress) 

11 

12Right now this is running on self-signed, hard-coded certificates with default 

13SSL module options. 

14 

15To use this, generate keys as with:: 

16 

17 $ openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 5 -nodes 

18 

19and state your hostname (eg. localhost) when asked for the Common Name. 

20""" 

21 

22from .tcp import TCPClient, TCPServer 

23 

24from aiocoap import COAPS_PORT 

25 

26class _TLSMixIn: 

27 _scheme = 'coaps+tcp' 

28 _default_port = COAPS_PORT 

29 

30class TLSServer(_TLSMixIn, TCPServer): 

31 @classmethod 

32 async def create_server(cls, bind, tman, log, loop, server_context): 

33 return await super().create_server(bind, tman, log, loop, _server_context=server_context) 

34 

35class TLSClient(_TLSMixIn, TCPClient): 

36 def _ssl_context_factory(self, hostinfo): 

37 c = self.credentials.ssl_client_context(self._scheme, hostinfo) 

38 c.set_alpn_protocols(["coap"]) 

39 return c