Просмотр исходного кода

merged the relevant bits from lp:~mvo/apt/lp346386

Michael Vogt лет назад: 14
Родитель
Сommit
5a8cd0703b
4 измененных файлов с 39 добавлено и 6 удалено
  1. 13 1
      apt-pkg/acquire-item.cc
  2. 20 0
      apt-pkg/contrib/fileutl.cc
  3. 5 0
      apt-pkg/contrib/fileutl.h
  4. 1 5
      apt-pkg/indexcopy.cc

+ 13 - 1
apt-pkg/acquire-item.cc

@@ -1235,9 +1235,21 @@ void pkgAcqMetaIndex::Done(string Message,unsigned long long Size,string Hash,	/
       }
       }
       else
       else
       {
       {
+         // FIXME: move this into pkgAcqMetaClearSig::Done on the next
+         //        ABI break
+
+         // if we expect a ClearTextSignature (InRelase), ensure that
+         // this is what we get and if not fail to queue a 
+         // Release/Release.gpg, see #346386
+         if (SigFile == DestFile && 
+             !IsPgpClearTextSignature(DestFile))
+         {
+            Failed(Message, Cfg);
+            return;
+         }
+
          // There was a signature file, so pass it to gpgv for
          // There was a signature file, so pass it to gpgv for
          // verification
          // verification
-
          if (_config->FindB("Debug::pkgAcquire::Auth", false))
          if (_config->FindB("Debug::pkgAcquire::Auth", false))
             std::cerr << "Metaindex acquired, queueing gpg verification ("
             std::cerr << "Metaindex acquired, queueing gpg verification ("
                       << SigFile << "," << DestFile << ")\n";
                       << SigFile << "," << DestFile << ")\n";

+ 20 - 0
apt-pkg/contrib/fileutl.cc

@@ -852,6 +852,26 @@ bool ExecWait(pid_t Pid,const char *Name,bool Reap)
 }
 }
 									/*}}}*/
 									/*}}}*/
 
 
+// IsPgpClearTextSignature - Check if a file is Pgp/GPG clearsigned     /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool IsPgpClearTextSignature(string const &FileName)
+{
+   static const char* SIGMSG = "-----BEGIN PGP SIGNED MESSAGE-----\n";
+   char buffer[sizeof(SIGMSG)];
+   FILE* gpg = fopen(FileName.c_str(), "r");
+   if (gpg == NULL)
+      return false;
+
+   char const * const test = fgets(buffer, sizeof(buffer), gpg);
+   fclose(gpg);
+   if (test == NULL || strcmp(buffer, SIGMSG) != 0)
+      return false;
+
+   return true;
+}
+
+
 // FileFd::Open - Open a file						/*{{{*/
 // FileFd::Open - Open a file						/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* The most commonly used open mode combinations are given with Mode */
 /* The most commonly used open mode combinations are given with Mode */

+ 5 - 0
apt-pkg/contrib/fileutl.h

@@ -180,6 +180,9 @@ bool WaitFd(int Fd,bool write = false,unsigned long timeout = 0);
 pid_t ExecFork();
 pid_t ExecFork();
 bool ExecWait(pid_t Pid,const char *Name,bool Reap = false);
 bool ExecWait(pid_t Pid,const char *Name,bool Reap = false);
 
 
+// check if the given file starts with a PGP cleartext signature
+bool IsPgpClearTextSignature(std::string const &FileName);
+
 // File string manipulators
 // File string manipulators
 std::string flNotDir(std::string File);
 std::string flNotDir(std::string File);
 std::string flNotFile(std::string File);
 std::string flNotFile(std::string File);
@@ -187,4 +190,6 @@ std::string flNoLink(std::string File);
 std::string flExtension(std::string File);
 std::string flExtension(std::string File);
 std::string flCombine(std::string Dir,std::string File);
 std::string flCombine(std::string Dir,std::string File);
 
 
+
+
 #endif
 #endif

+ 1 - 5
apt-pkg/indexcopy.cc

@@ -648,16 +648,12 @@ bool SigVerify::RunGPGV(std::string const &File, std::string const &FileGPG,
 {
 {
    if (File == FileGPG)
    if (File == FileGPG)
    {
    {
-      #define SIGMSG "-----BEGIN PGP SIGNED MESSAGE-----\n"
-      char buffer[sizeof(SIGMSG)];
       FILE* gpg = fopen(File.c_str(), "r");
       FILE* gpg = fopen(File.c_str(), "r");
       if (gpg == NULL)
       if (gpg == NULL)
 	 return _error->Errno("RunGPGV", _("Could not open file %s"), File.c_str());
 	 return _error->Errno("RunGPGV", _("Could not open file %s"), File.c_str());
-      char const * const test = fgets(buffer, sizeof(buffer), gpg);
       fclose(gpg);
       fclose(gpg);
-      if (test == NULL || strcmp(buffer, SIGMSG) != 0)
+      if (!IsPgpClearTextSignature(File))
 	 return _error->Error(_("File %s doesn't start with a clearsigned message"), File.c_str());
 	 return _error->Error(_("File %s doesn't start with a clearsigned message"), File.c_str());
-      #undef SIGMSG
    }
    }