All Projects → awslabs → Aws Iot Certificate Vending Machine

awslabs / Aws Iot Certificate Vending Machine

Licence: apache-2.0
The CVM allows a device to apply for its own certificate and installation.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Aws Iot Certificate Vending Machine

go-localstack
Go Wrapper for using localstack
Stars: ✭ 56 (-12.5%)
Mutual labels:  lambda, cloudformation, dynamodb
Awesome Aws
A curated list of awesome Amazon Web Services (AWS) libraries, open source repos, guides, blogs, and other resources. Featuring the Fiery Meter of AWSome.
Stars: ✭ 9,895 (+15360.94%)
Mutual labels:  lambda, cloudformation, dynamodb
Aws Iot Chat Example
💬 Chat application using AWS IoT platform via MQTT over the WebSocket protocol
Stars: ✭ 474 (+640.63%)
Mutual labels:  aws-iot, dynamodb, mqtt
Hands-On-Serverless-Applications-with-Go
Hands-On Serverless Applications with Go, published by Packt.
Stars: ✭ 92 (+43.75%)
Mutual labels:  lambda, cloudformation, dynamodb
Aws Mobile React Sample
A React Starter App that displays how web developers can integrate their front end with AWS on the backend. The App interacts with AWS Cognito, API Gateway, Lambda and DynamoDB on the backend.
Stars: ✭ 650 (+915.63%)
Mutual labels:  lambda, dynamodb
Cloudformation templates
AWS - CloudFormation Templates
Stars: ✭ 505 (+689.06%)
Mutual labels:  lambda, cloudformation
Aws Sdk Js V3
Modularized AWS SDK for JavaScript.
Stars: ✭ 737 (+1051.56%)
Mutual labels:  lambda, dynamodb
Serverless Appsync Plugin
serverless plugin for appsync
Stars: ✭ 804 (+1156.25%)
Mutual labels:  lambda, dynamodb
Auto Tag
Automatically tag AWS resources on creation, for cost assignment
Stars: ✭ 322 (+403.13%)
Mutual labels:  lambda, cloudformation
Serverless Domain Manager
Serverless plugin for managing custom domains with API Gateways.
Stars: ✭ 783 (+1123.44%)
Mutual labels:  lambda, cloudformation
Flogo Contrib
Flogo Contribution repo. Contains activities, triggers, models and actions.
Stars: ✭ 60 (-6.25%)
Mutual labels:  lambda, mqtt
Dazn Lambda Powertools
Powertools (logger, HTTP client, AWS clients, middlewares, patterns) for Lambda functions.
Stars: ✭ 501 (+682.81%)
Mutual labels:  lambda, dynamodb
Sherlock Holmes Partying In The Jungle
Parses AWS events payloads into a plain JavaScript object
Stars: ✭ 12 (-81.25%)
Mutual labels:  lambda, dynamodb
Dawson Cli
A serverless web framework for Node.js on AWS (CloudFormation, CloudFront, API Gateway, Lambda)
Stars: ✭ 721 (+1026.56%)
Mutual labels:  lambda, cloudformation
Serverless Express
Run Node.js web applications and APIs using existing application frameworks on AWS #serverless technologies such as Lambda, API Gateway, Lambda@Edge, and ALB.
Stars: ✭ 4,265 (+6564.06%)
Mutual labels:  lambda, dynamodb
Thingsboard Gateway
Open-source IoT Gateway - integrates devices connected to legacy and third-party systems with ThingsBoard IoT Platform using Modbus, CAN bus, BACnet, BLE, OPC-UA, MQTT, ODBC and REST protocols
Stars: ✭ 796 (+1143.75%)
Mutual labels:  aws-iot, mqtt
Eskimo Stripper
Strips DynamoDB Stream Items of its schema and returns a plain JavaScript object
Stars: ✭ 12 (-81.25%)
Mutual labels:  lambda, dynamodb
Workshop Donkeytracker
Workshop to build a serverless tracking application for your mobile device with an AWS backend
Stars: ✭ 27 (-57.81%)
Mutual labels:  lambda, dynamodb
Serverless
This is intended to be a repo containing all of the official AWS Serverless architecture patterns built with CDK for developers to use. All patterns come in Typescript and Python with the exported CloudFormation also included.
Stars: ✭ 1,048 (+1537.5%)
Mutual labels:  cloudformation, dynamodb
Aws Cognito Apigw Angular Auth
A simple/sample AngularV4-based web app that demonstrates different API authentication options using Amazon Cognito and API Gateway with an AWS Lambda and Amazon DynamoDB backend that stores user details in a complete end to end Serverless fashion.
Stars: ✭ 278 (+334.38%)
Mutual labels:  cloudformation, dynamodb

