Added Pymesh Security content

This commit is contained in:
Catalin Ioana
2019-09-02 18:18:32 +03:00
parent 57cc2722b3
commit 8d3efeb293
4 changed files with 69 additions and 3 deletions

View File

@@ -1252,8 +1252,8 @@ theme = "doc-theme"
[[menu.main]]
name = "Advanced Security Example"
url = "/pymesh/security-advanced"
identifier = "pymesh@security-advanced"
url = "/pymesh/security"
identifier = "pymesh@security"
parent = "pymesh"
weight = 50

View File

@@ -29,4 +29,4 @@ Pymesh solution works on all of our LoRa supporting development boards, the LoPy
* [Pymesh Micropython API](/firmwareapi/pycom/network/lora/pymesh)
* [Simple Example](/pymesh/lora-mesh)
* [Border Router Example](/pymesh/pymesh-br)
* [Advanced Security Example](/pymesh/security-advanced)
* [Advanced Security Example](/pymesh/security)

View File

@@ -8,15 +8,19 @@ aliases:
Pymesh micropython library is a set of scripts included (as frozen) in the Pymesh firmware binary release (Not yet released).
[Open-source on github](https://github.com/pycom/pycom-libraries/tree/master/lib/pymesh)
It allows users to use Pymesh in a few lines of code, as shown in the following code snippet.
```python
import pycom
import time
from _pymesh_config import PymeshConfig
from _pymesh import Pymesh
# stop LED heartbeat, because it will be used to indicate current Node role
pycom.heartbeat(False)
# read config file, or set default values
@@ -42,4 +46,27 @@ def new_message_cb(rcv_ip, rcv_port, rcv_data):
# ...
return
######################################################################################
# Adding current node as Border Router, with a normal priority and a message handler callback
pymesh.br_set(PymeshConfig.BR_PRIORITY_NORM, new_br_message_cb)
# remove Border Router function from current node
#pymesh.br_remove()
# send data for Mesh-external, basically to the BR
ip = "1:2:3::4"
port = 5555
pymesh.send_mess_external(ip, port, "Hello World")
def new_br_message_cb(rcv_ip, rcv_port, rcv_data, dest_ip, dest_port):
''' callback triggered when a new packet arrived for the current Border Router,
having destination an IP which is external from Mesh '''
print('Incoming %d bytes from %s (port %d), to external IPv6 %s (port %d)' %
(len(rcv_data), rcv_ip, rcv_port, dest_ip, dest_port))
print(rcv_data)
# user code to be inserted, to send packet to the designated Mesh-external interface
# ...
return
```

View File

@@ -0,0 +1,39 @@
---
title: "Pymesh Security"
aliases:
- pymesh/security
---
Pymesh supports several levels of encryption.
## Mesh Masterkey
Each node (Lopy/Fipy) initializes Pymesh with a 128 bits Masterkey. This is used in:
* authentication
* a Node which does not have the Masterkey of the peer, can't connect to peer's Pymesh;
* further, it will create its own Pymesh, using its Masterkey, so it will become the Leader of a new Mesh network.
* encryption
* all traffic inside Pymesh is encrypted with Masterkey
* encryption is AES-128bits.
## End to end encryption
End to end encryption is used when Node A wants to communicate securely/secretly with Node B. The data packets will be routed by other nodes, but the actual message can't be decrypted by any middle Node.
This encryption can be used even for communicating between Nodes that are not in the same mesh, as message is encrypted until destination. For example, in the next picture, Node A can communicate encrypted with Node C.
The challenge is in distributing the keys used for encryption(decryption), this is
![](../../.gitbook/assets/pymesh_security.png)
### Symmetric encryption
Symmetric-key algorithms are algorithms for cryptography that use the same cryptographic keys for both encryption of plaintext and decryption of ciphertext. More info could be checked on [Symmetric-key algorithm](https://en.wikipedia.org/wiki/Symmetric-key_algorithm).
A micropython example script can be seen [here](../../firmwareapi/pycom/aes.md) using AES 128, 192 or 256 bits keys (`crypto.AES` class).
### Asymmetric encryption
Public-key cryptography, or asymmetric cryptography, is a cryptographic system that uses pairs of keys: public keys which may be disseminated widely, and private keys which are known only to the owner. More info could be checked on [Public-key cryptography](https://en.wikipedia.org/wiki/Public-key_cryptography).
A micropython example script can be seen [here](../../firmwareapi/micropython/ucrypto.md) using RSA 2048 bits keys (`crypto.rsa_encrypt()` method).