From 00b4aa9c1d7f50a6e45c72e7a7c417975932cabb Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 29 Nov 2024 09:38:00 +0100 Subject: Avoid extension check for .gpg We only ever documented .gpg and .asc and have ensured that only such files exist in the keyring, but people can set the Signed-By option to keys with any random extension, as that was not validated before by apt-key. This doesn't change the behavior for trusted.gpg.d: We filter the directory listing and only look at .gpg and .asc files. Closes: #1088656 --- apt-pkg/contrib/gpgv.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/apt-pkg/contrib/gpgv.cc b/apt-pkg/contrib/gpgv.cc index 43c634dde..19e7b9f87 100644 --- a/apt-pkg/contrib/gpgv.cc +++ b/apt-pkg/contrib/gpgv.cc @@ -230,18 +230,6 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG, apt_warning(std::cerr, statusfd, fd, "The key(s) in the keyring %s are ignored as the file is not readable by user executing apt-key.\n", k.c_str()); return ""; } - if (APT::String::Endswith(k, ".gpg") || APT::String::Endswith(k, ".pub")) - { - unsigned char c; - if (not keyFd.Read(&c, sizeof(c))) - goto err; - // Identify the leading byte of an OpenPGP public key packet - // 0x98 -- old-format OpenPGP public key packet, up to 255 octets - // 0x99 -- old-format OpenPGP public key packet, 256-65535 octets - // 0xc6 -- new-format OpenPGP public key packet, any length - if (c == 0x98 || c == 0x99 || c == 0xc6) - return k; - } else if (APT::String::Endswith(k, ".asc")) { std::string b64msg; @@ -269,6 +257,18 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG, local_exit.files.push_back(dearmoredFd.Name()); return dearmoredFd.Name(); } + else + { + unsigned char c; + if (not keyFd.Read(&c, sizeof(c))) + goto err; + // Identify the leading byte of an OpenPGP public key packet + // 0x98 -- old-format OpenPGP public key packet, up to 255 octets + // 0x99 -- old-format OpenPGP public key packet, 256-65535 octets + // 0xc6 -- new-format OpenPGP public key packet, any length + if (c == 0x98 || c == 0x99 || c == 0xc6) + return k; + } err: apt_warning(std::cerr, statusfd, fd, "The key(s) in the keyring %s are ignored as the file has an unsupported filetype.", k.c_str()); return ""; -- cgit v1.2.3-70-g09d2