Skip to content

JosephTiamzon/IOTS

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

209 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SMART DOOR LOCK (IOTS PROJECT)

Name Admission ID
Leong Ming Liang Timothy P1907799
Ron Tan Zi Yu P1908521
Tiamzon Joseph Martin P1907492

Concept

The user will use a keypad to enter a code to unlock the door. It also uses an LCD to give prompts to the user. Users will also be able to configure their device information through a website.

Components

  • Hardware
    • Esp32
    • 4x4 Keypad
    • I2C LCD 16x2 with PCF8574 IIC I2C Serial Interface Adapter
    • SG90 Servo Motor
    • 12x Female-to-Male Jumper Wires
    • 3x Male-to-Male Jumper Wires
    • Breadboard
  • Website
    • NextJS
    • ReactJS
    • Auth0
    • Vercel
  • Database
    • Mongodb

General Overview

diagram flow

How users are meant to operate and use the product

Setting up on the website
Users will need to set up their device to be connected to the database. To do that, the first thing a user will need to do is to register an account through the website. https://iots.vercel.app/ . After they signed in, they will click create a new device. They fill in the form then press create. Take not of the device id as you will need it later. You can create, read, update and delete your devices through the website.
Setting up on the door lock
After the user has created a new device in the website, they will go to the door lock and turn it on. After the door lock boots up, they will be prompted to add in the device id they got earlier on.

Thats it! Your smart door is ready to work

OAuth 2.0 framework

The implementation of our website follows the OAuth 2.0 framework. The user will first go through a Authorisation Request to Auth0. If the user is authorised, they will get a Authorisation Grant from Auth0. The user will then use the Authorisation Grant received to retrieve a Access Token from Auth0. The user can then use this Access Token to retrieve data from Mongodb. For a better user experience, Auth0 uses refresh token to silently retrieve a access token when it is expired without user intervention. This allows our user to stay authenticated in our application without needing to logging everytime. The access token expiry set in our application is 86,400 seconds (24 hours) and the refresh token expiry set is 2592000 seconds (30 days).

oauth2 diagram

TR64 Compliance Checklist

TR64 Category Compliance Request ID
Cryptographic Support CS-01, CS-02, CS-03, CS-04, CS-05
Security Function Protection FP-01, FP-02
Identification & Authentication IA-01, IA-02, IA-03, IA-04
Data Protection DP-02, DP-04
Access Protection AP-01, AP-02, AP-04, AP-05
Security Management MT-01, MT-02
Resiliency Support RS-03, RS-04
Security Audit AU-01, AU-02
Lifecycle Protection LP-01, LP-02, LP-03, LP-07, LP-09

Attack Surfaces

Attack Surface 1: Physical Attacks (ESP-32)

Vulnerabilities

Physically tampering with the door access system and injecting of external code into the microcontroller controlling the door system could potentially result in the whole system failing.

Assessment
Category Description
Damage An attack on the physical hardware would have a very high impact as the physical hardware is the core of the Door Access System.
Reproducability An attack on the hardware level would be very hard to reproduce as it would require the attacker to be physically present at the same location as the hardware
Exploitability This attack would be considered as medium level exploitability since our product is already placed in a tamper-proof box to secure it.
Affected Users The home owner would be the main affected user as it would compromise the entire security system, allowing anyone to enter the home of the home owner.
Discoverability An attack at this level would be very high on the discoverability scale as this attack requires the home owner to be physically present at the site where the security system is, which in this case is the home.

Calculated Vulnerability Score 1

CVSS:3.0/AV:P/AC:H/PR:H/UI:N/S:C/C:N/I:N/A:H

Mitigation

In order to mitigate this attack, physically securing the Door Access System with proper procedures would be recommended. In order to achieve this, we created a tamper proof enclosure for the ESP-32 microcontroller so that it would be very difficult for them to inject their own code and tamper with the microcontroller.

Attack Surface 2: ESP-32 Network Attack

Vulnerabilities

Intercepting of packets being sent from the "Door Access" terminal to the secure endpoint on MongoDB would result in the Personal Identifiable Information (PII/SPI) being leaked to the threat actor as they would be able to know the specific time as to when the home owner leaves and returns.

Assessment

