xref: /freebsd/lib/libsecureboot/h/libsecureboot.h (revision 2f513db72b034fd5ef7f080b11be5c711c15186a)
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  * $FreeBSD$
27  */
28 #ifndef _LIBSECUREBOOT_H_
29 #define _LIBSECUREBOOT_H_
30 
31 #include <sys/param.h>
32 #ifdef _STANDALONE
33 #include <stand.h>
34 #else
35 #include <sys/types.h>
36 #include <sys/stat.h>
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <unistd.h>
40 #include <fcntl.h>
41 #endif
42 
43 #include <bearssl.h>
44 
45 unsigned char * read_fd(int, size_t);
46 #ifndef NEED_BRSSL_H
47 unsigned char * read_file(const char *, size_t *);
48 #endif
49 
50 extern int DebugVe;
51 
52 #define DEBUG_PRINTF(n, x) if (DebugVe >= n) printf x
53 
54 int ve_trust_init(void);
55 size_t ve_trust_anchors_add_buf(unsigned char *, size_t);
56 size_t ve_trust_anchors_revoke(unsigned char *, size_t);
57 int ve_trust_add(const char *);
58 void ve_debug_set(int);
59 void ve_anchor_verbose_set(int);
60 int ve_anchor_verbose_get(void);
61 void ve_utc_set(time_t utc);
62 char *ve_error_get(void);
63 int ve_error_set(const char *, ...) __printflike(1,2);
64 int  ve_self_tests(void);
65 
66 void fingerprint_info_add(const char *, const char *, const char *,
67     const char *, struct stat *);
68 
69 int ve_check_hash(br_hash_compat_context *, const br_hash_class *,
70     const char *, const char *, size_t);
71 
72 struct vectx;
73 struct vectx* vectx_open(int, const char *, off_t, struct stat *, int *);
74 ssize_t vectx_read(struct vectx *, void *, size_t);
75 off_t vectx_lseek(struct vectx *, off_t, int);
76 int vectx_close(struct vectx *);
77 
78 char * hexdigest(char *, size_t, unsigned char *, size_t);
79 int  verify_fd(int, const char *, off_t, struct stat *);
80 int  verify_open(const char *, int);
81 
82 unsigned char *verify_signed(const char *, int);
83 unsigned char *verify_sig(const char *, int);
84 unsigned char *verify_asc(const char *, int); /* OpenPGP */
85 
86 void ve_pcr_init(void);
87 void ve_pcr_update(unsigned char *, size_t);
88 ssize_t ve_pcr_get(unsigned char *, size_t);
89 int ve_pcr_updating_get(void);
90 void ve_pcr_updating_set(int);
91 
92 /* flags for verify_{asc,sig,signed} */
93 #define VEF_VERBOSE		1
94 
95 #define VE_FINGERPRINT_OK	1
96 #define VE_FINGERPRINT_IGNORE	2
97 /* errors from verify_fd */
98 #define VE_FINGERPRINT_NONE	-2
99 #define VE_FINGERPRINT_WRONG	-3
100 #define VE_FINGERPRINT_UNKNOWN	-4	/* may not be an error */
101 
102 #endif	/* _LIBSECUREBOOT_H_ */
103