opnsense-src/crypto/objects/objects.pl
Enji Cooper e4520c8bd1 openssl: Vendor import of OpenSSL-3.0.8
Summary:

Release notes can be found at
https://www.openssl.org/news/openssl-3.0-notes.html .

Obtained from:  https://www.openssl.org/source/openssl-3.0.8.tar.gz
Differential Revision:	https://reviews.freebsd.org/D38835

Test Plan:
```
$ git status
On branch vendor/openssl-3.0
nothing to commit, working tree clean
$ (cd ..; fetch http://www.openssl.org/source/openssl-${OSSLVER}.tar.gz http://www.openssl.org/source/openssl-${OSSLVER}.tar.gz.asc)
openssl-3.0.8.tar.gz                                    14 MB 4507 kBps    04s
openssl-3.0.8.tar.gz.asc                               833  B   10 MBps    00s
$ set | egrep '(XLIST|OSSLVER)='
OSSLVER=3.0.8
XLIST=FREEBSD-Xlist
$ gpg --list-keys
/home/ngie/.gnupg/pubring.kbx
-----------------------------
pub   rsa4096 2014-10-04 [SC]
      7953AC1FBC3DC8B3B292393ED5E9E43F7DF9EE8C
uid           [ unknown] Richard Levitte <richard@levitte.org>
uid           [ unknown] Richard Levitte <levitte@lp.se>
uid           [ unknown] Richard Levitte <levitte@openssl.org>
sub   rsa4096 2014-10-04 [E]

$ gpg --verify openssl-${OSSLVER}.tar.gz.asc openssl-${OSSLVER}.tar.gz
gpg: Signature made Tue Feb  7 05:43:55 2023 PST
gpg:                using RSA key 7953AC1FBC3DC8B3B292393ED5E9E43F7DF9EE8C
gpg: Good signature from "Richard Levitte <richard@levitte.org>" [unknown]
gpg:                 aka "Richard Levitte <levitte@lp.se>" [unknown]
gpg:                 aka "Richard Levitte <levitte@openssl.org>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 7953 AC1F BC3D C8B3 B292  393E D5E9 E43F 7DF9 EE8C
$ (cd vendor.checkout/; git status; find . -type f -or -type l | cut -c 3- | sort > ../old)
On branch vendor/openssl-3.0
nothing to commit, working tree clean
$ tar -x -X $XLIST -f ../openssl-${OSSLVER}.tar.gz -C ..
$ rsync --exclude FREEBSD.* --delete -avzz ../openssl-${OSSLVER}/* .
$ cat .git
gitdir: /home/ngie/git/freebsd-src/.git/worktrees/vendor.checkout
$ diff -arq ../openssl-3.0.8  .
Only in .: .git
Only in .: FREEBSD-Xlist
Only in .: FREEBSD-upgrade
$ git status FREEBSD*
On branch vendor/openssl-3.0
nothing to commit, working tree clean
$
```

Reviewers: emaste, jkim

Subscribers: imp, andrew, dab

Differential Revision: https://reviews.freebsd.org/D38835
2023-03-06 12:41:29 -08:00

211 lines
4.9 KiB
Perl

