Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sonota: init at 2018-10-07 #50257

Merged
merged 1 commit into from Feb 7, 2019
Merged

sonota: init at 2018-10-07 #50257

merged 1 commit into from Feb 7, 2019

Conversation

peterhoeg
Copy link
Member

Motivation for this change

This is super useful for doing what is essentially a MITM attack on Sonoff devices in order to do OTA upgrades to open source firmware.

Tried it out successfully on a few different devices (S20, T1-1, T1-3). Doesn't work with the B1 though.

Cc: @fpletz

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: sonota

Partial log (click to expand)

installing
post-installation fixup
shrinking RPATHs of ELF executables and libraries in /nix/store/m1varz5jnz6s82xpz4yr2457brmrxgz7-sonota-20181007
strip is /nix/store/vcc4svb8gy29g4pam2zja6llkbcwsyiq-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/m1varz5jnz6s82xpz4yr2457brmrxgz7-sonota-20181007/bin
patching script interpreter paths in /nix/store/m1varz5jnz6s82xpz4yr2457brmrxgz7-sonota-20181007
/nix/store/m1varz5jnz6s82xpz4yr2457brmrxgz7-sonota-20181007/bin/sonota: interpreter directive changed from "/usr/bin/env python3" to "/nix/store/bwfygfcdvis9wd1c1v51xwnwhw1hx0a0-python3-3.6.6/bin/python3"
checking for references to /build in /nix/store/m1varz5jnz6s82xpz4yr2457brmrxgz7-sonota-20181007...
wrapping `/nix/store/m1varz5jnz6s82xpz4yr2457brmrxgz7-sonota-20181007/bin/sonota'...
/nix/store/m1varz5jnz6s82xpz4yr2457brmrxgz7-sonota-20181007

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: sonota

Partial log (click to expand)

installing
post-installation fixup
shrinking RPATHs of ELF executables and libraries in /nix/store/dds04k87ng9g8f6ramw36r4slfc6y6g8-sonota-20181007
strip is /nix/store/p9akxn2sfy4wkhqdqa3li97pc6jaz3r1-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/dds04k87ng9g8f6ramw36r4slfc6y6g8-sonota-20181007/bin
patching script interpreter paths in /nix/store/dds04k87ng9g8f6ramw36r4slfc6y6g8-sonota-20181007
/nix/store/dds04k87ng9g8f6ramw36r4slfc6y6g8-sonota-20181007/bin/sonota: interpreter directive changed from "/usr/bin/env python3" to "/nix/store/16wqq9ihrkdim3x8xs1lkxa3f4l3p3ir-python3-3.6.6/bin/python3"
checking for references to /build in /nix/store/dds04k87ng9g8f6ramw36r4slfc6y6g8-sonota-20181007...
wrapping `/nix/store/dds04k87ng9g8f6ramw36r4slfc6y6g8-sonota-20181007/bin/sonota'...
/nix/store/dds04k87ng9g8f6ramw36r4slfc6y6g8-sonota-20181007

sha256 = "0jd9xrhcyk8d2plbjnrlpn87536zr6n708797n0k5blf109q3c1z";
};

patches = [ ./set_resource_path.patch ];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this and the 'postPatch' be simplified with substituteAll?

patches = [
  (substituteAll {
     src = ./set_resource_path.patch;
     out = "$out";
  })
];

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost, we need out = placeholder "out";. Thanks for the tip!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Darn, forgot that placeholder doesn't work for substituteAll NixOS/nix#1846

So instead you'll have to do

postPatch = ''
  substituteInPlace sonota.py --subst-var out
'';

with the plain patch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it works though. This is the output:

def resource_path(relative_path):
    return os.path.join("/nix/store/9x9ahhb32yg2i4izxz9f250yi9vsc61n-set_resource_path.patch/share/sonota", relative_path)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But see that out is the patch /nix/store/9x9ahhb32yg2i4izxz9f250yi9vsc61n-set_resource_path.patch?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh crap. You're right.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@worldofpeace
Copy link
Contributor

The date should also be the same as the one in the derivation name.

@peterhoeg peterhoeg changed the title sonota: init at 20181007 sonota: init at 2018-10-07 Feb 4, 2019
Copy link
Contributor

@worldofpeace worldofpeace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and executes, though I can't test the function.

@peterhoeg peterhoeg merged commit 974024c into NixOS:master Feb 7, 2019
@peterhoeg
Copy link
Member Author

Thanks @worldofpeace

@peterhoeg peterhoeg deleted the p/sonota branch February 7, 2019 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants