Skip to content

Commit

Permalink
[fix] Verify downloaded tarball with configuration checksum #158
Browse files Browse the repository at this point in the history
Closes #158

Co-authored-by: Federico Capoano <[email protected]>
  • Loading branch information
devkapilbansal and nemesifier authored Dec 15, 2021
1 parent c1dc482 commit 90346b4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions openwisp-config/files/openwisp.agent
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,23 @@ update_configuration() {
logger -s "Failed to connect to controller while downloading new config: curl exit code $exit_code" \
-t openwisp \
-p daemon.err
# remove the checksum to ensure update is tried again at the next run
rm -f $CONFIGURATION_CHECKSUM
return 3
fi

local LOCAL_CHECKSUM=$(md5sum $CONFIGURATION_ARCHIVE | cut -d ' ' -f 1)
local REMOTE_CHECKSUM=$(tail -n 1 $CONFIGURATION_CHECKSUM 2> /dev/null)

if [ "$LOCAL_CHECKSUM" != "$REMOTE_CHECKSUM" ]; then
logger -s "Failed to download configuration: checksum mismatch" \
-t openwisp \
-p daemon.err
# remove the checksum to ensure update is tried again at the next run
rm -f $CONFIGURATION_CHECKSUM
return 4
fi

logger "Configuration downloaded, now applying it..." \
-t openwisp \
-p daemon.info
Expand Down

0 comments on commit 90346b4

Please sign in to comment.