#! /usr/bin/env perl
# 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
# in the file LICENSE in the source distribution or at
# 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 = OpenSSL::copyright::latest(($0, $ARGV[1], $ARGV[0]));
open (NUMIN,"$ARGV[1]") || die "Can't open number file $ARGV[1]";
$max_nid=0;
$o=0;
while(<NUMIN>)
{
s|\R$||;
$o++;
s/#.*$//;
next if /^\s*$/;
$_ = 'X'.$_;
($Cname,$mynum) = split;
$Cname =~ s/^X//;
if (defined($nidn{$mynum}))
{ die "$ARGV[1]:$o:There's already an object with NID ",$mynum," on line ",$order{$mynum},"\n"; }
if (defined($nid{$Cname}))
{ die "$ARGV[1]:$o:There's already an object with name ",$Cname," on line ",$order{$nid{$Cname}},"\n"; }
$nid{$Cname} = $mynum;
$nidn{$mynum} = $Cname;
$order{$mynum} = $o;
$max_nid = $mynum if $mynum > $max_nid;
}
close NUMIN;
open (IN,"$ARGV[0]") || die "Can't open input file $ARGV[0]";
$Cname="";
$o=0;
while (<IN>)
{
s|\R$||;
$o++;
if (/^!module\s+(.*)$/)
{
$module = $1."-";
$module =~ s/\./_/g;
$module =~ s/-/_/g;
}
if (/^!global$/)
{ $module = ""; }
if (/^!Cname\s+(.*)$/)
{ $Cname = $1; }
if (/^!Alias\s+(.+?)\s+(.*)$/)
{
$Cname = $module.$1;
$myoid = $2;
$myoid = &process_oid($myoid);
$Cname =~ s/-/_/g;
$ordern{$o} = $Cname;
$order{$Cname} = $o;
$obj{$Cname} = $myoid;
$_ = "";
$Cname = "";
}
s/!.*$//;
s/#.*$//;
next if /^\s*$/;
($myoid,$mysn,$myln) = split ':';
$mysn =~ s/^\s*//;
$mysn =~ s/\s*$//;
$myln =~ s/^\s*//;
$myln =~ s/\s*$//;
$myoid =~ s/^\s*//;
$myoid =~ s/\s*$//;
if ($myoid ne "")
{
$myoid = &process_oid($myoid);
}
if ($Cname eq "" && ($myln =~ /^[_A-Za-z][\w.-]*$/ ))
{
$Cname = $myln;
$Cname =~ s/\./_/g;
$Cname =~ s/-/_/g;
if ($Cname ne "" && defined($ln{$module.$Cname}))
{ die "objects.txt:$o:There's already an object with long name ",$ln{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; }
}
if ($Cname eq "")
{
$Cname = $mysn;
$Cname =~ s/-/_/g;
if ($Cname ne "" && defined($sn{$module.$Cname}))
{ die "objects.txt:$o:There's already an object with short name ",$sn{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; }
}
if ($Cname eq "")
{
$Cname = $myln;
$Cname =~ s/-/_/g;
$Cname =~ s/\./_/g;
$Cname =~ s/ /_/g;
if ($Cname ne "" && defined($ln{$module.$Cname}))
{ die "objects.txt:$o:There's already an object with long name ",$ln{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; }
}
$Cname =~ s/\./_/g;
$Cname =~ s/-/_/g;
$Cname = $module.$Cname;
$ordern{$o} = $Cname;
$order{$Cname} = $o;
$sn{$Cname} = $mysn;
$ln{$Cname} = $myln;
$obj{$Cname} = $myoid;
if (!defined($nid{$Cname}))
{
$max_nid++;
$nid{$Cname} = $max_nid;
$nidn{$max_nid} = $Cname;
print STDERR "Added OID $Cname\n";
}
$Cname="";
}
close IN;
if ( $opt_n ) {
foreach (sort { $a <=> $b } keys %nidn)
{
print $nidn{$_},"\t\t",$_,"\n";
}
exit;
}
print <<"EOF";
/*
* WARNING: do not edit!
* Generated by crypto/objects/objects.pl
*
* Copyright 2000-$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
*/
#ifndef OPENSSL_OBJ_MAC_H
# define OPENSSL_OBJ_MAC_H
# pragma once
#define SN_undef "UNDEF"
#define LN_undef "undefined"
#define NID_undef 0
#define OBJ_undef 0L
EOF
sub expand
{
my $string = shift;
1 while $string =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e;
return $string;
}
foreach (sort { $a <=> $b } keys %ordern)
{
$Cname=$ordern{$_};
print "\n";
print expand("#define SN_$Cname\t\t\"$sn{$Cname}\"\n") if $sn{$Cname} ne "";
print expand("#define LN_$Cname\t\t\"$ln{$Cname}\"\n") if $ln{$Cname} ne "";
print expand("#define NID_$Cname\t\t$nid{$Cname}\n") if $nid{$Cname} ne "";
print expand("#define OBJ_$Cname\t\t$obj{$Cname}\n") if $obj{$Cname} ne "";
}
print <<EOF;
#endif /* OPENSSL_OBJ_MAC_H */
EOF
sub process_oid
{
local($oid)=@_;
local(@a,$oid_pref);
@a = split(/\s+/,$myoid);
$pref_oid = "";
$pref_sep = "";
if (!($a[0] =~ /^[0-9]+$/))
{
$a[0] =~ s/-/_/g;
if (!defined($obj{$a[0]}))
{ die "$ARGV[0]:$o:Undefined identifier ",$a[0],"\n"; }
$pref_oid = "OBJ_" . $a[0];
$pref_sep = ",";
shift @a;
}
$oids = join('L,',@a) . "L";
if ($oids ne "L")
{
$oids = $pref_oid . $pref_sep . $oids;
}
else
{
$oids = $pref_oid;
}
return($oids);
}