Is there any any way to change the server address programatically?


#1

Hi Folks,

I am currently using particle photon to do some IoT project. And I may need to vary server address programatically.

In the particle API docs, there is a series of system set configurations APIs providing capability of changing server and device keys during run time. By investigating into system firmware, I noticed the implementations of this key changing code snippet, where it shows how to modify the keys and softAP SSID. I am wondering is there any way to modify this code snippet and create a system call for changing server address during run time? If so, could you please indicate how to do this?

We tried to add some code snippet for making new system call, as is shown in the last 2 case conditions in the below code snippet. However the address of host name written into flash seems always be incorrect, causing whole system firmware crashed… It will be great if you can indicate me where the potential issues of the new added code can be?

Additionally, there is two server address showed in dct.h file which are DCT_SERVER_ADDRESS_OFFSET and DCT_ALT_SERVER_ADDRESS_OFFSET. I am wondering what’s the difference between this 2 server addresses?

Thank you!

int HAL_Set_System_Config(hal_system_config_t config_item, const void* data, unsigned data_length)
{
    unsigned offset = 0;
    unsigned length = -1;

    switch (config_item)
    {
    case SYSTEM_CONFIG_DEVICE_KEY:
        offset = DCT_DEVICE_PRIVATE_KEY_OFFSET;
        length = DCT_DEVICE_PRIVATE_KEY_SIZE;
        break;
    case SYSTEM_CONFIG_SERVER_KEY:
        offset = DCT_SERVER_PUBLIC_KEY_OFFSET;
        length = DCT_SERVER_PUBLIC_KEY_SIZE;
        break;
    case SYSTEM_CONFIG_SOFTAP_PREFIX:
        offset = DCT_SSID_PREFIX_OFFSET;
        length = DCT_SSID_PREFIX_SIZE-1;
        if (data_length>length)
            data_length = length;
        dct_write_app_data(&data_length, offset++, 1);
        break;
    case SYSTEM_CONFIG_SOFTAP_SUFFIX:
        offset = DCT_DEVICE_CODE_OFFSET;
        length = DCT_DEVICE_CODE_SIZE;
        break;
    case SYSTEM_CONFIG_SOFTAP_HOSTNAMES:
        break;

    //  THIS IS THE CODE WE ADDED FOR ADDING SYSTEM CALL TO MODIFY SERVER ADDRESS
    case SYSTEM_CONFIG_SERVER_ADDRESS:
        offset = DCT_SERVER_ADDRESS_OFFSET;
        length = DCT_SERVER_ADDRESS_SIZE;   // this is 128
        if (data_length>length)
            data_length = length;

        dct_write_app_data(&data_length, offset++, 1);
        break;

    case SYSTEM_CONFIG_ALT_SERVER_ADDRESS:
        offset = DCT_ALT_SERVER_ADDRESS_OFFSET;
        length = DCT_ALT_SERVER_ADDRESS_SIZE;   // this is 128
        if (data_length>length)
            data_length = length;

        dct_write_app_data(&data_length, offset++, 1);
        break;



    }

    if (length>=0)
        dct_write_app_data(data, offset, length>data_length ? data_length : length);

    return length;
}

Changing the Public and Private key on the Flash from the Application Firmware
#2

Hi All,

I am working on a project with particle photon and I was wondering if it was possible to change the public and private key (of device/server key) on the flash. Particle provides a system call Here :
System.set(SYSTEM_CONFIG_…, “value”);
With various SYSTEM_Config configuration values being modified as below:

  • SYSTEM_CONFIG_SERVER_KEY
  • SYSTEM_CONFIG_DEVICE_KEY, etc.

We tried modifying the SYSTEM_CONFIG_SERVER_KEY from the pub.pem file to something similar to the below one:

MIGfMA0GCSq ..................sKhmoT9Fb6R4hdlwQOjbsQg7Ej9euqtJxf7xTOrgabk
T7JNaC2R+CIEHtnH4wIDAQAB

When providing this as a value for SYSTEM_CONFIG_SERVER_KEY, we seem to have to overwritten the memory region for the Hostname on the flash:

00000180: 7157 6a63 7972 646d 6563 307a 7245 6b7a  qWjcyrdmec0zrEkz
00000190: 762b 6f76 5654 6374 3074 3235 6964 4e4b  v+ovVTct0t25idNK
000001a0: 3769 6135 5350 5a46 7a79 4177 4944 4151  7ia5SPZFzyAwIDAQ
000001b0: 4142 2e73 7061 726b 2e69 6f00 ffff ffff  AB.spark.io

Based on this we have few questions:

  • Do we need to convert it pub.pem to something like .der and use it? If so, how do we do it in the application firmware?
  • Is this is the only way to do it or is there another way to modify the server public key on the flash?

Thanks!


#3

I moved these two posts to the same topic since they are asking the same question in different ways.

What are you really trying to accomplish? Asking this low level technical detail without explanation makes it really hard to craft an answer.

Do you know about the local cloud that was open-sourced by Particle and has been extended by several folks here? It uses its own keys which are easily changed using the command line tool known here as the Particle CLI. It sure sounds like that is what you want and would be much easier than starting over in the DCT and reinventing the wheel.


#4

Hi @bko,

Thank you for the reply. We are aware of the particle local cloud and we are using it (brewskey’s fork and others). We also have the experience in using the particle-cli and we have used it to change the hostname and the keys on the device. Currently, we have several instances of the particle local cloud running which are using the same key, and for security reasons, we may have to change the public keys on the device. So, What we are trying to accomplish here is to see if you can modify the hostname and the keys on the device using the particle system calls.

The particle documentation provides information regarding the system calls(System.set(SYSTEM_CONFIG_SERVER_KEY etc)) which allows us to change the keys on the devices (Thanks folks at particle! :slight_smile: ). So based on this, It would be great if you are able to answer the above questions.

Thank you.


#5

Hi @sud335,

we are in the same situation - using Brewskey’s fork for production. Very rarely one of the devices loses either keys (issues with securing connection to our server) or our server address (defaulting to api.spark.io).

I am searching for a way how to be able to configure correct server address programatically - is there any way?

Thanks in advance