2019-02-26 06:09:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017-2018, Juniper Networks, Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include "../libsecureboot-priv.h"
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <verify_file.h>
|
|
|
|
|
2020-03-08 17:42:42 +00:00
|
|
|
size_t DestdirLen;
|
|
|
|
char *Destdir;
|
2019-02-26 06:09:10 +00:00
|
|
|
char *Skip;
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
int fd;
|
|
|
|
int c;
|
|
|
|
int Vflag;
|
|
|
|
char *cp;
|
|
|
|
char *prefix;
|
2020-03-08 17:42:42 +00:00
|
|
|
char *destdir;
|
2019-02-26 06:09:10 +00:00
|
|
|
|
2020-03-08 17:42:42 +00:00
|
|
|
Destdir = NULL;
|
|
|
|
DestdirLen = 0;
|
2019-02-26 06:09:10 +00:00
|
|
|
prefix = NULL;
|
|
|
|
Skip = NULL;
|
|
|
|
|
|
|
|
n = ve_trust_init();
|
|
|
|
printf("Trust %d\n", n);
|
|
|
|
Vflag = 0;
|
|
|
|
|
2020-03-08 17:42:42 +00:00
|
|
|
while ((c = getopt(argc, argv, "D:dp:s:T:V")) != -1) {
|
2019-02-26 06:09:10 +00:00
|
|
|
switch (c) {
|
2020-03-08 17:42:42 +00:00
|
|
|
case 'D':
|
|
|
|
Destdir = optarg;
|
|
|
|
DestdirLen = strlen(optarg);
|
|
|
|
break;
|
2019-02-26 06:09:10 +00:00
|
|
|
case 'd':
|
|
|
|
DebugVe++;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
prefix = optarg;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
Skip = optarg;
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
n = ve_trust_add(optarg);
|
|
|
|
printf("Local trust %s: %d\n", optarg, n);
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
Vflag = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
errx(1, "unknown option: -%c", c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-19 20:28:49 +00:00
|
|
|
#ifdef VE_PCR_SUPPORT
|
|
|
|
ve_pcr_updating_set(1);
|
|
|
|
#endif
|
2019-02-26 06:09:10 +00:00
|
|
|
ve_self_tests();
|
|
|
|
|
|
|
|
for ( ; optind < argc; optind++) {
|
|
|
|
if (Vflag) {
|
|
|
|
/*
|
|
|
|
* Simulate what loader does.
|
|
|
|
* verify_file should "just work"
|
|
|
|
*/
|
|
|
|
fd = open(argv[optind], O_RDONLY);
|
|
|
|
if (fd > 0) {
|
|
|
|
/*
|
|
|
|
* See if verify_file is happy
|
|
|
|
*/
|
|
|
|
int x;
|
|
|
|
|
2020-03-08 17:42:42 +00:00
|
|
|
x = verify_file(fd, argv[optind], 0, VE_GUESS, __func__);
|
2019-02-26 06:09:10 +00:00
|
|
|
printf("verify_file(%s) = %d\n", argv[optind], x);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#ifdef VE_OPENPGP_SUPPORT
|
|
|
|
if (strstr(argv[optind], "asc")) {
|
|
|
|
cp = (char *)verify_asc(argv[optind], 1);
|
|
|
|
if (cp) {
|
|
|
|
printf("Verified: %s: %.28s...\n",
|
|
|
|
argv[optind], cp);
|
|
|
|
fingerprint_info_add(argv[optind],
|
|
|
|
prefix, Skip, cp, NULL);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "%s: %s\n",
|
|
|
|
argv[optind], ve_error_get());
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (strstr(argv[optind], "sig")) {
|
|
|
|
cp = (char *)verify_sig(argv[optind], 1);
|
|
|
|
if (cp) {
|
|
|
|
printf("Verified: %s: %.28s...\n",
|
|
|
|
argv[optind], cp);
|
|
|
|
fingerprint_info_add(argv[optind],
|
|
|
|
prefix, Skip, cp, NULL);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "%s: %s\n",
|
|
|
|
argv[optind], ve_error_get());
|
|
|
|
}
|
|
|
|
} else if (strstr(argv[optind], "manifest")) {
|
|
|
|
cp = (char *)read_file(argv[optind], NULL);
|
|
|
|
if (cp) {
|
|
|
|
fingerprint_info_add(argv[optind],
|
|
|
|
prefix, Skip, cp, NULL);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fd = verify_open(argv[optind], O_RDONLY);
|
|
|
|
printf("verify_open(%s) = %d %s\n", argv[optind], fd,
|
|
|
|
(fd < 0) ? ve_error_get() : "");
|
|
|
|
if (fd > 0) {
|
|
|
|
/*
|
|
|
|
* Check that vectx_* can also verify the file.
|
|
|
|
*/
|
|
|
|
void *vp;
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
struct stat st;
|
|
|
|
int error;
|
|
|
|
size_t off, n;
|
|
|
|
|
|
|
|
fstat(fd, &st);
|
|
|
|
lseek(fd, 0, SEEK_SET);
|
|
|
|
off = st.st_size % 512;
|
|
|
|
vp = vectx_open(fd, argv[optind], off,
|
2020-03-08 17:42:42 +00:00
|
|
|
&st, &error, __func__);
|
2019-02-26 06:09:10 +00:00
|
|
|
if (!vp) {
|
|
|
|
printf("vectx_open(%s) failed: %d %s\n",
|
|
|
|
argv[optind], error,
|
|
|
|
ve_error_get());
|
|
|
|
} else {
|
|
|
|
off = vectx_lseek(vp,
|
|
|
|
(st.st_size % 1024), SEEK_SET);
|
2020-03-08 17:42:42 +00:00
|
|
|
/* we can seek backwards! */
|
|
|
|
off = vectx_lseek(vp, off/2, SEEK_SET);
|
2019-02-26 06:09:10 +00:00
|
|
|
if (off < st.st_size) {
|
|
|
|
n = vectx_read(vp, buf,
|
|
|
|
sizeof(buf));
|
|
|
|
if (n > 0)
|
|
|
|
off += n;
|
|
|
|
}
|
|
|
|
off = vectx_lseek(vp, 0, SEEK_END);
|
|
|
|
/* repeating that should be harmless */
|
|
|
|
off = vectx_lseek(vp, 0, SEEK_END);
|
2020-03-08 17:42:42 +00:00
|
|
|
error = vectx_close(vp, VE_MUST, __func__);
|
2019-02-26 06:09:10 +00:00
|
|
|
if (error) {
|
|
|
|
printf("vectx_close(%s) == %d %s\n",
|
|
|
|
argv[optind], error,
|
|
|
|
ve_error_get());
|
|
|
|
} else {
|
|
|
|
printf("vectx_close: Verified: %s\n",
|
|
|
|
argv[optind]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-19 20:28:49 +00:00
|
|
|
#ifdef VE_PCR_SUPPORT
|
|
|
|
verify_pcr_export();
|
|
|
|
printf("pcr=%s\n", getenv("loader.ve.pcr"));
|
|
|
|
#endif
|
2019-02-26 06:09:10 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|