From: Michael Tremer Date: Tue, 10 Dec 2019 18:53:21 +0000 (+0000) Subject: location-downloader: Add command to verify the downloaded database manually X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8e753500cf20c43e38718ab71fd7ad72b8f64456;p=people%2Fsennis%2Flibloc.git location-downloader: Add command to verify the downloaded database manually Signed-off-by: Michael Tremer --- diff --git a/man/location-downloader.txt b/man/location-downloader.txt index 93b27fb..e7251d1 100644 --- a/man/location-downloader.txt +++ b/man/location-downloader.txt @@ -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. diff --git a/src/python/location-downloader.in b/src/python/location-downloader.in index a9b74db..1b5932d 100644 --- a/src/python/location-downloader.in +++ b/src/python/location-downloader.in @@ -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():