From 94ccd7d968cf604ae20fb73ff5b92ee2bf025c76 Mon Sep 17 00:00:00 2001 From: Lateefah Bello <2019cinnamon@gmail.com> Date: Thu, 17 Jun 2021 17:18:07 +0100 Subject: [PATCH] chapter 5 and 6 (#86) * Chapter two(lesson one) commit * Update README.md * Update pi-temp.md * Update virtual-device-temp.md * fixes * fixes * Update README.md * chapter two(lesson 2) * Update README.md * Chapter two (lesson three) * changed images * chapter two (lesson 4) * Update README.md * Update wio-terminal-connect-hub.md * Update wio-terminal-connect-hub.md * Update wio-terminal-connect-hub.md * Update wio-terminal-connect-hub.md * chapter 5 and 6 * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * fixed typos Co-authored-by: Jim Bennett --- .../virtual-device-sensor.md | 2 +- .../lessons/4-connect-internet/README.md | 2 +- .../README.md | 21 +++++++++++++++++-- .../6-keep-your-plant-secure/README.md | 10 ++++----- .../single-board-computer-x509.md | 4 +++- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/1-getting-started/lessons/3-sensors-and-actuators/virtual-device-sensor.md b/1-getting-started/lessons/3-sensors-and-actuators/virtual-device-sensor.md index 930c4e9..7259032 100644 --- a/1-getting-started/lessons/3-sensors-and-actuators/virtual-device-sensor.md +++ b/1-getting-started/lessons/3-sensors-and-actuators/virtual-device-sensor.md @@ -95,7 +95,7 @@ Program the device. * Check the *Random* checkbox, and enter a *Min* and *Max* value, then select the **Set** button. Every time the sensor reads a value, it will read a random number between *Min* and *Max*. - The values you set will be output to in the console. Change the *Value* or the *Random* settings to make the value change. + The values you set will be output to the console. Change the *Value* or the *Random* settings to make the value change. ```output (.venv) ➜ GroveTest python3 app.py diff --git a/1-getting-started/lessons/4-connect-internet/README.md b/1-getting-started/lessons/4-connect-internet/README.md index 72451c8..46f35e0 100644 --- a/1-getting-started/lessons/4-connect-internet/README.md +++ b/1-getting-started/lessons/4-connect-internet/README.md @@ -198,7 +198,7 @@ Configure a Python virtual environment and install the MQTT pip packages. source ./.venv/bin/activate ``` -1. Once the virtual environment has been activated, the default `python` command will run the version of Python that was used to create the virtual environment. Run the following to get this version: +1. Once the virtual environment has been activated, the default `python` command will run the version of Python that was used to create the virtual environment. Run the following to get the version: ```sh python --version diff --git a/2-farm/lessons/5-migrate-application-to-the-cloud/README.md b/2-farm/lessons/5-migrate-application-to-the-cloud/README.md index 5abbe4e..5fcbacb 100644 --- a/2-farm/lessons/5-migrate-application-to-the-cloud/README.md +++ b/2-farm/lessons/5-migrate-application-to-the-cloud/README.md @@ -46,7 +46,7 @@ Despite the name, serverless does actually use servers. The naming is because yo As an IoT developer, the serverless model is ideal. You can write a function that is called in response to messages sent from any IoT device that is connected to your cloud-hosted IoT service. Your code will handle all messages sent, but only be running when needed. -✅ Look back at the code you wrote as server code listening to messages over MQTT. As is, how might this run in the cloud using serverless? How do you think the code might be changed to support serverless computing? +✅ Look back at the code you wrote as server code listening to messages over MQTT. How might this run in the cloud using serverless? How do you think the code might be changed to support serverless computing? > 💁 The serverless model is moving to other cloud services in addition to running code. For example, serverless databases are available in the cloud using a serverless pricing model where you pay per request made against the database, such as a query or insert, usually using pricing based on how much work is done to service the request. For example a single select of one row against a primary key will cost less than a complicated operation joining many tables and returning thousands of rows. @@ -213,6 +213,23 @@ The Azure Functions CLI can be used to create a new Functions app. 1. Make sure the Python virtual environment is running in the VS Code terminal. Terminate it and restart it if necessary. +1. There may be warnings in the output: + + ```output + (.venv) ➜ soil-moisture-trigger func start + Found Python version 3.9.1 (python3). + + Azure Functions Core Tools + Core Tools Version: 3.0.3442 Commit hash: 6bfab24b2743f8421475d996402c398d2fe4a9e0 (64-bit) + Function Runtime Version: 3.0.15417.0 + + [2021-06-16T08:18:28.315Z] Cannot create directory for shared memory usage: /dev/shm/AzureFunctions + [2021-06-16T08:18:28.316Z] System.IO.FileSystem: Access to the path '/dev/shm/AzureFunctions' is denied. Operation not permitted. + [2021-06-16T08:18:30.361Z] No job functions found. + ``` + + but don't worry about them as long as the Functions app starts correctly and lists the running functions. As mentioned in this question on the [Docs Q&A](https://docs.microsoft.com/answers/questions/396617/azure-functions-core-tools-error-osx-devshmazurefu.html?WT.mc_id=academic-17441-jabenn) it can be ignored. + ## Create an IoT Hub event trigger The Functions app is the shell of your serverless code. To respond to IoT hub events, you can add an IoT Hub trigger to this app. This trigger needs to connect to the stream of messages that are sent to the IoT Hub and respond to them. To get this stream of messages, your trigger needs to connect to the IoT Hubs *event hub compatible endpoint*. @@ -370,7 +387,7 @@ To connect to the Registry Manager, you need a connection string. Replace `` with the name you used for your IoT Hub. - The connection string is requested for the *ServiceConnect* policy using the `--policy-name service` parameter. When you request a connection string, you can specify what permissions that connection string will allow. The ServiceConnect policy allows yor code to connect and send messages to IoT devices. + The connection string is requested for the *ServiceConnect* policy using the `--policy-name service` parameter. When you request a connection string, you can specify what permissions that connection string will allow. The ServiceConnect policy allows your code to connect and send messages to IoT devices. ✅ Do some research: Read up on the different policies in the [IoT Hub permissions documentation](https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-security#iot-hub-permissions?WT.mc_id=academic-17441-jabenn) diff --git a/2-farm/lessons/6-keep-your-plant-secure/README.md b/2-farm/lessons/6-keep-your-plant-secure/README.md index fe4b661..b642a26 100644 --- a/2-farm/lessons/6-keep-your-plant-secure/README.md +++ b/2-farm/lessons/6-keep-your-plant-secure/README.md @@ -39,7 +39,7 @@ If your IoT application is not secure, there are a number of risks: These are real world scenarios, and happen all the time. Some examples were given in earlier lessons, but here are some more: -* In 2018 hackers used an open WiFi access point on a fish tank thermostat to gain access to a casino's network to steal data. [The Hacker News - Casino Gets Hacked Through Its Internet-Connected Fish Tank Thermometer](https://thehackernews.com/2018/04/iot-hacking-thermometer.html) +* In 2018, hackers used an open WiFi access point on a fish tank thermostat to gain access to a casino's network to steal data. [The Hacker News - Casino Gets Hacked Through Its Internet-Connected Fish Tank Thermometer](https://thehackernews.com/2018/04/iot-hacking-thermometer.html) * In 2016, the Mirai Botnet launched a denial of service attack against Dyn, an Internet service provider, taking down large portions of the Internet. This botnet used malware to connect to IoT devices such as DVRs and cameras that used default usernames and passwords, and from there launched the attack. [The Guardian - DDoS attack that disrupted internet was largest of its kind in history, experts say](https://www.theguardian.com/technology/2016/oct/26/ddos-attack-dyn-mirai-botnet) * Spiral Toys had a database of users of their CloudPets connected toys publicly available over the Internet. [Troy Hunt - Data from connected CloudPets teddy bears leaked and ransomed, exposing kids' voice messages](https://www.troyhunt.com/data-from-connected-cloudpets-teddy-bears-leaked-and-ransomed-exposing-kids-voice-messages/). * Strava tagged runners that you ran past and showed their routes, allowing strangers to effectively see where you live. [Kim Komndo - Fitness app could lead a stranger right to your home — change this setting](https://www.komando.com/security-privacy/strava-fitness-app-privacy/755349/). @@ -90,7 +90,7 @@ Unfortunately, not everything is secure. Some devices have no security, others a Encryption comes in two types - symmetric and asymmetric. -**Symmetric** encryption uses the same key to encrypt and decrypt the data. Both the sender and receive need to know the same key. This is the least secure type, as the key needs to be shared somehow. For a sender to send an encrypted message to a recipient, the sender first might have to send the recipient the key. +**Symmetric** encryption uses the same key to encrypt and decrypt the data. Both the sender and receiver need to know the same key. This is the least secure type, as the key needs to be shared somehow. For a sender to send an encrypted message to a recipient, the sender first might have to send the recipient the key. ![Symmetric key encryption uses the same key to encrypt and decrypt a message](../../../images/send-message-symmetric-key.png) @@ -148,7 +148,7 @@ After the connection, all data sent to the IoT Hub from the device, or to the de ### X.509 certificates -When you are using a asymmetric encryption with a public/private key pair, you need to provide your public key to anyone who wants to send you data. The problem is, how can the recipient of your key be sure it's actually your public key, not someone else pretending to be you? Instead of providing a key, you can instead provide your public key inside a certificate that has been verified by a trusted third party, called an X.509 certificate. +When you are using an asymmetric encryption with a public/private key pair, you need to provide your public key to anyone who wants to send you data. The problem is, how can the recipient of your key be sure it's actually your public key, not someone else pretending to be you? Instead of providing a key, you can instead provide your public key inside a certificate that has been verified by a trusted third party, called an X.509 certificate. X.509 certificates are digital documents that contain the public key part of the public/private key pair. They are usually issued by one of a number of trusted organizations called [Certification authorities](https://wikipedia.org/wiki/Certificate_authority) (CAs), and digitally signed by the CA to indicate the key is valid and comes from you. You trust the certificate and that the public key is from who the certificate says it is from, because you trust the CA, similar to how you would trust a passport or driving license because you trust the country issuing it. Certificates cost money, so you can also 'self-sign', that is create a certificate yourself that is signed by you, for testing purposes. @@ -162,7 +162,7 @@ When using X.509 certificates, both the sender and the recipient will have their ![Instead of sharing a public key, you can share a certificate. The user of the certificate can verify that it comes from you by checking with the certificate authority who signed it.](../../../images/send-message-certificate.png) -***nstead of sharing a public key, you can share a certificate. The user of the certificate can verify that it comes from you by checking with the certificate authority who signed it. Certificate by alimasykurm from the [Noun Project](https://thenounproject.com)*** +***Instead of sharing a public key, you can share a certificate. The user of the certificate can verify that it comes from you by checking with the certificate authority who signed it. Certificate by alimasykurm from the [Noun Project](https://thenounproject.com)*** One big advantage of using X.509 certificates is that they can be shared between devices. You can create one certificate, upload it to IoT Hub, and use this for all your devices. Each device then just needs to know the private key to decrypt the messages it receives from IoT Hub. @@ -176,7 +176,7 @@ The certificate used by your device to encrypt messages it sends to the IoT Hub The steps to generate an X.509 certificate are: -1. Create a public/private key pair. One of the most widely used algorithm to generate a public/private key pair is called [RSA](https://wikipedia.org/wiki/RSA_(cryptosystem)). +1. Create a public/private key pair. One of the most widely used algorithm to generate a public/private key pair is called [Rivest–Shamir–Adleman](https://wikipedia.org/wiki/RSA_(cryptosystem))(RSA). 1. Submit the public key with associated data for signing, either by a CA, or by self-signing diff --git a/2-farm/lessons/6-keep-your-plant-secure/single-board-computer-x509.md b/2-farm/lessons/6-keep-your-plant-secure/single-board-computer-x509.md index 93bf798..00ddabf 100644 --- a/2-farm/lessons/6-keep-your-plant-secure/single-board-computer-x509.md +++ b/2-farm/lessons/6-keep-your-plant-secure/single-board-computer-x509.md @@ -47,8 +47,10 @@ The next step is to connect your device to IoT Hub using the X.509 certificates. ``` This will connect using the X.509 certificate instead of a connection string. + +1. Delete the line with `connection_string` variable. -1, RUn your code. Monitor the messages sent to IoT Hub, and send direct method requests as before. You will see the device connecting and sending soil moisture readings, as well as receiving direct method requests. +1. Run your code. Monitor the messages sent to IoT Hub, and send direct method requests as before. You will see the device connecting and sending soil moisture readings, as well as receiving direct method requests. > 💁 You can find this code in the [code/pi](code/pi) or [code/virtual-device](code/virtual-device) folder.