Permalink
Browse files

dji_fwcon: Added firmware encryption key.

The key for encryption type 1 was published by Dji, so adding it to
the code. Firmwares will now be automatically decrypted during
extraction, and encrypted when adding to package.
  • Loading branch information...
mefistotelis committed Jan 17, 2018
1 parent 875e097 commit 9d261d819d31aceafe6ff30b7b6453a2d401af5f
Showing with 5 additions and 4 deletions.
  1. +5 −4 dji_fwcon.py
@@ -422,8 +422,9 @@ def dji_extract(po, fwpkgfile):
if (chksum_enctype != 0):
if (po.no_crypto):
hde.preencrypted = 1
#elif (chksum_enctype == 1):
#TODO Find out what the key is
elif (chksum_enctype == 1):
encrypt_key = bytes.fromhex("96709aD326674AC382B66927E6d88421")
encrypt_iv = bytes.fromhex("00000000000000000000000000000000")
else:
# Since we cannot decode the encryption, mark the entry as pre-encrypted to extract in encrypted form
eprint("{}: Warning: Unknown encryption {:d} in module {:d}, extracting encrypted.".format(po.fwpkgfile,chksum_enctype,i))
@@ -548,8 +549,8 @@ def dji_create(po, fwpkgfile):
hde.set_encrypt_type(0)
chksum_enctype = hde.get_encrypt_type()
elif (chksum_enctype == 1):
#TODO Find out what the encryption algorithm is, then write an encoder
eprint("{}: Warning: NOT IMPLEMENTED encryption {:d} in module {:d}; decrypted checksum bad.".format(po.fwpkgfile,chksum_enctype,i))
encrypt_key = bytes.fromhex("96709aD326674AC382B66927E6d88421")
encrypt_iv = bytes.fromhex("00000000000000000000000000000000")
else:
if (not po.force_continue):
eprint("{}: Error: Unknown encryption {:d} in module {:d}; cannot encrypt.".format(po.fwpkgfile,chksum_enctype,i))

8 comments on commit 9d261d8

@MAVProxyUser

This comment has been minimized.

MAVProxyUser replied Jan 19, 2018

@digdat0

This comment has been minimized.

digdat0 replied Jan 20, 2018

thank you mefistotelis for updating the tool and MAVPROXY for the dumsterfire :) can confirm that things work QUITE well on newer FW :) now to test non-p3 AC. I did find i had to be on python 3.4 or earlier and also the pcrypto binary (I'm on windows). This is a great resource for that binary http://www.voidspace.org.uk/python/modules.shtml

@mefistotelis

This comment has been minimized.

Collaborator

mefistotelis replied Jan 20, 2018

I did find i had to be on python 3.4 or earlier

I don't think that's right. I'm using:
python3 --version
Python 3.6.2

@danieltroger

This comment has been minimized.

danieltroger replied Jan 20, 2018

can confirm that things work QUITE well on newer FW :)

Yep, I can also confirm it works on the phantom 3. Successfully flashed a repacked fw yesterday.

@tuxxy

This comment has been minimized.

tuxxy replied Jan 25, 2018

Ah, and an all-zero IV for AES-CBC...

@ferraript

This comment has been minimized.

ferraript replied Apr 29, 2018

I just noticed that since this commit I'm getting this error:

Traceback (most recent call last):
  File "dji_fwcon.py", line 672, in <module>
    main(sys.argv[1:])
  File "dji_fwcon.py", line 653, in main
    dji_extract(po,fwpkgfile)
  File "dji_fwcon.py", line 426, in dji_extract
    encrypt_key = bytes.fromhex("96709aD326674AC382B66927E6d88421")
AttributeError: type object 'str' has no attribute 'fromhex'

am I doing something wrong, @mefistotelis ?

@mefistotelis

This comment has been minimized.

Collaborator

mefistotelis replied Apr 29, 2018

Are you by any chance trying to use the script with Python 2.x?
In there, bytes is same as str, so you would get that error. I think bytearray.fromhex should be used there.
As the script header suggests, it is intended for Python 3.

@ferraript

This comment has been minimized.

ferraript replied Apr 29, 2018

aah, yeah, I was using version 2.7
it's not easy to work with both 2.x and 3.x installed
anyway, with 3.6 it's working fine, thanks a lot

Please sign in to comment.