nrfcloud-utils 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+ Copyright (c) 2025, Nordic Semiconductor ASA
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright
11
+ notice, this list of conditions and the following disclaimer in the
12
+ documentation and/or other materials provided with the distribution.
13
+
14
+ 3. Neither the name of Nordic Semiconductor ASA nor the names of its
15
+ contributors may be used to endorse or promote products derived from this
16
+ software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE
21
+ ARE DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
22
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
+ POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,109 @@
1
+ Metadata-Version: 2.3
2
+ Name: nrfcloud-utils
3
+ Version: 0.0.1
4
+ Summary: Scripts and utilities for working with the nRF Cloud
5
+ License: BSD-3-Clause
6
+ Author: Nordic Semiconductor ASA
7
+ Requires-Python: >=3.10,<4.0
8
+ Classifier: License :: OSI Approved :: BSD License
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Requires-Dist: cbor2 (>=5.4.2.post1,<6.0.0)
15
+ Requires-Dist: colorama (>=0.4.4,<0.5.0)
16
+ Requires-Dist: cryptography (>=44.0.1,<45.0.0)
17
+ Requires-Dist: pyjwt (>=2.3.0,<3.0.0)
18
+ Requires-Dist: pynrfjprog (>=10.23.0,<11.0.0)
19
+ Requires-Dist: pyserial (>=3.5,<4.0)
20
+ Requires-Dist: requests (>=2.32.0,<3.0.0)
21
+ Requires-Dist: semver (>=3.0.0,<4.0.0)
22
+ Requires-Dist: urllib3 (>=2.2.2,<3.0.0)
23
+ Project-URL: Repository, https://github.com/nRFCloud/utils
24
+ Description-Content-Type: text/markdown
25
+
26
+ # nRF Cloud Utilities
27
+
28
+ nRF Cloud Utils is a script collection to make it easier to interface with nRF Cloud.
29
+ A common use-case is to register devices with your account or to run a fota job.
30
+
31
+ The scripts in this repository mainly use endpoints in [the REST API](https://api.nrfcloud.com/v1).
32
+
33
+ The scripts are gathered from various teams and organized according to their programmatic language: [Python](https://github.com/nRFCloud/utils/tree/master/python/modem-firmware-1.3%2B).
34
+
35
+ See also the official [nRF Cloud documentation](https://docs.nordicsemi.com/bundle/nrf-cloud/page/index.html).
36
+
37
+ ## Install
38
+
39
+ Run the following command to use this package as a dependency:
40
+
41
+ pip3 install nrfcloud-utils
42
+
43
+ ## Requirements
44
+
45
+ Do you already have an nRF Cloud account? If not, please visit [nrfcloud.com](https://nrfcloud.com) and register. Then, click on the burger on the top-right to get to your user account. Take note of your API key, you will need it soon. Note that if you are part of multiple teams on nRF Cloud, the API key will be different for each one.
46
+
47
+ To register a device, you need compatible firmware flashed to it. Most scripts work with an [AT Host library](https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/libraries/modem/at_host.html) enabled app or the [AT Client sample](https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/samples/cellular/at_client/README.html) flashed.
48
+ However, if you intend to use the [Provisioning Service](https://docs.nordicsemi.com/bundle/nrf-cloud/page/SecurityServices/ProvisioningService/ProvisioningOverview.html), you will need to enable its [library](https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/libraries/networking/nrf_provisioning.html) in your firmware or flash the nRF Cloud Multi Service sample.
49
+
50
+ ## How-To: Registering devices quickly
51
+
52
+ Start by creating a local certificate authority (CA). Its contents won't be checked, but you need one to make certificates for your devices. Optionally, pass options to the script to specify owner information.
53
+
54
+ create_ca_cert
55
+
56
+ Now, you should have three `.pem` files containing the key pair and the CA certificate of your CA. The files have a unique prefix.
57
+
58
+ The fastest way to get your device registered is using the Device Credentials Installer:
59
+
60
+ device_credentials_installer -d --ca *_ca.pem --ca-key *_prv.pem --coap --verify
61
+
62
+ Upon success, you can find an `onboard.csv` file with information about your device. We need this file to register the certificate with your account.
63
+ If you encounter a `No device found` error, you might need to specify the serial port using the `--port` option.
64
+
65
+ Finally, add the device to your account with the Onboarding script:
66
+
67
+ nrf_cloud_onboard --api-key $API_KEY --csv onboard.csv
68
+
69
+ You can also install credentials on many devices in a row using the `--append` option and add the bulk `onboard.csv` to your account with the same command.
70
+
71
+ Congratulations! You have successfully registered your device. When compiling with the nRF Cloud Libraries, make sure to use the correct KConfig options:
72
+
73
+ CONFIG_NRF_CLOUD_CLIENT_ID_SRC_INTERNAL_UUID=y
74
+ CONFIG_NRF_CLOUD_SEC_TAG=16842753
75
+
76
+ For a more detailed overview of the scripts, see [Advanced Usage](ADVANCED.md). There, you can also find details on how to use the Provisioning Service instead of provisioning your devices locally.
77
+
78
+ ## Development installation
79
+
80
+ Clone the repository:
81
+
82
+ git clone https://github.com/nRFCloud/utils.git nrfcloud-utils
83
+ cd nrfcloud-utils
84
+
85
+ For development mode, you need [poetry](https://python-poetry.org/):
86
+
87
+ curl -sSL https://install.python-poetry.org | python3 -
88
+
89
+ Make sure `poetry` is in your PATH. If you're using `bash`:
90
+
91
+ echo 'export PATH=/home/$USER/.local/bin:$PATH' | tee -a ~/.bashrc
92
+ source ~/.bashrc
93
+
94
+ Install package dependencies, development dependencies, and the nrfcloud-utils into poetry's internal virtual environment:
95
+
96
+ poetry install
97
+
98
+ ## Test
99
+
100
+ Unit tests are included in the `tests` folder. Each test script corresponds to a script in the sources.
101
+ Static files used in the tests are put in the `tests/fixtures` folder.
102
+ Running the tests depends on a [development installation](#development-installation).
103
+
104
+ poetry run pytest
105
+
106
+ Check coverage
107
+
108
+ poetry run pytest --cov=. tests
109
+
@@ -0,0 +1,83 @@
1
+ # nRF Cloud Utilities
2
+
3
+ nRF Cloud Utils is a script collection to make it easier to interface with nRF Cloud.
4
+ A common use-case is to register devices with your account or to run a fota job.
5
+
6
+ The scripts in this repository mainly use endpoints in [the REST API](https://api.nrfcloud.com/v1).
7
+
8
+ The scripts are gathered from various teams and organized according to their programmatic language: [Python](https://github.com/nRFCloud/utils/tree/master/python/modem-firmware-1.3%2B).
9
+
10
+ See also the official [nRF Cloud documentation](https://docs.nordicsemi.com/bundle/nrf-cloud/page/index.html).
11
+
12
+ ## Install
13
+
14
+ Run the following command to use this package as a dependency:
15
+
16
+ pip3 install nrfcloud-utils
17
+
18
+ ## Requirements
19
+
20
+ Do you already have an nRF Cloud account? If not, please visit [nrfcloud.com](https://nrfcloud.com) and register. Then, click on the burger on the top-right to get to your user account. Take note of your API key, you will need it soon. Note that if you are part of multiple teams on nRF Cloud, the API key will be different for each one.
21
+
22
+ To register a device, you need compatible firmware flashed to it. Most scripts work with an [AT Host library](https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/libraries/modem/at_host.html) enabled app or the [AT Client sample](https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/samples/cellular/at_client/README.html) flashed.
23
+ However, if you intend to use the [Provisioning Service](https://docs.nordicsemi.com/bundle/nrf-cloud/page/SecurityServices/ProvisioningService/ProvisioningOverview.html), you will need to enable its [library](https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/libraries/networking/nrf_provisioning.html) in your firmware or flash the nRF Cloud Multi Service sample.
24
+
25
+ ## How-To: Registering devices quickly
26
+
27
+ Start by creating a local certificate authority (CA). Its contents won't be checked, but you need one to make certificates for your devices. Optionally, pass options to the script to specify owner information.
28
+
29
+ create_ca_cert
30
+
31
+ Now, you should have three `.pem` files containing the key pair and the CA certificate of your CA. The files have a unique prefix.
32
+
33
+ The fastest way to get your device registered is using the Device Credentials Installer:
34
+
35
+ device_credentials_installer -d --ca *_ca.pem --ca-key *_prv.pem --coap --verify
36
+
37
+ Upon success, you can find an `onboard.csv` file with information about your device. We need this file to register the certificate with your account.
38
+ If you encounter a `No device found` error, you might need to specify the serial port using the `--port` option.
39
+
40
+ Finally, add the device to your account with the Onboarding script:
41
+
42
+ nrf_cloud_onboard --api-key $API_KEY --csv onboard.csv
43
+
44
+ You can also install credentials on many devices in a row using the `--append` option and add the bulk `onboard.csv` to your account with the same command.
45
+
46
+ Congratulations! You have successfully registered your device. When compiling with the nRF Cloud Libraries, make sure to use the correct KConfig options:
47
+
48
+ CONFIG_NRF_CLOUD_CLIENT_ID_SRC_INTERNAL_UUID=y
49
+ CONFIG_NRF_CLOUD_SEC_TAG=16842753
50
+
51
+ For a more detailed overview of the scripts, see [Advanced Usage](ADVANCED.md). There, you can also find details on how to use the Provisioning Service instead of provisioning your devices locally.
52
+
53
+ ## Development installation
54
+
55
+ Clone the repository:
56
+
57
+ git clone https://github.com/nRFCloud/utils.git nrfcloud-utils
58
+ cd nrfcloud-utils
59
+
60
+ For development mode, you need [poetry](https://python-poetry.org/):
61
+
62
+ curl -sSL https://install.python-poetry.org | python3 -
63
+
64
+ Make sure `poetry` is in your PATH. If you're using `bash`:
65
+
66
+ echo 'export PATH=/home/$USER/.local/bin:$PATH' | tee -a ~/.bashrc
67
+ source ~/.bashrc
68
+
69
+ Install package dependencies, development dependencies, and the nrfcloud-utils into poetry's internal virtual environment:
70
+
71
+ poetry install
72
+
73
+ ## Test
74
+
75
+ Unit tests are included in the `tests` folder. Each test script corresponds to a script in the sources.
76
+ Static files used in the tests are put in the `tests/fixtures` folder.
77
+ Running the tests depends on a [development installation](#development-installation).
78
+
79
+ poetry run pytest
80
+
81
+ Check coverage
82
+
83
+ poetry run pytest --cov=. tests
@@ -0,0 +1,47 @@
1
+ [build-system]
2
+ requires = ["poetry-core"]
3
+ build-backend = "poetry.core.masonry.api"
4
+
5
+ [tool.poetry]
6
+ name = "nrfcloud-utils"
7
+ version = "v0.0.1"
8
+ description = "Scripts and utilities for working with the nRF Cloud"
9
+ authors = ["Nordic Semiconductor ASA"]
10
+ license = "BSD-3-Clause"
11
+ readme = "README.md"
12
+ repository = "https://github.com/nRFCloud/utils"
13
+ packages = [
14
+ { include = "nrfcloud_utils", from = "src" }
15
+ ]
16
+
17
+ [tool.poetry.dependencies]
18
+ python = "^3.10"
19
+ pyserial = "^3.5"
20
+ cbor2 = "^5.4.2.post1"
21
+ colorama = "^0.4.4"
22
+ cryptography = "^44.0.1"
23
+ pynrfjprog = "^10.23.0"
24
+ requests = "^2.32.0"
25
+ urllib3 = "^2.2.2"
26
+ semver = "^3.0.0"
27
+ pyjwt = "^2.3.0"
28
+
29
+ [tool.poetry.group.dev.dependencies]
30
+ pytest = "^7.3.1"
31
+ pytest-cov = "^4.0.0"
32
+ pytest-watch = "^4.2.0"
33
+
34
+ [tool.poetry.scripts]
35
+ claim_and_provision_device = "nrfcloud_utils.claim_and_provision_device:run"
36
+ claim_devices = "nrfcloud_utils.claim_devices:run"
37
+ create_ca_cert = "nrfcloud_utils.create_ca_cert:run"
38
+ create_device_credentials = "nrfcloud_utils.create_device_credentials:run"
39
+ create_proxy_jwt = "nrfcloud_utils.create_proxy_jwt:run"
40
+ device_credentials_installer = "nrfcloud_utils.device_credentials_installer:run"
41
+ gather_attestation_tokens = "nrfcloud_utils.gather_attestation_tokens:run"
42
+ modem_credentials_parser = "nrfcloud_utils.modem_credentials_parser:run"
43
+ nrf_cloud_device_mgmt = "nrfcloud_utils.nrf_cloud_device_mgmt:run"
44
+ nrf_cloud_onboard = "nrfcloud_utils.nrf_cloud_onboard:run"
45
+
46
+ [tool.pytest.ini_options]
47
+ addopts = ["--import-mode=importlib"]
File without changes
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env python3
2
+ #
3
+ # Copyright (c) 2025 Nordic Semiconductor ASA
4
+ #
5
+ # SPDX-License-Identifier: BSD-3-Clause
6
+
7
+ # Amazon Root CA 1 for connection to nRF Cloud: MQTT, REST, file downloads
8
+ aws_ca = """-----BEGIN CERTIFICATE-----
9
+ MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF
10
+ ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6
11
+ b24gUm9vdCBDQSAxMB4XDTE1MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFowOTEL
12
+ MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJv
13
+ b3QgQ0EgMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALJ4gHHKeNXj
14
+ ca9HgFB0fW7Y14h29Jlo91ghYPl0hAEvrAIthtOgQ3pOsqTQNroBvo3bSMgHFzZM
15
+ 9O6II8c+6zf1tRn4SWiw3te5djgdYZ6k/oI2peVKVuRF4fn9tBb6dNqcmzU5L/qw
16
+ IFAGbHrQgLKm+a/sRxmPUDgH3KKHOVj4utWp+UhnMJbulHheb4mjUcAwhmahRWa6
17
+ VOujw5H5SNz/0egwLX0tdHA114gk957EWW67c4cX8jJGKLhD+rcdqsq08p8kDi1L
18
+ 93FcXmn/6pUCyziKrlA4b9v7LWIbxcceVOF34GfID5yHI9Y/QCB/IIDEgEw+OyQm
19
+ jgSubJrIqg0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC
20
+ AYYwHQYDVR0OBBYEFIQYzIU07LwMlJQuCFmcx7IQTgoIMA0GCSqGSIb3DQEBCwUA
21
+ A4IBAQCY8jdaQZChGsV2USggNiMOruYou6r4lK5IpDB/G/wkjUu0yKGX9rbxenDI
22
+ U5PMCCjjmCXPI6T53iHTfIUJrU6adTrCC2qJeHZERxhlbI1Bjjt/msv0tadQ1wUs
23
+ N+gDS63pYaACbvXy8MWy7Vu33PqUXHeeE6V/Uq2V8viTO96LXFvKWlJbYK8U90vv
24
+ o/ufQJVtMVT8QtPHRh8jrdkPSHCa2XV4cdFyQzR1bldZwgJcJmApzyMZFo6IQ6XU
25
+ 5MsI+yMRQ+hDKXJioaldXgjUkK642M4UwtBV8ob2xJNDd2ZhwLnoQdeXeGADbkpy
26
+ rqXRfboQnoZsG4q5WTP468SQvvG5
27
+ -----END CERTIFICATE-----
28
+ """
29
+
30
+ # nRF Cloud CoAP CA (coap.nrfcloud.com)
31
+ nrf_cloud_coap_ca = """-----BEGIN CERTIFICATE-----
32
+ MIIBjzCCATagAwIBAgIUOEakGUS/7BfSlprkly7UK43ZAwowCgYIKoZIzj0EAwIw
33
+ FDESMBAGA1UEAwwJblJGIENsb3VkMB4XDTIzMDUyNDEyMzUzMloXDTQ4MTIzMDEy
34
+ MzUzMlowFDESMBAGA1UEAwwJblJGIENsb3VkMFkwEwYHKoZIzj0CAQYIKoZIzj0D
35
+ AQcDQgAEPVmJXT4TA1ljMcbPH0hxlzMDiPX73FHsdGM/6mqAwq9m2Nunr5/gTQQF
36
+ MBUZJaQ/rUycLmrT8i+NZ0f/OzoFsKNmMGQwHQYDVR0OBBYEFGusC7QaV825v0Ci
37
+ qEv2m1HhiScSMB8GA1UdIwQYMBaAFGusC7QaV825v0CiqEv2m1HhiScSMBIGA1Ud
38
+ EwEB/wQIMAYBAf8CAQAwDgYDVR0PAQH/BAQDAgGGMAoGCCqGSM49BAMCA0cAMEQC
39
+ IH/C3yf5aNFSFlm44CoP5P8L9aW/5woNrzN/kU5I+H38AiAwiHYlPclp25LgY8e2
40
+ n7e2W/H1LXJ7S3ENDBwKUF4qyw==
41
+ -----END CERTIFICATE-----
42
+ """
43
+
44
+ # nRF Cloud CoAP CA (dev)
45
+ nrf_cloud_coap_ca_dev = """-----BEGIN CERTIFICATE-----
46
+ MIIBmzCCAUKgAwIBAgIUOdcovsGv94HR18N97qIgq6mfyXowCgYIKoZIzj0EAwIw
47
+ GjEYMBYGA1UEAwwPblJGIENsb3VkIC0gRGV2MB4XDTIzMDMzMTEyMTM1NVoXDTQ4
48
+ MTIzMTEyMTM1NVowGjEYMBYGA1UEAwwPblJGIENsb3VkIC0gRGV2MFkwEwYHKoZI
49
+ zj0CAQYIKoZIzj0DAQcDQgAEsWwBJY6XL1tD+3qs62oHPzIR+gxAd2suL38kvJWP
50
+ rxeEJjDqUBP2+UvAMpDuChG/aQ3x5bw9enFlN1EUJaJrt6NmMGQwHQYDVR0OBBYE
51
+ FHJV6uiRFXRDMrIejIAbDRUkF2CAMB8GA1UdIwQYMBaAFHJV6uiRFXRDMrIejIAb
52
+ DRUkF2CAMBIGA1UdEwEB/wQIMAYBAf8CAQAwDgYDVR0PAQH/BAQDAgGGMAoGCCqG
53
+ SM49BAMCA0cAMEQCIDJdB0q6IVTSMBJCjgrdqsazeUbkxWG019X/yJTQyd2QAiA8
54
+ AmLG/0x09X2Qm+30MgNxOE4BiybZuwH9NF8KQVqQlg==
55
+ -----END CERTIFICATE-----
56
+ """
57
+
58
+ # nRF Cloud CoAP CA (beta)
59
+ nrf_cloud_coap_ca_beta = """-----BEGIN CERTIFICATE-----
60
+ MIIBnzCCAUSgAwIBAgIUWfE1+Lh4L1RP15WBkwINIgLZgtIwCgYIKoZIzj0EAwIw
61
+ GzEZMBcGA1UEAwwQblJGIENsb3VkIC0gQmV0YTAeFw0yMzA1MDgwODI4MDdaFw00
62
+ ODEyMzEwODI4MDdaMBsxGTAXBgNVBAMMEG5SRiBDbG91ZCAtIEJldGEwWTATBgcq
63
+ hkjOPQIBBggqhkjOPQMBBwNCAARvM7cUr6xL9C992usqvq6aH+LLNbG6IWoiOYBo
64
+ QJEHnFo0Zb6sIwBWPJUj/DhQxu73/oCF6IAcv5yDdXJBl0fBo2YwZDAdBgNVHQ4E
65
+ FgQUt7i3/I+0fTq7gaFSKfxkV2wpiv0wHwYDVR0jBBgwFoAUt7i3/I+0fTq7gaFS
66
+ KfxkV2wpiv0wEgYDVR0TAQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwCgYI
67
+ KoZIzj0EAwIDSQAwRgIhAMDbNg4llzbBpmCKHu7Vv0WtyQnEwWbEr5eRhtX33O4a
68
+ AiEA7sD3ABtaQa4df/uhnytbO5W2Qf8YfHtZLsrWmPKKR5w=
69
+ -----END CERTIFICATE-----
70
+ """
71
+
72
+ def get_ca_certs(coap=False, stage="prod"):
73
+ if not coap:
74
+ return aws_ca
75
+
76
+ if stage == "dev":
77
+ return nrf_cloud_coap_ca_dev + aws_ca
78
+ if stage == "beta":
79
+ return nrf_cloud_coap_ca_beta + aws_ca
80
+
81
+ return nrf_cloud_coap_ca + aws_ca