From 8e255013aed142f6fe18bbc884d3962566ef08f7 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Fri, 3 Jan 2025 19:06:59 -0500 Subject: [PATCH 1/3] Clean up "copyright consolidation" tools Now that the change has been applied, we no longer need these. Bug: 364634028 Change-Id: I2979b62489d640807c6b2568227c015a05af4d4b Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/74767 Reviewed-by: Adam Langley Commit-Queue: David Benjamin --- util/copyright.pl | 111 ------------ util/copyright_summary.go | 62 ------- util/mapping.txt | 354 -------------------------------------- 3 files changed, 527 deletions(-) delete mode 100644 util/copyright.pl delete mode 100644 util/mapping.txt diff --git a/util/copyright.pl b/util/copyright.pl deleted file mode 100644 index 74d1779b8..000000000 --- a/util/copyright.pl +++ /dev/null @@ -1,111 +0,0 @@ -#! /usr/bin/env perl -# Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. -# -# Licensed under the OpenSSL license (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 - -# Add new copyright and delete old ones. Used as -# find . -name '*.[ch]' -type f -exec perl -i.bak util/copyright.pl '{}' ';' -# This does not do everything that's needed for the consolidation. - -use strict; -use warnings; - -my %mapping; -open(my $mapping_file, "<", "util/mapping.txt") or die; -while (my $line = <$mapping_file>) { - chomp($line); - $line =~ s/#.*//; - next if $line =~ /^$/; - - my ($path, $mapped) = split(/:/, $line, 2); - $mapped =~ s/^ +//; - $mapped =~ s/ +$//; - my @mapped = split(/ +/, $mapped); - $mapping{$path} = \@mapped; -} -close($mapping_file) or die; - -sub find_copyright_line($) -{ - my ($path) = @_; - my $mapped = $mapping{$path}; - die "No mapping for $path found!" unless $mapped && @$mapped; - my $ret = find_mapped_copyright_line($mapped->[0]); - foreach my $m (@$mapped) { - my $other = find_mapped_copyright_line($m); - die "Copyright lines in $mapped->[0] and $m did not match" unless $other eq $ret; - } - return $ret; -} - -sub find_mapped_copyright_line($) -{ - my ($path) = @_; - open(my $f, "<", "../openssl/$path") or die; - while (my $line = <$f>) { - chomp($line); - if ($line =~ /^ \* Copyright [-0-9]+ The OpenSSL Project Authors\. All Rights Reserved\.$/) { - close($f) or die; - return $line; - } - } - die "Could not find copyright line in ../openssl/$path"; -} - -# Read a multi-line comments. If it matches a "fingerprint" of a legacy -# copyright block, then just delete it. -sub check_comment() -{ - my @lines = ( @_ ); - my $skipit = 0; - - if ($lines[$#lines] !~ m@\*/@) { - while ( <> ) { - push @lines, $_; - last if m@\*/@; - $skipit = 1 if /Copyright remains Eric Young's/i; - $skipit = 1 if /Copyright.*The OpenSSL Project/i; - $skipit = 1 if /Written by.*for the OpenSSL Project/i; - } - } - - # Look for a multi-line "written by" comment. - if ( ! $skipit ) { - my $text = join('', @lines); - $skipit = 1 if $text =~ m/Written by.*for the OpenSSL Project/is; - } - - print @lines unless $skipit; - return $skipit; -} - -# Look for leading copyright blocks and process (print/swallow) them. -while ( <> ) { - if ($. == 1) { - my $copyright_line = find_copyright_line($ARGV); - print < ); -} diff --git a/util/copyright_summary.go b/util/copyright_summary.go index 0e8cdc024..9c7b7ee30 100644 --- a/util/copyright_summary.go +++ b/util/copyright_summary.go @@ -26,17 +26,14 @@ import ( "iter" "maps" "os" - "path/filepath" "regexp" "slices" "strconv" - "strings" ) var ( outPath = flag.String("out", "", "The path to write the results in JSON format") comparePath = flag.String("compare", "", "The path to a JSON file to compare against") - useMapping = flag.Bool("use-mapping", false, "Apply the mapping and look up files in OpenSSL instead") ) func sortedKeyValuePairs[K cmp.Ordered, V any](m map[K]V) iter.Seq2[K, V] { @@ -69,35 +66,6 @@ var copyrightRE = regexp.MustCompile( // summary to double-check an otherwise mostly automated process. `([-a-zA-Z ]*[-a-zA-Z])`) -var fileMapping map[string][]string - -//go:embed mapping.txt -var fileMappingData string - -func parseMapping() (map[string][]string, error) { - ret := map[string][]string{} - for _, line := range strings.Split(fileMappingData, "\n") { - if idx := strings.IndexByte(line, '#'); idx >= 0 { - line = line[:idx] - } - line = strings.TrimSpace(line) - if len(line) == 0 { - continue - } - colon := strings.IndexByte(line, ':') - if colon < 0 { - return nil, fmt.Errorf("could not parse %q", line) - } - from := strings.TrimSpace(line[:colon]) - to := strings.TrimSpace(line[colon+1:]) - if _, ok := ret[from]; ok { - return nil, fmt.Errorf("duplicate mapping for %q", from) - } - ret[from] = strings.Fields(to) - } - return ret, nil -} - type CopyrightInfo struct { Name string StartYear int @@ -127,27 +95,6 @@ func summarize(info FileInfo) map[string]int { } func process(path string) (info FileInfo, err error) { - if !*useMapping { - return processImpl(path) - } - - newPaths, ok := fileMapping[path] - if !ok { - err = fmt.Errorf("no mapping found for %q", path) - return - } - for _, newPath := range newPaths { - var newInfo FileInfo - newInfo, err = processImpl(filepath.Join("../openssl", newPath)) - if err != nil { - return - } - info.MergeFrom(newInfo) - } - return -} - -func processImpl(path string) (info FileInfo, err error) { f, err := os.Open(path) if err != nil { return @@ -175,15 +122,6 @@ func processImpl(path string) (info FileInfo, err error) { func main() { flag.Parse() - if *useMapping { - var err error - fileMapping, err = parseMapping() - if err != nil { - fmt.Fprintf(os.Stderr, "Error parsing mapping file: %s\n", err) - os.Exit(1) - } - } - infos := map[string]FileInfo{} for _, path := range flag.Args() { info, err := process(path) diff --git a/util/mapping.txt b/util/mapping.txt deleted file mode 100644 index 657a73fe4..000000000 --- a/util/mapping.txt +++ /dev/null @@ -1,354 +0,0 @@ -# This maps BoringSSL files with the old OpenSSL copyright to those in -# b6cff313cbb1d0381b329fe4f6a8f009cdb270e4, for purposes of running their 2016 -# "copyright consolidation" script. This considers only those files which -# contained a pre-consolidation OpenSSL file header. Specifically, files -# returned from this command: -# -# git grep -l -E 'Copyright remains Eric Young|Copyright.*The OpenSSL Project\.|Written by.*for the OpenSSL Project' crypto/ decrepit/ include/ ssl/ | grep -v objects.go -# -# The above patterns match those in OpenSSL's copyright.pl, except that we -# specifically look for "The OpenSSL Project." to distinguish from the new -# header, which uses "The OpenSSL Project Authors." This is so we avoid -# rewriting files which we already imported from OpenSSL after that point. -# -# This mapping is only used to apply OpenSSL's "copyright consolidation" script -# and determine the starting year. It doesn't replace the information in version -# control, nor is it a complete history of how code evolved over the two -# projects' history. - -crypto/asn1/a_bitstr.cc: crypto/asn1/a_bitstr.c -crypto/asn1/a_bool.cc: crypto/asn1/asn1_lib.c -crypto/asn1/a_d2i_fp.cc: crypto/asn1/a_d2i_fp.c -crypto/asn1/a_dup.cc: crypto/asn1/a_dup.c -crypto/asn1/a_gentm.cc: crypto/asn1/a_gentm.c -crypto/asn1/a_i2d_fp.cc: crypto/asn1/a_i2d_fp.c -crypto/asn1/a_int.cc: crypto/asn1/a_int.c -crypto/asn1/a_mbstr.cc: crypto/asn1/a_mbstr.c -crypto/asn1/a_object.cc: crypto/asn1/a_object.c -crypto/asn1/a_octet.cc: crypto/asn1/a_octet.c -crypto/asn1/a_strex.cc: crypto/asn1/a_strex.c -crypto/asn1/a_strnid.cc: crypto/asn1/a_strnid.c -crypto/asn1/a_time.cc: crypto/asn1/a_time.c -crypto/asn1/a_type.cc: crypto/asn1/a_type.c -crypto/asn1/a_utctm.cc: crypto/asn1/a_utctm.c -crypto/asn1/asn1_lib.cc: crypto/asn1/asn1_lib.c -crypto/asn1/asn1_par.cc: crypto/asn1/asn1_par.c -crypto/asn1/asn_pack.cc: crypto/asn1/asn_pack.c -crypto/asn1/f_int.cc: crypto/asn1/f_int.c -crypto/asn1/f_string.cc: crypto/asn1/f_string.c -crypto/asn1/internal.h: crypto/asn1/asn1_locl.h -crypto/asn1/tasn_dec.cc: crypto/asn1/tasn_dec.c -crypto/asn1/tasn_enc.cc: crypto/asn1/tasn_enc.c -crypto/asn1/tasn_fre.cc: crypto/asn1/tasn_fre.c -crypto/asn1/tasn_new.cc: crypto/asn1/tasn_new.c -crypto/asn1/tasn_typ.cc: crypto/asn1/tasn_typ.c -crypto/asn1/tasn_utl.cc: crypto/asn1/tasn_utl.c -crypto/base64/base64.cc: crypto/evp/encode.c -crypto/bio/bio.cc: crypto/bio/bio_lib.c -crypto/bio/bio_mem.cc: crypto/bio/bss_mem.c -crypto/bio/connect.cc: crypto/bio/bss_conn.c -crypto/bio/errno.cc: crypto/bio/bss_fd.c -crypto/bio/fd.cc: crypto/bio/bss_fd.c -crypto/bio/file.cc: crypto/bio/bss_file.c -crypto/bio/hexdump.cc: crypto/bio/b_dump.c -crypto/bio/internal.h: include/openssl/bio.h -crypto/bio/pair.cc: crypto/bio/bss_bio.c -crypto/bio/printf.cc: crypto/bio/b_print.c -crypto/bio/socket.cc: crypto/bio/bss_sock.c -crypto/bn_extra/convert.cc: crypto/bn/bn_print.c -crypto/buf/buf.cc: crypto/buffer/buffer.c -crypto/cipher_extra/cipher_extra.cc: crypto/evp/evp_enc.c -crypto/cipher_extra/cipher_test.cc: test/evp_test.c -crypto/cipher_extra/derive_key.cc: crypto/evp/evp_key.c -crypto/cipher_extra/e_des.cc: crypto/evp/e_des.c -crypto/cipher_extra/e_null.cc: crypto/evp/e_null.c -crypto/cipher_extra/e_rc2.cc: crypto/evp/e_rc2.c -crypto/cipher_extra/e_rc4.cc: crypto/evp/e_rc4.c -# Mapping these is tricky as code moved around significantly across BoringSSL -# and OpenSSL, but the public evp.h seems most natural as all these structures -# were originally defined in the public evp.h header. -crypto/cipher_extra/internal.h: include/openssl/evp.h -crypto/cipher_extra/tls_cbc.cc: ssl/s3_cbc.c -# This file also contains code from conf_lib.c, but conf_def.c is the older one. -crypto/conf/conf.cc: crypto/conf/conf_def.c -crypto/constant_time_test.cc: test/constant_time_test.c -crypto/cpu_intel.cc: crypto/cryptlib.c -crypto/des/des.cc: crypto/des/des_enc.c -crypto/des/internal.h: crypto/des/des_locl.h -crypto/dh_extra/dh_asn1.cc: crypto/dh/dh_asn1.c -crypto/dh_extra/dh_test.cc: test/dhtest.c -crypto/dh_extra/params.cc: crypto/dh/dh_rfc5114.c -crypto/digest_extra/digest_extra.cc: crypto/evp/names.c -crypto/dsa/dsa.cc: crypto/dsa/dsa_lib.c crypto/dsa/dsa_ossl.c -crypto/dsa/dsa_asn1.cc: crypto/dsa/dsa_asn1.c -crypto/dsa/dsa_test.cc: test/dsatest.c -crypto/ec_extra/ec_asn1.cc: crypto/ec/ec_asn1.c -crypto/ecdh_extra/ecdh_extra.cc: crypto/ec/ecdh_ossl.c -crypto/ecdsa_extra/ecdsa_asn1.cc: crypto/ec/ec_asn1.c -crypto/err/err.cc: crypto/err/err.c -crypto/evp/evp.cc: crypto/evp/p_lib.c -crypto/evp/evp_asn1.cc: crypto/asn1/d2i_pr.c -crypto/evp/evp_ctx.cc: crypto/evp/pmeth_lib.c -crypto/evp/evp_test.cc: test/evp_test.c -crypto/evp/internal.h: crypto/evp/evp_locl.h -crypto/evp/p_dsa_asn1.cc: crypto/dsa/dsa_ameth.c -crypto/evp/p_ec.cc: crypto/ec/ec_pmeth.c -crypto/evp/p_ec_asn1.cc: crypto/ec/ec_ameth.c -crypto/evp/p_rsa.cc: crypto/rsa/rsa_pmeth.c -crypto/evp/p_rsa_asn1.cc: crypto/rsa/rsa_ameth.c -crypto/evp/pbkdf.cc: crypto/evp/p5_crpt2.c -crypto/evp/print.cc: crypto/dsa/dsa_ameth.c crypto/ec/ec_ameth.c crypto/rsa/rsa_ameth.c -crypto/evp/sign.cc: crypto/evp/p_sign.c -crypto/ex_data.cc: crypto/ex_data.c -crypto/fipsmodule/aes/aes.cc.inc: crypto/aes/aes_core.c -crypto/fipsmodule/aes/key_wrap.cc.inc: crypto/aes/aes_wrap.c -crypto/fipsmodule/aes/mode_wrappers.cc.inc: crypto/aes/aes_cfb.c -crypto/fipsmodule/bn/add.cc.inc: crypto/bn/bn_add.c -crypto/fipsmodule/bn/bn.cc.inc: crypto/bn/bn_lib.c -crypto/fipsmodule/bn/bn_test.cc: test/bntest.c -crypto/fipsmodule/bn/bytes.cc.inc: crypto/bn/bn_lib.c -crypto/fipsmodule/bn/cmp.cc.inc: crypto/bn/bn_lib.c -crypto/fipsmodule/bn/ctx.cc.inc: crypto/bn/bn_ctx.c -crypto/fipsmodule/bn/div.cc.inc: crypto/bn/bn_div.c -crypto/fipsmodule/bn/exponentiation.cc.inc: crypto/bn/bn_exp.c -crypto/fipsmodule/bn/gcd.cc.inc: crypto/bn/bn_gcd.c -crypto/fipsmodule/bn/generic.cc.inc: crypto/bn/bn_asm.c -crypto/fipsmodule/bn/internal.h: crypto/bn/bn_lcl.h -crypto/fipsmodule/bn/jacobi.cc.inc: crypto/bn/bn_kron.c -crypto/fipsmodule/bn/montgomery.cc.inc: crypto/bn/bn_mont.c -crypto/fipsmodule/bn/mul.cc.inc: crypto/bn/bn_mul.c -crypto/fipsmodule/bn/prime.cc.inc: crypto/bn/bn_prime.c -crypto/fipsmodule/bn/random.cc.inc: crypto/bn/bn_rand.c -crypto/fipsmodule/bn/shift.cc.inc: crypto/bn/bn_shift.c -crypto/fipsmodule/bn/sqrt.cc.inc: crypto/bn/bn_sqrt.c -crypto/fipsmodule/cipher/cipher.cc.inc: crypto/evp/evp_enc.c -crypto/fipsmodule/cipher/e_aes.cc.inc: crypto/evp/e_aes.c -crypto/fipsmodule/cipher/e_aesccm.cc.inc: crypto/modes/ccm128.c -# Mapping these is tricky as code moved around significantly across BoringSSL -# and OpenSSL, but the public evp.h seems most natural as all these structures -# were originally defined in the public evp.h header. -crypto/fipsmodule/cipher/internal.h: include/openssl/evp.h -crypto/fipsmodule/cmac/cmac.cc.inc: crypto/cmac/cmac.c -crypto/fipsmodule/dh/check.cc.inc: crypto/dh/dh_check.c -crypto/fipsmodule/dh/dh.cc.inc: crypto/dh/dh_lib.c -crypto/fipsmodule/digest/digest.cc.inc: crypto/evp/digest.c -crypto/fipsmodule/digest/digests.cc.inc: crypto/evp/m_sha1.c -# Mapping these is tricky as code moved around significantly across BoringSSL -# and OpenSSL, but the public evp.h seems most natural as all these structures -# were originally defined in the public evp.h header. -crypto/fipsmodule/digest/internal.h: include/openssl/evp.h -crypto/fipsmodule/digest/md32_common.h: crypto/include/internal/md32_common.h -crypto/fipsmodule/digestsign/digestsign.cc.inc: crypto/evp/m_sigver.c -crypto/fipsmodule/ec/ec.cc.inc: crypto/ec/ec_lib.c -crypto/fipsmodule/ec/ec_key.cc.inc: crypto/ec/ec_key.c -crypto/fipsmodule/ec/ec_montgomery.cc.inc: crypto/ec/ecp_mont.c -crypto/fipsmodule/ec/internal.h: crypto/ec/ec_lcl.h -crypto/fipsmodule/ec/oct.cc.inc: crypto/ec/ec_oct.c -crypto/fipsmodule/ec/simple.cc.inc: crypto/ec/ecp_smpl.c -crypto/fipsmodule/ec/wnaf.cc.inc: crypto/ec/ec_mult.c -crypto/fipsmodule/ecdh/ecdh.cc.inc: crypto/ec/ecdh_ossl.c -crypto/fipsmodule/ecdsa/ecdsa.cc.inc: crypto/ec/ecdsa_ossl.c -crypto/fipsmodule/ecdsa/ecdsa_test.cc: test/ecdsatest.c -crypto/fipsmodule/hmac/hmac.cc.inc: crypto/hmac/hmac.c -crypto/fipsmodule/modes/cbc.cc.inc: crypto/modes/cbc128.c -crypto/fipsmodule/modes/cfb.cc.inc: crypto/modes/cfb128.c -crypto/fipsmodule/modes/ctr.cc.inc: crypto/modes/ctr128.c -crypto/fipsmodule/modes/gcm.cc.inc: crypto/modes/gcm128.c -crypto/fipsmodule/modes/internal.h: crypto/modes/modes_lcl.h -crypto/fipsmodule/modes/ofb.cc.inc: crypto/modes/ofb128.c -crypto/fipsmodule/rsa/blinding.cc.inc: crypto/bn/bn_blind.c -crypto/fipsmodule/rsa/internal.h: include/openssl/rsa.h -crypto/fipsmodule/rsa/padding.cc.inc: crypto/rsa/rsa_pss.c -crypto/fipsmodule/rsa/rsa.cc.inc: crypto/rsa/rsa_lib.c -crypto/fipsmodule/rsa/rsa_impl.cc.inc: crypto/rsa/rsa_ossl.c -crypto/fipsmodule/sha/sha1.cc.inc: crypto/sha/sha_locl.h -crypto/fipsmodule/sha/sha256.cc.inc: crypto/sha/sha256.c -crypto/fipsmodule/sha/sha512.cc.inc: crypto/sha/sha512.c -crypto/fipsmodule/tls/kdf.cc.inc: ssl/t1_enc.c -crypto/hmac_extra/hmac_test.cc: test/hmactest.c -crypto/internal.h: include/openssl/crypto.h -crypto/lhash/internal.h: include/openssl/lhash.h -crypto/lhash/lhash.cc: crypto/lhash/lhash.c -crypto/md4/md4.cc: crypto/md4/md4_dgst.c -crypto/md5/md5.cc: crypto/md5/md5_dgst.c -crypto/mem.cc: crypto/mem.c -crypto/obj/obj.cc: crypto/objects/obj_lib.c -crypto/obj/obj_dat.h: crypto/objects/obj_dat.h -crypto/obj/obj_xref.cc: crypto/objects/obj_xref.c -crypto/pem/pem_all.cc: crypto/pem/pem_all.c -crypto/pem/pem_info.cc: crypto/pem/pem_info.c -crypto/pem/pem_lib.cc: crypto/pem/pem_lib.c -crypto/pem/pem_oth.cc: crypto/pem/pem_oth.c -crypto/pem/pem_pk8.cc: crypto/pem/pem_pk8.c -crypto/pem/pem_pkey.cc: crypto/pem/pem_pkey.c -crypto/pem/pem_x509.cc: crypto/pem/pem_x509.c -crypto/pem/pem_xaux.cc: crypto/pem/pem_xaux.c -crypto/pkcs8/internal.h: include/openssl/pkcs12.h -crypto/pkcs8/p5_pbev2.cc: crypto/asn1/p5_pbev2.c -crypto/pkcs8/pkcs8.cc: crypto/pkcs12/p12_decr.c -crypto/pkcs8/pkcs8_x509.cc: crypto/pkcs12/p12_decr.c -crypto/rc4/rc4.cc: crypto/rc4/rc4_skey.c crypto/rc4/rc4_enc.c -crypto/rsa_extra/internal.h: include/openssl/rsa.h -crypto/rsa_extra/rsa_asn1.cc: crypto/rsa/rsa_asn1.c -crypto/rsa_extra/rsa_crypt.cc: crypto/rsa/rsa_crpt.c -crypto/rsa_extra/rsa_test.cc: test/rsa_test.c -crypto/stack/stack.cc: crypto/stack/stack.c -crypto/thread.cc: crypto/cryptlib.c -crypto/x509/a_digest.cc: crypto/asn1/a_digest.c -crypto/x509/a_sign.cc: crypto/asn1/a_sign.c -crypto/x509/a_verify.cc: crypto/asn1/a_verify.c -crypto/x509/algorithm.cc: crypto/asn1/a_verify.c -crypto/x509/asn1_gen.cc: crypto/asn1/asn1_gen.c -crypto/x509/by_dir.cc: crypto/x509/by_dir.c -crypto/x509/by_file.cc: crypto/x509/by_file.c -crypto/x509/ext_dat.h: crypto/x509v3/ext_dat.h -crypto/x509/i2d_pr.cc: crypto/asn1/i2d_pr.c -crypto/x509/internal.h: crypto/x509/x509_lcl.h -crypto/x509/name_print.cc: crypto/asn1/a_strex.c -crypto/x509/rsa_pss.cc: crypto/rsa/rsa_ameth.c -crypto/x509/t_crl.cc: crypto/x509/t_crl.c -crypto/x509/t_req.cc: crypto/x509/t_req.c -crypto/x509/t_x509.cc: crypto/x509/t_x509.c -crypto/x509/t_x509a.cc: crypto/x509/t_x509.c -crypto/x509/tab_test.cc: ./crypto/x509v3/tabtest.c -crypto/x509/v3_akey.cc: crypto/x509v3/v3_akey.c -crypto/x509/v3_akeya.cc: crypto/x509v3/v3_akeya.c -crypto/x509/v3_alt.cc: crypto/x509v3/v3_alt.c -crypto/x509/v3_bcons.cc: crypto/x509v3/v3_bcons.c -crypto/x509/v3_bitst.cc: crypto/x509v3/v3_bitst.c -crypto/x509/v3_conf.cc: crypto/x509v3/v3_conf.c -crypto/x509/v3_cpols.cc: crypto/x509v3/v3_cpols.c -crypto/x509/v3_crld.cc: crypto/x509v3/v3_crld.c -crypto/x509/v3_enum.cc: crypto/x509v3/v3_enum.c -crypto/x509/v3_extku.cc: crypto/x509v3/v3_extku.c -crypto/x509/v3_genn.cc: crypto/x509v3/v3_genn.c -crypto/x509/v3_ia5.cc: crypto/x509v3/v3_ia5.c -crypto/x509/v3_info.cc: crypto/x509v3/v3_info.c -crypto/x509/v3_int.cc: crypto/x509v3/v3_int.c -crypto/x509/v3_lib.cc: crypto/x509v3/v3_lib.c -crypto/x509/v3_ncons.cc: crypto/x509v3/v3_ncons.c -crypto/x509/v3_pcons.cc: crypto/x509v3/v3_pcons.c -crypto/x509/v3_pmaps.cc: crypto/x509v3/v3_pmaps.c -crypto/x509/v3_prn.cc: crypto/x509v3/v3_prn.c -crypto/x509/v3_purp.cc: crypto/x509v3/v3_purp.c -crypto/x509/v3_skey.cc: crypto/x509v3/v3_skey.c -crypto/x509/v3_utl.cc: crypto/x509v3/v3_utl.c -crypto/x509/x509.cc: crypto/x509/t_x509.c -crypto/x509/x509_att.cc: crypto/x509/x509_att.c -crypto/x509/x509_cmp.cc: crypto/x509/x509_cmp.c -crypto/x509/x509_d2.cc: crypto/x509/x509_d2.c -crypto/x509/x509_def.cc: crypto/x509/x509_def.c -crypto/x509/x509_ext.cc: crypto/x509/x509_ext.c -crypto/x509/x509_lu.cc: crypto/x509/x509_lu.c -crypto/x509/x509_obj.cc: crypto/x509/x509_obj.c -crypto/x509/x509_req.cc: crypto/x509/x509_req.c -crypto/x509/x509_set.cc: crypto/x509/x509_set.c -crypto/x509/x509_trs.cc: crypto/x509/x509_trs.c -crypto/x509/x509_txt.cc: crypto/x509/x509_txt.c -crypto/x509/x509_v3.cc: crypto/x509/x509_v3.c -crypto/x509/x509_vfy.cc: crypto/x509/x509_vfy.c -crypto/x509/x509_vpm.cc: crypto/x509/x509_vpm.c -crypto/x509/x509cset.cc: crypto/x509/x509cset.c -crypto/x509/x509name.cc: crypto/x509/x509name.c -crypto/x509/x509rset.cc: crypto/x509/x509rset.c -crypto/x509/x509spki.cc: crypto/x509/x509spki.c -crypto/x509/x_algor.cc: crypto/asn1/x_algor.c -crypto/x509/x_all.cc: crypto/x509/x_all.c -crypto/x509/x_attrib.cc: crypto/x509/x_attrib.c -crypto/x509/x_crl.cc: crypto/x509/x_crl.c -crypto/x509/x_exten.cc: crypto/x509/x_exten.c -crypto/x509/x_name.cc: crypto/x509/x_name.c -crypto/x509/x_pubkey.cc: crypto/x509/x_pubkey.c -crypto/x509/x_req.cc: crypto/x509/x_req.c -crypto/x509/x_sig.cc: crypto/asn1/x_sig.c -crypto/x509/x_spki.cc: crypto/asn1/x_spki.c -crypto/x509/x_val.cc: crypto/asn1/x_val.c -crypto/x509/x_x509.cc: crypto/x509/x_x509.c -crypto/x509/x_x509a.cc: crypto/x509/x_x509a.c -decrepit/bio/base64_bio.cc: crypto/evp/bio_b64.c -decrepit/blowfish/blowfish.cc: crypto/bf/bf_enc.c -decrepit/cast/cast.cc: crypto/cast/c_enc.c crypto/cast/c_skey.c -decrepit/cast/cast_tables.cc: crypto/cast/cast_s.h -decrepit/cast/internal.h: crypto/cast/cast_lcl.h -decrepit/des/cfb64ede.cc: crypto/des/cfb64ede.c -decrepit/dh/dh_decrepit.cc: crypto/dh/dh_depr.c -decrepit/dsa/dsa_decrepit.cc: crypto/dsa/dsa_depr.c -decrepit/macros.h: crypto/bf/bf_locl.h -decrepit/rc4/rc4_decrepit.cc: crypto/rc4/rc4_skey.c -decrepit/ripemd/ripemd.cc: crypto/ripemd/rmd_dgst.c -decrepit/rsa/rsa_decrepit.cc: crypto/rsa/rsa_depr.c -decrepit/ssl/ssl_decrepit.cc: ssl/ssl_cert.c -decrepit/xts/xts.cc: crypto/modes/xts128.c -include/openssl/aes.h: include/openssl/aes.h -include/openssl/arm_arch.h: crypto/arm_arch.h -include/openssl/asn1.h: include/openssl/asn1.h -include/openssl/asn1t.h: include/openssl/asn1t.h -include/openssl/base.h: include/openssl/ossl_typ.h -include/openssl/base64.h: include/openssl/evp.h -include/openssl/bio.h: include/openssl/bio.h -include/openssl/blowfish.h: include/openssl/blowfish.h -include/openssl/bn.h: include/openssl/bn.h -include/openssl/buf.h: include/openssl/buffer.h -include/openssl/cast.h: include/openssl/cast.h -include/openssl/cipher.h: include/openssl/evp.h -include/openssl/conf.h: include/openssl/conf.h -include/openssl/des.h: include/openssl/des.h -include/openssl/dh.h: include/openssl/dh.h -include/openssl/digest.h: include/openssl/evp.h -include/openssl/dsa.h: include/openssl/dsa.h -include/openssl/ec.h: include/openssl/ec.h -include/openssl/ec_key.h: include/openssl/ec.h -include/openssl/ecdh.h: include/openssl/ecdh.h -include/openssl/ecdsa.h: include/openssl/ecdsa.h -include/openssl/err.h: include/openssl/err.h -include/openssl/evp.h: include/openssl/evp.h -include/openssl/evp_errors.h: include/openssl/evp.h -include/openssl/ex_data.h: include/openssl/crypto.h -include/openssl/hmac.h: include/openssl/hmac.h -include/openssl/lhash.h: include/openssl/lhash.h -include/openssl/md4.h: include/openssl/md4.h -include/openssl/md5.h: include/openssl/md5.h -include/openssl/mem.h: include/openssl/crypto.h -include/openssl/nid.h: include/openssl/obj_mac.h -include/openssl/obj.h: include/openssl/objects.h -include/openssl/pem.h: include/openssl/pem.h -include/openssl/pkcs8.h: include/openssl/pkcs12.h -include/openssl/rc4.h: include/openssl/rc4.h -include/openssl/ripemd.h: include/openssl/ripemd.h -include/openssl/rsa.h: include/openssl/rsa.h -include/openssl/sha.h: include/openssl/sha.h -include/openssl/ssl.h: include/openssl/ssl.h -include/openssl/ssl3.h: include/openssl/ssl3.h -include/openssl/stack.h: include/openssl/stack.h -include/openssl/thread.h: include/openssl/crypto.h -include/openssl/tls1.h: include/openssl/tls1.h -include/openssl/type_check.h: include/openssl/safestack.h -include/openssl/x509.h: include/openssl/x509.h -include/openssl/x509v3_errors.h: include/openssl/x509v3.h -ssl/d1_both.cc: ssl/statem/statem_dtls.c -ssl/d1_lib.cc: ssl/d1_lib.c -ssl/d1_pkt.cc: ssl/record/rec_layer_d1.c -ssl/d1_srtp.cc: ssl/d1_srtp.c -ssl/dtls_method.cc: ssl/methods.c -ssl/dtls_record.cc: ssl/record/rec_layer_d1.c -ssl/extensions.cc: ssl/t1_lib.c -ssl/handshake.cc: ssl/statem/statem_lib.c -ssl/handshake_client.cc: ssl/statem/statem_clnt.c -ssl/handshake_server.cc: ssl/statem/statem_srvr.c -ssl/internal.h: ssl/ssl_locl.h -ssl/s3_both.cc: ssl/statem/statem_lib.c -ssl/s3_lib.cc: ssl/s3_lib.c -ssl/s3_pkt.cc: ssl/record/rec_layer_s3.c -ssl/ssl_asn1.cc: ssl/ssl_asn1.c -ssl/ssl_cert.cc: ssl/ssl_cert.c -ssl/ssl_cipher.cc: ssl/ssl_ciph.c -ssl/ssl_file.cc: ssl/ssl_cert.c ssl/ssl_rsa.c -ssl/ssl_lib.cc: ssl/ssl_lib.c -ssl/ssl_privkey.cc: ssl/ssl_rsa.c -ssl/ssl_session.cc: ssl/ssl_sess.c -ssl/ssl_stat.cc: ssl/ssl_stat.c -ssl/ssl_transcript.cc: ssl/s3_enc.c -ssl/ssl_x509.cc: ssl/ssl_lib.c -ssl/t1_enc.cc: ssl/t1_enc.c -ssl/tls_method.cc: ssl/methods.c -ssl/tls_record.cc: ssl/record/rec_layer_s3.c From 1d3c5608c8c94952c9cebf56078eb55949e4b4f1 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Sat, 4 Jan 2025 14:43:52 -0500 Subject: [PATCH 2/3] Move implicit OPENSSL_STATIC_ARMCAP definition to target.h We have some logic to implicitly define OPENSSL_STATIC_ARMCAP on some platforms. This was being done a hair too late for the NEED_CPUID logic in crypto/internal.h to pick up. I'm not sure why this is only tripping the Android build now. It seems to have been broken for a long while. I put it in the public headers because is also sensitive to OPENSSL_STATIC_ARMCAP, so it seems prudent for it to be set all in one place. Change-Id: I53691b018282a71f5d0cb0f6a6c457e1ee4d1df9 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/74787 Auto-Submit: David Benjamin Commit-Queue: Adam Langley Reviewed-by: Adam Langley --- crypto/internal.h | 10 ---------- include/openssl/target.h | 10 ++++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crypto/internal.h b/crypto/internal.h index bbaa619e7..d50e755ba 100644 --- a/crypto/internal.h +++ b/crypto/internal.h @@ -1314,16 +1314,6 @@ extern uint32_t OPENSSL_armcap_P; // merged by the compiler. OPENSSL_ATTR_CONST uint32_t OPENSSL_get_armcap(void); -// We do not detect any features at runtime on several 32-bit Arm platforms. -// Apple platforms and OpenBSD require NEON and moved to 64-bit to pick up Armv8 -// extensions. Android baremetal does not aim to support 32-bit Arm at all, but -// it simplifies things to make it build. -#if defined(OPENSSL_ARM) && !defined(OPENSSL_STATIC_ARMCAP) && \ - (defined(OPENSSL_APPLE) || defined(OPENSSL_OPENBSD) || \ - defined(ANDROID_BAREMETAL)) -#define OPENSSL_STATIC_ARMCAP -#endif - // Normalize some older feature flags to their modern ACLE values. // https://developer.arm.com/architectures/system-architectures/software-standards/acle #if defined(__ARM_NEON__) && !defined(__ARM_NEON) diff --git a/include/openssl/target.h b/include/openssl/target.h index 71ce6034a..77f8ac935 100644 --- a/include/openssl/target.h +++ b/include/openssl/target.h @@ -226,4 +226,14 @@ #endif #endif // OPENSSL_ASM_INCOMPATIBLE +// We do not detect any features at runtime on several 32-bit Arm platforms. +// Apple platforms and OpenBSD require NEON and moved to 64-bit to pick up Armv8 +// extensions. Android baremetal does not aim to support 32-bit Arm at all, but +// it simplifies things to make it build. +#if defined(OPENSSL_ARM) && !defined(OPENSSL_STATIC_ARMCAP) && \ + (defined(OPENSSL_APPLE) || defined(OPENSSL_OPENBSD) || \ + defined(ANDROID_BAREMETAL)) +#define OPENSSL_STATIC_ARMCAP +#endif + #endif // OPENSSL_HEADER_TARGET_H From 3fe5e2a25ea9fb5e882d208cfcb3af387ee9662c Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Sun, 5 Jan 2025 10:57:35 -0500 Subject: [PATCH 3/3] Unexport a couple internal PEM functions from pem.h These aren't used externally. While I'm here, const-correct PEM_do_header. Really we could have just made these file-local except that PEM_X509_INFO_read_bio does something weird. Bug: 42290574 Change-Id: I455b9c31da0efb854925bbe38797d3c0e221fcdf Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/74807 Reviewed-by: Adam Langley Auto-Submit: David Benjamin Commit-Queue: David Benjamin --- build.json | 1 + crypto/pem/internal.h | 42 ++++++++++++++++++++++++++++++++++++++++++ crypto/pem/pem_info.cc | 2 ++ crypto/pem/pem_lib.cc | 9 +++++---- gen/sources.bzl | 1 + gen/sources.cmake | 1 + gen/sources.gni | 1 + gen/sources.json | 1 + include/openssl/pem.h | 5 ----- 9 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 crypto/pem/internal.h diff --git a/build.json b/build.json index 6ffa520ca..4d3fb4ece 100644 --- a/build.json +++ b/build.json @@ -533,6 +533,7 @@ "crypto/lhash/internal.h", "crypto/md5/internal.h", "crypto/obj/obj_dat.h", + "crypto/pem/internal.h", "crypto/pkcs7/internal.h", "crypto/pkcs8/internal.h", "crypto/poly1305/internal.h", diff --git a/crypto/pem/internal.h b/crypto/pem/internal.h new file mode 100644 index 000000000..3cfc8ac36 --- /dev/null +++ b/crypto/pem/internal.h @@ -0,0 +1,42 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (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_HEADER_PEM_INTERNAL_H +#define OPENSSL_HEADER_PEM_INTERNAL_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +// PEM_get_EVP_CIPHER_INFO decodes |header| as a PEM header block and writes the +// specified cipher and IV to |cipher|. It returns one on success and zero on +// error. |header| must be a NUL-terminated string. If |header| does not +// specify encryption, this function will return success and set +// |cipher->cipher| to NULL. +// +// WARNING: This function will internally write to the string pointed by +// |header|. |header| must not point to constant storage. +int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher); + +// PEM_do_header decrypts |*len| bytes from |data| in-place according to the +// information in |cipher|. On success, it returns one and sets |*len| to the +// length of the plaintext. Otherwise, it returns zero. If |cipher| specifies +// encryption, the key is derived from a password returned from |callback|. +int PEM_do_header(const EVP_CIPHER_INFO *cipher, uint8_t *data, long *len, + pem_password_cb *callback, void *u); + + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // OPENSSL_HEADER_PEM_INTERNAL_H diff --git a/crypto/pem/pem_info.cc b/crypto/pem/pem_info.cc index 3c1d57573..27d4edc50 100644 --- a/crypto/pem/pem_info.cc +++ b/crypto/pem/pem_info.cc @@ -21,6 +21,8 @@ #include #include +#include "internal.h" + static X509_PKEY *X509_PKEY_new(void) { return reinterpret_cast(OPENSSL_zalloc(sizeof(X509_PKEY))); diff --git a/crypto/pem/pem_lib.cc b/crypto/pem/pem_lib.cc index a59801047..6683beea6 100644 --- a/crypto/pem/pem_lib.cc +++ b/crypto/pem/pem_lib.cc @@ -24,6 +24,7 @@ #include #include "../internal.h" +#include "internal.h" #define MIN_LENGTH 4 @@ -326,8 +327,8 @@ err: return ret; } -int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen, - pem_password_cb *callback, void *u) { +int PEM_do_header(const EVP_CIPHER_INFO *cipher, unsigned char *data, + long *plen, pem_password_cb *callback, void *u) { int i = 0, j, o, pass_len; long len; EVP_CIPHER_CTX ctx; @@ -350,14 +351,14 @@ int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen, return 0; } - if (!EVP_BytesToKey(cipher->cipher, EVP_md5(), &(cipher->iv[0]), + if (!EVP_BytesToKey(cipher->cipher, EVP_md5(), cipher->iv, (unsigned char *)buf, pass_len, 1, key, NULL)) { return 0; } j = (int)len; EVP_CIPHER_CTX_init(&ctx); - o = EVP_DecryptInit_ex(&ctx, cipher->cipher, NULL, key, &(cipher->iv[0])); + o = EVP_DecryptInit_ex(&ctx, cipher->cipher, NULL, key, cipher->iv); if (o) { o = EVP_DecryptUpdate(&ctx, data, &i, data, j); } diff --git a/gen/sources.bzl b/gen/sources.bzl index 7a475517e..f91b49e00 100644 --- a/gen/sources.bzl +++ b/gen/sources.bzl @@ -633,6 +633,7 @@ crypto_internal_headers = [ "crypto/lhash/internal.h", "crypto/md5/internal.h", "crypto/obj/obj_dat.h", + "crypto/pem/internal.h", "crypto/pkcs7/internal.h", "crypto/pkcs8/internal.h", "crypto/poly1305/internal.h", diff --git a/gen/sources.cmake b/gen/sources.cmake index 6d168c684..369a9e658 100644 --- a/gen/sources.cmake +++ b/gen/sources.cmake @@ -651,6 +651,7 @@ set( crypto/lhash/internal.h crypto/md5/internal.h crypto/obj/obj_dat.h + crypto/pem/internal.h crypto/pkcs7/internal.h crypto/pkcs8/internal.h crypto/poly1305/internal.h diff --git a/gen/sources.gni b/gen/sources.gni index 1be0b7410..d9862d97a 100644 --- a/gen/sources.gni +++ b/gen/sources.gni @@ -633,6 +633,7 @@ crypto_internal_headers = [ "crypto/lhash/internal.h", "crypto/md5/internal.h", "crypto/obj/obj_dat.h", + "crypto/pem/internal.h", "crypto/pkcs7/internal.h", "crypto/pkcs8/internal.h", "crypto/poly1305/internal.h", diff --git a/gen/sources.json b/gen/sources.json index c29dfcb41..1b482e1bd 100644 --- a/gen/sources.json +++ b/gen/sources.json @@ -615,6 +615,7 @@ "crypto/lhash/internal.h", "crypto/md5/internal.h", "crypto/obj/obj_dat.h", + "crypto/pem/internal.h", "crypto/pkcs7/internal.h", "crypto/pkcs8/internal.h", "crypto/poly1305/internal.h", diff --git a/include/openssl/pem.h b/include/openssl/pem.h index 32fef2f6a..797e7f097 100644 --- a/include/openssl/pem.h +++ b/include/openssl/pem.h @@ -265,11 +265,6 @@ extern "C" { // "userdata": new with OpenSSL 0.9.4 typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata); -OPENSSL_EXPORT int PEM_get_EVP_CIPHER_INFO(char *header, - EVP_CIPHER_INFO *cipher); -OPENSSL_EXPORT int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, - long *len, pem_password_cb *callback, void *u); - // PEM_read_bio reads from |bp|, until the next PEM block. If one is found, it // returns one and sets |*name|, |*header|, and |*data| to newly-allocated // buffers containing the PEM type, the header block, and the decoded data,