From c37b94795730a857485c6cebac6402c03246dce5 Mon Sep 17 00:00:00 2001 From: Rich Salz Date: Tue, 5 Jan 2021 20:26:05 -0500 Subject: [PATCH] Add a local perl module to get year last changed This is used for generating a more-correct copyright statement for the "build_generated" targets. Fixes: #13765 Reviewed-by: Matt Caswell Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/13791) --- crypto/asn1/charmap.pl | 8 +++++-- crypto/bn/bn_prime.pl | 8 +++++-- crypto/conf/keysets.pl | 7 ++++-- crypto/objects/obj_dat.pl | 7 ++++-- crypto/objects/objects.pl | 5 +++- crypto/objects/objxref.pl | 8 ++++--- fuzz/mkfuzzoids.pl | 20 ++++++++++++---- fuzz/oids.txt | 9 +++++++ util/perl/OpenSSL/copyright.pm | 43 ++++++++++++++++++++++++++++++++++ 9 files changed, 99 insertions(+), 16 deletions(-) create mode 100644 util/perl/OpenSSL/copyright.pm diff --git a/crypto/asn1/charmap.pl b/crypto/asn1/charmap.pl index 43102a136a..78053dee15 100644 --- a/crypto/asn1/charmap.pl +++ b/crypto/asn1/charmap.pl @@ -1,5 +1,5 @@ #! /usr/bin/env perl -# Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy @@ -7,6 +7,9 @@ # https://www.openssl.org/source/license.html use strict; +use FindBin; +use lib "$FindBin::Bin/../../util/perl"; +use OpenSSL::copyright; my ($i, @arr); @@ -83,7 +86,8 @@ $arr[ord("?")] |= $PSTRING_CHAR; # Now generate the C code # Year the file was generated. -my $YEAR = [localtime()]->[5] + 1900; +my $YEAR = OpenSSL::copyright::year_of($0); + print <[5] + 1900; +my $YEAR = OpenSSL::copyright::year_of($0); + print <<"EOF"; /* * WARNING: do not edit! diff --git a/crypto/conf/keysets.pl b/crypto/conf/keysets.pl index f4c4b807c6..7e83d80050 100644 --- a/crypto/conf/keysets.pl +++ b/crypto/conf/keysets.pl @@ -1,5 +1,5 @@ #! /usr/bin/env perl -# Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy @@ -8,6 +8,9 @@ use strict; use warnings; +use FindBin; +use lib "$FindBin::Bin/../../util/perl"; +use OpenSSL::copyright; my $NUMBER = 0x0001; my $UPPER = 0x0002; @@ -58,7 +61,7 @@ foreach (0 .. 127) { } # The year the output file is generated. -my $YEAR = [localtime()]->[5] + 1900; +my $YEAR = OpenSSL::copyright::year_of($0); print <<"EOF"; /* * WARNING: do not edit! diff --git a/crypto/objects/obj_dat.pl b/crypto/objects/obj_dat.pl index ea77b9d242..60a5e5a683 100644 --- a/crypto/objects/obj_dat.pl +++ b/crypto/objects/obj_dat.pl @@ -1,5 +1,5 @@ #! /usr/bin/env perl -# Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy @@ -9,6 +9,9 @@ use integer; use strict; use warnings; +use FindBin; +use lib "$FindBin::Bin/../../util/perl"; +use OpenSSL::copyright; # Generate the DER encoding for the given OID. sub der_it @@ -37,7 +40,7 @@ sub der_it } # The year the output file is generated. -my $YEAR = [localtime()]->[5] + 1900; +my $YEAR = OpenSSL::copyright::latest(($0, $ARGV[0])); # Read input, parse all #define's into OID name and value. # Populate %ln and %sn with long and short names (%dupln and %dupsn) diff --git a/crypto/objects/objects.pl b/crypto/objects/objects.pl index 8c80b2f83f..51bc248b3f 100644 --- a/crypto/objects/objects.pl +++ b/crypto/objects/objects.pl @@ -7,12 +7,15 @@ # https://www.openssl.org/source/license.html use Getopt::Std; +use FindBin; +use lib "$FindBin::Bin/../../util/perl"; +use OpenSSL::copyright; our($opt_n); getopts('n'); # The year the output file is generated. -my $YEAR = [localtime()]->[5] + 1900; +my $YEAR = OpenSSL::copyright::latest(($0, $ARGV[1], $ARGV[0])); open (NUMIN,"$ARGV[1]") || die "Can't open number file $ARGV[1]"; $max_nid=0; diff --git a/crypto/objects/objxref.pl b/crypto/objects/objxref.pl index bf45d66046..a6748f00f4 100644 --- a/crypto/objects/objxref.pl +++ b/crypto/objects/objxref.pl @@ -1,13 +1,15 @@ #! /usr/bin/env perl -# Copyright 1998-2020 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 1998-2021 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy # in the file LICENSE in the source distribution or at # https://www.openssl.org/source/license.html - use strict; +use FindBin; +use lib "$FindBin::Bin/../../util/perl"; +use OpenSSL::copyright; my %xref_tbl; my %oid_tbl; @@ -15,7 +17,7 @@ my %oid_tbl; my ($mac_file, $xref_file) = @ARGV; # The year the output file is generated. -my $YEAR = [localtime()]->[5] + 1900; +my $YEAR = OpenSSL::copyright::latest(($0, $mac_file, $xref_file)); open(IN, $mac_file) || die "Can't open $mac_file, $!\n"; diff --git a/fuzz/mkfuzzoids.pl b/fuzz/mkfuzzoids.pl index 8fff764b96..56021717a8 100755 --- a/fuzz/mkfuzzoids.pl +++ b/fuzz/mkfuzzoids.pl @@ -1,15 +1,27 @@ #! /usr/bin/env perl -# Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy # in the file LICENSE in the source distribution or at # https://www.openssl.org/source/license.html +use FindBin; +use lib "$FindBin::Bin/../util/perl"; +use OpenSSL::copyright; my $obj_dat_h = $ARGV[0]; - -# The year the output file is generated. -my $YEAR = [localtime()]->[5] + 1900; +my $YEAR = OpenSSL::copyright::latest(($0, $obj_dat_h)); +print <<"EOF"; +# WARNING: do not edit! +# Generated by fuzz/mkfuzzoids.pl +# +# Copyright 2020-$YEAR The OpenSSL Project Authors. All Rights Reserved. +# +# Licensed under the Apache License 2.0 (the "License"). You may not use +# this file except in compliance with the License. You can obtain a copy +# in the file LICENSE in the source distribution or at +# https://www.openssl.org/source/license.html +EOF open IN, '<', $obj_dat_h || die "Couldn't open $obj_dat_h : $!\n"; diff --git a/fuzz/oids.txt b/fuzz/oids.txt index cec6a70151..8ca5291a01 100644 --- a/fuzz/oids.txt +++ b/fuzz/oids.txt @@ -1,3 +1,12 @@ +# WARNING: do not edit! +# Generated by fuzz/mkfuzzoids.pl +# +# Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved. +# +# Licensed under the Apache License 2.0 (the "License"). You may not use +# this file except in compliance with the License. You can obtain a copy +# in the file LICENSE in the source distribution or at +# https://www.openssl.org/source/license.html OBJ_rsadsi="\x2A\x86\x48\x86\xF7\x0D" OBJ_pkcs="\x2A\x86\x48\x86\xF7\x0D\x01" OBJ_md2="\x2A\x86\x48\x86\xF7\x0D\x02\x02" diff --git a/util/perl/OpenSSL/copyright.pm b/util/perl/OpenSSL/copyright.pm new file mode 100644 index 0000000000..1fd9f353f7 --- /dev/null +++ b/util/perl/OpenSSL/copyright.pm @@ -0,0 +1,43 @@ +#! /usr/bin/env perl +# Copyright 2021 The OpenSSL Project Authors. All Rights Reserved. +# +# Licensed under the Apache License 2.0 (the "License"). You may not use +# this file except in compliance with the License. You can obtain a copy +# in the file LICENSE in the source distribution or at +# https://www.openssl.org/source/license.html + +use strict; +use warnings; + +package OpenSSL::copyright; + +sub year_of { + my $file = shift; + + return $ENV{'OSSL_COPYRIGHT_YEAR'} if defined $ENV{'OSSL_COPYRIGHT_YEAR'}; + + # Get the current year. We use that as the default because the other + # common case is that someone unpacked a tarfile and the file dates + # are't properly set on extract. + my $YEAR = [localtime()]->[5] + 1900; + + # See if git's available + open my $FH, + "git log -1 --date=format:%Y --format=format:%ad $file 2>/dev/null|" + or return $YEAR; + my $LINE = <$FH>; + close $FH; + chomp($LINE); + $YEAR = $LINE if $LINE; + return $YEAR; +} + +sub latest { + my $l = 0; + foreach my $f (@_ ) { + my $y = year_of($f); + $l = $y if $y > $l; + } + return $l +} +1;