diff options
author | nicoo <nicoo@debian.org> | 2020-02-12 13:42:22 +0100 |
---|---|---|
committer | Nicolas Braud-Santoni <nicolas@braud-santoni.eu> | 2020-02-12 13:42:22 +0100 |
commit | c79050aa44b8836d836c5dd22a383a073c28b74b (patch) | |
tree | 7bcca9fabd7718bf87ca600a6594f57b76d8de7d /fuzz/fuzz_bio.c |
Import upstream release 1.3.0
Closes: #951184
Diffstat (limited to 'fuzz/fuzz_bio.c')
-rw-r--r-- | fuzz/fuzz_bio.c | 755 |
1 files changed, 755 insertions, 0 deletions
diff --git a/fuzz/fuzz_bio.c b/fuzz/fuzz_bio.c new file mode 100644 index 0000000..f1596a7 --- /dev/null +++ b/fuzz/fuzz_bio.c | |||
@@ -0,0 +1,755 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2019 Yubico AB. All rights reserved. | ||
3 | * Use of this source code is governed by a BSD-style | ||
4 | * license that can be found in the LICENSE file. | ||
5 | */ | ||
6 | |||
7 | #include <assert.h> | ||
8 | #include <stdint.h> | ||
9 | #include <stdlib.h> | ||
10 | #include <string.h> | ||
11 | #include <stdio.h> | ||
12 | |||
13 | #include "mutator_aux.h" | ||
14 | #include "fido.h" | ||
15 | #include "fido/bio.h" | ||
16 | |||
17 | #include "../openbsd-compat/openbsd-compat.h" | ||
18 | |||
19 | #define TAG_PIN 0x01 | ||
20 | #define TAG_NAME 0x02 | ||
21 | #define TAG_SEED 0x03 | ||
22 | #define TAG_ID 0x04 | ||
23 | #define TAG_INFO_WIRE_DATA 0x05 | ||
24 | #define TAG_ENROLL_WIRE_DATA 0x06 | ||
25 | #define TAG_LIST_WIRE_DATA 0x07 | ||
26 | #define TAG_SET_NAME_WIRE_DATA 0x08 | ||
27 | #define TAG_REMOVE_WIRE_DATA 0x09 | ||
28 | |||
29 | /* Parameter set defining a FIDO2 credential management operation. */ | ||
30 | struct param { | ||
31 | char pin[MAXSTR]; | ||
32 | char name[MAXSTR]; | ||
33 | int seed; | ||
34 | struct blob id; | ||
35 | struct blob info_wire_data; | ||
36 | struct blob enroll_wire_data; | ||
37 | struct blob list_wire_data; | ||
38 | struct blob set_name_wire_data; | ||
39 | struct blob remove_wire_data; | ||
40 | }; | ||
41 | |||
42 | /* Example parameters. */ | ||
43 | static const uint8_t dummy_id[] = { 0x5e, 0xd2, }; | ||
44 | static const char dummy_pin[] = "3Q;I){TAx"; | ||
45 | static const char dummy_name[] = "finger1"; | ||
46 | |||
47 | /* | ||
48 | * Collection of HID reports from an authenticator issued with a FIDO2 | ||
49 | * 'getFingerprintSensorInfo' bio enrollment command. | ||
50 | */ | ||
51 | static const uint8_t dummy_info_wire_data[] = { | ||
52 | 0xff, 0xff, 0xff, 0xff, 0x86, 0x00, 0x11, 0xf0, | ||
53 | 0x08, 0xc1, 0x8f, 0x76, 0x4b, 0x8f, 0xa9, 0x00, | ||
54 | 0x10, 0x00, 0x04, 0x02, 0x00, 0x04, 0x06, 0x05, | ||
55 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
56 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
57 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
58 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
59 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
60 | 0x00, 0x10, 0x00, 0x04, 0x90, 0x00, 0x06, 0x00, | ||
61 | 0xa2, 0x02, 0x01, 0x03, 0x04, 0x00, 0x00, 0x00, | ||
62 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
63 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
64 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
65 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
66 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
67 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
68 | }; | ||
69 | |||
70 | /* | ||
71 | * Collection of HID reports from an authenticator issued with FIDO2 | ||
72 | * 'enrollBegin' + 'enrollCaptureNextSample' bio enrollment commands. | ||
73 | */ | ||
74 | static const uint8_t dummy_enroll_wire_data[] = { | ||
75 | 0xff, 0xff, 0xff, 0xff, 0x86, 0x00, 0x11, 0x06, | ||
76 | 0xb4, 0xba, 0x2e, 0xb3, 0x88, 0x24, 0x38, 0x00, | ||
77 | 0x0a, 0x00, 0x05, 0x02, 0x00, 0x04, 0x06, 0x05, | ||
78 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
79 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
80 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
81 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
82 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
83 | 0x00, 0x0a, 0x00, 0x05, 0x90, 0x00, 0x51, 0x00, | ||
84 | 0xa1, 0x01, 0xa5, 0x01, 0x02, 0x03, 0x38, 0x18, | ||
85 | 0x20, 0x01, 0x21, 0x58, 0x20, 0xc9, 0x12, 0x01, | ||
86 | 0xab, 0x88, 0xd7, 0x0a, 0x24, 0xdd, 0xdc, 0xde, | ||
87 | 0x16, 0x27, 0x50, 0x77, 0x37, 0x06, 0xd3, 0x48, | ||
88 | 0xe6, 0xf9, 0xdb, 0xaa, 0x10, 0x83, 0x81, 0xac, | ||
89 | 0x13, 0x3c, 0xf9, 0x77, 0x2d, 0x22, 0x58, 0x20, | ||
90 | 0xda, 0x20, 0x71, 0x03, 0x01, 0x40, 0xac, 0xd0, | ||
91 | 0x00, 0x0a, 0x00, 0x05, 0x00, 0xb8, 0xdf, 0x2a, | ||
92 | 0x95, 0xd3, 0x88, 0x1c, 0x06, 0x34, 0x30, 0xf1, | ||
93 | 0xf3, 0xcd, 0x27, 0x40, 0x90, 0x5c, 0xc6, 0x74, | ||
94 | 0x66, 0xff, 0x10, 0xde, 0xb6, 0x00, 0x00, 0x00, | ||
95 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
96 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
97 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
98 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
99 | 0x00, 0x0a, 0x00, 0x05, 0x90, 0x00, 0x14, 0x00, | ||
100 | 0xa1, 0x02, 0x50, 0x18, 0x81, 0xff, 0xf2, 0xf5, | ||
101 | 0xde, 0x74, 0x43, 0xd5, 0xe0, 0x77, 0x37, 0x6b, | ||
102 | 0x6c, 0x18, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
103 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
104 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
105 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
106 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
107 | 0x00, 0x0a, 0x00, 0x05, 0xbb, 0x00, 0x01, 0x02, | ||
108 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
109 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
110 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
111 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
112 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
113 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
114 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
115 | 0x00, 0x0a, 0x00, 0x05, 0xbb, 0x00, 0x01, 0x02, | ||
116 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
117 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
118 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
119 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
120 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
121 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
122 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
123 | 0x00, 0x0a, 0x00, 0x05, 0xbb, 0x00, 0x01, 0x02, | ||
124 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
125 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
126 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
127 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
128 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
129 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
130 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
131 | 0x00, 0x0a, 0x00, 0x05, 0xbb, 0x00, 0x01, 0x02, | ||
132 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
133 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
134 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
135 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
136 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
137 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
138 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
139 | 0x00, 0x0a, 0x00, 0x05, 0xbb, 0x00, 0x01, 0x02, | ||
140 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
141 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
142 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
143 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
144 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
145 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
146 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
147 | 0x00, 0x0a, 0x00, 0x05, 0xbb, 0x00, 0x01, 0x02, | ||
148 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
149 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
150 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
151 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
152 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
153 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
154 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
155 | 0x00, 0x0a, 0x00, 0x05, 0xbb, 0x00, 0x01, 0x02, | ||
156 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
157 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
158 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
159 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
160 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
161 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
162 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
163 | 0x00, 0x0a, 0x00, 0x05, 0xbb, 0x00, 0x01, 0x02, | ||
164 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
165 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
166 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
167 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
168 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
169 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
170 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
171 | 0x00, 0x0a, 0x00, 0x05, 0xbb, 0x00, 0x01, 0x02, | ||
172 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
173 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
174 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
175 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
176 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
177 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
178 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
179 | 0x00, 0x0a, 0x00, 0x05, 0xbb, 0x00, 0x01, 0x02, | ||
180 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
181 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
182 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
183 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
184 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
185 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
186 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
187 | 0x00, 0x0a, 0x00, 0x05, 0x90, 0x00, 0x0a, 0x00, | ||
188 | 0xa3, 0x04, 0x42, 0x68, 0x96, 0x05, 0x00, 0x06, | ||
189 | 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
190 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
191 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
192 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
193 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
194 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
195 | 0x00, 0x0a, 0x00, 0x05, 0xbb, 0x00, 0x01, 0x02, | ||
196 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
197 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
198 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
199 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
200 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
201 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
202 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
203 | 0x00, 0x0a, 0x00, 0x05, 0xbb, 0x00, 0x01, 0x02, | ||
204 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
205 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
206 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
207 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
208 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
209 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
210 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
211 | 0x00, 0x0a, 0x00, 0x05, 0xbb, 0x00, 0x01, 0x02, | ||
212 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
213 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
214 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
215 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
216 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
217 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
218 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
219 | 0x00, 0x0a, 0x00, 0x05, 0xbb, 0x00, 0x01, 0x02, | ||
220 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
221 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
222 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
223 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
224 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
225 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
226 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
227 | 0x00, 0x0a, 0x00, 0x05, 0xbb, 0x00, 0x01, 0x02, | ||
228 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
229 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
230 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
231 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
232 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
233 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
234 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
235 | 0x00, 0x0a, 0x00, 0x05, 0x90, 0x00, 0x06, 0x00, | ||
236 | 0xa2, 0x05, 0x00, 0x06, 0x01, 0x00, 0x00, 0x00, | ||
237 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
238 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
239 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
240 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
241 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
242 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
243 | 0x00, 0x0a, 0x00, 0x05, 0xbb, 0x00, 0x01, 0x02, | ||
244 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
245 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
246 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
247 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
248 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
249 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
250 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
251 | 0x00, 0x0a, 0x00, 0x05, 0xbb, 0x00, 0x01, 0x02, | ||
252 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
253 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
254 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
255 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
256 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
257 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
258 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
259 | 0x00, 0x0a, 0x00, 0x05, 0xbb, 0x00, 0x01, 0x02, | ||
260 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
261 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
262 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
263 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
264 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
265 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
266 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
267 | 0x00, 0x0a, 0x00, 0x05, 0xbb, 0x00, 0x01, 0x02, | ||
268 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
269 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
270 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
271 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
272 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
273 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
274 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
275 | 0x00, 0x0a, 0x00, 0x05, 0xbb, 0x00, 0x01, 0x02, | ||
276 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
277 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
278 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
279 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
280 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
281 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
282 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
283 | 0x00, 0x0a, 0x00, 0x05, 0x90, 0x00, 0x06, 0x00, | ||
284 | 0xa2, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, | ||
285 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
286 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
287 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
288 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
289 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
290 | }; | ||
291 | |||
292 | /* | ||
293 | * Collection of HID reports from an authenticator issued with a FIDO2 | ||
294 | * 'enumerateEnrollments' bio enrollment command. | ||
295 | */ | ||
296 | static const uint8_t dummy_list_wire_data[] = { | ||
297 | 0xff, 0xff, 0xff, 0xff, 0x86, 0x00, 0x11, 0xae, | ||
298 | 0x21, 0x88, 0x51, 0x09, 0x6f, 0xd7, 0xbb, 0x00, | ||
299 | 0x10, 0x00, 0x0f, 0x02, 0x00, 0x04, 0x06, 0x05, | ||
300 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
301 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
302 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
303 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
304 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
305 | 0x00, 0x10, 0x00, 0x0f, 0x90, 0x00, 0x51, 0x00, | ||
306 | 0xa1, 0x01, 0xa5, 0x01, 0x02, 0x03, 0x38, 0x18, | ||
307 | 0x20, 0x01, 0x21, 0x58, 0x20, 0x5a, 0x70, 0x63, | ||
308 | 0x11, 0x5b, 0xa6, 0xe1, 0x8e, 0x4a, 0xb0, 0x75, | ||
309 | 0xe7, 0xfd, 0x39, 0x26, 0x29, 0xed, 0x69, 0xb0, | ||
310 | 0xc1, 0x1f, 0xa5, 0x7d, 0xcb, 0x64, 0x1e, 0x7c, | ||
311 | 0x9f, 0x60, 0x5e, 0xb2, 0xf8, 0x22, 0x58, 0x20, | ||
312 | 0xec, 0xe9, 0x1b, 0x11, 0xac, 0x2a, 0x0d, 0xd5, | ||
313 | 0x00, 0x10, 0x00, 0x0f, 0x00, 0x3b, 0x9f, 0xba, | ||
314 | 0x0f, 0x25, 0xd5, 0x24, 0x33, 0x4c, 0x5d, 0x0f, | ||
315 | 0x63, 0xbf, 0xf1, 0xf3, 0x64, 0x55, 0x78, 0x1a, | ||
316 | 0x59, 0x6e, 0x65, 0x59, 0xfc, 0x00, 0x00, 0x00, | ||
317 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
318 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
319 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
320 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
321 | 0x00, 0x10, 0x00, 0x0f, 0x90, 0x00, 0x14, 0x00, | ||
322 | 0xa1, 0x02, 0x50, 0xb9, 0x31, 0x34, 0xe2, 0x71, | ||
323 | 0x6a, 0x8e, 0xa3, 0x60, 0xec, 0x5e, 0xd2, 0x13, | ||
324 | 0x2e, 0x19, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
325 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
326 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
327 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
328 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
329 | 0x00, 0x10, 0x00, 0x0f, 0x90, 0x00, 0x2e, 0x00, | ||
330 | 0xa1, 0x07, 0x83, 0xa2, 0x01, 0x42, 0xce, 0xa3, | ||
331 | 0x02, 0x67, 0x66, 0x69, 0x6e, 0x67, 0x65, 0x72, | ||
332 | 0x31, 0xa2, 0x01, 0x42, 0xbf, 0x5e, 0x02, 0x67, | ||
333 | 0x66, 0x69, 0x6e, 0x67, 0x65, 0x72, 0x32, 0xa2, | ||
334 | 0x01, 0x42, 0x5e, 0xd2, 0x02, 0x67, 0x66, 0x69, | ||
335 | 0x6e, 0x67, 0x65, 0x72, 0x33, 0x00, 0x00, 0x00, | ||
336 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
337 | }; | ||
338 | |||
339 | /* | ||
340 | * Collection of HID reports from an authenticator issued with a FIDO2 | ||
341 | * 'setFriendlyName' bio enrollment command. | ||
342 | */ | ||
343 | static const uint8_t dummy_set_name_wire_data[] = { | ||
344 | 0xff, 0xff, 0xff, 0xff, 0x86, 0x00, 0x11, 0xac, | ||
345 | 0x48, 0xfd, 0xbd, 0xdd, 0x36, 0x24, 0x4d, 0x00, | ||
346 | 0x10, 0x00, 0x10, 0x02, 0x00, 0x04, 0x06, 0x05, | ||
347 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
348 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
349 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
350 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
351 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
352 | 0x00, 0x10, 0x00, 0x10, 0x90, 0x00, 0x51, 0x00, | ||
353 | 0xa1, 0x01, 0xa5, 0x01, 0x02, 0x03, 0x38, 0x18, | ||
354 | 0x20, 0x01, 0x21, 0x58, 0x20, 0x5a, 0x70, 0x63, | ||
355 | 0x11, 0x5b, 0xa6, 0xe1, 0x8e, 0x4a, 0xb0, 0x75, | ||
356 | 0xe7, 0xfd, 0x39, 0x26, 0x29, 0xed, 0x69, 0xb0, | ||
357 | 0xc1, 0x1f, 0xa5, 0x7d, 0xcb, 0x64, 0x1e, 0x7c, | ||
358 | 0x9f, 0x60, 0x5e, 0xb2, 0xf8, 0x22, 0x58, 0x20, | ||
359 | 0xec, 0xe9, 0x1b, 0x11, 0xac, 0x2a, 0x0d, 0xd5, | ||
360 | 0x00, 0x10, 0x00, 0x10, 0x00, 0x3b, 0x9f, 0xba, | ||
361 | 0x0f, 0x25, 0xd5, 0x24, 0x33, 0x4c, 0x5d, 0x0f, | ||
362 | 0x63, 0xbf, 0xf1, 0xf3, 0x64, 0x55, 0x78, 0x1a, | ||
363 | 0x59, 0x6e, 0x65, 0x59, 0xfc, 0x00, 0x00, 0x00, | ||
364 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
365 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
366 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
367 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
368 | 0x00, 0x10, 0x00, 0x10, 0x90, 0x00, 0x14, 0x00, | ||
369 | 0xa1, 0x02, 0x50, 0x40, 0x95, 0xf3, 0xcb, 0xae, | ||
370 | 0xf2, 0x8d, 0xd9, 0xe0, 0xe0, 0x8a, 0xbd, 0xc3, | ||
371 | 0x03, 0x58, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
372 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
373 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
374 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
375 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
376 | 0x00, 0x10, 0x00, 0x10, 0x90, 0x00, 0x01, 0x00, | ||
377 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
378 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
379 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
380 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
381 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
382 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
383 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
384 | }; | ||
385 | |||
386 | /* | ||
387 | * Collection of HID reports from an authenticator issued with a FIDO2 | ||
388 | * 'removeEnrollment' bio enrollment command. | ||
389 | */ | ||
390 | static const uint8_t dummy_remove_wire_data[] = { | ||
391 | 0xff, 0xff, 0xff, 0xff, 0x86, 0x00, 0x11, 0x4b, | ||
392 | 0x24, 0xde, 0xd9, 0x06, 0x57, 0x1a, 0xbd, 0x00, | ||
393 | 0x10, 0x00, 0x15, 0x02, 0x00, 0x04, 0x06, 0x05, | ||
394 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
395 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
396 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
397 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
398 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
399 | 0x00, 0x10, 0x00, 0x15, 0x90, 0x00, 0x51, 0x00, | ||
400 | 0xa1, 0x01, 0xa5, 0x01, 0x02, 0x03, 0x38, 0x18, | ||
401 | 0x20, 0x01, 0x21, 0x58, 0x20, 0x5a, 0x70, 0x63, | ||
402 | 0x11, 0x5b, 0xa6, 0xe1, 0x8e, 0x4a, 0xb0, 0x75, | ||
403 | 0xe7, 0xfd, 0x39, 0x26, 0x29, 0xed, 0x69, 0xb0, | ||
404 | 0xc1, 0x1f, 0xa5, 0x7d, 0xcb, 0x64, 0x1e, 0x7c, | ||
405 | 0x9f, 0x60, 0x5e, 0xb2, 0xf8, 0x22, 0x58, 0x20, | ||
406 | 0xec, 0xe9, 0x1b, 0x11, 0xac, 0x2a, 0x0d, 0xd5, | ||
407 | 0x00, 0x10, 0x00, 0x15, 0x00, 0x3b, 0x9f, 0xba, | ||
408 | 0x0f, 0x25, 0xd5, 0x24, 0x33, 0x4c, 0x5d, 0x0f, | ||
409 | 0x63, 0xbf, 0xf1, 0xf3, 0x64, 0x55, 0x78, 0x1a, | ||
410 | 0x59, 0x6e, 0x65, 0x59, 0xfc, 0x00, 0x00, 0x00, | ||
411 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
412 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
413 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
414 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
415 | 0x00, 0x10, 0x00, 0x15, 0x90, 0x00, 0x14, 0x00, | ||
416 | 0xa1, 0x02, 0x50, 0xb0, 0xd0, 0x71, 0x2f, 0xa7, | ||
417 | 0x8b, 0x89, 0xbd, 0xca, 0xa4, 0x1e, 0x6c, 0x43, | ||
418 | 0xa1, 0x71, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
419 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
420 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
421 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
422 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
423 | 0x00, 0x10, 0x00, 0x15, 0x90, 0x00, 0x01, 0x00, | ||
424 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
425 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
426 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
427 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
428 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
429 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
430 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
431 | }; | ||
432 | |||
433 | int LLVMFuzzerTestOneInput(const uint8_t *, size_t); | ||
434 | size_t LLVMFuzzerCustomMutator(uint8_t *, size_t, size_t, unsigned int); | ||
435 | |||
436 | static int | ||
437 | unpack(const uint8_t *ptr, size_t len, struct param *p) NO_MSAN | ||
438 | { | ||
439 | uint8_t **pp = (void *)&ptr; | ||
440 | |||
441 | if (unpack_string(TAG_PIN, pp, &len, p->pin) < 0 || | ||
442 | unpack_string(TAG_NAME, pp, &len, p->name) < 0 || | ||
443 | unpack_int(TAG_SEED, pp, &len, &p->seed) < 0 || | ||
444 | unpack_blob(TAG_ID, pp, &len, &p->id) < 0 || | ||
445 | unpack_blob(TAG_INFO_WIRE_DATA, pp, &len, &p->info_wire_data) < 0 || | ||
446 | unpack_blob(TAG_ENROLL_WIRE_DATA, pp, &len, &p->enroll_wire_data) < 0 || | ||
447 | unpack_blob(TAG_LIST_WIRE_DATA, pp, &len, &p->list_wire_data) < 0 || | ||
448 | unpack_blob(TAG_SET_NAME_WIRE_DATA, pp, &len, &p->set_name_wire_data) < 0 || | ||
449 | unpack_blob(TAG_REMOVE_WIRE_DATA, pp, &len, &p->remove_wire_data) < 0) | ||
450 | return (-1); | ||
451 | |||
452 | return (0); | ||
453 | } | ||
454 | |||
455 | static size_t | ||
456 | pack(uint8_t *ptr, size_t len, const struct param *p) | ||
457 | { | ||
458 | const size_t max = len; | ||
459 | |||
460 | if (pack_string(TAG_PIN, &ptr, &len, p->pin) < 0 || | ||
461 | pack_string(TAG_NAME, &ptr, &len, p->name) < 0 || | ||
462 | pack_int(TAG_SEED, &ptr, &len, p->seed) < 0 || | ||
463 | pack_blob(TAG_ID, &ptr, &len, &p->id) < 0 || | ||
464 | pack_blob(TAG_INFO_WIRE_DATA, &ptr, &len, &p->info_wire_data) < 0 || | ||
465 | pack_blob(TAG_ENROLL_WIRE_DATA, &ptr, &len, &p->enroll_wire_data) < 0 || | ||
466 | pack_blob(TAG_LIST_WIRE_DATA, &ptr, &len, &p->list_wire_data) < 0 || | ||
467 | pack_blob(TAG_SET_NAME_WIRE_DATA, &ptr, &len, &p->set_name_wire_data) < 0 || | ||
468 | pack_blob(TAG_REMOVE_WIRE_DATA, &ptr, &len, &p->remove_wire_data) < 0) | ||
469 | return (0); | ||
470 | |||
471 | return (max - len); | ||
472 | } | ||
473 | |||
474 | static fido_dev_t * | ||
475 | prepare_dev() | ||
476 | { | ||
477 | fido_dev_t *dev; | ||
478 | fido_dev_io_t io; | ||
479 | |||
480 | io.open = dev_open; | ||
481 | io.close = dev_close; | ||
482 | io.read = dev_read; | ||
483 | io.write = dev_write; | ||
484 | |||
485 | if ((dev = fido_dev_new()) == NULL || fido_dev_set_io_functions(dev, | ||
486 | &io) != FIDO_OK || fido_dev_open(dev, "nodev") != FIDO_OK) { | ||
487 | fido_dev_free(&dev); | ||
488 | return (NULL); | ||
489 | } | ||
490 | |||
491 | return (dev); | ||
492 | } | ||
493 | |||
494 | static void | ||
495 | get_info(struct param *p) | ||
496 | { | ||
497 | fido_dev_t *dev = NULL; | ||
498 | fido_bio_info_t *i = NULL; | ||
499 | uint8_t type; | ||
500 | uint8_t max_samples; | ||
501 | |||
502 | set_wire_data(p->info_wire_data.body, p->info_wire_data.len); | ||
503 | |||
504 | if ((dev = prepare_dev()) == NULL || (i = fido_bio_info_new()) == NULL) | ||
505 | goto done; | ||
506 | |||
507 | fido_bio_dev_get_info(dev, i); | ||
508 | |||
509 | type = fido_bio_info_type(i); | ||
510 | max_samples = fido_bio_info_max_samples(i); | ||
511 | consume(&type, sizeof(type)); | ||
512 | consume(&max_samples, sizeof(max_samples)); | ||
513 | |||
514 | done: | ||
515 | if (dev) | ||
516 | fido_dev_close(dev); | ||
517 | |||
518 | fido_dev_free(&dev); | ||
519 | fido_bio_info_free(&i); | ||
520 | } | ||
521 | |||
522 | static void | ||
523 | consume_template(const fido_bio_template_t *t) | ||
524 | { | ||
525 | consume(fido_bio_template_name(t), xstrlen(fido_bio_template_name(t))); | ||
526 | consume(fido_bio_template_id_ptr(t), fido_bio_template_id_len(t)); | ||
527 | } | ||
528 | |||
529 | static void | ||
530 | consume_enroll(fido_bio_enroll_t *e) | ||
531 | { | ||
532 | uint8_t last_status; | ||
533 | uint8_t remaining_samples; | ||
534 | |||
535 | last_status = fido_bio_enroll_last_status(e); | ||
536 | remaining_samples = fido_bio_enroll_remaining_samples(e); | ||
537 | consume(&last_status, sizeof(last_status)); | ||
538 | consume(&remaining_samples, sizeof(remaining_samples)); | ||
539 | } | ||
540 | |||
541 | static void | ||
542 | enroll(struct param *p) | ||
543 | { | ||
544 | fido_dev_t *dev = NULL; | ||
545 | fido_bio_template_t *t = NULL; | ||
546 | fido_bio_enroll_t *e = NULL; | ||
547 | size_t cnt = 0; | ||
548 | |||
549 | set_wire_data(p->enroll_wire_data.body, p->enroll_wire_data.len); | ||
550 | |||
551 | if ((dev = prepare_dev()) == NULL || | ||
552 | (t = fido_bio_template_new()) == NULL || | ||
553 | (e = fido_bio_enroll_new()) == NULL) | ||
554 | goto done; | ||
555 | |||
556 | fido_bio_dev_enroll_begin(dev, t, e, p->seed, p->pin); | ||
557 | |||
558 | consume_template(t); | ||
559 | consume_enroll(e); | ||
560 | |||
561 | while (fido_bio_enroll_remaining_samples(e) > 0 && cnt++ < 5) { | ||
562 | fido_bio_dev_enroll_continue(dev, t, e, p->seed); | ||
563 | consume_template(t); | ||
564 | consume_enroll(e); | ||
565 | } | ||
566 | |||
567 | done: | ||
568 | if (dev) | ||
569 | fido_dev_close(dev); | ||
570 | |||
571 | fido_dev_free(&dev); | ||
572 | fido_bio_template_free(&t); | ||
573 | fido_bio_enroll_free(&e); | ||
574 | } | ||
575 | |||
576 | static void | ||
577 | list(struct param *p) | ||
578 | { | ||
579 | fido_dev_t *dev = NULL; | ||
580 | fido_bio_template_array_t *ta = NULL; | ||
581 | const fido_bio_template_t *t = NULL; | ||
582 | |||
583 | set_wire_data(p->list_wire_data.body, p->list_wire_data.len); | ||
584 | |||
585 | if ((dev = prepare_dev()) == NULL || | ||
586 | (ta = fido_bio_template_array_new()) == NULL) | ||
587 | goto done; | ||
588 | |||
589 | fido_bio_dev_get_template_array(dev, ta, p->pin); | ||
590 | |||
591 | /* +1 on purpose */ | ||
592 | for (size_t i = 0; i < fido_bio_template_array_count(ta) + 1; i++) | ||
593 | if ((t = fido_bio_template(ta, i)) != NULL) | ||
594 | consume_template(t); | ||
595 | |||
596 | done: | ||
597 | if (dev) | ||
598 | fido_dev_close(dev); | ||
599 | |||
600 | fido_dev_free(&dev); | ||
601 | fido_bio_template_array_free(&ta); | ||
602 | } | ||
603 | |||
604 | static void | ||
605 | set_name(struct param *p) | ||
606 | { | ||
607 | fido_dev_t *dev = NULL; | ||
608 | fido_bio_template_t *t = NULL; | ||
609 | |||
610 | set_wire_data(p->set_name_wire_data.body, p->set_name_wire_data.len); | ||
611 | |||
612 | if ((dev = prepare_dev()) == NULL || | ||
613 | (t = fido_bio_template_new()) == NULL) | ||
614 | goto done; | ||
615 | |||
616 | fido_bio_template_set_name(t, p->name); | ||
617 | fido_bio_template_set_id(t, p->id.body, p->id.len); | ||
618 | consume_template(t); | ||
619 | |||
620 | fido_bio_dev_set_template_name(dev, t, p->pin); | ||
621 | |||
622 | done: | ||
623 | if (dev) | ||
624 | fido_dev_close(dev); | ||
625 | |||
626 | fido_dev_free(&dev); | ||
627 | fido_bio_template_free(&t); | ||
628 | } | ||
629 | |||
630 | static void | ||
631 | del(struct param *p) | ||
632 | { | ||
633 | fido_dev_t *dev = NULL; | ||
634 | fido_bio_template_t *t = NULL; | ||
635 | |||
636 | set_wire_data(p->remove_wire_data.body, p->remove_wire_data.len); | ||
637 | |||
638 | if ((dev = prepare_dev()) == NULL || | ||
639 | (t = fido_bio_template_new()) == NULL) | ||
640 | goto done; | ||
641 | |||
642 | fido_bio_template_set_id(t, p->id.body, p->id.len); | ||
643 | consume_template(t); | ||
644 | |||
645 | fido_bio_dev_enroll_remove(dev, t, p->pin); | ||
646 | |||
647 | done: | ||
648 | if (dev) | ||
649 | fido_dev_close(dev); | ||
650 | |||
651 | fido_dev_free(&dev); | ||
652 | fido_bio_template_free(&t); | ||
653 | } | ||
654 | |||
655 | int | ||
656 | LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) | ||
657 | { | ||
658 | struct param p; | ||
659 | |||
660 | memset(&p, 0, sizeof(p)); | ||
661 | |||
662 | if (unpack(data, size, &p) < 0) | ||
663 | return (0); | ||
664 | |||
665 | srandom((unsigned int)p.seed); | ||
666 | |||
667 | fido_init(0); | ||
668 | |||
669 | get_info(&p); | ||
670 | enroll(&p); | ||
671 | list(&p); | ||
672 | set_name(&p); | ||
673 | del(&p); | ||
674 | |||
675 | return (0); | ||
676 | } | ||
677 | |||
678 | static size_t | ||
679 | pack_dummy(uint8_t *ptr, size_t len) | ||
680 | { | ||
681 | struct param dummy; | ||
682 | uint8_t blob[32768]; | ||
683 | size_t blob_len; | ||
684 | |||
685 | memset(&dummy, 0, sizeof(dummy)); | ||
686 | |||
687 | strlcpy(dummy.pin, dummy_pin, sizeof(dummy.pin)); | ||
688 | strlcpy(dummy.name, dummy_name, sizeof(dummy.name)); | ||
689 | |||
690 | dummy.info_wire_data.len = sizeof(dummy_info_wire_data); | ||
691 | dummy.enroll_wire_data.len = sizeof(dummy_enroll_wire_data); | ||
692 | dummy.list_wire_data.len = sizeof(dummy_list_wire_data); | ||
693 | dummy.set_name_wire_data.len = sizeof(dummy_set_name_wire_data); | ||
694 | dummy.remove_wire_data.len = sizeof(dummy_remove_wire_data); | ||
695 | dummy.id.len = sizeof(dummy_id); | ||
696 | |||
697 | memcpy(&dummy.info_wire_data.body, &dummy_info_wire_data, | ||
698 | dummy.info_wire_data.len); | ||
699 | memcpy(&dummy.enroll_wire_data.body, &dummy_enroll_wire_data, | ||
700 | dummy.enroll_wire_data.len); | ||
701 | memcpy(&dummy.list_wire_data.body, &dummy_list_wire_data, | ||
702 | dummy.list_wire_data.len); | ||
703 | memcpy(&dummy.set_name_wire_data.body, &dummy_set_name_wire_data, | ||
704 | dummy.set_name_wire_data.len); | ||
705 | memcpy(&dummy.remove_wire_data.body, &dummy_remove_wire_data, | ||
706 | dummy.remove_wire_data.len); | ||
707 | memcpy(&dummy.id.body, &dummy_id, dummy.id.len); | ||
708 | |||
709 | blob_len = pack(blob, sizeof(blob), &dummy); | ||
710 | assert(blob_len != 0); | ||
711 | |||
712 | if (blob_len > len) { | ||
713 | memcpy(ptr, blob, len); | ||
714 | return (len); | ||
715 | } | ||
716 | |||
717 | memcpy(ptr, blob, blob_len); | ||
718 | |||
719 | return (blob_len); | ||
720 | } | ||
721 | |||
722 | size_t | ||
723 | LLVMFuzzerCustomMutator(uint8_t *data, size_t size, size_t maxsize, | ||
724 | unsigned int seed) NO_MSAN | ||
725 | { | ||
726 | struct param p; | ||
727 | uint8_t blob[16384]; | ||
728 | size_t blob_len; | ||
729 | |||
730 | memset(&p, 0, sizeof(p)); | ||
731 | |||
732 | if (unpack(data, size, &p) < 0) | ||
733 | return (pack_dummy(data, maxsize)); | ||
734 | |||
735 | p.seed = (int)seed; | ||
736 | |||
737 | mutate_blob(&p.id); | ||
738 | mutate_blob(&p.info_wire_data); | ||
739 | mutate_blob(&p.enroll_wire_data); | ||
740 | mutate_blob(&p.list_wire_data); | ||
741 | mutate_blob(&p.set_name_wire_data); | ||
742 | mutate_blob(&p.remove_wire_data); | ||
743 | |||
744 | mutate_string(p.pin); | ||
745 | mutate_string(p.name); | ||
746 | |||
747 | blob_len = pack(blob, sizeof(blob), &p); | ||
748 | |||
749 | if (blob_len == 0 || blob_len > maxsize) | ||
750 | return (0); | ||
751 | |||
752 | memcpy(data, blob, blob_len); | ||
753 | |||
754 | return (blob_len); | ||
755 | } | ||