Has anyone been able to get the HAL branch for gcc to connect to the cloud or a local spark-server?


#1

I am hoping to setup a virtual device for testing purposes and I was able to successfully compile the HAL branch for gcc to get an executable. This executable comes with instructions/help as follows:

Other than that, there doesn’t seem to be any documentation on the usage of the executable. I attempted to use the private der encoded rsa key from a particle device and the public server key for the actual particle cloud; however, I was unable to connect. In a second attempt I turned to a fork of the spark-server https://github.com/Brewskey/spark-server but was still unable to get the virtual device to connect (I was unsure how to register the devices ID with the server without using the particle cli which gives errors when no actual device is plugged in or the hacky approach of manually editing the spark-server’s data files which I would prefer to avoid). Eventually I hope to get the virtual device connected to the cloud (or a local server) and to be able to flash it with my project for local memory testing. Could anyone point me to documentation or give me some pointers on usage, generating appropriate RSA keys for a virtual device, or flashing a virtual device?


#2

Using a device private key and ID (saved from a particle electron that is registered and previously was connected to the cloud so that the keys are registered), the standard particle server public key, and protocol set to UDP I get the following error(s):

NOTE: I have removed references to my Device ID and replaced them with (DEVICE_ID) and redacted the server/device key.

0000000000 [system] INFO: Device (DEVICE_ID) started
0000000000 [hal] INFO: Virtual WLAN init
0000000000 [hal] INFO: Virtual WLAN on
0000000000 [hal] INFO: Virtual WLAN connecting
0000000000 [system] INFO: ARM_WLAN_WD 1
0000001005 [system] INFO: ARM_WLAN_WD 2
0000001005 [hal] INFO: Virtual WLAN connected
0000001005 [system] INFO: CLR_WLAN_WD 1, DHCP success
0000001005 [hal] INFO: device key: ******* REDACTED *******
0000001006 [hal] INFO: server key: ******* REDACTED *******
0000001006 [comm] INFO: channel inited
0000001006 [system] INFO: Cloud: connecting
0000001006 [system] WARN: Public Server Address was blank, restoring.
0000001006 [system] INFO: Read Server Address = type:1,domain:$id.udp.particle.io
0000001006 [system] ERROR: Failed to load session data from persistent storage
0000001006 [system] INFO: Discarding session data
0000001006 [system] TRACE: Resolving (DEVICE_ID).udp.particle.io
0000001031 [system] INFO: Resolved (DEVICE_ID).udp.particle.io to 54.209.210.255
0000001032 [system] TRACE: Connection attempt to 54.209.210.255:5684
0000001032 [system] INFO: Cloud socket connected
0000001032 [system] INFO: Starting handshake: presense_announce=0
0000001032 [comm.protocol.handshake] INFO: Establish secure connection
0000001032 [comm.dtls] INFO: (CMPL,RENEG,NO_SESS,ERR) restoreStatus=2
mbedtls/library/ssl_cli.c:2723: bad server key exchange message
0000001074 [comm.dtls] ERROR: handshake failed -6d00
0000001074 [comm.protocol.handshake] ERROR: handshake failed with code 17
0000001074 [system] INFO: Send event spark/device/key/error=4
0000001074 [system] WARN: Cloud handshake failed, code=17
0000001324 [system] INFO: Cloud: disconnecting
0000001324 [system] INFO: Cloud: disconnected

My vdev.conf is as follows:

device_id=(DEVICE_ID)
device_key=keys/(DEVICE_ID).der
server_key=keys/cloud_public.der
protocol=udp
verbosity=70

#3

@rickkas7 Is this a key issue? Any chance there is a good way to generate valid keys for the GCC target?

We’re trying to get it working with Tinker, then our app so we can run Valgrind/GDB against the whole system.


#4

Update:
I was able to get the virtual device to connect to both the local spark-server as well as the particle cloud. It appears that particle is using EC encoded keys (even if the keys are being saved by particle-cli with RSA in the name, they are actually EC encoded). Using a device previously registered/claimed on the cloud I was able to upload new RSA keys which I then used to get my virtual device to connect.

You can generate RSA encoded keys using openssl:

openssl genrsa -out rsaEncodedPrivateKey.pem 1024

Convert the key to der format

openssl rsa -inform pem -outform der -in rsaEncodedPrivateKey.pem -out rsaEncodedPrivateKey.der

Then you can upload this key to a particle device using the particle-cli

particle keys load rsaEncodedPrivateKey.der

Then make sure you have the proper server public key uploaded to your device for either your local or cloud server. (The particle public server key can be downloaded HERE

particle keys server serverPubKey.der

Next, login to the cloud if you aren’t already

particle login

enter your user name and password

Extract your device’s public key from the pem encoded private key you generated earlier

openssl rsa -pubout -inform pem -outform pem -in rsaEncodedPrivateKey.pem -out rsaEncodedPublicKey.pub.pem

Send your updated key to the server

particle keys send device_id rsaEncodedPublicKey.pub.pem

Finally, if this was all successful. In the directory with the virtual device’s executable particle/firmware/build/target/main/platform-3/
Create a vdev.conf file in the following format so that you can just call ./main instead of having to pass in the key files as command line arguments every time you run the virtual device.

NOTE: I set max verbosity for debugging and I found that tcp worked but was getting seg_faults with udp and will need to explore udp further.

device_id='YOUR_DEVICE_ID_HERE'
device_key=rsaEncodedPrivateKey.der
server_key=serverPubKey.der
protocol=tcp
verbosity=70