NordicSemiconductor / asset-tracker-cloud-azure-js

A reference implementation of a serverless backend for an IoT product developed using in TypeScript.
https://docs.nordicsemi.com/bundle/nrf-asset-tracker-saga/
BSD 3-Clause "New" or "Revised" License
0 stars 2 forks source link

Backport create-and-provision-device-cert fixes to v1.8.x branch #306

Closed coderbyheart closed 2 years ago

coderbyheart commented 2 years ago

Recent changes to have the device create the private key makes some of the code in the create-and-provision-device-cert CLI command no longer work.

This has been fixed in 7d512c05337f600c5c6f6b241d37147078124ef2 but this change can't be cherry picked directly to v1.8.x branch, because there was an update to the way the serialport package is used. So more work is needed to make the fix work with v1.8.x without including other breaking changes from v9 and v8.

coderbyheart commented 2 years ago

Works.

$ node cli create-and-provision-device-cert --dk --debug --delete-private-key

Flasing certificate /dev/ttyACM0
Connecting to /dev/ttyACM0
Inactivity timeout 10 seconds
/dev/ttyACM0 connected
AT Host h 
w4 4001e504 2
w4 4001e50c 1
sleep 100
rx 1000
h
w4 4001e504 1
loadfile /home/m/nrf-asset-tracker/azure/node_modules/@nordicsemiconductor/firmware-ci-device-helpers/at_host/91dk_at_host_increased_buf.hex
rx 1000
g
exit
AT Host SEGGER J-Link Commander V7.62c (Compiled Mar 23 2022 16:44:40)
AT Host DLL version V7.62c, compiled Mar 23 2022 16:44:26
AT Host J-Link Command File read successfully.
AT Host Processing script file...
AT Host J-Link>h 
AT Host J-Link connection not established yet but required for command.
AT Host Connecting to J-Link via USB...
AT Host O.K.
AT Host Firmware: J-Link OB-K22-NordicSemi compiled Dec  3 2021 15:46:55
AT Host Hardware version: V1.00
AT Host S/N: 960013621
AT Host License(s): RDI, FlashBP, FlashDL, JFlash, GDB
AT Host VTref=3.300V
AT Host Target connection not established yet but required for command.
AT Host Device "NRF9160_XXAA" selected.
AT Host Connecting to target via SWD
AT Host ConfigTargetSettings() start
AT Host ---Setting ROM table---
AT Host ConfigTargetSettings() end
AT Host Found SW-DP with ID 0x6BA02477
AT Host DPIDR: 0x6BA02477
AT Host CoreSight SoC-400 or earlier
AT Host Scanning AP map to find all available APs
AT Host AP[7]: Stopped AP scan as end of AP map has been reached
AT Host AP[0]: AHB-AP (IDR: 0x84770001)
AT Host AP[1]: AHB-AP (IDR: 0x24770011)
AT Host AP[2]: JTAG-AP (IDR: 0x12880000)
AT Host AP[3]: APB-AP (IDR: 0x54770002)
AT Host AP[4]: JTAG-AP (IDR: 0x12880000)
AT Host AP[5]: JTAG-AP (IDR: 0x12880000)
AT Host AP[6]: MEM-AP (IDR: 0x128800A1)
AT Host Iterating through AP map to find AHB-AP to use
AT Host AP[0]: Core found
AT Host AP[0]: AHB-AP ROM base: 0xE00FF000
AT Host CPUID register: 0x410FD212. Implementer code: 0x41 (ARM)
AT Host Feature set: Mainline
AT Host Found Cortex-M33 r0p2, Little endian.
AT Host FPUnit: 8 code (BP) slots and 0 literal slots
AT Host Security extension: implemented
AT Host Secure debug: enabled
AT Host CoreSight components:
AT Host ROMTbl[0] @ E00FF000
AT Host [0][0]: E000E000 CID B105900D PID 000BBD21 DEVARCH 47702A04 DEVTYPE 00 Cortex-M33
AT Host [0][1]: E0001000 CID B105900D PID 000BBD21 DEVARCH 47701A02 DEVTYPE 00 DWT
AT Host [0][2]: E0002000 CID B105900D PID 000BBD21 DEVARCH 47701A03 DEVTYPE 00 FPB
AT Host [0][3]: E0000000 CID B105900D PID 000BBD21 DEVARCH 47701A01 DEVTYPE 43 ITM
AT Host [0][5]: E0041000 CID B105900D PID 002BBD21 DEVARCH 47724A13 DEVTYPE 13 ETM
AT Host [0][6]: E0042000 CID B105900D PID 000BBD21 DEVARCH 47701A14 DEVTYPE 14 CSS600-CTI
AT Host Cortex-M33 identified.
AT Host PC = 00011AB6, CycleCnt = 001D943C
AT Host R0 = 00000000, R1 = 00000000, R2 = 00000000, R3 = 00000000
AT Host R4 = 20014FE0, R5 = 00000000, R6 = 00000000, R7 = 00000000
AT Host R8 = 00000000, R9 = 00000000, R10= 00000000, R11= 00000000
AT Host R12= 00000000
AT Host SP(R13)= 20018720, MSP= 20018F30, PSP= 20018720, R14(LR) = 00018969
AT Host XPSR = 61000000: APSR = nZCvq, EPSR = 01000000, IPSR = 000 (NoException)
AT Host CFBP = 02000001, CONTROL = 02, FAULTMASK = 00, BASEPRI = 00, PRIMASK = 01
AT Host MSPLIM = 20018730
AT Host PSPLIM = 200185F0
AT Host Security extension regs:
AT Host MSP_S = 20002E38, MSP_NS = 20018F30
AT Host MSPLIM_S = 20002638, MSPLIM_NS = 20018730
AT Host PSP_S = 20002418, PSP_NS = 20018720
AT Host PSPLIM_S = 200014F8, PSPLIM_NS = 200185F0
AT Host CONTROL_S  = 02, FAULTMASK_S  = 00, BASEPRI_S  = 00, PRIMASK_S  = 00
AT Host CONTROL_NS = 02, FAULTMASK_NS = 00, BASEPRI_NS = 00, PRIMASK_NS = 01
AT Host FPS0 = 00000000, FPS1 = 00000000, FPS2 = 00000000, FPS3 = 00000000
AT Host FPS4 = 00000000, FPS5 = 00000000, FPS6 = 00000000, FPS7 = 00000000
AT Host FPS8 = 00000000, FPS9 = 00000000, FPS10= 00000000, FPS11= 00000000
AT Host FPS12= 00000000, FPS13= 00000000, FPS14= 00000000, FPS15= 00000000
AT Host FPS16= 00000000, FPS17= 00000000, FPS18= 00000000, FPS19= 00000000
AT Host FPS20= 00000000, FPS21= 00000000, FPS22= 00000000, FPS23= 00000000
AT Host FPS24= 00000000, FPS25= 00000000, FPS26= 00000000, FPS27= 00000000
AT Host FPS28= 00000000, FPS29= 00000000, FPS30= 00000000, FPS31= 00000000
AT Host FPSCR= 00000000
AT Host J-Link>w4 4001e504 2
AT Host Writing 00000002 -> 4001E504
AT Host J-Link>w4 4001e50c 1
AT Host Writing 00000001 -> 4001E50C
AT Host J-Link>sleep 100
AT Host Sleep(100)
AT Host J-Link>rx 1000
AT Host Reset delay: 1000 ms
AT Host Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.
AT Host Reset: ARMv8M core with Security Extension enabled detected.
AT Host Reset: Halt core after reset via DEMCR.VC_CORERESET.
AT Host Reset: Reset device via AIRCR.SYSRESETREQ.
AT Host J-Link>h
AT Host PC = 000022BC, CycleCnt = 00000000
AT Host R0 = 00000000, R1 = 00000000, R2 = 00000000, R3 = 00000000
AT Host R4 = 00000000, R5 = 00000000, R6 = 00000000, R7 = 00000000
AT Host R8 = 00000000, R9 = 00000000, R10= 00000000, R11= 00000000
AT Host R12= 00000000
AT Host SP(R13)= 200024F8, MSP= 200024F8, PSP= 00000000, R14(LR) = FFFFFFFF
AT Host XPSR = F9000000: APSR = NZCVQ, EPSR = 01000000, IPSR = 000 (NoException)
AT Host CFBP = 00000000, CONTROL = 00, FAULTMASK = 00, BASEPRI = 00, PRIMASK = 00
AT Host MSPLIM = 00000000
AT Host PSPLIM = 00000000
AT Host Security extension regs:
AT Host MSP_S = 200024F8, MSP_NS = 00000000
AT Host MSPLIM_S = 00000000, MSPLIM_NS = 00000000
AT Host PSP_S = 00000000, PSP_NS = 20018720
AT Host PSPLIM_S = 00000000, PSPLIM_NS = 00000000
AT Host CONTROL_S  = 00, FAULTMASK_S  = 00, BASEPRI_S  = 00, PRIMASK_S  = 00
AT Host CONTROL_NS = 00, FAULTMASK_NS = 00, BASEPRI_NS = 00, PRIMASK_NS = 00
AT Host FPS0 = 00000000, FPS1 = 00000000, FPS2 = 00000000, FPS3 = 00000000
AT Host FPS4 = 00000000, FPS5 = 00000000, FPS6 = 00000000, FPS7 = 00000000
AT Host FPS8 = 00000000, FPS9 = 00000000, FPS10= 00000000, FPS11= 00000000
AT Host FPS12= 00000000, FPS13= 00000000, FPS14= 00000000, FPS15= 00000000
AT Host FPS16= 00000000, FPS17= 00000000, FPS18= 00000000, FPS19= 00000000
AT Host FPS20= 00000000, FPS21= 00000000, FPS22= 00000000, FPS23= 00000000
AT Host FPS24= 00000000, FPS25= 00000000, FPS26= 00000000, FPS27= 00000000
AT Host FPS28= 00000000, FPS29= 00000000, FPS30= 00000000, FPS31= 00000000
AT Host FPSCR= 00000000
AT Host J-Link>w4 4001e504 1
AT Host Writing 00000001 -> 4001E504
AT Host J-Link>loadfile /home/m/nrf-asset-tracker/azure/node_modules/@nordicsemiconductor/firmware-ci-device-helpers/at_host/91dk_at_host_increased_buf.hex
AT Host Downloading file [/home/m/nrf-asset-tracker/azure/node_modules/@nordicsemiconductor/firmware-ci-device-helpers/at_host/91dk_at_host_increased_buf.hex]...
AT Host Comparing flash   [000%]
AT 050%]
AT 050%]
AT 100%] Done.
AT Host J-Link: Flash download: Bank 2 @ 0x00000000: Skipped. Contents already match
AT Host O.K.
AT Host J-Link>rx 1000
AT Host Reset delay: 1000 ms
AT Host Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.
AT Host Reset: ARMv8M core with Security Extension enabled detected.
AT Host Reset: Halt core after reset via DEMCR.VC_CORERESET.
AT Host Reset: Reset device via AIRCR.SYSRESETREQ.
AT Host J-Link>g
AT Host J-Link>exit
AT Host Script processing completed.
/dev/ttyACM0 *** Booting Zephyr OS build v2.7.0-ncs1  ***
/dev/ttyACM0 Flash regions              Domain          Permissions
/dev/ttyACM0 00 01 0x00000 0x10000      Secure          rwxl
/dev/ttyACM0 02 31 0x10000 0x100000     Non-Secure      rwxl
/dev/ttyACM0 Non-secure callable region 0 placed in flash region 1 with size 32.
/dev/ttyACM0 SRAM region                Domain          Permissions
/dev/ttyACM0 00 07 0x00000 0x10000      Secure          rwxl
/dev/ttyACM0 08 31 0x10000 0x40000      Non-Secure      rwxl
/dev/ttyACM0 Peripheral         Domain          Status
/dev/ttyACM0 00 NRF_P0               Non-Secure OK
/dev/ttyACM0 01 NRF_CLOCK            Non-Secure OK
/dev/ttyACM0 02 NRF_RTC0             Non-Secure OK
/dev/ttyACM0 03 NRF_RTC1             Non-Secure OK
/dev/ttyACM0 04 NRF_NVMC             Non-Secure OK
/dev/ttyACM0 05 NRF_UARTE1           Non-Secure OK
/dev/ttyACM0 06 NRF_UARTE2           Secure             SKIP
/dev/ttyACM0 07 NRF_TWIM2            Non-Secure OK
/dev/ttyACM0 08 NRF_SPIM3            Non-Secure OK
/dev/ttyACM0 09 NRF_TIMER0           Non-Secure OK
/dev/ttyACM0 10 NRF_TIMER1           Non-Secure OK
/dev/ttyACM0 11 NRF_TIMER2           Non-Secure OK
/dev/ttyACM0 12 NRF_SAADC            Non-Secure OK
/dev/ttyACM0 13 NRF_PWM0             Non-Secure OK
/dev/ttyACM0 14 NRF_PWM1             Non-Secure OK
/dev/ttyACM0 15 NRF_PWM2             Non-Secure OK
/dev/ttyACM0 16 NRF_PWM3             Non-Secure OK
/dev/ttyACM0 17 NRF_WDT              Non-Secure OK
/dev/ttyACM0 18 NRF_IPC              Non-Secure OK
/dev/ttyACM0 19 NRF_VMC              Non-Secure OK
/dev/ttyACM0 20 NRF_FPU              Non-Secure OK
/dev/ttyACM0 21 NRF_EGU0             Non-Secure OK
/dev/ttyACM0 22 NRF_EGU1             Non-Secure OK
/dev/ttyACM0 23 NRF_EGU2             Non-Secure OK
/dev/ttyACM0 24 NRF_EGU3             Non-Secure OK
/dev/ttyACM0 25 NRF_EGU4             Non-Secure OK
/dev/ttyACM0 26 NRF_EGU5             Non-Secure OK
/dev/ttyACM0 27 NRF_DPPIC            Non-Secure OK
/dev/ttyACM0 28 NRF_REGULATORS       Non-Secure OK
/dev/ttyACM0 29 NRF_PDM              Non-Secure OK
/dev/ttyACM0 30 NRF_I2S              Non-Secure OK
/dev/ttyACM0 31 NRF_GPIOTE1          Non-Secure OK
/dev/ttyACM0 SPM: NS image at 0x10000
/dev/ttyACM0 SPM: NS MSP at 0x200185f0
/dev/ttyACM0 SPM: NS reset vector at 0x11ff5
/dev/ttyACM0 SPM: prepare to jump to Non-Secure image.
/dev/ttyACM0 *** Booting Zephyr OS build v2.7.0-ncs1  ***
/dev/ttyACM0 The AT host sample started
/dev/ttyACM0 AT> AT+CGSN=1
/dev/ttyACM0 +CGSN: "352656100391948"
/dev/ttyACM0 <AT +CGSN: "352656100391948"
/dev/ttyACM0 OK
/dev/ttyACM0 <AT OK
IMEI: 352656100391948
/dev/ttyACM0 AT> AT+CGMR
/dev/ttyACM0 mfw_nrf9160_1.3.1
/dev/ttyACM0 <AT mfw_nrf9160_1.3.1
/dev/ttyACM0 OK
/dev/ttyACM0 <AT OK
/dev/ttyACM0 AT> AT+CGSN=1
/dev/ttyACM0 +CGSN: "352656100391948"
/dev/ttyACM0 <AT +CGSN: "352656100391948"
/dev/ttyACM0 OK
/dev/ttyACM0 <AT OK
/dev/ttyACM0 AT> AT+CFUN=4
/dev/ttyACM0 OK
/dev/ttyACM0 <AT OK
/dev/ttyACM0 AT> AT%CMNG=3,42,2
/dev/ttyACM0 OK
/dev/ttyACM0 <AT OK
/dev/ttyACM0 AT> AT%KEYGEN=42,2,0,"CN=352656100391948","101010000"
/dev/ttyACM0 %KEYGEN: "MIH1MIGaAgEAMBoxGDAWBgNVBAMMDzM1MjY1NjEwMDM5MTk0ODBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABFRSVWK0NSRxpUIpLC692G5_jC0rfpXG7Hz1uy6g3SWKUhSjCwUNGarVqggew7nw6qS0dtt-8Fp98p4gVd3DHumgHjAcBgkqhkiG9w0BCQ4xDzANMAsGA1UdDwQEAwIDqDAMBggqhkjOPQQDAgUAA0gAMEUCIQCo5aJNgnjd7PIkxsUCMWNC8qDSkjgQJZoL5l62_520qQIgOeDDZH8Ms1YO4d_qJ0N1_39-ytwczt8JVyzBFhfxGUs.0oRDoQEmoQRBIVhM2dn3hQlQUDYxVDkwTViAwhgVjzEMRkIYKlggmP26JyPZJNtJaWFc55jPD-4iAHMC1YL9_d0nOAtMazJQV_MSkAN4DA4d8uQ-QECxn1hAKu67wPVyGwBNsfQrwUfSrhKJ2vOYsNOiBIwe0fOGllAPa8jI1VTTK9K_DDChXIAAeOIm-4n_e2HJoOlPVmB44A"
/dev/ttyACM0 <AT %KEYGEN: "MIH1MIGaAgEAMBoxGDAWBgNVBAMMDzM1MjY1NjEwMDM5MTk0ODBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABFRSVWK0NSRxpUIpLC692G5_jC0rfpXG7Hz1uy6g3SWKUhSjCwUNGarVqggew7nw6qS0dtt-8Fp98p4gVd3DHumgHjAcBgkqhkiG9w0BCQ4xDzANMAsGA1UdDwQEAwIDqDAMBggqhkjOPQQDAgUAA0gAMEUCIQCo5aJNgnjd7PIkxsUCMWNC8qDSkjgQJZoL5l62_520qQIgOeDDZH8Ms1YO4d_qJ0N1_39-ytwczt8JVyzBFhfxGUs.0oRDoQEmoQRBIVhM2dn3hQlQUDYxVDkwTViAwhgVjzEMRkIYKlggmP26JyPZJNtJaWFc55jPD-4iAHMC1YL9_d0nOAtMazJQV_MSkAN4DA4d8uQ-QECxn1hAKu67wPVyGwBNsfQrwUfSrhKJ2vOYsNOiBIwe0fOGllAPa8jI1VTTK9K_DDChXIAAeOIm-4n_e2HJoOlPVmB44A"
/dev/ttyACM0 OK
/dev/ttyACM0 <AT OK
/dev/ttyACM0 AT> AT+CFUN=1
/dev/ttyACM0 OK
/dev/ttyACM0 <AT OK
Intermediate certificate: 3d8f5621-064f-4cc6-903d-f0ab62398594
Generating certificate for device 352656100391948
-----BEGIN CERTIFICATE-----
MIICNDCCARygAwIBAgIEIGGvgzANBgkqhkiG9w0BAQsFADBLMUkwRwYDVQQDDEBB
...
V0p6eE/VM0RFXKMgn8+f0hqKCuK1u35d2rzvp4/+9eqLkPEZtXztNw==
-----END CERTIFICATE-----
/home/m/nrf-asset-tracker/azure/certificates/assettrackerprodIotHub.azure-devices.net/device-352656100391948.bundle.pem written
/home/m/nrf-asset-tracker/azure/certificates/assettrackerprodIotHub.azure-devices.net/device-352656100391948.intermediateCertId written
/home/m/nrf-asset-tracker/azure/certificates/assettrackerprodIotHub.azure-devices.net/device-352656100391948.pem written
Certificate for device generated.
Certificate ID: 352656100391948

Firmware configuration:

DPS hostname: global.azure-devices-provisioning.net
ID scope: 0ne002847CD
/dev/ttyACM0 No data received after 10 seconds
/dev/ttyACM0 closing port
/dev/ttyACM0 port closed
/dev/ttyACM0 port closed