1*5fff9558SSimon J. Gerraty /*-
2*5fff9558SSimon J. Gerraty * Copyright (c) 2018, Juniper Networks, Inc.
3*5fff9558SSimon J. Gerraty *
4*5fff9558SSimon J. Gerraty * Redistribution and use in source and binary forms, with or without
5*5fff9558SSimon J. Gerraty * modification, are permitted provided that the following conditions
6*5fff9558SSimon J. Gerraty * are met:
7*5fff9558SSimon J. Gerraty * 1. Redistributions of source code must retain the above copyright
8*5fff9558SSimon J. Gerraty * notice, this list of conditions and the following disclaimer.
9*5fff9558SSimon J. Gerraty * 2. Redistributions in binary form must reproduce the above copyright
10*5fff9558SSimon J. Gerraty * notice, this list of conditions and the following disclaimer in the
11*5fff9558SSimon J. Gerraty * documentation and/or other materials provided with the distribution.
12*5fff9558SSimon J. Gerraty *
13*5fff9558SSimon J. Gerraty * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14*5fff9558SSimon J. Gerraty * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15*5fff9558SSimon J. Gerraty * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16*5fff9558SSimon J. Gerraty * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
17*5fff9558SSimon J. Gerraty * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18*5fff9558SSimon J. Gerraty * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19*5fff9558SSimon J. Gerraty * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20*5fff9558SSimon J. Gerraty * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21*5fff9558SSimon J. Gerraty * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22*5fff9558SSimon J. Gerraty * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23*5fff9558SSimon J. Gerraty * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*5fff9558SSimon J. Gerraty */
25*5fff9558SSimon J. Gerraty #include <sys/cdefs.h>
26*5fff9558SSimon J. Gerraty #include <libsecureboot.h>
27*5fff9558SSimon J. Gerraty
28*5fff9558SSimon J. Gerraty #include <vse.h>
29*5fff9558SSimon J. Gerraty
30*5fff9558SSimon J. Gerraty /**
31*5fff9558SSimon J. Gerraty * @brief
32*5fff9558SSimon J. Gerraty * verify signed file
33*5fff9558SSimon J. Gerraty *
34*5fff9558SSimon J. Gerraty * We look for a signature using the extensions
35*5fff9558SSimon J. Gerraty * recorded in signature_exts.
36*5fff9558SSimon J. Gerraty * If we find a match we pass it to a suitable verify method.
37*5fff9558SSimon J. Gerraty *
38*5fff9558SSimon J. Gerraty * @return content of verified file or NULL on error.
39*5fff9558SSimon J. Gerraty */
40*5fff9558SSimon J. Gerraty unsigned char *
verify_signed(const char * filename,int flags)41*5fff9558SSimon J. Gerraty verify_signed(const char *filename, int flags)
42*5fff9558SSimon J. Gerraty {
43*5fff9558SSimon J. Gerraty struct stat st;
44*5fff9558SSimon J. Gerraty char buf[MAXPATHLEN];
45*5fff9558SSimon J. Gerraty const char **se;
46*5fff9558SSimon J. Gerraty
47*5fff9558SSimon J. Gerraty for (se = signature_exts; *se; se++) {
48*5fff9558SSimon J. Gerraty snprintf(buf, sizeof(buf), "%s.%s", filename, *se);
49*5fff9558SSimon J. Gerraty if (stat(buf, &st) < 0 || !S_ISREG(st.st_mode))
50*5fff9558SSimon J. Gerraty continue;
51*5fff9558SSimon J. Gerraty DEBUG_PRINTF(5, ("verify_signed: %s\n", buf));
52*5fff9558SSimon J. Gerraty #ifdef VE_OPENPGP_SUPPORT
53*5fff9558SSimon J. Gerraty if (strncmp(*se, "asc", 3) == 0)
54*5fff9558SSimon J. Gerraty return (verify_asc(buf, flags));
55*5fff9558SSimon J. Gerraty #endif
56*5fff9558SSimon J. Gerraty return (verify_sig(buf, flags));
57*5fff9558SSimon J. Gerraty }
58*5fff9558SSimon J. Gerraty return (NULL);
59*5fff9558SSimon J. Gerraty }
60