samples: net: cloud: drop Google Cloud IoT Core
Google Cloud IoT Core has been retired on August 16, 2023. Removed the sample and the link to it in a previous release note. Added a redirect to other IoT cloud samples. Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
This commit is contained in:
parent
7140b6f9c1
commit
c26679be42
|
@ -163,4 +163,5 @@ REDIRECTS = [
|
|||
('reference/usermode/overview', 'kernel/usermode/overview'),
|
||||
('reference/usermode/syscalls', 'kernel/usermode/syscalls'),
|
||||
('reference/util/index', 'kernel/util/index'),
|
||||
('samples/net/cloud/google_iot_mqtt', 'samples/net/cloud'),
|
||||
]
|
||||
|
|
|
@ -858,7 +858,7 @@ Networking
|
|||
* Added support for SOCKS5 proxy in MQTT client.
|
||||
* Added support for IPSO Timer object in LWM2M.
|
||||
* Added support for receiving gratuitous ARP request.
|
||||
* Added :ref:`sample application <google-iot-mqtt-sample>` for Google IoT Cloud.
|
||||
* Added sample application for Google IoT Cloud.
|
||||
* :ref:`Network interface <net_if_interface>` numbering starts now from 1 for
|
||||
POSIX compatibility.
|
||||
* :ref:`OpenThread <thread_protocol_interface>` enhancements.
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(google_iot_mqtt)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
||||
zephyr_include_directories(${APPLICATION_SOURCE_DIR}/src/tls_config)
|
||||
|
||||
if(USE_DUMMY_KEY)
|
||||
target_sources(app PRIVATE ${APPLICATION_SOURCE_DIR}/src/private_info/test_key.c)
|
||||
else()
|
||||
if(NOT EXISTS ${APPLICATION_SOURCE_DIR}/src/private_info/key.c)
|
||||
message(FATAL_ERROR "!!!!!! Generate key file before continuing. See README !!!!!")
|
||||
endif()
|
||||
|
||||
target_sources(app PRIVATE ${APPLICATION_SOURCE_DIR}/src/private_info/key.c)
|
||||
endif()
|
|
@ -1,33 +0,0 @@
|
|||
# Private config options for Google Cloud IOT application
|
||||
|
||||
# Copyright (c) 2018 Linaro
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
mainmenu "Google IOT MQTT/TLS sample application"
|
||||
|
||||
config CLOUD_CLIENT_ID
|
||||
string "Client ID string"
|
||||
default "put client string here"
|
||||
help
|
||||
Set required client string that matches Google Cloud project
|
||||
|
||||
config CLOUD_AUDIENCE
|
||||
string "Audience string"
|
||||
default "put audience string here"
|
||||
help
|
||||
Set required audience string that matches Google Cloud project
|
||||
|
||||
config CLOUD_SUBSCRIBE_CONFIG
|
||||
string "Subscription string for config"
|
||||
default "put subscription string here"
|
||||
help
|
||||
Set required subscription string that matches Google Cloud project
|
||||
config item.
|
||||
|
||||
config CLOUD_PUBLISH_TOPIC
|
||||
string "Publish topic string"
|
||||
default "put topic string here"
|
||||
help
|
||||
Set publish topics string that matches Google Cloud project
|
||||
|
||||
source "Kconfig.zephyr"
|
|
@ -1,64 +0,0 @@
|
|||
.. _google-iot-mqtt-sample:
|
||||
|
||||
Google IOT MQTT Sample
|
||||
######################
|
||||
|
||||
Overview
|
||||
********
|
||||
|
||||
This sample application demonstrates a "full stack" application. This
|
||||
currently is able to
|
||||
|
||||
- Acquire a DHCPv4 lease.
|
||||
- Connect to an SNTP server and acquire current time
|
||||
- Establish a TLS connection with the Google IOT Cloud servers
|
||||
- Publish data to the Google IOT Cloud
|
||||
- Send/Receive keep alive / pings from cloud server
|
||||
|
||||
The source code for this sample application can be found at:
|
||||
:zephyr_file:`samples/net/cloud/google_iot_mqtt`.
|
||||
|
||||
Requirements
|
||||
************
|
||||
- Entropy source
|
||||
- Google IOT Cloud account
|
||||
- Google IOT Cloud credentials and required information
|
||||
- Network connectivity
|
||||
|
||||
Building and Running
|
||||
********************
|
||||
This application has been built and tested on the NXP FRDMK64F. RSA or
|
||||
ECDSA certs/keys are required to authenticate to the Google IOT Cloud.
|
||||
The application includes a key creation script.
|
||||
|
||||
Run the ``create_keys.py`` script in the
|
||||
``samples/net/cloud/google_iot_mqtt/src/private_info/`` directory.
|
||||
Be sure that they key type generated (RSA or ECDSA) matches your
|
||||
config of either :code:`JWT_SIGN_RSA` or :code:`JWT_SIGN_ECDSA`.
|
||||
|
||||
Users will also be required to configure the following Kconfig options
|
||||
based on their Google Cloud IOT project. The following values come
|
||||
from the Google Cloud Platform itself:
|
||||
|
||||
- PROJECT_ID: When you select your project at the top of the UI, it
|
||||
should have a "name", and there should be an ID field as well. This
|
||||
seems to be two words and a number, separated by hyphens.
|
||||
- REGION: The Region shows in the list of registries for your
|
||||
registry. And example is "us-central1".
|
||||
- REGISTRY_ID: Each registry has an id. This is a string given when
|
||||
creating the registry.
|
||||
- DEVICE_ID: A name given for each device. When viewing the table of
|
||||
devices, this will be shown.
|
||||
|
||||
From these values, the config values can be set using the following
|
||||
template:
|
||||
|
||||
.. code-block:: kconfig
|
||||
|
||||
CLOUD_CLIENT_ID="projects/PROJECT_ID/locations/REGION/registries/REGISTRY_ID/devices/DEVICE_ID"
|
||||
CLOUD_AUDIENCE="PROJECT_ID"
|
||||
CLOUD_SUBSCRIBE_CONFIG="/devices/DEVICE_ID/config"
|
||||
CLOUD_PUBLISH_TOPIC="/devices/DEVICE_ID/state"
|
||||
|
||||
See `Google Cloud MQTT Documentation
|
||||
<https://cloud.google.com/iot/docs/how-tos/mqtt-bridge>`_.
|
|
@ -1,64 +0,0 @@
|
|||
CONFIG_NETWORKING=y
|
||||
CONFIG_NET_IPV6=n
|
||||
CONFIG_NET_IPV4=y
|
||||
CONFIG_NET_UDP=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_DHCPV4=y
|
||||
CONFIG_STDOUT_CONSOLE=y
|
||||
|
||||
CONFIG_NET_PKT_RX_COUNT=4
|
||||
CONFIG_NET_PKT_TX_COUNT=4
|
||||
CONFIG_NET_BUF_RX_COUNT=12
|
||||
CONFIG_NET_BUF_TX_COUNT=12
|
||||
|
||||
CONFIG_INIT_STACKS=y
|
||||
|
||||
CONFIG_JWT=y
|
||||
CONFIG_JWT_SIGN_ECDSA=y
|
||||
|
||||
CONFIG_NET_MGMT=y
|
||||
CONFIG_NET_MGMT_EVENT=y
|
||||
|
||||
CONFIG_LOG=y
|
||||
|
||||
# This shouldn't need to be set, but isn't selected properly.
|
||||
CONFIG_NEWLIB_LIBC=y
|
||||
|
||||
CONFIG_DNS_SERVER_IP_ADDRESSES=y
|
||||
CONFIG_DNS_SERVER1="8.8.8.8"
|
||||
|
||||
CONFIG_DNS_RESOLVER=y
|
||||
CONFIG_DNS_RESOLVER_ADDITIONAL_BUF_CTR=2
|
||||
CONFIG_SNTP=y
|
||||
|
||||
CONFIG_SLIP_STATISTICS=n
|
||||
|
||||
CONFIG_HW_STACK_PROTECTION=y
|
||||
CONFIG_MAIN_STACK_SIZE=4096
|
||||
|
||||
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=16384
|
||||
|
||||
CONFIG_PTHREAD_IPC=n
|
||||
CONFIG_NET_SOCKETS=y
|
||||
CONFIG_MQTT_LIB=y
|
||||
CONFIG_MQTT_LIB_TLS=y
|
||||
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
|
||||
|
||||
|
||||
# Enable MBEDTLS
|
||||
CONFIG_MBEDTLS=y
|
||||
CONFIG_MBEDTLS_BUILTIN=y
|
||||
|
||||
CONFIG_NET_SOCKETS_POSIX_NAMES=y
|
||||
|
||||
CONFIG_MBEDTLS_ENABLE_HEAP=y
|
||||
CONFIG_MBEDTLS_HEAP_SIZE=56240
|
||||
CONFIG_MBEDTLS_USER_CONFIG_ENABLE=y
|
||||
CONFIG_MBEDTLS_USER_CONFIG_FILE="user-tls-conf.h"
|
||||
|
||||
# Please see README.rst in this directory for instructions
|
||||
# on where to get the values for these config entries.
|
||||
CONFIG_CLOUD_CLIENT_ID="projects/<PROJECT_ID>/locations/<REGION>/registries/<REGISTRY_ID>/devices/<DEVICE_ID>"
|
||||
CONFIG_CLOUD_AUDIENCE="<PROJECT_ID>"
|
||||
CONFIG_CLOUD_SUBSCRIBE_CONFIG="/devices/<DEVICE_ID>/config"
|
||||
CONFIG_CLOUD_PUBLISH_TOPIC="/devices/<DEVICE_ID>/state"
|
|
@ -1,19 +0,0 @@
|
|||
sample:
|
||||
description: MQTT sample app to Google IoT cloud
|
||||
name: google_iot_mqtt
|
||||
common:
|
||||
tags:
|
||||
- net
|
||||
- mqtt
|
||||
- cloud
|
||||
harness: net
|
||||
filter: TOOLCHAIN_HAS_NEWLIB == 1
|
||||
extra_args: USE_DUMMY_KEY=1
|
||||
tests:
|
||||
sample.net.cloud.google_iot_mqtt:
|
||||
depends_on: netif
|
||||
platform_allow:
|
||||
- frdm_k64f
|
||||
- qemu_x86
|
||||
integration_platforms:
|
||||
- qemu_x86
|
|
@ -1,66 +0,0 @@
|
|||
/* DHCPv4 client startup. */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2018 Linaro Ltd
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
LOG_MODULE_DECLARE(net_google_iot_mqtt, LOG_LEVEL_DBG);
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
|
||||
#include <zephyr/net/net_if.h>
|
||||
#include <zephyr/net/net_core.h>
|
||||
#include <zephyr/net/net_context.h>
|
||||
#include <zephyr/net/net_mgmt.h>
|
||||
|
||||
static struct net_mgmt_event_callback mgmt_cb;
|
||||
|
||||
/* Semaphore to indicate a lease has been acquired. */
|
||||
static K_SEM_DEFINE(got_address, 0, 1);
|
||||
|
||||
static void handler(struct net_mgmt_event_callback *cb,
|
||||
uint32_t mgmt_event,
|
||||
struct net_if *iface)
|
||||
{
|
||||
int i;
|
||||
bool notified = false;
|
||||
|
||||
if (mgmt_event != NET_EVENT_IPV4_ADDR_ADD) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) {
|
||||
|
||||
if (iface->config.ip.ipv4->unicast[i].addr_type !=
|
||||
NET_ADDR_DHCP) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!notified) {
|
||||
k_sem_give(&got_address);
|
||||
notified = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a DHCP client, and wait for a lease to be acquired.
|
||||
*/
|
||||
void app_dhcpv4_startup(void)
|
||||
{
|
||||
LOG_INF("starting DHCPv4");
|
||||
|
||||
net_mgmt_init_event_callback(&mgmt_cb, handler,
|
||||
NET_EVENT_IPV4_ADDR_ADD);
|
||||
net_mgmt_add_event_callback(&mgmt_cb);
|
||||
|
||||
net_dhcpv4_start(net_if_get_default());
|
||||
|
||||
/* Wait for a lease. */
|
||||
k_sem_take(&got_address, K_FOREVER);
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
/* DHCPv4 client startup. */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2018 Linaro Ltd
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef __DHCP_H__
|
||||
#define __DHCP_H__
|
||||
|
||||
void app_dhcpv4_startup(void);
|
||||
|
||||
#endif /* not __DHCP_H__ */
|
|
@ -1,107 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Linaro Ltd
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* vim: ft=c
|
||||
*
|
||||
* Generated from downloading GlobalSign Root Certificate R2 from
|
||||
* https://aboutssl.org/globalsign-root-certificates-licensing-and-use/
|
||||
* and extracting the following information using openssl:
|
||||
*
|
||||
* openssl x509 -in GlobalSign_Root_CA_-_R2.pem -inform pem -noout -C
|
||||
*/
|
||||
/* subject:/OU=GlobalSign Root CA - R2/O=GlobalSign/CN=GlobalSign */
|
||||
/* issuer :/OU=GlobalSign Root CA - R2/O=GlobalSign/CN=GlobalSign */
|
||||
/*
|
||||
unsigned char XXX_subject_name[78]={
|
||||
0x30,0x4C,0x31,0x20,0x30,0x1E,0x06,0x03,0x55,0x04,0x0B,0x13,0x17,0x47,0x6C,0x6F,
|
||||
0x62,0x61,0x6C,0x53,0x69,0x67,0x6E,0x20,0x52,0x6F,0x6F,0x74,0x20,0x43,0x41,0x20,
|
||||
0x2D,0x20,0x52,0x32,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x0A,0x13,0x0A,0x47,
|
||||
0x6C,0x6F,0x62,0x61,0x6C,0x53,0x69,0x67,0x6E,0x31,0x13,0x30,0x11,0x06,0x03,0x55,
|
||||
0x04,0x03,0x13,0x0A,0x47,0x6C,0x6F,0x62,0x61,0x6C,0x53,0x69,0x67,0x6E,
|
||||
};
|
||||
unsigned char XXX_public_key[294]={
|
||||
0x30,0x82,0x01,0x22,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,
|
||||
0x01,0x05,0x00,0x03,0x82,0x01,0x0F,0x00,0x30,0x82,0x01,0x0A,0x02,0x82,0x01,0x01,
|
||||
0x00,0xA6,0xCF,0x24,0x0E,0xBE,0x2E,0x6F,0x28,0x99,0x45,0x42,0xC4,0xAB,0x3E,0x21,
|
||||
0x54,0x9B,0x0B,0xD3,0x7F,0x84,0x70,0xFA,0x12,0xB3,0xCB,0xBF,0x87,0x5F,0xC6,0x7F,
|
||||
0x86,0xD3,0xB2,0x30,0x5C,0xD6,0xFD,0xAD,0xF1,0x7B,0xDC,0xE5,0xF8,0x60,0x96,0x09,
|
||||
0x92,0x10,0xF5,0xD0,0x53,0xDE,0xFB,0x7B,0x7E,0x73,0x88,0xAC,0x52,0x88,0x7B,0x4A,
|
||||
0xA6,0xCA,0x49,0xA6,0x5E,0xA8,0xA7,0x8C,0x5A,0x11,0xBC,0x7A,0x82,0xEB,0xBE,0x8C,
|
||||
0xE9,0xB3,0xAC,0x96,0x25,0x07,0x97,0x4A,0x99,0x2A,0x07,0x2F,0xB4,0x1E,0x77,0xBF,
|
||||
0x8A,0x0F,0xB5,0x02,0x7C,0x1B,0x96,0xB8,0xC5,0xB9,0x3A,0x2C,0xBC,0xD6,0x12,0xB9,
|
||||
0xEB,0x59,0x7D,0xE2,0xD0,0x06,0x86,0x5F,0x5E,0x49,0x6A,0xB5,0x39,0x5E,0x88,0x34,
|
||||
0xEC,0xBC,0x78,0x0C,0x08,0x98,0x84,0x6C,0xA8,0xCD,0x4B,0xB4,0xA0,0x7D,0x0C,0x79,
|
||||
0x4D,0xF0,0xB8,0x2D,0xCB,0x21,0xCA,0xD5,0x6C,0x5B,0x7D,0xE1,0xA0,0x29,0x84,0xA1,
|
||||
0xF9,0xD3,0x94,0x49,0xCB,0x24,0x62,0x91,0x20,0xBC,0xDD,0x0B,0xD5,0xD9,0xCC,0xF9,
|
||||
0xEA,0x27,0x0A,0x2B,0x73,0x91,0xC6,0x9D,0x1B,0xAC,0xC8,0xCB,0xE8,0xE0,0xA0,0xF4,
|
||||
0x2F,0x90,0x8B,0x4D,0xFB,0xB0,0x36,0x1B,0xF6,0x19,0x7A,0x85,0xE0,0x6D,0xF2,0x61,
|
||||
0x13,0x88,0x5C,0x9F,0xE0,0x93,0x0A,0x51,0x97,0x8A,0x5A,0xCE,0xAF,0xAB,0xD5,0xF7,
|
||||
0xAA,0x09,0xAA,0x60,0xBD,0xDC,0xD9,0x5F,0xDF,0x72,0xA9,0x60,0x13,0x5E,0x00,0x01,
|
||||
0xC9,0x4A,0xFA,0x3F,0xA4,0xEA,0x07,0x03,0x21,0x02,0x8E,0x82,0xCA,0x03,0xC2,0x9B,
|
||||
0x8F,0x02,0x03,0x01,0x00,0x01,
|
||||
};
|
||||
*/
|
||||
unsigned char globalsign_certificate[958]={
|
||||
0x30,0x82,0x03,0xBA,0x30,0x82,0x02,0xA2,0xA0,0x03,0x02,0x01,0x02,0x02,0x0B,0x04,
|
||||
0x00,0x00,0x00,0x00,0x01,0x0F,0x86,0x26,0xE6,0x0D,0x30,0x0D,0x06,0x09,0x2A,0x86,
|
||||
0x48,0x86,0xF7,0x0D,0x01,0x01,0x05,0x05,0x00,0x30,0x4C,0x31,0x20,0x30,0x1E,0x06,
|
||||
0x03,0x55,0x04,0x0B,0x13,0x17,0x47,0x6C,0x6F,0x62,0x61,0x6C,0x53,0x69,0x67,0x6E,
|
||||
0x20,0x52,0x6F,0x6F,0x74,0x20,0x43,0x41,0x20,0x2D,0x20,0x52,0x32,0x31,0x13,0x30,
|
||||
0x11,0x06,0x03,0x55,0x04,0x0A,0x13,0x0A,0x47,0x6C,0x6F,0x62,0x61,0x6C,0x53,0x69,
|
||||
0x67,0x6E,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0A,0x47,0x6C,0x6F,
|
||||
0x62,0x61,0x6C,0x53,0x69,0x67,0x6E,0x30,0x1E,0x17,0x0D,0x30,0x36,0x31,0x32,0x31,
|
||||
0x35,0x30,0x38,0x30,0x30,0x30,0x30,0x5A,0x17,0x0D,0x32,0x31,0x31,0x32,0x31,0x35,
|
||||
0x30,0x38,0x30,0x30,0x30,0x30,0x5A,0x30,0x4C,0x31,0x20,0x30,0x1E,0x06,0x03,0x55,
|
||||
0x04,0x0B,0x13,0x17,0x47,0x6C,0x6F,0x62,0x61,0x6C,0x53,0x69,0x67,0x6E,0x20,0x52,
|
||||
0x6F,0x6F,0x74,0x20,0x43,0x41,0x20,0x2D,0x20,0x52,0x32,0x31,0x13,0x30,0x11,0x06,
|
||||
0x03,0x55,0x04,0x0A,0x13,0x0A,0x47,0x6C,0x6F,0x62,0x61,0x6C,0x53,0x69,0x67,0x6E,
|
||||
0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0A,0x47,0x6C,0x6F,0x62,0x61,
|
||||
0x6C,0x53,0x69,0x67,0x6E,0x30,0x82,0x01,0x22,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,
|
||||
0x86,0xF7,0x0D,0x01,0x01,0x01,0x05,0x00,0x03,0x82,0x01,0x0F,0x00,0x30,0x82,0x01,
|
||||
0x0A,0x02,0x82,0x01,0x01,0x00,0xA6,0xCF,0x24,0x0E,0xBE,0x2E,0x6F,0x28,0x99,0x45,
|
||||
0x42,0xC4,0xAB,0x3E,0x21,0x54,0x9B,0x0B,0xD3,0x7F,0x84,0x70,0xFA,0x12,0xB3,0xCB,
|
||||
0xBF,0x87,0x5F,0xC6,0x7F,0x86,0xD3,0xB2,0x30,0x5C,0xD6,0xFD,0xAD,0xF1,0x7B,0xDC,
|
||||
0xE5,0xF8,0x60,0x96,0x09,0x92,0x10,0xF5,0xD0,0x53,0xDE,0xFB,0x7B,0x7E,0x73,0x88,
|
||||
0xAC,0x52,0x88,0x7B,0x4A,0xA6,0xCA,0x49,0xA6,0x5E,0xA8,0xA7,0x8C,0x5A,0x11,0xBC,
|
||||
0x7A,0x82,0xEB,0xBE,0x8C,0xE9,0xB3,0xAC,0x96,0x25,0x07,0x97,0x4A,0x99,0x2A,0x07,
|
||||
0x2F,0xB4,0x1E,0x77,0xBF,0x8A,0x0F,0xB5,0x02,0x7C,0x1B,0x96,0xB8,0xC5,0xB9,0x3A,
|
||||
0x2C,0xBC,0xD6,0x12,0xB9,0xEB,0x59,0x7D,0xE2,0xD0,0x06,0x86,0x5F,0x5E,0x49,0x6A,
|
||||
0xB5,0x39,0x5E,0x88,0x34,0xEC,0xBC,0x78,0x0C,0x08,0x98,0x84,0x6C,0xA8,0xCD,0x4B,
|
||||
0xB4,0xA0,0x7D,0x0C,0x79,0x4D,0xF0,0xB8,0x2D,0xCB,0x21,0xCA,0xD5,0x6C,0x5B,0x7D,
|
||||
0xE1,0xA0,0x29,0x84,0xA1,0xF9,0xD3,0x94,0x49,0xCB,0x24,0x62,0x91,0x20,0xBC,0xDD,
|
||||
0x0B,0xD5,0xD9,0xCC,0xF9,0xEA,0x27,0x0A,0x2B,0x73,0x91,0xC6,0x9D,0x1B,0xAC,0xC8,
|
||||
0xCB,0xE8,0xE0,0xA0,0xF4,0x2F,0x90,0x8B,0x4D,0xFB,0xB0,0x36,0x1B,0xF6,0x19,0x7A,
|
||||
0x85,0xE0,0x6D,0xF2,0x61,0x13,0x88,0x5C,0x9F,0xE0,0x93,0x0A,0x51,0x97,0x8A,0x5A,
|
||||
0xCE,0xAF,0xAB,0xD5,0xF7,0xAA,0x09,0xAA,0x60,0xBD,0xDC,0xD9,0x5F,0xDF,0x72,0xA9,
|
||||
0x60,0x13,0x5E,0x00,0x01,0xC9,0x4A,0xFA,0x3F,0xA4,0xEA,0x07,0x03,0x21,0x02,0x8E,
|
||||
0x82,0xCA,0x03,0xC2,0x9B,0x8F,0x02,0x03,0x01,0x00,0x01,0xA3,0x81,0x9C,0x30,0x81,
|
||||
0x99,0x30,0x0E,0x06,0x03,0x55,0x1D,0x0F,0x01,0x01,0xFF,0x04,0x04,0x03,0x02,0x01,
|
||||
0x06,0x30,0x0F,0x06,0x03,0x55,0x1D,0x13,0x01,0x01,0xFF,0x04,0x05,0x30,0x03,0x01,
|
||||
0x01,0xFF,0x30,0x1D,0x06,0x03,0x55,0x1D,0x0E,0x04,0x16,0x04,0x14,0x9B,0xE2,0x07,
|
||||
0x57,0x67,0x1C,0x1E,0xC0,0x6A,0x06,0xDE,0x59,0xB4,0x9A,0x2D,0xDF,0xDC,0x19,0x86,
|
||||
0x2E,0x30,0x36,0x06,0x03,0x55,0x1D,0x1F,0x04,0x2F,0x30,0x2D,0x30,0x2B,0xA0,0x29,
|
||||
0xA0,0x27,0x86,0x25,0x68,0x74,0x74,0x70,0x3A,0x2F,0x2F,0x63,0x72,0x6C,0x2E,0x67,
|
||||
0x6C,0x6F,0x62,0x61,0x6C,0x73,0x69,0x67,0x6E,0x2E,0x6E,0x65,0x74,0x2F,0x72,0x6F,
|
||||
0x6F,0x74,0x2D,0x72,0x32,0x2E,0x63,0x72,0x6C,0x30,0x1F,0x06,0x03,0x55,0x1D,0x23,
|
||||
0x04,0x18,0x30,0x16,0x80,0x14,0x9B,0xE2,0x07,0x57,0x67,0x1C,0x1E,0xC0,0x6A,0x06,
|
||||
0xDE,0x59,0xB4,0x9A,0x2D,0xDF,0xDC,0x19,0x86,0x2E,0x30,0x0D,0x06,0x09,0x2A,0x86,
|
||||
0x48,0x86,0xF7,0x0D,0x01,0x01,0x05,0x05,0x00,0x03,0x82,0x01,0x01,0x00,0x99,0x81,
|
||||
0x53,0x87,0x1C,0x68,0x97,0x86,0x91,0xEC,0xE0,0x4A,0xB8,0x44,0x0B,0xAB,0x81,0xAC,
|
||||
0x27,0x4F,0xD6,0xC1,0xB8,0x1C,0x43,0x78,0xB3,0x0C,0x9A,0xFC,0xEA,0x2C,0x3C,0x6E,
|
||||
0x61,0x1B,0x4D,0x4B,0x29,0xF5,0x9F,0x05,0x1D,0x26,0xC1,0xB8,0xE9,0x83,0x00,0x62,
|
||||
0x45,0xB6,0xA9,0x08,0x93,0xB9,0xA9,0x33,0x4B,0x18,0x9A,0xC2,0xF8,0x87,0x88,0x4E,
|
||||
0xDB,0xDD,0x71,0x34,0x1A,0xC1,0x54,0xDA,0x46,0x3F,0xE0,0xD3,0x2A,0xAB,0x6D,0x54,
|
||||
0x22,0xF5,0x3A,0x62,0xCD,0x20,0x6F,0xBA,0x29,0x89,0xD7,0xDD,0x91,0xEE,0xD3,0x5C,
|
||||
0xA2,0x3E,0xA1,0x5B,0x41,0xF5,0xDF,0xE5,0x64,0x43,0x2D,0xE9,0xD5,0x39,0xAB,0xD2,
|
||||
0xA2,0xDF,0xB7,0x8B,0xD0,0xC0,0x80,0x19,0x1C,0x45,0xC0,0x2D,0x8C,0xE8,0xF8,0x2D,
|
||||
0xA4,0x74,0x56,0x49,0xC5,0x05,0xB5,0x4F,0x15,0xDE,0x6E,0x44,0x78,0x39,0x87,0xA8,
|
||||
0x7E,0xBB,0xF3,0x79,0x18,0x91,0xBB,0xF4,0x6F,0x9D,0xC1,0xF0,0x8C,0x35,0x8C,0x5D,
|
||||
0x01,0xFB,0xC3,0x6D,0xB9,0xEF,0x44,0x6D,0x79,0x46,0x31,0x7E,0x0A,0xFE,0xA9,0x82,
|
||||
0xC1,0xFF,0xEF,0xAB,0x6E,0x20,0xC4,0x50,0xC9,0x5F,0x9D,0x4D,0x9B,0x17,0x8C,0x0C,
|
||||
0xE5,0x01,0xC9,0xA0,0x41,0x6A,0x73,0x53,0xFA,0xA5,0x50,0xB4,0x6E,0x25,0x0F,0xFB,
|
||||
0x4C,0x18,0xF4,0xFD,0x52,0xD9,0x8E,0x69,0xB1,0xE8,0x11,0x0F,0xDE,0x88,0xD8,0xFB,
|
||||
0x1D,0x49,0xF7,0xAA,0xDE,0x95,0xCF,0x20,0x78,0xC2,0x60,0x12,0xDB,0x25,0x40,0x8C,
|
||||
0x6A,0xFC,0x7E,0x42,0x38,0x40,0x64,0x12,0xF7,0x9E,0x81,0xE1,0x93,0x2E,
|
||||
};
|
|
@ -1,79 +0,0 @@
|
|||
/* Full-stack IoT client example. */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2018 Linaro Ltd
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
|
||||
#include "dhcp.h"
|
||||
#include "protocol.h"
|
||||
|
||||
#include <zephyr/net/sntp.h>
|
||||
#include <zephyr/net/net_config.h>
|
||||
#include <zephyr/net/net_event.h>
|
||||
|
||||
#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
LOG_MODULE_REGISTER(net_google_iot_mqtt, LOG_LEVEL_INF);
|
||||
|
||||
/* This comes from newlib. */
|
||||
#include <time.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
int64_t time_base;
|
||||
|
||||
int do_sntp(void)
|
||||
{
|
||||
int rc;
|
||||
struct sntp_time sntp_time;
|
||||
char time_str[sizeof("1970-01-01T00:00:00")];
|
||||
|
||||
LOG_INF("Sending NTP request for current time:");
|
||||
|
||||
rc = sntp_simple("time.google.com", SYS_FOREVER_MS, &sntp_time);
|
||||
if (rc == 0) {
|
||||
time_base = sntp_time.seconds * MSEC_PER_SEC - k_uptime_get();
|
||||
|
||||
/* Convert time to make sure. */
|
||||
time_t now = sntp_time.seconds;
|
||||
struct tm now_tm;
|
||||
|
||||
gmtime_r(&now, &now_tm);
|
||||
strftime(time_str, sizeof(time_str), "%FT%T", &now_tm);
|
||||
LOG_INF(" Acquired time: %s", time_str);
|
||||
|
||||
} else {
|
||||
LOG_ERR(" Failed to acquire SNTP, code %d\n", rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
* Things that make sense in a demo app that would need to be more
|
||||
* robust in a real application:
|
||||
*
|
||||
* - DHCP happens once. If it fails, or we change networks, the
|
||||
* network will just stop working.
|
||||
*
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
LOG_INF("Main entered");
|
||||
|
||||
app_dhcpv4_startup();
|
||||
|
||||
LOG_INF("Should have DHCPv4 lease at this point.");
|
||||
|
||||
/* early return if we failed to acquire time */
|
||||
if (do_sntp() != 0) {
|
||||
LOG_ERR("Failed to get NTP time");
|
||||
return 0;
|
||||
}
|
||||
|
||||
mqtt_startup("mqtt.googleapis.com", 8883);
|
||||
return 0;
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
*-cert.pem
|
||||
*-private.pem
|
||||
*.der
|
||||
key.c
|
|
@ -1,116 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright (c) 2018 Linaro
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import sys
|
||||
import subprocess
|
||||
import argparse
|
||||
|
||||
def parse_args():
|
||||
global args
|
||||
|
||||
parser = argparse.ArgumentParser(description=__doc__,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter, allow_abbrev=False)
|
||||
|
||||
parser.add_argument(
|
||||
"-d", "--device", required=True,
|
||||
help="Name of device")
|
||||
|
||||
parser.add_argument(
|
||||
"-e", "--ecdsa", required=False,
|
||||
action='store_true',
|
||||
help="Use elliptic curve")
|
||||
|
||||
parser.add_argument(
|
||||
"-r", "--rsa", required=False,
|
||||
action='store_true',
|
||||
help="Use RSA")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
split_string = lambda x, n: [x[i:i+n] for i in range(0, len(x), n)]
|
||||
|
||||
def main():
|
||||
parse_args()
|
||||
|
||||
fd = open("key.c", "w")
|
||||
|
||||
pem_file = args.device + "-private.pem"
|
||||
cert_file = args.device + "-cert.pem"
|
||||
der_file = args.device + "-private.der"
|
||||
|
||||
if args.ecdsa:
|
||||
print("Generating ecdsa private key")
|
||||
try:
|
||||
subprocess.call(["openssl", "ecparam", "-noout", "-name", "prime256v1", "-genkey",
|
||||
"-out", pem_file])
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(e.output)
|
||||
else:
|
||||
print("Generating rsa private key")
|
||||
try:
|
||||
subprocess.call(["openssl", "genrsa", "-out", pem_file, "2048"])
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(e.output)
|
||||
|
||||
print("Generating certificate")
|
||||
|
||||
try:
|
||||
subprocess.check_call(["openssl", "req", "-new", "-x509", "-key", pem_file, "-out",
|
||||
cert_file, "-days", "1000000", "-subj", "/CN=" + args.device])
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(e.output)
|
||||
|
||||
|
||||
if args.ecdsa:
|
||||
print("Parsing ECDSA private key")
|
||||
o = subprocess.Popen(["openssl", "asn1parse", "-in", pem_file,
|
||||
"-offset", "5", "-length", "34"], stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT)
|
||||
|
||||
if o.returncode == 0:
|
||||
sys.exit("failed to parse ECDSA private key")
|
||||
|
||||
tmp = o.communicate()[0].decode('ascii').split(":")[3].lower().strip()
|
||||
|
||||
if o.returncode:
|
||||
sys.exit("failed to parse ECDSA private key")
|
||||
|
||||
tmp = split_string(tmp, 2)
|
||||
output = ["0x" + s for s in tmp]
|
||||
output = ', '.join(output)
|
||||
|
||||
else:
|
||||
print("Parsing RSA private key and generating DER output")
|
||||
try:
|
||||
subprocess.call(["openssl", "pkcs8", "-nocrypt", "-topk8",
|
||||
"-inform", "pem", "-outform", "der", "-in", pem_file, "-out",
|
||||
der_file])
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(e.output)
|
||||
|
||||
der_fd = open(der_file, "r")
|
||||
o = subprocess.Popen(["xxd", "-i"], stdin=der_fd, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT)
|
||||
|
||||
output = o.communicate()[0].decode('ascii')
|
||||
|
||||
if o.returncode:
|
||||
sys.exit("failed to parse RSA private key")
|
||||
|
||||
print("Generating key.c")
|
||||
fd.write("unsigned char zepfull_private_der[] = {\n")
|
||||
key_len = len(output.split(','))
|
||||
fd.write(output)
|
||||
fd.write("};\n\n")
|
||||
|
||||
fd.write("unsigned int zepfull_private_der_len = " + str(key_len) + ";\n")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -1,112 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
unsigned char zepfull_private_der[] = {
|
||||
0x30, 0x82, 0x04, 0xbe, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a,
|
||||
0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
|
||||
0x04, 0xa8, 0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01,
|
||||
0x01, 0x00, 0xc7, 0xa1, 0x91, 0x8d, 0x6c, 0xed, 0x88, 0xbe, 0x23, 0x01,
|
||||
0x4a, 0x49, 0x64, 0x3f, 0x45, 0xe7, 0x1e, 0xab, 0x3e, 0xf4, 0x60, 0xaf,
|
||||
0x64, 0x60, 0xda, 0x5e, 0xf8, 0xfe, 0x5b, 0xd0, 0x49, 0x61, 0xd9, 0x1e,
|
||||
0x7d, 0xb1, 0xaf, 0xf4, 0x32, 0xa1, 0x54, 0xf7, 0xce, 0x3f, 0xaa, 0x7d,
|
||||
0x93, 0xef, 0x96, 0xa5, 0x84, 0x8b, 0x1c, 0xd5, 0x31, 0x67, 0xc7, 0xcd,
|
||||
0xd0, 0x17, 0xa3, 0xbf, 0x75, 0xae, 0x4b, 0x26, 0xc2, 0x82, 0x1f, 0x1f,
|
||||
0x40, 0xfd, 0xd0, 0xdd, 0x89, 0x64, 0x6b, 0xed, 0x83, 0xd9, 0x33, 0xfc,
|
||||
0x2d, 0xec, 0x7a, 0xfb, 0x9b, 0x12, 0xae, 0x65, 0x8b, 0x8d, 0x9d, 0x85,
|
||||
0x2b, 0x34, 0x42, 0xa6, 0x59, 0x74, 0x08, 0x34, 0xaa, 0x66, 0xf2, 0x52,
|
||||
0xac, 0xbf, 0xe2, 0x55, 0x2e, 0x64, 0xb0, 0x04, 0x2d, 0xa6, 0x0f, 0xe0,
|
||||
0xc1, 0xf2, 0x48, 0x21, 0x9b, 0x5d, 0x96, 0x36, 0x0a, 0xeb, 0xfa, 0xdf,
|
||||
0xcb, 0xc7, 0x95, 0x86, 0xec, 0x85, 0xd8, 0xa3, 0xb9, 0xc4, 0x6f, 0x9f,
|
||||
0xb3, 0x52, 0xec, 0xc3, 0xae, 0x7b, 0x51, 0x4e, 0x76, 0x6c, 0x59, 0xdc,
|
||||
0x05, 0xb1, 0x20, 0xdc, 0x4f, 0x21, 0x57, 0x19, 0x93, 0x42, 0x1b, 0xf2,
|
||||
0x38, 0x84, 0x15, 0xf3, 0x5a, 0xe6, 0x9c, 0x5c, 0xff, 0x8b, 0x7a, 0x09,
|
||||
0x66, 0x96, 0xa4, 0x53, 0x00, 0xb0, 0x75, 0xac, 0xdb, 0xb2, 0xa4, 0x5d,
|
||||
0x18, 0x7d, 0x76, 0xf6, 0xc5, 0x69, 0x37, 0x6b, 0xfd, 0xc4, 0x56, 0x01,
|
||||
0x13, 0xf7, 0x7d, 0xcd, 0xf7, 0x3b, 0xa8, 0xec, 0x11, 0x95, 0x53, 0x25,
|
||||
0x5e, 0x99, 0xb9, 0x13, 0xf9, 0xa8, 0x68, 0x25, 0x23, 0x2c, 0x36, 0xc7,
|
||||
0xb6, 0x39, 0x7f, 0xe9, 0xf9, 0x70, 0x2b, 0x29, 0xbc, 0x70, 0xe9, 0x7a,
|
||||
0x00, 0xd2, 0x76, 0xa1, 0xef, 0x3c, 0x98, 0x71, 0x77, 0xbb, 0xcd, 0x83,
|
||||
0xf2, 0x3a, 0x7a, 0x5e, 0xc0, 0x27, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02,
|
||||
0x82, 0x01, 0x01, 0x00, 0xb8, 0xf8, 0x67, 0x99, 0x16, 0xf8, 0xf0, 0xde,
|
||||
0xdc, 0x28, 0x71, 0xe0, 0x96, 0xd6, 0x59, 0xba, 0xd0, 0x9b, 0xf3, 0x75,
|
||||
0x13, 0xb0, 0xef, 0xdd, 0x1d, 0xf9, 0x29, 0xd4, 0xe4, 0xd5, 0x95, 0x68,
|
||||
0xe8, 0x78, 0x6c, 0x16, 0x9b, 0xe6, 0x34, 0x93, 0x6f, 0xdb, 0x3c, 0x6b,
|
||||
0x99, 0x59, 0x4a, 0x1d, 0x91, 0x04, 0x44, 0x4f, 0x71, 0xa3, 0xc8, 0x67,
|
||||
0x54, 0xa6, 0xca, 0xcd, 0x5c, 0x98, 0x26, 0x3e, 0x1c, 0xbc, 0x09, 0x35,
|
||||
0xf0, 0x08, 0x51, 0x7b, 0xdc, 0x6f, 0xa8, 0xc2, 0x37, 0x8e, 0x97, 0xc0,
|
||||
0x45, 0x7e, 0xc0, 0x3e, 0x81, 0xa5, 0x68, 0x06, 0x63, 0x39, 0x0b, 0x99,
|
||||
0x67, 0xfe, 0xe0, 0x0d, 0x48, 0x44, 0x42, 0x56, 0x54, 0xd4, 0x17, 0x9f,
|
||||
0xd3, 0x9f, 0xef, 0x18, 0xcc, 0x6a, 0x08, 0xd6, 0x9a, 0x91, 0x04, 0x8a,
|
||||
0xfd, 0xe3, 0x4f, 0x51, 0x62, 0xac, 0x60, 0xfc, 0xd2, 0x15, 0xb8, 0xff,
|
||||
0x53, 0x3e, 0xc0, 0x07, 0xe3, 0x75, 0x42, 0xbe, 0x35, 0x1b, 0x7e, 0xf5,
|
||||
0x00, 0x1a, 0x26, 0x10, 0x89, 0xb4, 0x8c, 0x21, 0x54, 0xb5, 0x1e, 0x1a,
|
||||
0x23, 0x32, 0xaf, 0x80, 0x38, 0x0a, 0xfa, 0xc0, 0x17, 0xb1, 0x49, 0x92,
|
||||
0xfa, 0x08, 0x15, 0x02, 0xa6, 0xe3, 0x36, 0x57, 0x03, 0xbd, 0x56, 0xd2,
|
||||
0x24, 0xaf, 0xb9, 0x45, 0xd0, 0x43, 0x16, 0xd1, 0x78, 0x86, 0x2e, 0xae,
|
||||
0xf6, 0xac, 0x1d, 0x0b, 0x03, 0xac, 0x90, 0x0d, 0x5d, 0xbe, 0xc0, 0xc0,
|
||||
0x9e, 0x30, 0x38, 0x9b, 0x61, 0x7b, 0x51, 0x39, 0xc2, 0x3d, 0x30, 0x85,
|
||||
0xf2, 0x33, 0x94, 0x53, 0xb0, 0x5a, 0x12, 0x72, 0xeb, 0x30, 0xb2, 0x8c,
|
||||
0x66, 0xec, 0xc2, 0x1f, 0x4d, 0xa5, 0x67, 0x20, 0xde, 0x3b, 0x05, 0x72,
|
||||
0xe9, 0x0e, 0x77, 0x1f, 0x3f, 0xd8, 0x8a, 0x77, 0x5c, 0x4c, 0xc0, 0x81,
|
||||
0xf2, 0xe3, 0x41, 0x96, 0x94, 0xa6, 0xe5, 0xc1, 0x02, 0x81, 0x81, 0x00,
|
||||
0xe3, 0xd3, 0x76, 0x49, 0x5f, 0x18, 0x58, 0x74, 0x31, 0x37, 0xca, 0xfa,
|
||||
0x42, 0x39, 0x74, 0x61, 0x4b, 0xec, 0x0c, 0x14, 0xc7, 0xfa, 0xff, 0xe5,
|
||||
0xa4, 0xb0, 0x33, 0xba, 0x7b, 0x0a, 0x02, 0xf4, 0x07, 0x6e, 0xf3, 0xbe,
|
||||
0xde, 0xe6, 0x1b, 0xb3, 0x72, 0xbf, 0x10, 0x82, 0x3b, 0xf5, 0x1d, 0x9f,
|
||||
0x43, 0x0d, 0x0a, 0x42, 0xcf, 0x1a, 0xbd, 0x94, 0x65, 0xb9, 0xdc, 0x73,
|
||||
0x9b, 0xbe, 0xda, 0xc9, 0xb9, 0xa6, 0x65, 0x99, 0x48, 0xae, 0xa8, 0x62,
|
||||
0xe3, 0xc2, 0xe1, 0x53, 0x57, 0x01, 0x06, 0xa3, 0x63, 0xac, 0x3c, 0x7e,
|
||||
0x32, 0xa1, 0xf7, 0xbf, 0x73, 0xec, 0x38, 0x0e, 0x4d, 0x9b, 0x88, 0x94,
|
||||
0x5f, 0xbc, 0x1d, 0x8d, 0xd1, 0xff, 0x2d, 0x84, 0x73, 0x67, 0x24, 0x91,
|
||||
0x34, 0x65, 0xa9, 0xec, 0x70, 0x0d, 0x50, 0x52, 0x0d, 0xee, 0x94, 0x6a,
|
||||
0x43, 0xd9, 0x66, 0x57, 0x9e, 0x04, 0x2e, 0xa9, 0x02, 0x81, 0x81, 0x00,
|
||||
0xe0, 0x51, 0x82, 0x81, 0xb0, 0x47, 0xcc, 0xf7, 0xb3, 0xc2, 0x1e, 0xc7,
|
||||
0xc0, 0xc5, 0x35, 0xcf, 0x3e, 0xc7, 0x40, 0xa3, 0x01, 0x18, 0x4b, 0x8b,
|
||||
0x8a, 0xbd, 0x6c, 0x21, 0x9d, 0xf7, 0x73, 0xc6, 0x92, 0x04, 0x6e, 0x5a,
|
||||
0xf8, 0x89, 0x42, 0x1f, 0x27, 0x26, 0x9c, 0x00, 0x22, 0x0f, 0xa4, 0xbe,
|
||||
0xc9, 0x96, 0x20, 0xb5, 0xaa, 0xa7, 0x3e, 0x1d, 0xa2, 0x23, 0x3a, 0xa6,
|
||||
0x80, 0x1d, 0x52, 0xbb, 0xf2, 0xe8, 0x2d, 0x84, 0xa1, 0x81, 0x75, 0x6c,
|
||||
0x60, 0xc9, 0x39, 0x15, 0xaa, 0x6c, 0x56, 0x0a, 0x08, 0x24, 0x3f, 0xda,
|
||||
0xd4, 0x62, 0xed, 0xf2, 0x59, 0x10, 0x34, 0x14, 0xfa, 0x91, 0x08, 0x80,
|
||||
0xb2, 0x90, 0xba, 0x0f, 0x39, 0x45, 0x84, 0x69, 0x4a, 0xce, 0xbc, 0x71,
|
||||
0x24, 0x49, 0x4e, 0x53, 0x26, 0xd7, 0x38, 0x79, 0x05, 0xf7, 0x57, 0x7a,
|
||||
0x43, 0xd0, 0x55, 0xb6, 0xc1, 0x0b, 0xca, 0x4f, 0x02, 0x81, 0x80, 0x77,
|
||||
0x43, 0xc7, 0xf4, 0x78, 0xf7, 0xc1, 0xb6, 0x71, 0xdd, 0x87, 0x40, 0xa3,
|
||||
0x52, 0x78, 0x7e, 0x46, 0xc4, 0x77, 0x3e, 0x99, 0xc1, 0xe8, 0x1c, 0x4b,
|
||||
0xae, 0x82, 0x25, 0xe9, 0x2b, 0x40, 0x88, 0x87, 0x2b, 0xaa, 0x26, 0x0d,
|
||||
0x81, 0xe0, 0x96, 0x7c, 0x47, 0x51, 0x59, 0x1c, 0x12, 0x21, 0x43, 0xb2,
|
||||
0x52, 0x2d, 0x40, 0xf4, 0x32, 0x47, 0x74, 0x5c, 0x1c, 0x84, 0x2f, 0x71,
|
||||
0x24, 0xe4, 0x5c, 0x1d, 0xf7, 0xe1, 0xcf, 0xf0, 0xa0, 0x9e, 0x3d, 0xc6,
|
||||
0x85, 0xca, 0x77, 0x5a, 0x60, 0x8b, 0x1d, 0x15, 0x9c, 0xa0, 0xbe, 0x5f,
|
||||
0xbb, 0x32, 0x7a, 0xe3, 0x30, 0x91, 0xd7, 0xcb, 0x00, 0xd4, 0xea, 0xf7,
|
||||
0x82, 0xfe, 0xe5, 0xb3, 0x3d, 0x26, 0x92, 0xe3, 0xe6, 0xe6, 0xd9, 0xac,
|
||||
0xd8, 0x5b, 0xb0, 0x0e, 0xa8, 0xa9, 0x97, 0x8a, 0xfb, 0x8e, 0x6e, 0x62,
|
||||
0xbe, 0x78, 0x38, 0xfd, 0xdb, 0xaa, 0xa1, 0x02, 0x81, 0x81, 0x00, 0x93,
|
||||
0x65, 0x1b, 0xc3, 0x09, 0xc8, 0xf4, 0x26, 0xa3, 0x08, 0x5f, 0xdf, 0x53,
|
||||
0x8c, 0x82, 0x22, 0x0e, 0x97, 0x30, 0xa2, 0xab, 0x1a, 0x82, 0xb1, 0x4b,
|
||||
0x55, 0xd2, 0x52, 0x78, 0x90, 0xdb, 0x93, 0x53, 0xe8, 0xf3, 0x76, 0x75,
|
||||
0x2f, 0x03, 0xb2, 0xa2, 0xb0, 0x1c, 0xfb, 0x7d, 0x66, 0x18, 0x13, 0x81,
|
||||
0x34, 0x53, 0x83, 0xeb, 0x81, 0x7f, 0x30, 0x4b, 0x94, 0xa8, 0x7a, 0x35,
|
||||
0x5e, 0x8f, 0x39, 0x8e, 0x8f, 0xff, 0x30, 0xd2, 0x4a, 0xd5, 0x94, 0x84,
|
||||
0x38, 0x54, 0x79, 0x27, 0x05, 0x8e, 0xb7, 0x82, 0xc8, 0x06, 0xe9, 0x4c,
|
||||
0x7b, 0x40, 0xec, 0xe8, 0x96, 0xdc, 0x12, 0x18, 0xde, 0xe9, 0xde, 0x5e,
|
||||
0xf6, 0xf8, 0x3a, 0xfe, 0x9f, 0xee, 0x34, 0x9d, 0x82, 0x20, 0x92, 0x9b,
|
||||
0x8c, 0x4b, 0x9a, 0x19, 0xc0, 0x7b, 0x8c, 0x12, 0x5e, 0x87, 0x2d, 0x80,
|
||||
0x97, 0xc9, 0x6a, 0x8f, 0x88, 0xa6, 0xc3, 0x02, 0x81, 0x80, 0x4b, 0x44,
|
||||
0xe8, 0xb7, 0x47, 0xb0, 0x59, 0xf1, 0x58, 0x4e, 0x3f, 0x51, 0x37, 0x63,
|
||||
0xe0, 0xc5, 0xad, 0xf9, 0x32, 0x8d, 0x8f, 0xa4, 0xa6, 0xd3, 0x8e, 0x01,
|
||||
0xf4, 0xc0, 0xbd, 0x8e, 0x2d, 0xd7, 0x99, 0xf7, 0x23, 0x2d, 0x36, 0xd8,
|
||||
0xc9, 0x9e, 0xc0, 0x63, 0x00, 0xb1, 0xe7, 0xb6, 0xab, 0x0c, 0x95, 0x17,
|
||||
0xe3, 0x7c, 0x86, 0x64, 0x0c, 0x06, 0x00, 0x10, 0x8a, 0x23, 0x14, 0x1b,
|
||||
0xa6, 0xdb, 0xc9, 0xcc, 0xcb, 0x96, 0xcd, 0x38, 0x77, 0xa5, 0xb1, 0x02,
|
||||
0xf7, 0x49, 0x87, 0x1d, 0x6a, 0x2b, 0xfb, 0x40, 0x6b, 0x03, 0x4d, 0x04,
|
||||
0xdf, 0xed, 0x16, 0x1b, 0xbe, 0x3c, 0x03, 0xca, 0x68, 0x3f, 0x4c, 0x28,
|
||||
0xfc, 0x99, 0xf0, 0xdd, 0x23, 0x51, 0xc0, 0x87, 0x85, 0x17, 0xa9, 0x1f,
|
||||
0x18, 0xe0, 0x10, 0xd6, 0xca, 0xbf, 0xb6, 0x5c, 0x0c, 0xce, 0x4d, 0x2e,
|
||||
0x9e, 0x75, 0xf0, 0x71, 0xe0, 0x01
|
||||
};
|
||||
|
||||
unsigned int zepfull_private_der_len = 1218;
|
|
@ -1,407 +0,0 @@
|
|||
/* Protocol implementation. */
|
||||
/*
|
||||
* Copyright (c) 2018-2019 Linaro Ltd
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
LOG_MODULE_DECLARE(net_google_iot_mqtt, LOG_LEVEL_DBG);
|
||||
#include "protocol.h"
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <string.h>
|
||||
#include <zephyr/data/jwt.h>
|
||||
#include <zephyr/drivers/entropy.h>
|
||||
|
||||
#include <zephyr/net/tls_credentials.h>
|
||||
#include <zephyr/net/mqtt.h>
|
||||
|
||||
#include <mbedtls/platform.h>
|
||||
#include <mbedtls/ssl.h>
|
||||
#include <mbedtls/entropy.h>
|
||||
#include <mbedtls/ctr_drbg.h>
|
||||
|
||||
#include <mbedtls/debug.h>
|
||||
|
||||
extern int64_t time_base;
|
||||
|
||||
/* private key information */
|
||||
extern unsigned char zepfull_private_der[];
|
||||
extern unsigned int zepfull_private_der_len;
|
||||
|
||||
/*
|
||||
* This is the hard-coded root certificate that we accept.
|
||||
*/
|
||||
#include "globalsign.inc"
|
||||
|
||||
static uint8_t client_id[] = CONFIG_CLOUD_CLIENT_ID;
|
||||
static uint8_t client_username[] = "none";
|
||||
static uint8_t pub_topic[] = CONFIG_CLOUD_PUBLISH_TOPIC;
|
||||
|
||||
static struct mqtt_publish_param pub_data;
|
||||
|
||||
static uint8_t token[512];
|
||||
|
||||
static bool connected;
|
||||
static uint64_t next_alive;
|
||||
|
||||
/* The mqtt client struct */
|
||||
static struct mqtt_client client_ctx;
|
||||
|
||||
/* MQTT Broker details. */
|
||||
static struct sockaddr_storage broker;
|
||||
|
||||
/* Buffers for MQTT client. */
|
||||
static uint8_t rx_buffer[1024];
|
||||
static uint8_t tx_buffer[1024];
|
||||
|
||||
static sec_tag_t m_sec_tags[] = {
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
1,
|
||||
#endif
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
|
||||
APP_PSK_TAG,
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Zephyr implementation of POSIX `time`. Has to be called k_time
|
||||
* because time is already taken by newlib. The clock will be set by
|
||||
* the SNTP client when it receives the time. We make no attempt to
|
||||
* adjust it smoothly, and it should not be used for measuring
|
||||
* intervals. Use `k_uptime_get()` directly for that. Also the
|
||||
* time_t defined by newlib is a signed 32-bit value, and will
|
||||
* overflow in 2037.
|
||||
*/
|
||||
time_t my_k_time(time_t *ptr)
|
||||
{
|
||||
int64_t stamp;
|
||||
time_t now;
|
||||
|
||||
stamp = k_uptime_get();
|
||||
now = (time_t)((stamp + time_base) / 1000);
|
||||
|
||||
if (ptr) {
|
||||
*ptr = now;
|
||||
}
|
||||
|
||||
return now;
|
||||
}
|
||||
|
||||
void mqtt_subscribe_config(struct mqtt_client *const client)
|
||||
{
|
||||
#ifdef CONFIG_CLOUD_SUBSCRIBE_CONFIG
|
||||
/* subscribe to config information */
|
||||
struct mqtt_topic subs_topic = {
|
||||
.topic = {
|
||||
.utf8 = CONFIG_CLOUD_SUBSCRIBE_CONFIG,
|
||||
.size = strlen(CONFIG_CLOUD_SUBSCRIBE_CONFIG)
|
||||
},
|
||||
.qos = MQTT_QOS_1_AT_LEAST_ONCE
|
||||
};
|
||||
const struct mqtt_subscription_list subs_list = {
|
||||
.list = &subs_topic,
|
||||
.list_count = 1U,
|
||||
.message_id = 1U
|
||||
};
|
||||
int err;
|
||||
|
||||
err = mqtt_subscribe(client, &subs_list);
|
||||
if (err) {
|
||||
LOG_ERR("Failed to subscribe to %s item, error %d",
|
||||
subs_topic.topic.utf8, err);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void mqtt_evt_handler(struct mqtt_client *const client,
|
||||
const struct mqtt_evt *evt)
|
||||
{
|
||||
switch (evt->type) {
|
||||
case MQTT_EVT_SUBACK:
|
||||
LOG_INF("SUBACK packet id: %u", evt->param.suback.message_id);
|
||||
break;
|
||||
|
||||
case MQTT_EVT_UNSUBACK:
|
||||
LOG_INF("UNSUBACK packet id: %u",
|
||||
evt->param.suback.message_id);
|
||||
break;
|
||||
|
||||
case MQTT_EVT_CONNACK:
|
||||
if (evt->result != 0) {
|
||||
LOG_ERR("MQTT connect failed %d", evt->result);
|
||||
break;
|
||||
}
|
||||
|
||||
connected = true;
|
||||
LOG_INF("MQTT client connected!");
|
||||
|
||||
mqtt_subscribe_config(client);
|
||||
|
||||
break;
|
||||
|
||||
case MQTT_EVT_DISCONNECT:
|
||||
LOG_INF("MQTT client disconnected %d", evt->result);
|
||||
|
||||
connected = false;
|
||||
|
||||
break;
|
||||
|
||||
#ifdef CONFIG_CLOUD_SUBSCRIBE_CONFIG
|
||||
case MQTT_EVT_PUBLISH: {
|
||||
const struct mqtt_publish_param *pub = &evt->param.publish;
|
||||
uint8_t d[33];
|
||||
int len = pub->message.payload.len;
|
||||
int bytes_read;
|
||||
|
||||
LOG_INF("MQTT publish received %d, %d bytes",
|
||||
evt->result, len);
|
||||
LOG_INF(" id: %d, qos: %d",
|
||||
pub->message_id,
|
||||
pub->message.topic.qos);
|
||||
LOG_INF(" item: %s",
|
||||
pub->message.topic.topic.utf8);
|
||||
|
||||
/* assuming the config message is textual */
|
||||
while (len) {
|
||||
bytes_read = mqtt_read_publish_payload_blocking(
|
||||
client, d,
|
||||
len >= 32 ? 32 : len);
|
||||
if (bytes_read < 0) {
|
||||
LOG_ERR("failure to read payload");
|
||||
break;
|
||||
}
|
||||
|
||||
d[bytes_read] = '\0';
|
||||
LOG_INF(" payload: %s", d);
|
||||
len -= bytes_read;
|
||||
}
|
||||
|
||||
/* for MQTT_QOS_0_AT_MOST_ONCE no acknowledgment needed */
|
||||
if (pub->message.topic.qos == MQTT_QOS_1_AT_LEAST_ONCE) {
|
||||
struct mqtt_puback_param puback = {
|
||||
.message_id = pub->message_id
|
||||
};
|
||||
|
||||
mqtt_publish_qos1_ack(client, &puback);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
case MQTT_EVT_PUBACK:
|
||||
if (evt->result != 0) {
|
||||
LOG_ERR("MQTT PUBACK error %d", evt->result);
|
||||
break;
|
||||
}
|
||||
|
||||
/* increment message id for when we send next message */
|
||||
pub_data.message_id += 1U;
|
||||
LOG_INF("PUBACK packet id: %u",
|
||||
evt->param.puback.message_id);
|
||||
break;
|
||||
|
||||
default:
|
||||
LOG_INF("MQTT event received %d", evt->type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int wait_for_input(int timeout)
|
||||
{
|
||||
int res;
|
||||
struct zsock_pollfd fds[1] = {
|
||||
[0] = {.fd = client_ctx.transport.tls.sock,
|
||||
.events = ZSOCK_POLLIN,
|
||||
.revents = 0},
|
||||
};
|
||||
|
||||
res = zsock_poll(fds, 1, timeout);
|
||||
if (res < 0) {
|
||||
LOG_ERR("poll read event error");
|
||||
return -errno;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#define ALIVE_TIME (60 * MSEC_PER_SEC)
|
||||
|
||||
static struct mqtt_utf8 password = {
|
||||
.utf8 = token
|
||||
};
|
||||
|
||||
static struct mqtt_utf8 username = {
|
||||
.utf8 = client_username,
|
||||
.size = sizeof(client_username)
|
||||
};
|
||||
|
||||
void mqtt_startup(char *hostname, int port)
|
||||
{
|
||||
int err, cnt;
|
||||
char pub_msg[64];
|
||||
struct sockaddr_in *broker4 = (struct sockaddr_in *)&broker;
|
||||
struct mqtt_client *client = &client_ctx;
|
||||
struct jwt_builder jb;
|
||||
static struct zsock_addrinfo hints;
|
||||
struct zsock_addrinfo *haddr;
|
||||
int res = 0;
|
||||
int retries = 5;
|
||||
|
||||
mbedtls_platform_set_time(my_k_time);
|
||||
|
||||
err = tls_credential_add(1, TLS_CREDENTIAL_CA_CERTIFICATE,
|
||||
globalsign_certificate,
|
||||
sizeof(globalsign_certificate));
|
||||
if (err < 0) {
|
||||
LOG_ERR("Failed to register public certificate: %d", err);
|
||||
}
|
||||
|
||||
while (retries) {
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = 0;
|
||||
cnt = 0;
|
||||
while ((err = getaddrinfo("mqtt.googleapis.com", "8883", &hints,
|
||||
&haddr)) && cnt < 3) {
|
||||
LOG_ERR("Unable to get address for broker, retrying");
|
||||
cnt++;
|
||||
}
|
||||
|
||||
if (err != 0) {
|
||||
LOG_ERR("Unable to get address for broker, error %d",
|
||||
err);
|
||||
return;
|
||||
}
|
||||
LOG_INF("DNS resolved for mqtt.googleapis.com:8883");
|
||||
|
||||
mqtt_client_init(client);
|
||||
|
||||
time_t now = my_k_time(NULL);
|
||||
|
||||
res = jwt_init_builder(&jb, token, sizeof(token));
|
||||
if (res != 0) {
|
||||
LOG_ERR("Error with JWT token");
|
||||
return;
|
||||
}
|
||||
|
||||
res = jwt_add_payload(&jb, now + 60 * 60, now,
|
||||
CONFIG_CLOUD_AUDIENCE);
|
||||
if (res != 0) {
|
||||
LOG_ERR("Error with JWT token");
|
||||
return;
|
||||
}
|
||||
|
||||
res = jwt_sign(&jb, zepfull_private_der,
|
||||
zepfull_private_der_len);
|
||||
|
||||
if (res != 0) {
|
||||
LOG_ERR("Error with JWT token");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
broker4->sin_family = AF_INET;
|
||||
broker4->sin_port = htons(port);
|
||||
net_ipaddr_copy(&broker4->sin_addr,
|
||||
&net_sin(haddr->ai_addr)->sin_addr);
|
||||
|
||||
/* MQTT client configuration */
|
||||
client->broker = &broker;
|
||||
client->evt_cb = mqtt_evt_handler;
|
||||
client->client_id.utf8 = client_id;
|
||||
client->client_id.size = strlen(client_id);
|
||||
client->password = &password;
|
||||
password.size = jwt_payload_len(&jb);
|
||||
client->user_name = &username;
|
||||
client->protocol_version = MQTT_VERSION_3_1_1;
|
||||
|
||||
/* MQTT buffers configuration */
|
||||
client->rx_buf = rx_buffer;
|
||||
client->rx_buf_size = sizeof(rx_buffer);
|
||||
client->tx_buf = tx_buffer;
|
||||
client->tx_buf_size = sizeof(tx_buffer);
|
||||
|
||||
/* MQTT transport configuration */
|
||||
client->transport.type = MQTT_TRANSPORT_SECURE;
|
||||
|
||||
struct mqtt_sec_config *tls_config =
|
||||
&client->transport.tls.config;
|
||||
|
||||
tls_config->peer_verify = TLS_PEER_VERIFY_REQUIRED;
|
||||
tls_config->cipher_list = NULL;
|
||||
tls_config->sec_tag_list = m_sec_tags;
|
||||
tls_config->sec_tag_count = ARRAY_SIZE(m_sec_tags);
|
||||
tls_config->hostname = hostname;
|
||||
|
||||
LOG_INF("Connecting to host: %s", hostname);
|
||||
err = mqtt_connect(client);
|
||||
if (err != 0) {
|
||||
LOG_ERR("could not connect, error %d", err);
|
||||
mqtt_disconnect(client);
|
||||
retries--;
|
||||
k_msleep(ALIVE_TIME);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (wait_for_input(5 * MSEC_PER_SEC) > 0) {
|
||||
mqtt_input(client);
|
||||
if (!connected) {
|
||||
LOG_ERR("failed to connect to mqtt_broker");
|
||||
mqtt_disconnect(client);
|
||||
retries--;
|
||||
k_msleep(ALIVE_TIME);
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
LOG_ERR("failed to connect to mqtt broker");
|
||||
mqtt_disconnect(client);
|
||||
retries--;
|
||||
k_msleep(ALIVE_TIME);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!connected) {
|
||||
LOG_ERR("Failed to connect to client, aborting");
|
||||
return;
|
||||
}
|
||||
|
||||
/* initialize publish structure */
|
||||
pub_data.message.topic.topic.utf8 = pub_topic;
|
||||
pub_data.message.topic.topic.size = strlen(pub_topic);
|
||||
pub_data.message.topic.qos = MQTT_QOS_1_AT_LEAST_ONCE;
|
||||
pub_data.message.payload.data = (uint8_t *)pub_msg;
|
||||
pub_data.message_id = 1U;
|
||||
pub_data.dup_flag = 0U;
|
||||
pub_data.retain_flag = 1U;
|
||||
|
||||
mqtt_live(client);
|
||||
|
||||
next_alive = k_uptime_get() + ALIVE_TIME;
|
||||
|
||||
while (1) {
|
||||
LOG_INF("Publishing data");
|
||||
sprintf(pub_msg, "%s: %d\n", "payload", pub_data.message_id);
|
||||
pub_data.message.payload.len = strlen(pub_msg);
|
||||
err = mqtt_publish(client, &pub_data);
|
||||
if (err) {
|
||||
LOG_ERR("could not publish, error %d", err);
|
||||
break;
|
||||
}
|
||||
|
||||
/* idle and process messages */
|
||||
while (k_uptime_get() < next_alive) {
|
||||
LOG_INF("... idling ...");
|
||||
if (wait_for_input(5 * MSEC_PER_SEC) > 0) {
|
||||
mqtt_input(client);
|
||||
}
|
||||
}
|
||||
|
||||
mqtt_live(client);
|
||||
next_alive += ALIVE_TIME;
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Linaro Ltd
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
* MQTT-based cloud protocol engine.
|
||||
*/
|
||||
|
||||
#ifndef PROTOCOL_H__
|
||||
#define PROTOCOL_H__
|
||||
|
||||
#include <zephyr/net/socket.h>
|
||||
|
||||
void mqtt_startup(char *hostname, int port);
|
||||
|
||||
#endif
|
|
@ -1,5 +0,0 @@
|
|||
#define MBEDTLS_AES_ROM_TABLES
|
||||
|
||||
#define MBEDTLS_HAVE_TIME
|
||||
#define MBEDTLS_HAVE_TIME_DATE
|
||||
#define MBEDTLS_PLATFORM_TIME_ALT
|
Loading…
Reference in a new issue