diff options
author | Charles Baylis <charles.baylis@linaro.org> | 2016-11-14 18:54:33 +0100 |
---|---|---|
committer | Charles Baylis <charles.baylis@linaro.org> | 2016-11-14 20:56:36 +0100 |
commit | 457ab3a3bed2e65de4384145a661da2a269c2891 (patch) | |
tree | a2eed96de8fb039e804ca983960eedc54fb200e7 | |
parent | 13f6ead3594616211de6d02cfd94d756e6d313bd (diff) |
Validate manifestid field for version 1.3 manifests.
For manifests with a version 1.3 or newer, require the presence
of a manifestid field and check that its value is correct.
Change-Id: I5b01e9359d96fe8b732cd2fab65a0b0ff39e0f5f
-rwxr-xr-x | validate-manifest.pl | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/validate-manifest.pl b/validate-manifest.pl index f9ea150..eb9a6a4 100755 --- a/validate-manifest.pl +++ b/validate-manifest.pl @@ -1,6 +1,7 @@ #!/usr/bin/perl use Digest::MD5 qw(md5_hex); +use Digest::SHA qw(sha1_hex); use warnings; use strict; @@ -153,6 +154,7 @@ check_all_flags($manifest); check_all_components($manifest); check_url_locations($manifest) if $opt_release; check_gdbserver($manifest); +check_manifestid($manifest); check_online($manifest) if $opt_online; output_normalized($manifest, $opt_output_normalized) if $opt_output_normalized; @@ -266,6 +268,9 @@ sub check_all_flags my ($m) = @_; my @required_flags=qw(target clibrary); my $err; + + push @required_flags,"manifestid" if version_ge($m, "1.3"); + foreach my $flag (@required_flags) { if (!defined $m->{flag_info}{$flag}) @@ -413,10 +418,10 @@ sub check_components_list sub check_manifest_version { my ($m) = @_; - if ($m->{mani_ver} !~ /^1\.[12]$/) + if ($m->{mani_ver} !~ /^1\.[123]$/) { - error($m, "Unknown manifest version $m->{mani_ver}, treating as 1.2"); - $m->{mani_ver} = "1.2"; + error($m, "Unknown manifest version $m->{mani_ver}, treating as 1.3"); + $m->{mani_ver} = "1.3"; } } @@ -435,6 +440,49 @@ sub version_ge } } +sub calculate_manifest_id +{ + my ($m) = @_; + + # This is used to accumulate the string which will be passed to sha1_hex + # to calculate the manifest ID. + my $str = ""; + + $str=sprintf("%s%s=%s\n", $str, "manifest_format", $m->{mani_ver}); + foreach my $comp (sort keys %{$m->{component_info}}) + { + foreach my $field (sort keys %{$m->{component_info}{$comp}}) + { + my $field_value = $m->{component_info}{$comp}{$field}; + $str=sprintf("%s%s_%s=%s\n", $str, $comp, $field, $field_value); + } + } + + foreach my $flag (sort keys %{$m->{flag_info}}) + { + next if $flag eq "manifestid"; + $str=sprintf("%s%s=%s\n", $str, $flag, $m->{flag_info}{$flag}); + } + + return sha1_hex($str); +} + +sub check_manifestid +{ + my ($m) = @_; + + my $calculated_id=calculate_manifest_id($m); + my $real_id = $m->{flag_info}{manifestid}; + + # we don't need to check the manifest id if it is not present. + return if !defined $real_id; + + if ($calculated_id ne $real_id) + { + error($m, "Manifest ID mismatch. Expected $real_id, got $calculated_id."); + } +} + sub output_normalized { my ($m, $outfile) = @_; |