]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
location-downloader: Add command to verify the downloaded database manually
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 10 Dec 2019 18:53:21 +0000 (18:53 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 10 Dec 2019 18:53:21 +0000 (18:53 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
man/location-downloader.txt
src/python/location-downloader.in

index 93b27fb85532d76655ad990856d28c2e96138085..e7251d1da8bdacc2abfa4c1e2e395aa86fce2a04 100644 (file)
@@ -31,6 +31,9 @@ location database.
        successfully updated. 1 on error, 2 on invalid call and 3 if the
        database was already the latest version.
 
+'verify'::
+       Verifies the downloaded database.
+
 '--help'::
        Shows a short help text on using this program.
 
index a9b74dbbe449b560561e147b4efcaa5382d55d85..1b5932d5822e03737d32b2a27816815b2f7e74dd 100644 (file)
@@ -267,6 +267,11 @@ class CLI(object):
                update = subparsers.add_parser("update", help=_("Update database"))
                update.set_defaults(func=self.handle_update)
 
+               # Verify
+               verify = subparsers.add_parser("verify",
+                       help=_("Verify the downloaded database"))
+               verify.set_defaults(func=self.handle_verify)
+
                args = parser.parse_args()
 
                # Enable debug logging
@@ -336,7 +341,24 @@ class CLI(object):
                # Remove temporary file
                os.unlink(t.name)
 
-                return 0
+               return 0
+
+       def handle_verify(self, ns):
+               try:
+                       db = location.Database(ns.database)
+               except FileNotFoundError as e:
+                       log.error("%s: %s" % (ns.database, e))
+                       return 127
+
+               # Verify the database
+               with open(ns.public_key, "r") as f:
+                       if not db.verify(f):
+                               log.error("Could not verify database")
+                               return 1
+
+               # Success
+               log.debug("Database successfully verified")
+               return 0
 
 
 def main():