On Tue, Sep 19, 2023 at 05:58:23PM +0000, Chris Thompson via pacsat-dev wrote:
Corey, I was delayed by another bug but managed to look at this today. It looks very good.
I can calculate the same hash value with the default key using the Java Mac class and the HmacSHA256 algorithm. So that is great. It uses the public algorithm.
I did notice that the default key in the code you implemented is 28 bytes and not 32 bytes as you stated in an earlier email. Is that correct? It works with the 28 byte key.
Oops, that was an off-by-one bug in my brain. It will still work, it will just be padded with zeros at the end. It's better to add the four extra bytes.
One other thing. The existing code prevents a replay attack by sending the reset/uptime on the spacecraft in the command. We have to send the same reset and an uptime that is the same or no more than 300 seconds after the actual uptime on the spacecraft. I think this could cause issues with an unresponsive spacecraft where we don't know the time onboard. I'm sure that is why there is a special command that goes around the requirement and turns it off.
I would instead propose we send a serial number in the command, with no other meaning. Any command can only be used once and we store the highest serial number used so far. The serial number would be in the hash of the command of course. To make it easy to sync the serial numbers across different command stations I propose that the serial number be unix time in UTC, or the time based on a later epoch if we want something with less than 32 bits. It will just be treated as a serial number that is checked for duplicates when received at the spacecraft. Specifically all commands must have a serial number greater than the largest one received so far.
Using current epoch as the serial number would be an excellent idea. All it has to be is non-reusable and increasing.
It will cause a problem on January 2038 when the epoch rolls over. However, if you used an unsigned 32-bit integer and calculated it from a 64-bit epoch, you get another 70 years beyond that. Or you could do you own epoch from spacecraft launch time.
-corey
Maybe that is not secure enough. Let me know.
73 Chris
On Sat, Sep 16, 2023 at 6:56 PM Chris Thompson via pacsat-dev < pacsat-dev@amsat.org> wrote:
Sounds very good. I will try to have a look at it tomorrow or Monday.
73 Chris
On Sat, Sept 16, 2023, 15:53 Corey Minyard minyard@acm.org wrote:
On Sat, Sep 16, 2023 at 1:58 PM Chris Thompson via pacsat-dev pacsat-dev@amsat.org wrote:
Just for reference, the sha.c algorithm did match what I get from Java
with the standard sha-256 digest. So it does work for the 18 bytes of our commands. But it sounds like it will not work if we append the secret key twice.
Yes, my impetus for replacing it, plus the new algorithm allows partial adds of data to make the process easier.
I have pushed up an update-sha-hmac branch that reworks all the keying. It uses the hmac-sha256 algorithm for authentication, it adds the code to load the key from NVRAM, and reworks the keysize to be 32 bytes. Reworking the key size will rearrange NVRAM, unfortunately. With this, you should be able to add a key from the command line and have it write it to NVRAM, and use it for the hmac-sha256 authentication. It does remove the AES code.
-corey - AE5KM
73 Chris
On Sat, Sept 16, 2023, 12:49 Corey Minyard via pacsat-dev <
pacsat-dev@amsat.org> wrote:
I just pulled Authenticate/src/sha.c out of the code and moved it into a separate file and played with it a bit. It wasn't matching the results from sha256sum, and looking at the code, I realized that the implementation only accepts up to 64 bytes of data. It works for buffers less than 64 bytes. It also won't do partial pieces, which would make the implementation of HMAC easier.
I'm going to recommend we adapt https://github.com/h5p9sl/hmac_sha256 to our needs. I'll work on that a bit.
Also, I couldn't find any evidence of any cryptanalysis of encrypting the sha256 output with AES. Sometimes those things work, sometimes you get surprising results. Since the HMAC approach is well known and heavily analyzed, that would seem a better approach.
-corey - AE5KM
On Fri, Sep 15, 2023 at 1:21 PM Chris Thompson via pacsat-dev pacsat-dev@amsat.org wrote:
I did not implement it yet. It would go in Command task.c and
replace or perhaps duplicate the authenticate function.
Feel free to code it.
I don't know if we will ultimately go this way. I would still like
to make the AES authentication work but I agree this could be simpler and faster. So it would be good to test it.
Chris
On Fri, Sept 15, 2023, 11:20 Corey Minyard minyard@acm.org wrote: > > On Fri, Sep 15, 2023 at 10:06 AM Chris Thompson via pacsat-dev > pacsat-dev@amsat.org wrote: > > > > Ok, thanks for that Corey. Very interesting. We may not be
susceptible to the length extension attack vulnerability though. If I understand correctly, then a message sent as: Hash( key + "Watch the enemy") could be manipulated to Hash(key + "Watch the enemy and attack them after 5 mins"), without knowing the key. But our commands are fixed at 18 bytes length (for now at least). So any extra appended message would be ignored. With that said, it may not be much harder to implement the scheme as described.
> > Yes, I was more worried about the "various security papers have > suggested vulnerabilities with this approach" comment in the article > on the key || message || key approach. It probably means there are > other issues with the approach, possibly key extraction attacks.
The
> HMAC approach seems generally more cryptographically sound. > > I was going to say that I could implement it, though it's pretty > trivial. You've probably already done it :). > > -corey - AE5KM
pacsat-dev mailing list -- pacsat-dev@amsat.org View archives of this mailing list at
https://mailman.amsat.org/hyperkitty/list/pacsat-dev@amsat.org
To unsubscribe send an email to pacsat-dev-leave@amsat.org Manage all of your AMSAT-NA mailing list preferences at
pacsat-dev mailing list -- pacsat-dev@amsat.org View archives of this mailing list at
https://mailman.amsat.org/hyperkitty/list/pacsat-dev@amsat.org
To unsubscribe send an email to pacsat-dev-leave@amsat.org Manage all of your AMSAT-NA mailing list preferences at
pacsat-dev mailing list -- pacsat-dev@amsat.org View archives of this mailing list at
https://mailman.amsat.org/hyperkitty/list/pacsat-dev@amsat.org
To unsubscribe send an email to pacsat-dev-leave@amsat.org Manage all of your AMSAT-NA mailing list preferences at
pacsat-dev mailing list -- pacsat-dev@amsat.org View archives of this mailing list at https://mailman.amsat.org/hyperkitty/list/pacsat-dev@amsat.org To unsubscribe send an email to pacsat-dev-leave@amsat.org Manage all of your AMSAT-NA mailing list preferences at https://mailman.amsat.org
-- Chris E. Thompson chrisethompson@gmail.com g0kla@arrl.net
pacsat-dev mailing list -- pacsat-dev@amsat.org View archives of this mailing list at https://mailman.amsat.org/hyperkitty/list/pacsat-dev@amsat.org To unsubscribe send an email to pacsat-dev-leave@amsat.org Manage all of your AMSAT-NA mailing list preferences at https://mailman.amsat.org