From owner-svn-src-all@FreeBSD.ORG Sat Oct 26 03:44:08 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id BEBDF3B8; Sat, 26 Oct 2013 03:44:08 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id AC38A2466; Sat, 26 Oct 2013 03:44:08 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9Q3i8cM081486; Sat, 26 Oct 2013 03:44:08 GMT (envelope-from bdrewery@svn.freebsd.org) Received: (from bdrewery@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9Q3i8cl081485; Sat, 26 Oct 2013 03:44:08 GMT (envelope-from bdrewery@svn.freebsd.org) Message-Id: <201310260344.r9Q3i8cl081485@svn.freebsd.org> From: Bryan Drewery Date: Sat, 26 Oct 2013 03:44:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r257148 - head/usr.sbin/pkg X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 26 Oct 2013 03:44:08 -0000 Author: bdrewery (ports committer) Date: Sat Oct 26 03:44:08 2013 New Revision: 257148 URL: http://svnweb.freebsd.org/changeset/base/257148 Log: Tell which fingerprint pkg is being validated against. Approved by: bapt MFC after: 2 days Modified: head/usr.sbin/pkg/pkg.c Modified: head/usr.sbin/pkg/pkg.c ============================================================================== --- head/usr.sbin/pkg/pkg.c Sat Oct 26 03:43:02 2013 (r257147) +++ head/usr.sbin/pkg/pkg.c Sat Oct 26 03:44:08 2013 (r257148) @@ -58,6 +58,7 @@ __FBSDID("$FreeBSD$"); #include "config.h" struct sig_cert { + char *name; unsigned char *sig; int siglen; unsigned char *cert; @@ -72,6 +73,7 @@ typedef enum { struct fingerprint { hash_t type; + char *name; char hash[BUFSIZ]; STAILQ_ENTRY(fingerprint) next; }; @@ -316,6 +318,19 @@ parse_fingerprint(yaml_document_t *doc, return (f); } +static void +free_fingerprint_list(struct fingerprint_list* list) +{ + struct fingerprint* fingerprint; + + STAILQ_FOREACH(fingerprint, list, next) { + if (fingerprint->name) + free(fingerprint->name); + free(fingerprint); + } + free(list); +} + static struct fingerprint * load_fingerprint(const char *dir, const char *filename) { @@ -342,6 +357,7 @@ load_fingerprint(const char *dir, const goto out; f = parse_fingerprint(&doc, node); + f->name = strdup(filename); out: yaml_document_delete(&doc); @@ -511,7 +527,6 @@ rsa_verify_cert(int fd, const unsigned c } /* Verify signature of the SHA256(pkg) is valid. */ - printf("Verifying signature... "); if ((mdctx = EVP_MD_CTX_create()) == NULL) { warnx("%s", ERR_error_string(ERR_get_error(), errbuf)); goto error; @@ -631,6 +646,7 @@ verify_signature(int fd_pkg, int fd_sig) char path[MAXPATHLEN]; char hash[SHA256_DIGEST_LENGTH * 2 + 1]; + sc = NULL; trusted = revoked = NULL; ret = false; @@ -672,8 +688,9 @@ verify_signature(int fd_pkg, int fd_sig) if (revoked != NULL) { STAILQ_FOREACH(fingerprint, revoked, next) { if (strcasecmp(fingerprint->hash, hash) == 0) { - fprintf(stderr, "The certificate has been " - "revoked\n"); + fprintf(stderr, "The package was signed with " + "revoked certificate %s\n", + fingerprint->name); goto cleanup; } } @@ -682,17 +699,19 @@ verify_signature(int fd_pkg, int fd_sig) STAILQ_FOREACH(fingerprint, trusted, next) { if (strcasecmp(fingerprint->hash, hash) == 0) { sc->trusted = true; + sc->name = strdup(fingerprint->name); break; } } if (sc->trusted == false) { - fprintf(stderr, "No trusted certificate found matching " + fprintf(stderr, "No trusted fingerprint found matching " "package's certificate\n"); goto cleanup; } /* Verify the signature. */ + printf("Verifying signature with trusted certificate %s... ", sc->name); if (rsa_verify_cert(fd_pkg, sc->cert, sc->certlen, sc->sig, sc->siglen) == false) { fprintf(stderr, "Signature is not valid\n"); @@ -702,21 +721,17 @@ verify_signature(int fd_pkg, int fd_sig) ret = true; cleanup: - if (trusted) { - STAILQ_FOREACH(fingerprint, trusted, next) - free(fingerprint); - free(trusted); - } - if (revoked) { - STAILQ_FOREACH(fingerprint, revoked, next) - free(fingerprint); - free(revoked); - } + if (trusted) + free_fingerprint_list(trusted); + if (revoked) + free_fingerprint_list(revoked); if (sc) { if (sc->cert) free(sc->cert); if (sc->sig) free(sc->sig); + if (sc->name) + free(sc->name); free(sc); }