1#!/usr/bin/env python3
2
3# This file is part of the Python aiocoap library project.
4#
5# Copyright (c) 2012-2014 Maciej Wasilak <http://sixpinetrees.blogspot.com/>,
6#               2013-2014 Christian Amsüss <c.amsuess@energyharvesting.at>
7#
8# aiocoap is free software, this file is published under the MIT license as
9# described in the accompanying LICENSE file.
10
11import logging
12from aiocoap import oscore_sitewrapper
13import aiocoap.resource as resource
14import aiocoap
15import asyncio
16
17logging.basicConfig(level=logging.INFO)
18logging.getLogger("coap-server").setLevel(logging.DEBUG)
19
20def main():
21    # Resource tree creation
22    root = resource.Site()
23
24    root.add_resource(['.well-known', 'core'],
25            resource.WKCResource(root.get_resources_as_linkheader))
26
27    server_credentials = aiocoap.credentials.CredentialsMap()
28
29    root = oscore_sitewrapper.OscoreSiteWrapper(root, server_credentials)
30
31    protocol = asyncio.get_event_loop().run_until_complete(aiocoap.Context.create_server_context(root))
32
33    # Keys from IETF109 plug test: Rikard Test 2 Entity 1
34    server_credentials[":a"] = \
35            aiocoap.oscore.SimpleGroupContext(
36                    algorithm = aiocoap.oscore.algorithms[aiocoap.oscore.DEFAULT_ALGORITHM],
37                    hashfun = aiocoap.oscore.hashfunctions[aiocoap.oscore.DEFAULT_HASHFUNCTION],
38                    alg_countersign = aiocoap.oscore.Ed25519(),
39                    group_id = bytes.fromhex('DD11'),
40                    master_secret = bytes.fromhex('11223344556677889900AABBCCDDEEFF'),
41                    master_salt = bytes.fromhex('1F2E3D4C5B6A7081'),
42                    sender_id = bytes.fromhex('0A'),
43                    private_key = bytes.fromhex('397CEB5A8D21D74A9258C20C33FC45AB152B02CF479B2E3081285F77454CF347'),
44                    peers = {
45                        bytes.fromhex('51'): bytes.fromhex('2668BA6CA302F14E952228DA1250A890C143FDBA4DAED27246188B9E42C94B6D'),
46                        bytes.fromhex('52'): bytes.fromhex('5394E43633CDAC96F05120EA9F21307C9355A1B66B60A834B53E9BF60B1FB7DF'),
47                        bytes.fromhex('dc'): aiocoap.oscore.DETERMINISTIC_KEY,
48                        },
49                    )
50
51    asyncio.get_event_loop().run_forever()
52
53if __name__ == "__main__":
54    main()
55