]> git.saurik.com Git - apt.git/commitdiff
add TrustedParts so in the future new keyrings can just be dropped
authorDavid Kalnischkies <kalnischkies@gmail.com>
Mon, 4 Jan 2010 12:45:14 +0000 (13:45 +0100)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Mon, 4 Jan 2010 12:45:14 +0000 (13:45 +0100)
into /etc/apt/trusted.gpg.d/ which eliminates the need to have
gpg installed to add keys to APTs trusted keyring (with apt-key)
(Closes #304846) - Thanks to Timo Weingärtner & Peter Palfrader
for providing different patchs/ideas for this!

cmdline/apt-key
debian/apt.dirs
debian/changelog
doc/apt-key.8.xml
doc/apt.ent
doc/examples/configure-index
methods/gpgv.cc

index 24010edf3fb390078a275edc52ad4dd8ded58245..1950723f36db35867a1ca7868d2e47e14b55bcb9 100755 (executable)
@@ -5,10 +5,8 @@ unset GREP_OPTIONS
 
 # We don't use a secret keyring, of course, but gpg panics and
 # implodes if there isn't one available
-
 GPG_CMD="gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /etc/apt/secring.gpg --trustdb-name /etc/apt/trustdb.gpg"
-GPG="$GPG_CMD --keyring /etc/apt/trusted.gpg"
-
+GPG="$GPG_CMD"
 
 MASTER_KEYRING=""
 ARCHIVE_KEYRING_URI=""
@@ -115,7 +113,7 @@ update() {
 
 
 usage() {
-    echo "Usage: apt-key [command] [arguments]"
+    echo "Usage: apt-key [--keyring file] [command] [arguments]"
     echo
     echo "Manage apt's list of trusted keys"
     echo
@@ -129,8 +127,39 @@ usage() {
     echo "  apt-key finger              - list fingerprints"
     echo "  apt-key adv                 - pass advanced options to gpg (download key)"
     echo
+    echo "If no specific keyring file is given the command applies to all keyring files."
 }
 
+# Determine on which keyring we want to work
+if [ "$1" = "--keyring" ]; then
+       echo "keyfile given"
+       shift
+       TRUSTEDFILE="$1"
+       if [ -r "$TRUSTEDFILE" ]; then
+               GPG="$GPG --keyring $TRUSTEDFILE --primary-keyring $TRUSTEDFILE"
+       else
+               echo >&2 "Error: The specified keyring »$TRUSTEDFILE« is missing or not readable"
+               exit 1
+       fi
+       shift
+else
+       echo "generate list"
+       TRUSTEDFILE="/etc/apt/trusted.gpg"
+       if [ -r "$TRUSTEDFILE" ]; then
+               GPG="$GPG --keyring $TRUSTEDFILE"
+       fi
+       GPG="$GPG --primary-keyring $TRUSTEDFILE"
+       TRUSTEDPARTS="/etc/apt/trusted.gpg.d"
+       if [ -d "$TRUSTEDPARTS" ]; then
+               echo "parts active"
+               for trusted in $(run-parts --list $TRUSTEDPARTS --regex '^.*\.gpg$'); do
+                       echo "part -> $trusted"
+                       GPG="$GPG --keyring $trusted"
+               done
+       fi
+fi
+echo "COMMAND: $GPG"
+
 command="$1"
 if [ -z "$command" ]; then
     usage
index fb6716c35bc89bd3bb9a8db813c79b7dba9888f7..66556e45374fea275c07a0fabd0e72ceefe84584 100644 (file)
@@ -5,6 +5,7 @@ etc/apt
 etc/apt/apt.conf.d
 etc/apt/preferences.d
 etc/apt/sources.list.d
+etc/apt/trusted.gpg.d
 etc/logrotate.d
 var/cache/apt/archives/partial
 var/lib/apt/lists/partial
index f70c5735f9cb424290f837f877381dbadc5682f3..fca8d3ccb0db8e379003cdb87ae79de77bd01719 100644 (file)
@@ -41,6 +41,10 @@ apt (0.7.26) UNRELEASED; urgency=low
       the keyring so we don't need to ship our own version
   * cmdline/apt-key:
     - errors out if wget is not installed (Closes: #545754)
+    - add --keyring option as we have now possibly many
+  * methods/gpgv.cc:
+    - pass all keyrings (TrustedParts) to gpgv instead of
+      using only one trusted.gpg keyring (Closes: #304846)
 
  -- Michael Vogt <mvo@debian.org>  Thu, 10 Dec 2009 22:02:38 +0100
 
index 7b0691b5efdaac67ce86adbbd630abb5cc55a563..8f445b7f95e8e8a0e258fe78b5c0752186b53af6 100644 (file)
@@ -26,7 +26,8 @@
  <refsynopsisdiv>
    <cmdsynopsis>
       <command>apt-key</command>
-      <arg><replaceable>command</replaceable>/</arg>
+      <arg><option>--keyring <replaceable>filename</replaceable></option></arg>
+      <arg><replaceable>command</replaceable></arg>
       <arg rep="repeat"><option><replaceable>arguments</replaceable></option></arg>
    </cmdsynopsis>
  </refsynopsisdiv>
    </variablelist>
 </refsect1>
 
+ <refsect1><title>Options</title>
+<para>Note that options need to be defined before the commands described in the previous section.</para>
+   <variablelist>
+      <varlistentry><term>--keyring <replaceable>filename</replaceable></term>
+      <listitem><para>With this option it is possible to specify a specific keyring
+      file the command should operate on. The default is that a command is executed
+      on the <filename>trusted.gpg</filename> file as well as on all parts in the
+      <filename>trusted.gpg.d</filename> directory, through <filename>trusted.gpg</filename>
+      is the primary keyring which means that e.g. new keys are added to this one.
+      </para></listitem>
+      </varlistentry>
+   </variablelist>
+ </refsect1>
+
  <refsect1><title>Files</title>
    <variablelist>
-     <varlistentry><term><filename>/etc/apt/trusted.gpg</filename></term>
-     <listitem><para>Keyring of local trusted keys, new keys will be added here.</para></listitem>
-     </varlistentry>
+
+     &file-trustedgpg;
 
      <varlistentry><term><filename>/etc/apt/trustdb.gpg</filename></term>
      <listitem><para>Local trust database of archive keys.</para></listitem>
      <listitem><para>Keyring of Debian archive removed trusted keys.</para></listitem>
      </varlistentry>
 
-
-
    </variablelist>
 
 </refsect1>
index 0b341ec14550c1e8a3178341c11891e1962fc732..da43d8f3d42204f3c3bab313eb068e6cea6bbe81 100644 (file)
      Configuration Item: <literal>Dir::State::Lists</literal> (implicit partial).</para></listitem>
      </varlistentry>
 ">
+
+<!ENTITY file-trustedgpg "
+     <varlistentry><term><filename>/etc/apt/trusted.gpg</filename></term>
+     <listitem><para>Keyring of local trusted keys, new keys will be added here.
+     Configuration Item: <literal>Dir::Etc::Trusted</literal>.</para></listitem>
+     </varlistentry>
+
+     <varlistentry><term><filename>/etc/apt/trusted.gpg.d/</filename></term>
+     <listitem><para>File fragments for the trusted keys, additional keyrings can
+     be stored here (by other packages or the administrator).
+     Configuration Item <literal>Dir::Etc::TrustedParts</literal>.</para></listitem>
+     </varlistentry>
+">
index be461aaad15aee43ac9ff0a0368a1e0ba9b16b44..87cf97ffed6fd875f8eb6c25b9fd6ef925ba4c44 100644 (file)
@@ -90,11 +90,6 @@ APT
      TrustCDROM "false";            // consider the CDROM always trusted
   };
 
-  GPGV
-  {
-     TrustedKeyring "/etc/apt/trusted.gpg";
-  };
-
   // Some general options
   Ignore-Hold "false";
   Clean-Installed "true";
@@ -320,6 +315,8 @@ Dir "/"
      SourceParts "sources.list.d";
      VendorList "vendors.list";
      VendorParts "vendors.list.d";
+     Trusted "trusted.gpg";
+     TrustedParts "trusted.gpg.d";
   };
   
   // Locations of binaries
index 150c1d315ebe33ee530150a20e8a72c1c6b2bf16..e3e849827372f65ddd965f2fe922cbbc73e98f09 100644 (file)
@@ -1,10 +1,9 @@
 #include <apt-pkg/error.h>
 #include <apt-pkg/acquire-method.h>
 #include <apt-pkg/strutl.h>
+#include <apt-pkg/fileutl.h>
 #include <apti18n.h>
 
-#include <sys/stat.h>
-#include <unistd.h>
 #include <utime.h>
 #include <stdio.h>
 #include <fcntl.h>
@@ -45,42 +44,47 @@ string GPGVMethod::VerifyGetSigners(const char *file, const char *outfile,
                                         vector<string> &WorthlessSigners,
                                         vector<string> &NoPubKeySigners)
 {
+   bool const Debug = _config->FindB("Debug::Acquire::gpgv", false);
    // setup a (empty) stringstream for formating the return value
    std::stringstream ret;
    ret.str("");
 
-   if (_config->FindB("Debug::Acquire::gpgv", false))
-   {
-      std::cerr << "inside VerifyGetSigners" << std::endl;
-   }
+   if (Debug == true)
+      std::clog << "inside VerifyGetSigners" << std::endl;
+
    pid_t pid;
    int fd[2];
    FILE *pipein;
    int status;
-   struct stat buff;
-   string gpgvpath = _config->Find("Dir::Bin::gpg", "/usr/bin/gpgv");
-   string pubringpath = _config->Find("APT::GPGV::TrustedKeyring", "/etc/apt/trusted.gpg");
-   if (_config->FindB("Debug::Acquire::gpgv", false))
+   string const gpgvpath = _config->Find("Dir::Bin::gpg", "/usr/bin/gpgv");
+   // FIXME: remove support for deprecated APT::GPGV setting
+   string const trustedFile = _config->FindFile("Dir::Etc::Trusted",
+                       _config->Find("APT::GPGV::TrustedKeyring", "/etc/apt/trusted.gpg").c_str());
+   string const trustedPath = _config->FindDir("Dir::Etc::TrustedParts", "/etc/apt/trusted.gpg.d");
+   if (Debug == true)
    {
-      std::cerr << "gpgv path: " << gpgvpath << std::endl;
-      std::cerr << "Keyring path: " << pubringpath << std::endl;
+      std::clog << "gpgv path: " << gpgvpath << std::endl;
+      std::clog << "Keyring file: " << trustedFile << std::endl;
+      std::clog << "Keyring path: " << trustedPath << std::endl;
    }
 
-   if (stat(pubringpath.c_str(), &buff) != 0) 
+   vector<string> keyrings = GetListOfFilesInDir(trustedPath, "gpg", false);
+   if (FileExists(trustedFile) == true)
+      keyrings.push_back(trustedFile);
+
+   if (keyrings.empty() == true)
    {
-      ioprintf(ret, _("Couldn't access keyring: '%s'"), strerror(errno)); 
+      // TRANSLATOR: %s is the trusted keyring parts directory
+      ioprintf(ret, _("No keyring installed in %s."), trustedPath.c_str());
       return ret.str();
    }
+
    if (pipe(fd) < 0)
-   {
       return "Couldn't create pipe";
-   }
 
    pid = fork();
    if (pid < 0)
-   {
       return string("Couldn't spawn new process") + strerror(errno);
-   }
    else if (pid == 0)
    {
       const char *Args[400];
@@ -90,8 +94,16 @@ string GPGVMethod::VerifyGetSigners(const char *file, const char *outfile,
       Args[i++] = "--status-fd";
       Args[i++] = "3";
       Args[i++] = "--ignore-time-conflict";
-      Args[i++] = "--keyring";
-      Args[i++] = pubringpath.c_str();
+      for (vector<string>::const_iterator K = keyrings.begin();
+          K != keyrings.end(); ++K)
+      {
+        Args[i++] = "--keyring";
+        Args[i++] = K->c_str();
+        if(i >= 395) {
+           std::clog << _("E: Too many keyrings should be passed to gpgv. Exiting.") << std::endl;
+           exit(111);
+        }
+      }
 
       Configuration::Item const *Opts;
       Opts = _config->Tree("Acquire::gpgv::Options");
@@ -104,7 +116,7 @@ string GPGVMethod::VerifyGetSigners(const char *file, const char *outfile,
                continue;
             Args[i++] = Opts->Value.c_str();
            if(i >= 395) { 
-              std::cerr << _("E: Argument list from Acquire::gpgv::Options too long. Exiting.") << std::endl;
+              std::clog << _("E: Argument list from Acquire::gpgv::Options too long. Exiting.") << std::endl;
               exit(111);
            }
          }
@@ -113,14 +125,14 @@ string GPGVMethod::VerifyGetSigners(const char *file, const char *outfile,
       Args[i++] = outfile;
       Args[i++] = NULL;
 
-      if (_config->FindB("Debug::Acquire::gpgv", false))
+      if (Debug == true)
       {
-         std::cerr << "Preparing to exec: " << gpgvpath;
+         std::clog << "Preparing to exec: " << gpgvpath;
         for(unsigned int j=0;Args[j] != NULL; j++)
-           std::cerr << " " << Args[j];
-        std::cerr << std::endl;
+           std::clog << " " << Args[j];
+        std::clog << std::endl;
       }
-      int nullfd = open("/dev/null", O_RDONLY);
+      int const nullfd = open("/dev/null", O_RDONLY);
       close(fd[0]);
       // Redirect output to /dev/null; we read from the status fd
       dup2(nullfd, STDOUT_FILENO); 
@@ -159,8 +171,8 @@ string GPGVMethod::VerifyGetSigners(const char *file, const char *outfile,
          break;
       *(buffer+bufferoff) = '\0';
       bufferoff = 0;
-      if (_config->FindB("Debug::Acquire::gpgv", false))
-         std::cerr << "Read: " << buffer << std::endl;
+      if (Debug == true)
+         std::clog << "Read: " << buffer << std::endl;
 
       // Push the data into three separate vectors, which
       // we later concatenate.  They're kept separate so
@@ -168,33 +180,33 @@ string GPGVMethod::VerifyGetSigners(const char *file, const char *outfile,
       // it will be better.
       if (strncmp(buffer, GNUPGBADSIG, sizeof(GNUPGBADSIG)-1) == 0)
       {
-         if (_config->FindB("Debug::Acquire::gpgv", false))
-            std::cerr << "Got BADSIG! " << std::endl;
+         if (Debug == true)
+            std::clog << "Got BADSIG! " << std::endl;
          BadSigners.push_back(string(buffer+sizeof(GNUPGPREFIX)));
       }
       
       if (strncmp(buffer, GNUPGNOPUBKEY, sizeof(GNUPGNOPUBKEY)-1) == 0)
       {
-         if (_config->FindB("Debug::Acquire::gpgv", false))
-            std::cerr << "Got NO_PUBKEY " << std::endl;
+         if (Debug == true)
+            std::clog << "Got NO_PUBKEY " << std::endl;
          NoPubKeySigners.push_back(string(buffer+sizeof(GNUPGPREFIX)));
       }
       if (strncmp(buffer, GNUPGNODATA, sizeof(GNUPGBADSIG)-1) == 0)
       {
-         if (_config->FindB("Debug::Acquire::gpgv", false))
-            std::cerr << "Got NODATA! " << std::endl;
+         if (Debug == true)
+            std::clog << "Got NODATA! " << std::endl;
          BadSigners.push_back(string(buffer+sizeof(GNUPGPREFIX)));
       }
       if (strncmp(buffer, GNUPGKEYEXPIRED, sizeof(GNUPGKEYEXPIRED)-1) == 0)
       {
-         if (_config->FindB("Debug::Acquire::gpgv", false))
-            std::cerr << "Got KEYEXPIRED! " << std::endl;
+         if (Debug == true)
+            std::clog << "Got KEYEXPIRED! " << std::endl;
          WorthlessSigners.push_back(string(buffer+sizeof(GNUPGPREFIX)));
       }
       if (strncmp(buffer, GNUPGREVKEYSIG, sizeof(GNUPGREVKEYSIG)-1) == 0)
       {
-         if (_config->FindB("Debug::Acquire::gpgv", false))
-            std::cerr << "Got REVKEYSIG! " << std::endl;
+         if (Debug == true)
+            std::clog << "Got REVKEYSIG! " << std::endl;
          WorthlessSigners.push_back(string(buffer+sizeof(GNUPGPREFIX)));
       }
       if (strncmp(buffer, GNUPGGOODSIG, sizeof(GNUPGGOODSIG)-1) == 0)
@@ -204,17 +216,17 @@ string GPGVMethod::VerifyGetSigners(const char *file, const char *outfile,
          while (*p && isxdigit(*p)) 
             p++;
          *p = 0;
-         if (_config->FindB("Debug::Acquire::gpgv", false))
-            std::cerr << "Got GOODSIG, key ID:" << sig << std::endl;
+         if (Debug == true)
+            std::clog << "Got GOODSIG, key ID:" << sig << std::endl;
          GoodSigners.push_back(string(sig));
       }
    }
    fclose(pipein);
 
    waitpid(pid, &status, 0);
-   if (_config->FindB("Debug::Acquire::gpgv", false))
+   if (Debug == true)
    {
-      std::cerr << "gpgv exited\n";
+      std::clog << "gpgv exited\n";
    }
    
    if (WEXITSTATUS(status) == 0)
@@ -305,7 +317,7 @@ bool GPGVMethod::Fetch(FetchItem *Itm)
 
    if (_config->FindB("Debug::Acquire::gpgv", false))
    {
-      std::cerr << "gpgv succeeded\n";
+      std::clog << "gpgv succeeded\n";
    }
 
    return true;