Open SignorMercurio opened 1 year ago
I don't know if this is the proper way but based on the code on contrib/oscore-plugtest
I got OSCORE working using OscoreSiteWrapper
. Using the following on the server in the above example.
from aiocoap.oscore_sitewrapper import OscoreSiteWrapper
...
async def main():
resource = SensorResource()
site = Site()
site.add_resource(('sensor_data',), resource)
credentials = aiocoap.credentials.CredentialsMap()
credentials.load_from_dict({
":client1": {"oscore": {"contextfile": "server/from-client1/"}}
})
site = OscoreSiteWrapper(site, credentials)
server = await Context.create_server_context(site, bind=('localhost', 5683))
print("Sensor server is running...")
await asyncio.sleep(3600)
Not sure how to check which transport is being used here but the network requests seem to be using OSCORE. I'd also like to know if there is a suggested way of setting up a server :smile:
Background
Thanks for the great library! I'm trying to implement a simple client/server communication demo with OSCORE, and have already read the docs here: https://aiocoap.readthedocs.io/en/latest/stateofoscore.html. However, the docs only include instructions on using the CLIs rather than code examples, which would be very helpful if added to the docs.
Attempts
So I tried to write the demo code for the client:
As well as the server:
The OSCORE context here is exactly the same with the docs, but I got an error
No Object-Security option present
. After some debugging, I believe the problem here is that the communication is usingsimple6
transport rather than the expectedoscore
transport.I'm aware that
simple6
is used for platforms like OSX so I switched to Linux, and it's still usingudp6
, notoscore
. I've also tried settingrequest1.opt.object_security = b''
, which resolves the above error but still usingsimple6
transport. In addition, I tried using the provided CLIsclient
andfileserver
and got the sameNo Object-Security option present
error with the samesimple6
transport.I wonder if there's anything wrong with the above code. I'll be happy to contribute a correct code example for simple client/server communication with OSCORE to the current docs.
Output of
python3 -m aiocoap.cli.defaults