AWS Iot Certificate Vending Machine

You can use the CVM allows the device to apply for their own certificate and installation.

README Languages: Chinese blog(中文)

Background Information

In order to ensure the secured communication between IoT devices and AWS IoT Core, Devices may use X.509 certificates to connect to AWS IoT using TLS mutual authentication protocols. AWS Cloud security mechanisms protect data as it moves between AWS IoT and other devices or AWS services.

Background

This mutual TLS authentication mode requires that a device certificate meets either of the following two conditions:

  1. The certificate used on the IoT device is issued by AWS IoT Core
  2. The CA certificate which is used to sign IoT device certificate is pre-imported into a customer’s AWS account and associated with their AWS IoT Core environment AWS understands that customers will have devices that currently do not have the ability to meet condition 1 or 2 immediately. Therefore, we have provided a reference application called, Certificate Vending Machine, which demonstrates how customers can provision devices with certificates created in AWS IoT.

When to use Certificate Vending Machine?

Certificate Vending Machine (CVM) is an ideal fit for customers who do not have certificates pre-installed on the devices and are unable to obtain CA certificates to pre-create device certificates during their manufacturing process. On this occasion, you can use CVM system which allows the device to apply for their own certificate and then install the certificate into storage on the device. This document provides the design ideas and associated source code, which can help customers quickly develop a CVM system. Since the original IoT device does not contain a certificate for TLS mutual authentication, we need to pay attention to three points.

  • When IoT devices and the CVM system are communicating, a trusted DNS environment is needed in order to prevent the man-in-middle attack along with using other secured communication method, such as HTTPS.
  • When an IoT device requests a certificate, it should have a unique identifier. The identifier, such as serial number, client ID or product ID, will be used for policy binding and to ensure that the device is a valid device.
  • All certificates submitted by the CVM system are AWS IoT Core signed certificates. If you need to use a custom CA certificate, refer to the Just-in-time Registration (JITR) certificate authentication method.

Implementation Methodology

The entire implementation can be divided into three modules: IoT devices, CVM system and AWS IoT Core.

  • IoT device side
  • Request a device certificate via HTTPS connection.
  • Submit the device serial number and the registration token when requested. Registration token is a one-time token to avoid device serial number spoofing.
  • CVM system
  • Provides remote access to IoT devices for certificate application.
  • Generates secured certificate for each IoT device that can be used to communicate to AWS IoT Core.
  • Uses database, like DynamoDB, to store information such as the device ID, key registration information, and the applied device certificate.
  • Associates IoT Thing Name, Certificate Policy, and Certificate ID by querying the association table in DynamoDB. In parallel, CVM modifies the certificate status attribute in DynamoDB to ensure that a device can only register for a single active certificate.
  • IoT Core
  • Response to API calls to generate the certificate and key pairs.

The basic workflow of the CVM system is as follows:

workflow

The architecture of CVM system is as follows:

Architecture

Using the API Gateway and Lambda solution for scalability, the detailed workflow is shown as follows:

  1. When IoT device requests access to IoT platform, it triggers a certificate application to CVM system. Then IoT device sends the appropriate API calls to the API Gateway for IoT device certificate application.
  2. AWS API Gateway invokes Lambda to initiate certificate request to IoT Core.
  3. After receiving the request from API Gateway, Lambda checks DynamoDB to validate if the request is legitimate and applies for a certificate to the backend IoT Core.
  4. The CVM system uses the AWS SDK to make a series of API calls to AWS IoT Core. These API calls perform actions such as creating a new thing in the AWS IoT Thing Registry and creating an associated device certificate.
  5. AWS IoT Core generates a device certificate, key pairs and returns the certificate information and the certificate ID to CVM system.
  6. Lambda uses a series of API calls to associate Thing Name, Certificate, and Policy on IoT Thing registry by querying pre-created DynamoDB association table according to product serial number.
  7. Update all the associated information of the current device to DynamoDB association table
  8. Lastly, the CVM system returns the certificate to the IoT devices

Security

In order to ensure the security of the CVM system, the AWS Lambda function needs to be scoped to the minimum permissions needed in order to create certificates. The following example shows how to assign the correct IAM role privilege to the CVM system.

First of all, you need to understand the CVM system needs to have the IAM authority to complete the certificate application and the issuance process.

  • Access AWS DynamoDB for querying, modifying, and updating device associations in DynamoDB table
  • Access the IoT platform to apply for IoT device certificates

The policy template for IAM role as follows, you should modify it more specifically for the minimum privilege.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "IoTCWlogsPolicy",
            "Effect": "Allow",
            "Action": [
                "logs:*",
                "iot:CreateThing",
                "iot:AttachPolicy",
                "iot:AttachThingPrincipal",
                "iot:CreatePolicy",
                "iot:CreateKeysAndCertificate"
            ],
            "Resource": "*"
        },
        {
            "Sid": "dynamodPolicy",
            "Effect": "Allow",
            "Action": [
                "dynamodb:Query",
                "dynamodb:UpdateItem"
            ],
            "Resource": "arn:aws:dynamodb:REGION:123456789012:table/TableName"
        }
    ]
}

Secondly, you need to allow lambda assume this role by adding trust relationship.

policy

In addition to the IAM authority division, you need to create an association table on DynamoDB for the binding relationship between the device, the certificate and policy. Specifically, you need to create the following database fields in DynamoDB:

  • Product id: IoT device ID
  • Access Token: IoT Token
  • timestamp: certificate request timestamp
  • applyState: request status (if the certificate is set to -1, it means that the device has already registered the certificate)
  • certID: certificate ID associated with the device

How do I deploy this?

1. Deploy the CVM to your AWS account

The solution is available as a AWS CloudFormation SAM template, and included in this repository (template.yml). Click the following button to deploy it to your AWS account in the us-east-1 region:

cloudformation-launch-stack

You will need to provide some parameters to point AWS Lambda.

When the cloudformation CREATE_COMPLETE, you can see the output of Cloudformation.

[cloudformation-stack-output]

2. Add Sample Device Data to your Device Dynamodb

You must create item in your device dynamodb table, or you will see access deny.

[Add Sample Data about serialNumber & deviceToken ]

3. Use output API Gateway Link to invoke your CVM

Please use the link from the first step. https://XXXXX.execute-api.us-east-1.amazonaws.com/PROD/getcert?serialNumber=ascas&deviceToken=zxcz

Code Description

The following CVM system reference source code uses the IoT interface provided by the AWS Node.js SDK to complete the certificate request and add the associated Thing Name and Policy.

// Create cert
  iot.createKeysAndCertificate(params, function(err, certdata) {
    console.log("certdata:");
    console.log(certdata);
    
    if (err) console.log(err, err.stack); // an error occurred
    else{
      
       // Create IoT Policy for above cert
       var params = {
        policyDocument: config.PILICY_DOCUMENT, /* required */
        policyName: serialNumber /* required */
      };
      iot.createPolicy(params, function(err, data) {
        if (err) console.log(err, err.stack); // an error occurred
        else{
          console.log(data);
          
          // Attach policy for cert
          var params = {
            policyName: serialNumber, /* required */
            target: certdata.certificateArn /* required */
          };
          iot.attachPolicy(params, function(err, data) {

Reference Link:

http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Iot.html

License

This library is licensed under the Apache 2.0 License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].