Skip to content

Commit 65b8344

Browse files
zayeshaatawsJustin Boswell
and
Justin Boswell
authored
Fleet provisioning (#113)
* Fleet provisioning Co-authored-by: Justin Boswell <boswej@amazon.com>
1 parent d492c96 commit 65b8344

30 files changed

+2519
-2
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ endif()
5757
add_subdirectory(jobs)
5858
add_subdirectory(shadow)
5959
add_subdirectory(discovery)
60+
add_subdirectory(identity)
6061

6162
if (BUILD_SAMPLES)
63+
add_subdirectory(samples/identity/fleet_provisioning)
6264
add_subdirectory(samples/mqtt/basic_pub_sub)
6365
add_subdirectory(samples/mqtt/raw_pub_sub)
6466
add_subdirectory(samples/jobs/describe_job_execution)

README.md

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,97 @@ is provided by code that been generated from a model of the service.
3030
## Build from source
3131
### Automatically Build and Install AWS Dependencies
3232
```
33+
mkdir sdk-cpp-workspace
34+
cd sdk-cpp-workspace
3335
git clone --recursive https://github.com/aws/aws-iot-device-sdk-cpp-v2.git
3436
mkdir aws-iot-device-sdk-cpp-v2-build
3537
cd aws-iot-device-sdk-cpp-v2-build
36-
cmake -DCMAKE_INSTALL_PREFIX="<path to where you install>" -DBUILD_DEPS=ON ../aws-iot-device-sdk-cpp-v2
38+
cmake -DCMAKE_INSTALL_PREFIX="<absolute path sdk-cpp-workspace dir>" -DBUILD_DEPS=ON ../aws-iot-device-sdk-cpp-v2
3739
cmake --build . --target install
3840
```
3941
### Using a Pre-Built aws-crt-cpp (Most useful for development of this package)
4042

4143
```
4244
mkdir aws-iot-device-sdk-cpp-v2-build
4345
cd aws-iot-device-sdk-cpp-v2-build
44-
cmake -DCMAKE_INSTALL_PREFIX="<path to where you install>" -DCMAKE_PREFIX_PATH="<path to where you install>" -DBUILD_DEPS=OFF ../aws-iot-device-sdk-cpp-v2
46+
cmake -DCMAKE_INSTALL_PREFIX="<absolute path sdk-cpp-workspace dir>" -DCMAKE_PREFIX_PATH="<absolute path sdk-cpp-workspace dir>" -DBUILD_DEPS=OFF ../aws-iot-device-sdk-cpp-v2
4547
cmake --build . --target install
4648
```
4749
# Samples
4850

51+
## fleet provisioning
52+
53+
This sample uses the AWS IoT
54+
[Fleet provisioning](https://docs.aws.amazon.com/iot/latest/developerguide/provision-wo-cert.html)
55+
to provision devices using either a CSR or KeysAndcertificate and subsequently calls RegisterThing.
56+
57+
On startup, the script subscribes to topics based on the request type of either CSR or Keys topics,
58+
publishes the request to corresponding topic and calls RegisterThing.
59+
60+
Source: `samples/identity/fleet_provisioning`
61+
62+
cd ~/aws-iot-device-sdk-cpp-v2-build/samples/identity/fleet_provisioning
63+
64+
Run the sample like this to provision using CreateKeysAndCertificate:
65+
66+
```
67+
./fleet-provisioning --endpoint <endpoint> --ca_file <path to root CA>
68+
--cert <path to the certificate> --key <path to the private key>
69+
--template_name <template name> --template_parameters <template parameters json>
70+
```
71+
72+
Run the sample like this to provision using Csr:
73+
74+
```
75+
./fleet-provisioning --endpoint <endpoint> --ca_file <path to root CA>
76+
--cert <path to the certificate> --key <path to the private key>
77+
--template_name <template name> --template_parameters <template parameters json> --csr <path to the CSR in PEM format>
78+
```
79+
80+
Your Thing's
81+
[Policy](https://docs.aws.amazon.com/iot/latest/developerguide/iot-policies.html)
82+
must provide privileges for this sample to connect, subscribe, publish,
83+
and receive.
84+
85+
```json
86+
{
87+
"Version": "2012-10-17",
88+
"Statement": [
89+
{
90+
"Effect": "Allow",
91+
"Action": [
92+
"iot:Publish"
93+
],
94+
"Resource": [
95+
"arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/certificates/create/json",
96+
"arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/certificates/create-from-csr/json",
97+
"arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/provisioning-templates/<b>templatename<b>/provision/json"
98+
]
99+
},
100+
{
101+
"Effect": "Allow",
102+
"Action": [
103+
"iot:Receive",
104+
"iot:Subscribe"
105+
],
106+
"Resource": [
107+
"arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/certificates/create/json/accepted",
108+
"arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/certificates/create/json/rejected",
109+
"arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/certificates/create-from-csr/json/accepted",
110+
"arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/certificates/create-from-csr/json/rejected",
111+
"arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/provisioning-templates/<b>templatename<b>/provision/json/accepted",
112+
"arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/provisioning-templates/<b>templatename<b>/provision/json/rejected"
113+
]
114+
},
115+
{
116+
"Effect": "Allow",
117+
"Action": "iot:Connect",
118+
"Resource": "arn:aws:iot:<b>region</b>:<b>account</b>:client/samples-client-id"
119+
}
120+
]
121+
}
122+
```
123+
49124
## Basic MQTT Pub-Sub
50125

51126
This sample uses the

identity/CMakeLists.txt

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(IotIdentity-cpp CXX)
3+
4+
set(RUNTIME_DIRECTORY bin)
5+
6+
if (UNIX AND NOT APPLE)
7+
include(GNUInstallDirs)
8+
elseif(NOT DEFINED CMAKE_INSTALL_LIBDIR)
9+
set(CMAKE_INSTALL_LIBDIR "lib")
10+
11+
if (${CMAKE_INSTALL_LIBDIR} STREQUAL "lib64")
12+
set(FIND_LIBRARY_USE_LIB64_PATHS true)
13+
endif()
14+
endif()
15+
16+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_PREFIX_PATH}/${CMAKE_INSTALL_LIBDIR}/cmake")
17+
18+
if (NOT CMAKE_CXX_STANDARD)
19+
set(CMAKE_CXX_STANDARD 11)
20+
endif()
21+
22+
file(GLOB AWS_IOTIDENTITY_HEADERS
23+
"include/aws/iotidentity/*.h"
24+
)
25+
26+
file(GLOB AWS_IOTIDENTITY_SRC
27+
"source/*.cpp"
28+
)
29+
30+
file(GLOB AWS_IOTIDENTITY_CPP_SRC
31+
${AWS_IOTIDENTITY_SRC}
32+
)
33+
34+
if (WIN32)
35+
if (MSVC)
36+
source_group("Header Files\\aws\\iotidentity\\" FILES ${AWS_IOTIDENTITY_HEADERS})
37+
38+
source_group("Source Files" FILES ${AWS_IOTIDENTITY_SRC})
39+
endif ()
40+
endif()
41+
42+
add_library(IotIdentity-cpp ${AWS_IOTIDENTITY_CPP_SRC})
43+
44+
set_target_properties(IotIdentity-cpp PROPERTIES LINKER_LANGUAGE CXX)
45+
46+
set(CMAKE_C_FLAGS_DEBUGOPT "")
47+
48+
#set warnings
49+
if (MSVC)
50+
target_compile_options(IotIdentity-cpp PRIVATE /W4 /WX)
51+
else ()
52+
target_compile_options(IotIdentity-cpp PRIVATE -Wall -Wno-long-long -pedantic -Werror)
53+
endif ()
54+
55+
if (CMAKE_BUILD_TYPE STREQUAL "" OR CMAKE_BUILD_TYPE MATCHES Debug)
56+
target_compile_definitions(IotIdentity-cpp PRIVATE "-DDEBUG_BUILD")
57+
endif ()
58+
59+
if (BUILD_SHARED_LIBS)
60+
target_compile_definitions(IotIdentity-cpp PUBLIC "-DAWS_IOTIDENTITY_USE_IMPORT_EXPORT")
61+
target_compile_definitions(IotIdentity-cpp PRIVATE "-DAWS_IOTIDENTITY_EXPORTS")
62+
63+
install(TARGETS IotIdentity-cpp
64+
EXPORT IotIdentity-cpp-targets
65+
ARCHIVE
66+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
67+
COMPONENT Development
68+
LIBRARY
69+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
70+
NAMELINK_SKIP
71+
COMPONENT Runtime
72+
RUNTIME
73+
DESTINATION ${RUNTIME_DIRECTORY}
74+
COMPONENT Runtime)
75+
76+
install(TARGETS IotIdentity-cpp
77+
EXPORT IotIdentity-cpp-targets
78+
LIBRARY
79+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
80+
NAMELINK_ONLY
81+
COMPONENT Development)
82+
else()
83+
install(TARGETS IotIdentity-cpp
84+
EXPORT IotIdentity-cpp-targets
85+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
86+
COMPONENT Development)
87+
endif()
88+
89+
target_include_directories(IotIdentity-cpp PUBLIC
90+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
91+
$<INSTALL_INTERFACE:include>)
92+
93+
if (NOT IS_SUBDIRECTORY_INCLUDE)
94+
aws_use_package(aws-crt-cpp)
95+
endif()
96+
97+
target_link_libraries(IotIdentity-cpp ${DEP_AWS_LIBS})
98+
99+
install(FILES ${AWS_IOTIDENTITY_HEADERS} DESTINATION "include/aws/iotidentity/" COMPONENT Development)
100+
101+
if (BUILD_SHARED_LIBS)
102+
set(TARGET_DIR "shared")
103+
else()
104+
set(TARGET_DIR "static")
105+
endif()
106+
107+
install(EXPORT "IotIdentity-cpp-targets"
108+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/IotIdentity-cpp/cmake/${TARGET_DIR}"
109+
NAMESPACE AWS::
110+
COMPONENT Development)
111+
112+
configure_file("cmake/IotIdentity-cpp-config.cmake"
113+
"${CMAKE_CURRENT_BINARY_DIR}/IotIdentity-cpp-config.cmake"
114+
@ONLY)
115+
116+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/IotIdentity-cpp-config.cmake"
117+
DESTINATION "lib/IotIdentity-cpp/cmake/"
118+
COMPONENT Development)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
include(CMakeFindDependencyMacro)
2+
3+
find_dependency(aws-crt-cpp)
4+
5+
if (BUILD_SHARED_LIBS)
6+
include(${CMAKE_CURRENT_LIST_DIR}/shared/@PROJECT_NAME@-targets.cmake)
7+
else()
8+
include(${CMAKE_CURRENT_LIST_DIR}/static/@PROJECT_NAME@-targets.cmake)
9+
endif()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#pragma once
2+
/* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
15+
* This file is generated
16+
*/
17+
18+
#include <aws/iotidentity/Exports.h>
19+
20+
#include <aws/crt/JsonObject.h>
21+
#include <aws/crt/StlAllocator.h>
22+
23+
namespace Aws
24+
{
25+
namespace Iotidentity
26+
{
27+
28+
class AWS_IOTIDENTITY_API CreateCertificateFromCsrRequest final
29+
{
30+
public:
31+
CreateCertificateFromCsrRequest() = default;
32+
33+
CreateCertificateFromCsrRequest(const Crt::JsonView &doc);
34+
CreateCertificateFromCsrRequest &operator=(const Crt::JsonView &doc);
35+
36+
void SerializeToObject(Crt::JsonObject &doc) const;
37+
38+
Aws::Crt::Optional<Aws::Crt::String> CertificateSigningRequest;
39+
40+
private:
41+
static void LoadFromObject(CreateCertificateFromCsrRequest &obj, const Crt::JsonView &doc);
42+
};
43+
} // namespace Iotidentity
44+
} // namespace Aws
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#pragma once
2+
/* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
15+
* This file is generated
16+
*/
17+
18+
#include <aws/iotidentity/Exports.h>
19+
20+
#include <aws/crt/JsonObject.h>
21+
#include <aws/crt/StlAllocator.h>
22+
23+
namespace Aws
24+
{
25+
namespace Iotidentity
26+
{
27+
28+
class AWS_IOTIDENTITY_API CreateCertificateFromCsrResponse final
29+
{
30+
public:
31+
CreateCertificateFromCsrResponse() = default;
32+
33+
CreateCertificateFromCsrResponse(const Crt::JsonView &doc);
34+
CreateCertificateFromCsrResponse &operator=(const Crt::JsonView &doc);
35+
36+
void SerializeToObject(Crt::JsonObject &doc) const;
37+
38+
Aws::Crt::Optional<Aws::Crt::String> CertificateId;
39+
Aws::Crt::Optional<Aws::Crt::String> CertificateOwnershipToken;
40+
Aws::Crt::Optional<Aws::Crt::String> CertificatePem;
41+
42+
private:
43+
static void LoadFromObject(CreateCertificateFromCsrResponse &obj, const Crt::JsonView &doc);
44+
};
45+
} // namespace Iotidentity
46+
} // namespace Aws
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#pragma once
2+
/* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
15+
* This file is generated
16+
*/
17+
18+
#include <aws/iotidentity/Exports.h>
19+
20+
#include <aws/crt/JsonObject.h>
21+
#include <aws/crt/StlAllocator.h>
22+
23+
namespace Aws
24+
{
25+
namespace Iotidentity
26+
{
27+
28+
class AWS_IOTIDENTITY_API CreateCertificateFromCsrSubscriptionRequest final
29+
{
30+
public:
31+
CreateCertificateFromCsrSubscriptionRequest() = default;
32+
33+
CreateCertificateFromCsrSubscriptionRequest(const Crt::JsonView &doc);
34+
CreateCertificateFromCsrSubscriptionRequest &operator=(const Crt::JsonView &doc);
35+
36+
void SerializeToObject(Crt::JsonObject &doc) const;
37+
38+
private:
39+
static void LoadFromObject(CreateCertificateFromCsrSubscriptionRequest &obj, const Crt::JsonView &doc);
40+
};
41+
} // namespace Iotidentity
42+
} // namespace Aws

0 commit comments

Comments
 (0)