Category Description
Damage An attack at this level would be be very low risk as there are proper security procedures implemented into this. For example, packets are sent through using TLS, meaning that it is very hard for hackers to identify and decrypt the Personal Identifiabe Information.
Reproducability In order to reproduce this type of attack, it would be very easy. However, the exploitaility of this attack is not easy.
Exploitability This attack has a medium level exploitability as it would require a specific skillset from the threat actor in order to perform this successfully.
Affected Users Home Owners are the only users that would be affected.
Discoverability Discovering a vulnerability in order to perform an eavesdropping attack would be considered low since it is not very easy to find a vulnerability to intercept the packets.

Calculated Vulnerability Score 2

CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:N/A:N

Mitigation

In order to mitigate this attack, we chose to encrypt the data at rest as well as the data in transit. The data at rest is encrpted using the PBKDF2 algorithm and the data in transit is encrypted using TLS. This way, even if there was an attacker listening on the packets being transmitted, they would have to find out the encryption algorithm and decrypt the packet before being able to identify the data.

Attack Surface 3: Database Attacks (MongoDB)

Vulnerabilities

Breach of Administrator account credentials. With a breached administrator account, the threat actor would have a full access to the Mongo Database which consists of all the information of end users.

Assessment
Category Description
Damage The damage would be high if the administrator account were to be accessed by a threat actor. This is because the administrator has full access to all the data that resides in the database and is able to configure all the server settings
Reproducability The reproducability is would be considered high if the threat actor has found the credentials of the administrator account as they have full access to the database and can make changes as and when they please
Exploitability The exploitability would be considered as low since the administrator account for the MongoDB database is securely protected with the use of social logins and 2 factor authentication. The social login also consists of a strong password, reducing the possibility of having a breached administrator account.
Affected Users An attack on the database would affect all users, including the Administrator and all end-users
Discoverability The discovery of an IoT threat at this level would be considered as low as we have proper procedures in place to prevent a breached user account from having too much of an impact.

Calculated Vulnerability Score 3

CVSS:3.0/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H

Mitigation

The best mitigation techniques would be implementing social logins that make use of 2 factor authentication, creating a strong password for the social login account, limiting the amount of people that have administrator privileges and having an audit log for important events such as authentications. The main purpose of implementing a strong password would be to minimize the risk of having a compromised password. Having a 2 factor authentication on top of the strong password would act as a gateway to the account, reducing the impact of a compromised user account. Limiting the number of administrator accounts would then help limit the number of potential compromised administrator accounts, reducing the risk of having an administrator account be compromised.

Atack Surface 3

Attack Surface 4: Web Server Attacks (Vercel)

Vulnerabilities

Distributed Denial of Service (DDoS) of the Vercel webserver to take down the entire website. This attack would have a big impact on availability as the website will become inaccessible to all end-users.

Assessment
Category Description
Damage An attack of a web server attack would be considered as a middle damage level attack as it would completely prevent users from CRUD functions (Create, Read, Update and Delete functions). This would result in the end-users being unable to change any configuration related to their security system.
Reproducability In order to reproduce an attack at this level, it would be extremely difficult as Vercal has taken proper precautions to prevent high level threats such as DDoS which could reflect badly on the companys reputation
Exploitability To perform a DDoS at such a large scale, one that is able to take down a major cloud hosting such as Vercel, the threat actor would be required to be highly skilled and knowledgeable. They would also be require to make use of a extremely large number of zombies
Affected Users All users would be affected if Vercel were to be taken down as it would prevent them from being able to access and view their cloud based dashboards, which prevents them from using CRUD functions.
Discoverability It is not easy to discover how perform a DDoS attack that would work on major cloud hosts such as Vercel due to the security precautions that are already in place.

Calculated Vulnerability Score 4

CVSS:3.0/AV:N/AC:H/PR:H/UI:N/S:C/C:H/I:H/A:H
Mitigation

Proper mitigation techniques for this type of attack would be an automatic identification of any and all suspicious activities from users as well as black listing of the User/IP addresses that may be considered as attempting any malicious activities.

Attack Surface 4

CVSS:3.0/AV:N/AC:H/PR:H/UI:N/S:C/C:H/I:H/A:H

Attack Surface 5: Web Application Attacks (Auth0)

Vulnerabilities

