Revert "Update squashfs sort file."
[tails-test.git] / vagrant / lib / vagrant_verified_download.rb
blob976aa4771e26e29684cca7f4a139927861d8ed1d
1 # Tails: The Amnesic Incognito Live System
2 # Copyright © 2012 Tails developers <tails@boum.org>
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 require 'digest'
19 # The following will monkeypatch Vagrant (successfuly tested against Vagrant
20 # 1.0.2) in order to verify the checksum of a downloaded box.
21 module Vagrant
22   class Config::VMConfig
23     attr_accessor :box_checksum
24   end
26   class Action::Box::Download
27     alias :unverified_download :download
28     def download
29       unverified_download
31       checksum = Digest::SHA256.new.file(@temp_path).hexdigest
32       if checksum != @env['global_config'].vm.box_checksum
33         raise Errors::BoxVerificationFailed.new
34       end
35     end
36   end
37 end