1 /*- 2 * Copyright (c) 2017-2018, Juniper Networks, Inc. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 14 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 15 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 16 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 17 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 19 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 /* 26 */ 27 #ifndef _LIBSECUREBOOT_H_ 28 #define _LIBSECUREBOOT_H_ 29 30 #include <sys/param.h> 31 #ifdef _STANDALONE 32 #include <stand.h> 33 #else 34 #include <sys/types.h> 35 #include <sys/stat.h> 36 #include <stdlib.h> 37 #include <stdio.h> 38 #include <unistd.h> 39 #include <fcntl.h> 40 #endif 41 42 #include <bearssl.h> 43 44 unsigned char * read_fd(int, size_t); 45 #ifndef NEED_BRSSL_H 46 unsigned char * read_file(const char *, size_t *); 47 #endif 48 49 extern int DebugVe; 50 extern int VerifyFlags; 51 52 #ifndef DEBUG_PRINTF 53 #define DEBUG_PRINTF(n, x) if (DebugVe >= n) printf x 54 #endif 55 56 int ve_trust_init(void); 57 size_t ve_trust_anchors_add_buf(unsigned char *, size_t); 58 size_t ve_trust_anchors_revoke(unsigned char *, size_t); 59 int ve_trust_add(const char *); 60 void ve_debug_set(int); 61 void ve_enforce_validity_set(int); 62 void ve_anchor_verbose_set(int); 63 int ve_anchor_verbose_get(void); 64 void ve_utc_set(time_t utc); 65 char *ve_error_get(void); 66 int ve_error_set(const char *, ...) __printflike(1,2); 67 int ve_self_tests(void); 68 69 void fingerprint_info_add(const char *, const char *, const char *, 70 const char *, struct stat *); 71 72 char * hexdigest(char *, size_t, unsigned char *, size_t); 73 int verify_fd(int, const char *, off_t, struct stat *); 74 int verify_open(const char *, int); 75 76 unsigned char *verify_signed(const char *, int); 77 unsigned char *verify_sig(const char *, int); 78 unsigned char *verify_asc(const char *, int); /* OpenPGP */ 79 80 void ve_pcr_init(void); 81 void ve_pcr_update(const char *, unsigned char *, size_t); 82 ssize_t ve_pcr_get(unsigned char *, size_t); 83 int ve_pcr_updating_get(void); 84 void ve_pcr_updating_set(int); 85 char * ve_pcr_hashed_get(int); 86 87 /* flags for verify_{asc,sig,signed} */ 88 #define VEF_VERBOSE 1 89 90 #define VE_FINGERPRINT_OK 1 91 #define VE_FINGERPRINT_IGNORE 2 92 /* errors from verify_fd */ 93 #define VE_FINGERPRINT_NONE -2 94 #define VE_FINGERPRINT_WRONG -3 95 #define VE_FINGERPRINT_UNKNOWN -4 /* may not be an error */ 96 97 #endif /* _LIBSECUREBOOT_H_ */ 98