One of the most common IoT attacks on web applications that require authentications would be brute force attack. Brute force attack is the act where the threat actor constantly attempts to get into the system by guessing the user credentials on the website application.

Assessment
Category Description
Damage The damage would be considered high for this attack as the threat actor would be able to reconfigure the settings of the home owner, potentially allowing the threat actor to get into the home of the account owner.
Reproducability The reproducability of this attack would be considered as low since there are proper precautions in place to prevent such attacks. Some examples would be a restriction and notification alert sent to the account owner if there was a number of failed attempts.
Exploitability A brute force attack would be considered as low exploitability since it required a large amount of effort and time to enter each potential password.
Affected Users The only affected user would be the end-user whose account was breached by this attack.
Discoverability It does not difficult for a threat actor perform a brute force attack as it requires little to no knowledge about IoT attacks.
Mitigation

Recommended mitigation techniques for this attack would include an alert and locking of the account after a set number of failed attempts. This has been implemented as part of Auth0's compliance. An additional method in preventing this attack would be the implementation of 2FA. With the use of 2FA, if the threat actor were to successfully authenticate themselves with the use of the username and password, they would still require authentication from the 2nd factor, which is highly unlikely.

Calculated Vulnerability Score 5

CVSS:3.0/AV:N/AC:H/PR:H/UI:N/S:U/C:H/I:H/A:L

Compliance Lists

Webpage Compliance List

TR64 Req IDs: CS-02; FP-02; IA-01;RS-03;MT-02
TR64 Req ID Explanation
CS-02;IA-01 User created passwords for Auth0 are hashed using bcrypt.
FP-02 FP-02: Website application configuration variables are stored under vercel environment variables which are encrypted via AES256
RS-03 Web server is secured by vercel with security grade procedures. Able to withstand malicious threats such as Denial of Service (DoS) and Distributed Denial of Service (DDoS).
MT-02 Users are only able to create, read, update and delete their own data so to uphold confidentiality and that data will not be tampered by unauthorized users.

MongoDB Atlas Compliance List

TR64 Req IDs: CS-01;CS-04;CS-05;FP-01;DP-04;RS-04;AU-01;AU-02;MT-02
TR64 Req ID Explanation
CS-01 API keys are generated by Mongo.
CS-04 RS256 asymmetric encryption algorithm is used to sign Json Web Tokens (JWTs) for authentication to web application.
CS-05;FP-01 API Keys are created for trusted endpoints and are fully managed by MongoDB with industrial grade security features.
DP-04 Role based access is assigned for different users.
RS-04 MongoDB Atlas provides a tool that enables backups of the entire database to be created easily. The backup can be used for disaster recovery in the event of an IoT attack.
AU-01;AU-02 Audit log consists of all entries, including Create, Read, Update and Delete (CRUD) as well as any successful or unsuccessful authentications. Audit logs are also secured and tamper proof. Only the authorized user with the proper credentials/API key would be able to access it.
MT-02 Role based access is granted to specific users such that there are no over privileged accounts, which poses as a IoT security vulnerability.

Auth0 Compliance List

TR64 Req IDs: CS-05;MT-01;IA-01;IA-02;IA-03;IA-04;DP-02;AP-01;AP-02;AP-05
TR64 Req ID Explanation
CS-05;IA-01 Passwords created for specific user accounts are hashed using bcrypt before being stored in the Auth0 database separate from our resource database (Mongodb) following OAuth 2.0 to ensure confidentiality of user credentials.
IA-02 Authentication to web server has a set session expiry of 7 days before the user is prompted to sign in again.
IA-03 Unique tokens are generated and assigned to users using JWTs to guarantee the Authenticity of users.
IA-04;AP-02;MT-01 Users are required to create a complex password upon signing up. 2 factor authentication is also required for users who sign in using third-party applications such as Google or Microsoft Account.
DP-02 Digital signatures are created using RS256 to sign Json Web Tokens for Non-Repudiation and Integrity, making sure the content has not been tampered with.
AP-01 Failure to enter password consecutively would result in an account lockout followed by blocking of the suspected user IP Address. Account owner would also be notified of the suspicious activity and given a choice to unblock the IP Address.

ESP32

