move the choice of signature type for checking into one single place
authorespie <espie@openbsd.org>
Wed, 25 Dec 2013 14:38:15 +0000 (14:38 +0000)
committerespie <espie@openbsd.org>
Wed, 25 Dec 2013 14:38:15 +0000 (14:38 +0000)
usr.sbin/pkg_add/OpenBSD/Delete.pm
usr.sbin/pkg_add/OpenBSD/PackingList.pm
usr.sbin/pkg_add/OpenBSD/PkgAdd.pm
usr.sbin/pkg_add/OpenBSD/PkgCheck.pm
usr.sbin/pkg_add/OpenBSD/x509.pm

index 43320f0..162943f 100644 (file)
@@ -1,5 +1,5 @@
 # ex:ts=8 sw=4:
-# $OpenBSD: Delete.pm,v 1.120 2013/09/24 21:00:57 espie Exp $
+# $OpenBSD: Delete.pm,v 1.121 2013/12/25 14:38:15 espie Exp $
 #
 # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
 #
@@ -106,8 +106,7 @@ sub delete_package
        }
        if ($plist->is_signed) {
                if (!$state->{quick}) {
-                       require OpenBSD::x509;
-                       if (!OpenBSD::x509::check_signature($plist, $state)) {
+                       if (!$plist->check_signature($state)) {
                                $state->fatal("package #1 was corrupted: signature check failed", $pkgname);
                        }
                }
index 998d065..7a09540 100644 (file)
@@ -1,5 +1,5 @@
 # ex:ts=8 sw=4:
-# $OpenBSD: PackingList.pm,v 1.121 2012/12/28 15:09:09 espie Exp $
+# $OpenBSD: PackingList.pm,v 1.122 2013/12/25 14:38:15 espie Exp $
 #
 # Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org>
 #
@@ -531,6 +531,18 @@ sub to_installation
        $self->tofile(OpenBSD::PackageInfo::installed_contents($self->pkgname));
 }
 
+sub check_signature
+{
+       my ($plist, $state) = @_;
+       my $sig = $plist->get('digital-signature');
+       if ($sig->{key} eq 'x509') {
+               require OpenBSD::x509;
+               return OpenBSD::x509::check_signature($plist, $state);
+       } else {
+               $state->log("Error: unknown signature style $sig->{key}");
+               return 0;
+       }
+}
 
 sub forget
 {
index 449d486..7c9fc61 100644 (file)
@@ -1,7 +1,7 @@
 #! /usr/bin/perl
 
 # ex:ts=8 sw=4:
-# $OpenBSD: PkgAdd.pm,v 1.39 2013/12/25 14:20:48 espie Exp $
+# $OpenBSD: PkgAdd.pm,v 1.40 2013/12/25 14:38:15 espie Exp $
 #
 # Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org>
 #
@@ -660,12 +660,9 @@ sub check_x509_signature
                                $state->errsay("NOT CHECKING DIGITAL SIGNATURE FOR #1",
                                    $plist->pkgname);
                        } else {
-                               require OpenBSD::x509;
-
-                               if (!OpenBSD::x509::check_signature($plist,
-                                   $state)) {
+                               if (!$plist->check_signature($state)) {
                                        $state->fatal("#1 is corrupted",
-                                           $set->print);
+                                           $plist->pkgname);
                                }
                                $state->{check_digest} = 1;
                                $state->{packages_with_sig}++;
index 1837dcd..7f9bb19 100644 (file)
@@ -1,7 +1,7 @@
 #! /usr/bin/perl
 
 # ex:ts=8 sw=4:
-# $OpenBSD: PkgCheck.pm,v 1.41 2013/09/11 15:36:18 espie Exp $
+# $OpenBSD: PkgCheck.pm,v 1.42 2013/12/25 14:38:15 espie Exp $
 #
 # Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org>
 #
@@ -688,9 +688,7 @@ sub package_files_check
                my $plist = OpenBSD::PackingList->from_installation($name);
                $state->log->set_context($name);
                if ($plist->is_signed && !$state->defines('nosig')) {
-                       require OpenBSD::x509;
-
-                       if (!OpenBSD::x509::check_signature($plist, $state)) {
+                       if (!$plist->check_signature($state)) {
                                $state->fatal("#1 is corrupted", $name);
                        }
                }
index 3ea6707..8cc266b 100644 (file)
@@ -1,5 +1,5 @@
 # ex:ts=8 sw=4:
-# $OpenBSD: x509.pm,v 1.11 2010/12/24 09:04:14 espie Exp $
+# $OpenBSD: x509.pm,v 1.12 2013/12/25 14:38:15 espie Exp $
 #
 # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
 #
@@ -81,10 +81,6 @@ sub check_signature
 {
        my ($plist, $state) = @_;
        my $sig = $plist->get('digital-signature');
-       if ($sig->{key} ne 'x509') {
-               $state->log("Error: unknown signature style");
-               return 0;
-       }
        my ($fh, $fname) = mkstemp("/tmp/pkgcontent.XXXXXXXXX");
        my ($fh2, $fname2) = mkstemp("/tmp/pkgsig.XXXXXXXXX");
        $plist->write_no_sig($fh);