]> git.saurik.com Git - apt.git/blobdiff - methods/gpgv.cc
methods/gpgv: Reject weak digest algorithms
[apt.git] / methods / gpgv.cc
index 490833d8cfce658dcacfc766cafdaae8d4e395c4..06e1612e61998cbb2b24bca17052fb17dc38f10e 100644 (file)
@@ -6,6 +6,7 @@
 #include <apt-pkg/gpgv.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/fileutl.h>
+#include "aptmethod.h"
 
 #include <ctype.h>
 #include <errno.h>
 #include <sys/wait.h>
 #include <unistd.h>
 
+#include <array>
 #include <algorithm>
+#include <sstream>
+#include <iterator>
 #include <iostream>
 #include <string>
 #include <vector>
@@ -35,7 +39,13 @@ using std::vector;
 #define GNUPGREVKEYSIG "[GNUPG:] REVKEYSIG"
 #define GNUPGNODATA "[GNUPG:] NODATA"
 
-class GPGVMethod : public pkgAcqMethod
+static const std::array<string, 1> WeakDigests {
+   "1", // MD5
+// "2", // SHA1
+// "3", // RIPEMD-160
+};
+
+class GPGVMethod : public aptMethod
 {
    private:
    string VerifyGetSigners(const char *file, const char *outfile,
@@ -47,22 +57,11 @@ class GPGVMethod : public pkgAcqMethod
    
    protected:
    virtual bool URIAcquire(std::string const &Message, FetchItem *Itm) APT_OVERRIDE;
-   virtual bool Configuration(string Message) APT_OVERRIDE;
    public:
    
-   GPGVMethod() : pkgAcqMethod("1.0",SingleInstance | SendConfig) {};
+   GPGVMethod() : aptMethod("gpgv","1.0",SingleInstance | SendConfig) {};
 };
 
-bool GPGVMethod::Configuration(string Message)
-{
-   if (pkgAcqMethod::Configuration(Message) == false)
-      return false;
-
-   DropPrivsOrDie();
-
-   return true;
-}
-
 string GPGVMethod::VerifyGetSigners(const char *file, const char *outfile,
                                         std::string const &key,
                                         vector<string> &GoodSigners,
@@ -149,12 +148,19 @@ string GPGVMethod::VerifyGetSigners(const char *file, const char *outfile,
       else if (strncmp(buffer, GNUPGVALIDSIG, sizeof(GNUPGVALIDSIG)-1) == 0)
       {
          char *sig = buffer + sizeof(GNUPGVALIDSIG);
+         std::istringstream iss((string(sig)));
+         vector<string> tokens{std::istream_iterator<string>{iss},
+                               std::istream_iterator<string>{}};
          char *p = sig;
          while (*p && isxdigit(*p))
             p++;
          *p = 0;
          if (Debug == true)
             std::clog << "Got VALIDSIG, key ID: " << sig << std::endl;
+         // Reject weak digest algorithms
+         if (std::find(WeakDigests.begin(), WeakDigests.end(), tokens[7]) != WeakDigests.end())
+            BadSigners.push_back(string(sig));
+
          ValidSigners.push_back(string(sig));
       }
    }