TR64 Compliance List: CS-02;IA-01;AP-04
TR64 Req ID Explanation
CS-02;IA-01 We used a cryptographic algorithm (PBKDF2) to hash the device password with salt for better confidentiality.
AP-04 In order to prevent threat actors from physically accessing the microcontroller, which is the core of the physical system, we created a tamper-resistant box which is used to hold the microcontroller

System Wide Compliance List

TR64 Compliance List: LP-01;LP-02;LP-03;LP-07;LP-09
TR64 Req ID Explanation
LP-01 Threat modelling was performed and used to improve our security features based on the DREAD threat modelling method
LP-02 System was designed using the secure systems engineering approach. Minimal inputs are taken from users, system was designed to be as simplified as possible and permissions are only granted as and when required.
LP-03 System was constructed using components provided by Singapore Polytechnic. Components were presumably sourced from a authorized seller.
LP-07 Penetration testing for the cloud services are done by the service providers upon new updates and releases. Penetration testing for the ESP-32 data transmission was done with Kali Linux by legal means and under a controlled environment.
LP-09 MongoDB manages all the user data for authenticated clients and Auth0 helps to provide certificates to allow proper authentication for all authorized clients.

Documentation (to run this system yourself)

Website

The website is hosted on vercel and is reachable via https://iots.vercel.app/ . The website is built on NextJS which is a meta ReactJS framework which allows developers to create full stack web application. It also uses MongoDB as a database to store the user device information and Auth0 to handle user authentication and storing of user information.
Website dependency
  • next (Framework built for full stack ReactJS web application)
  • next auth (Handle authentication and middleware of the website)
  • MUI (Design library)
  • cypto-js (Cyptography library for the PBKFD2 hashing client side)
  • ReactJS
