diff options
author | Charles Baylis <charles.baylis@linaro.org> | 2016-11-14 20:37:11 +0000 |
---|---|---|
committer | Linaro Code Review <review@review.linaro.org> | 2016-11-14 20:37:11 +0000 |
commit | c08d2ef1e2b30d01c1796e90ef8d032be1b9d46b (patch) | |
tree | e0dcca74af7ca538379b7d88a09c6027576830de | |
parent | 63478eb787c03500e36007fdb63aaeb5e198bd9b (diff) | |
parent | 457ab3a3bed2e65de4384145a661da2a269c2891 (diff) |
Merge "Validate manifestid field for version 1.3 manifests."
-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 2f160e2..3797917 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; @@ -267,6 +269,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}) @@ -414,10 +419,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"; } } @@ -436,6 +441,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) = @_; |