Brewskey / spark-server

An API compatible open source server for interacting with devices speaking the spark-protocol
https://www.particle.io/
GNU Affero General Public License v3.0
54 stars 27 forks source link

Particle keys #262

Closed bradfernandez closed 6 years ago

bradfernandez commented 6 years ago

Hello, I am having some trouble getting my keys right. I have started up the server. I connected to it using particle cli. It asked for a new user so I know I connected to the new server. "sudo particle keys server default_key.pub.pem ip_address" ran successfully. It responds "Okay! New keys in place..." But when I run "sudo particle keys doctor " it fails with an error of "Error sending public key to server: Error: Parse Error". Not sure why its failing everything else seems to work. I'll include the console log below.

pi@photondev:~ $ sudo particle keys doctor 22002e000147353138383138 Found DFU device 2b04:d006 Found DFU device 2b04:d006 New Key Created! Found DFU device 2b04:d006 This file already exists, please specify a different file, or use the --force flag. Continuing... spawning dfu-util -d 2b04:d006 -a 1 -i 0 -s 34:leave -D 22002e000147353138383138_rsa_new.der No valid DFU suffix signature Warning: File has no DFU suffix dfu-util 0.7

Copyright 2005-2008 Weston Schmidt, Harald Welte and OpenMoko Inc. Copyright 2010-2012 Tormod Volden and Stefan Schmidt This program is Free Software and has ABSOLUTELY NO WARRANTY Please report bugs to dfu-util@lists.gnumonks.org

Filter on vendor = 0x2b04 product = 0xd006 Opening DFU capable USB device... ID 2b04:d006 Run-time device DFU version 011a Found DFU: [2b04:d006] devnum=0, cfg=1, intf=0, alt=1, name="@DCT Flash /0x00000000/01*016Kg" Claiming USB DFU Interface... Setting Alternate Setting #1 ... Determining device status: state = dfuIDLE, status = 0 dfuIDLE, continuing DFU mode device DFU version 011a Device returned transfer size 4096 DfuSe interface name: "DCT Flash " Downloading to address = 0x00000022, size = 610 . File downloaded successfully Saved! attempting to add a new public key for device 22002e000147353138383138 Error sending public key to server: Error: Parse Error Make sure your device is in DFU mode (blinking yellow), and that your computer is online. Error - undefined

bradfernandez commented 6 years ago

Here is what the server displays as the Photon attempts to connect.

[2018-03-15T19:18:06.905Z] ERROR: DeviceServer.js/4398 on RobR_DVLP: Device startup failed Error: key passed to device during handshake doesn'tmatch saved public key: 22002e000147353138383138 at Handshake._callee5$ (/home/pi/spark-server/node_modules/spark-protocol/dist/lib/Handshake.js:384:21)

jlkalberer commented 6 years ago

When I see the error it's because I haven't set the correct key on the device while and my particle config is set to the wrong config (usually particle's).

I would run particle config localhost or whatever you're using. Then add the key to the device particle keys server... Then run particle key doctor ...


Another issue could be that you set up your local config incorrectly.

AntonPuko commented 6 years ago

If just connected my photon on fresh spark-server, using latest particle-cli doing the following steps: 1) npm install 2) npm start 3) particle config test apiUrl "http://192.168.1.37:8080" // the address should be yours ofc. 4) particle config test //actually switch to created config. You can ensure that you have right config selected typing particle config 5) particle setup -> create new account 6) go to dfu mode on device 7) particle keys server ./data/default_key.pub.pem --host 192.168.1.37 // in the old particle-cli version it was without --host flag 8) particle keys doctor 350023001951353337343731 9) at this step it should connect to the server sucessfully. If you have You probably have incorrect server key for device error - try to restart the server. We probably have a bug on server key intialization on the first ever server start.

AntonPuko commented 6 years ago

Also, this is suspicious in your logs This file already exists, please specify a different file, or use the --force flag. - it probably means that you're actually trying to send new device keys to origin particle cloud, not local server.

bradfernandez commented 6 years ago

ok here is what i did to get it working. when I use particle keys server I got the following error.

pi@RobR_DVLP:~/spark-server/temp $ sudo particle keys doctor 22002e000147353138383138 New Key Created! Saved! Saved! You're not logged in. Please login using particle cloud login before using this command Make sure your device is in DFU mode (blinking yellow), and that your computer is online. Error: Not logged in

I then logged in and tried again. same error.

I then did a particle keys load deviceid_rsa_new.der

then I did a particle keys send deviceID_rsa_new_pub.pem

Then I restart the Photon and it is now breathing cyan and showing the connection in my server console.

AntonPuko commented 6 years ago

hm..Thats weird why particle device doctor doesn't work for you, because doctor is just a shortcut for 3 commands in a row: keys new -> keys load -> keys send.

bradfernandez commented 6 years ago

Yeah that is odd and not the first time I have had to do it that way. oh well at least I have a procedure that is reproducible.