To get started
  1. You will need to have nodejs installed. Go over to https://nodejs.org/en/ to install nodejs
  2. Clone this repository or download the zip file
  3. Open it up using visual studio code or equivalent and go to the root path of the dashboard which is /IOTS/IOTS-dashboard
  4. From here you can choose to either run it in localhost mode or push it to the cloud.
    If you want to push it to the cloud
    1. Create a new github repository and push the code to the repository
    2. Create a vercel account and link it to your github https://vercel.com/
    3. After signing in to vercel, go to add new project
    4. Import the repository that you created
    5. Select the NextJS under the Framework Preset
    6. Ensure that the Root Directory is the root path of the website
    7. Then click deploy
    8. All codes that are commited to github will be rebuilt and redeployed on vercel.
    If you want to run it locally using localhost
    1. Go to the root path of the website locally from your terminal in visual studio code or equivalent
    2. Type in npm run dev
    3. Open your browser and go to http://localhost:3000/
    4. You should see the website running
  5. Now you need to create a new Auth0 account https://auth0.com/
  6. Login to auth0
  7. Go to applications and create a new application
  8. Select Regular Web Application
  9. Take note of the Client ID and Client Secret
  10. Scroll down to Allowed Callback URLs
  11. Add in https://YOUR-VERCEL-APP-URL/api/auth/callback/auth0, http://localhost:3000/api/auth/callback . You do not need to add in the first one if you did not push the code to vercel
  12. Scroll down and save your changes
  13. Now you need to create your MongoDB database
  14. Head over to https://www.mongodb.com/ and create a new account
  15. Create a new project and name it IOTS
  16. Create a new cluster and select shared and change the cluster name to IOTS-database
  17. Go to browse collection of IOTS-database
  18. Go to collections tab and create a new database
  19. Go to collections tab and create a new database
  20. Name the database name as IOTS_dashboard and the Collection name as users
  21. Hover over IOTS_dashboard and create another collection and name it as users
  22. Go over to App Services
  23. Go to Authentication tab
  24. Click on edit for Custom JWT Authentication
  25. Enable the provider and select Use a JWK URI
  26. Under JWK URI go back to auth0 application settings and scroll all the way down to advanced settings
  27. Go to the Endpoints tab and copy the JSON Web Key Set. It should look something like https://YOUR-TENANT/.well-known/jwks.json
  28. Go back to the MongoDB and paste what you copied to the JWK URI
  29. Go to trigger and add a new trigger
  30. Set the trigger type to Authentication
  31. Name the Trigger AddUserToDatabase
  32. Set your Cluster name to IOTS-database
  33. Set your Database name to IOTS-dashboard
  34. Set your Collection name to users
  35. Scroll down and click on select a function and create a new function
  36. Name the function addUserToDatabase
  37. Copy this code and place it in the function
    exports = function(authEvent) {
      const user = authEvent.user;
      const mongodb = context.services.get("IOTS-database");
      const usersCollection = mongodb.db("IOTS_dashboard").collection("users");
      usersCollection.insertOne({
        ...user
      });
    };
  38. Save it and go back to the Authentication tab
  39. Click on edit for the API Keys and create a new API Key and name it Door_Auth. Save the API key somewhere safe as you will not see it again. This will be your API key that you will use for the esp32 query
  40. While you are saving the api key, on the sidebar, at the top, there is a copy icon. Click on it as save it as that is your app id and you will need it later
  41. go back to the auth0
  42. Go over to APIs and create a new API
  43. Name it whatever you want and the identifier is the mongodb app id which you saved and the click create
  44. Now if you are running the code on localhost, create a .env file at the root directory. If you are using vercel go over to settings and Environment Variables. Then add this into your env either on vercel or your .env file in your root directory
    AUTH0_CLIENT_ID = <Your auth0 application client ID>
    AUTH0_CLIENT_SECRET = <Your auth0 application client secret>
    AUTH0_ISSUER = https://<your auth0 application domain> 
    NEXTAUTH_URL = <your website url either localhost or the vercel url>
    NEXT_PUBLIC_APP_ID= <your mongodb app id that you saved>
    AUTH0_AUDIENCE= <your mongodb app id that you saved>
    NEXTAUTH_SECRET= <random secret of any length that you can use openssl to generate for you. would recommend 32 characters long>
    NEXT_PUBLIC_SALT = <the salt that you will use to hash the users device password. would also recommend to use openssl and 32 characters long to generate the salt>
    
  45. Go back to mongodb app services
  46. Go to HTTPS Endpoints and create a new HTTPS Endpoint
  47. Set the route to be /doorauth
  48. Under Operation Type copy the url
  49. Set the HTTP Method to post
  50. Set the Return Type to JSON
  51. Under Function add a new function and copy this code
    exports = async function({ query, headers, body}, response) {
      const CryptoJS = require("crypto-js");
    
        const serialized = body.text();
        const data = JSON.parse(serialized);
        
        const {deviceId, userPassword} = data;
        console.log(deviceId);
        console.log(userPassword)
        const dbPassword = await context.services.get("IOTS-database").db("IOTS_dashboard").collection("iot").findOne(
        {device_id: deviceId},
        {password: 1}
        )
        console.log(dbPassword);
        
        console.log("dbpassword", dbPassword)
        
        if (dbPassword){
          console.log("not null")
           if (dbPassword.password === CryptoJS.PBKDF2(userPassword, "<Your salt that you generated just now>",  {
                  keySize: 256 / 32,
                  iterations: 1000,
                }).toString()){
                  console.log("authorised")
             return "authorised"
           }
            return "Username or Password is invalid"
        }else{
          console.log('invalid')
          return "Username or Password is invalid";
        }
    
    };
  52. Go to your esp32 code and add the API key of the doorauth you saved just now as well as add your http endpoint url to the endpoint variable
Circuit Diagram

The diagram below shows how the components are connected to create the circuit diagram. the tables shows the different pin connections to the Esp32 I/O pins.

IOTS Circuit Diagram

Esp32 Code
  1. Once the circuit has been set up, connect the Esp32 to the computer
  2. Install the necessary libraries needed:
    • keypad by Mark Stanley, Alexander Brevig
    • LiquidCrystal I2C by Frank de Brabander
    • ESP32Servo by Kevin Harrington, John K. Bennett
  3. Download and open the program file Esp32 INO file [6 kB]
  4. Upload the code
  5. Once the code is uploaded, hold on the 'boot' button on the Esp32 to run the program in the board

if the 'Output' displays an error of the I2C LCD not compatible with Esp32, proceed to file explorer to edit the library

  1. Go to file explorer/Arduino/libraries/LiquidCrystal_I2C
  2. open library.properties in notepad
  3. Include Esp32 to the architechtures. That line of the library property should look like "architectures=avr,esp32"
  4. save changes and run the code again

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • JavaScript 77.3%
  • C++ 16.4%
  • CSS 6.3%