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 /regress/cred.c |
Import upstream release 1.3.0
Closes: #951184
Diffstat (limited to 'regress/cred.c')
-rw-r--r-- | regress/cred.c | 816 |
1 files changed, 816 insertions, 0 deletions
diff --git a/regress/cred.c b/regress/cred.c new file mode 100644 index 0000000..4998649 --- /dev/null +++ b/regress/cred.c | |||
@@ -0,0 +1,816 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2018 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 <fido.h> | ||
9 | #include <string.h> | ||
10 | |||
11 | #define FAKE_DEV_HANDLE ((void *)0xdeadbeef) | ||
12 | |||
13 | static const unsigned char cdh[32] = { | ||
14 | 0xf9, 0x64, 0x57, 0xe7, 0x2d, 0x97, 0xf6, 0xbb, | ||
15 | 0xdd, 0xd7, 0xfb, 0x06, 0x37, 0x62, 0xea, 0x26, | ||
16 | 0x20, 0x44, 0x8e, 0x69, 0x7c, 0x03, 0xf2, 0x31, | ||
17 | 0x2f, 0x99, 0xdc, 0xaf, 0x3e, 0x8a, 0x91, 0x6b, | ||
18 | }; | ||
19 | |||
20 | static const unsigned char authdata[198] = { | ||
21 | 0x58, 0xc4, 0x49, 0x96, 0x0d, 0xe5, 0x88, 0x0e, | ||
22 | 0x8c, 0x68, 0x74, 0x34, 0x17, 0x0f, 0x64, 0x76, | ||
23 | 0x60, 0x5b, 0x8f, 0xe4, 0xae, 0xb9, 0xa2, 0x86, | ||
24 | 0x32, 0xc7, 0x99, 0x5c, 0xf3, 0xba, 0x83, 0x1d, | ||
25 | 0x97, 0x63, 0x41, 0x00, 0x00, 0x00, 0x00, 0xf8, | ||
26 | 0xa0, 0x11, 0xf3, 0x8c, 0x0a, 0x4d, 0x15, 0x80, | ||
27 | 0x06, 0x17, 0x11, 0x1f, 0x9e, 0xdc, 0x7d, 0x00, | ||
28 | 0x40, 0x53, 0xfb, 0xdf, 0xaa, 0xce, 0x63, 0xde, | ||
29 | 0xc5, 0xfe, 0x47, 0xe6, 0x52, 0xeb, 0xf3, 0x5d, | ||
30 | 0x53, 0xa8, 0xbf, 0x9d, 0xd6, 0x09, 0x6b, 0x5e, | ||
31 | 0x7f, 0xe0, 0x0d, 0x51, 0x30, 0x85, 0x6a, 0xda, | ||
32 | 0x68, 0x70, 0x85, 0xb0, 0xdb, 0x08, 0x0b, 0x83, | ||
33 | 0x2c, 0xef, 0x44, 0xe2, 0x36, 0x88, 0xee, 0x76, | ||
34 | 0x90, 0x6e, 0x7b, 0x50, 0x3e, 0x9a, 0xa0, 0xd6, | ||
35 | 0x3c, 0x34, 0xe3, 0x83, 0xe7, 0xd1, 0xbd, 0x9f, | ||
36 | 0x25, 0xa5, 0x01, 0x02, 0x03, 0x26, 0x20, 0x01, | ||
37 | 0x21, 0x58, 0x20, 0x17, 0x5b, 0x27, 0xa6, 0x56, | ||
38 | 0xb2, 0x26, 0x0c, 0x26, 0x0c, 0x55, 0x42, 0x78, | ||
39 | 0x17, 0x5d, 0x4c, 0xf8, 0xa2, 0xfd, 0x1b, 0xb9, | ||
40 | 0x54, 0xdf, 0xd5, 0xeb, 0xbf, 0x22, 0x64, 0xf5, | ||
41 | 0x21, 0x9a, 0xc6, 0x22, 0x58, 0x20, 0x87, 0x5f, | ||
42 | 0x90, 0xe6, 0xfd, 0x71, 0x27, 0x9f, 0xeb, 0xe3, | ||
43 | 0x03, 0x44, 0xbc, 0x8d, 0x49, 0xc6, 0x1c, 0x31, | ||
44 | 0x3b, 0x72, 0xae, 0xd4, 0x53, 0xb1, 0xfe, 0x5d, | ||
45 | 0xe1, 0x30, 0xfc, 0x2b, 0x1e, 0xd2, | ||
46 | }; | ||
47 | |||
48 | static const unsigned char authdata_dupkeys[200] = { | ||
49 | 0x58, 0xc6, 0x49, 0x96, 0x0d, 0xe5, 0x88, 0x0e, | ||
50 | 0x8c, 0x68, 0x74, 0x34, 0x17, 0x0f, 0x64, 0x76, | ||
51 | 0x60, 0x5b, 0x8f, 0xe4, 0xae, 0xb9, 0xa2, 0x86, | ||
52 | 0x32, 0xc7, 0x99, 0x5c, 0xf3, 0xba, 0x83, 0x1d, | ||
53 | 0x97, 0x63, 0x41, 0x00, 0x00, 0x00, 0x00, 0xf8, | ||
54 | 0xa0, 0x11, 0xf3, 0x8c, 0x0a, 0x4d, 0x15, 0x80, | ||
55 | 0x06, 0x17, 0x11, 0x1f, 0x9e, 0xdc, 0x7d, 0x00, | ||
56 | 0x40, 0x53, 0xfb, 0xdf, 0xaa, 0xce, 0x63, 0xde, | ||
57 | 0xc5, 0xfe, 0x47, 0xe6, 0x52, 0xeb, 0xf3, 0x5d, | ||
58 | 0x53, 0xa8, 0xbf, 0x9d, 0xd6, 0x09, 0x6b, 0x5e, | ||
59 | 0x7f, 0xe0, 0x0d, 0x51, 0x30, 0x85, 0x6a, 0xda, | ||
60 | 0x68, 0x70, 0x85, 0xb0, 0xdb, 0x08, 0x0b, 0x83, | ||
61 | 0x2c, 0xef, 0x44, 0xe2, 0x36, 0x88, 0xee, 0x76, | ||
62 | 0x90, 0x6e, 0x7b, 0x50, 0x3e, 0x9a, 0xa0, 0xd6, | ||
63 | 0x3c, 0x34, 0xe3, 0x83, 0xe7, 0xd1, 0xbd, 0x9f, | ||
64 | 0x25, 0xa6, 0x01, 0x02, 0x01, 0x02, 0x03, 0x26, | ||
65 | 0x20, 0x01, 0x21, 0x58, 0x20, 0x17, 0x5b, 0x27, | ||
66 | 0xa6, 0x56, 0xb2, 0x26, 0x0c, 0x26, 0x0c, 0x55, | ||
67 | 0x42, 0x78, 0x17, 0x5d, 0x4c, 0xf8, 0xa2, 0xfd, | ||
68 | 0x1b, 0xb9, 0x54, 0xdf, 0xd5, 0xeb, 0xbf, 0x22, | ||
69 | 0x64, 0xf5, 0x21, 0x9a, 0xc6, 0x22, 0x58, 0x20, | ||
70 | 0x87, 0x5f, 0x90, 0xe6, 0xfd, 0x71, 0x27, 0x9f, | ||
71 | 0xeb, 0xe3, 0x03, 0x44, 0xbc, 0x8d, 0x49, 0xc6, | ||
72 | 0x1c, 0x31, 0x3b, 0x72, 0xae, 0xd4, 0x53, 0xb1, | ||
73 | 0xfe, 0x5d, 0xe1, 0x30, 0xfc, 0x2b, 0x1e, 0xd2, | ||
74 | }; | ||
75 | |||
76 | static const unsigned char authdata_unsorted_keys[198] = { | ||
77 | 0x58, 0xc4, 0x49, 0x96, 0x0d, 0xe5, 0x88, 0x0e, | ||
78 | 0x8c, 0x68, 0x74, 0x34, 0x17, 0x0f, 0x64, 0x76, | ||
79 | 0x60, 0x5b, 0x8f, 0xe4, 0xae, 0xb9, 0xa2, 0x86, | ||
80 | 0x32, 0xc7, 0x99, 0x5c, 0xf3, 0xba, 0x83, 0x1d, | ||
81 | 0x97, 0x63, 0x41, 0x00, 0x00, 0x00, 0x00, 0xf8, | ||
82 | 0xa0, 0x11, 0xf3, 0x8c, 0x0a, 0x4d, 0x15, 0x80, | ||
83 | 0x06, 0x17, 0x11, 0x1f, 0x9e, 0xdc, 0x7d, 0x00, | ||
84 | 0x40, 0x53, 0xfb, 0xdf, 0xaa, 0xce, 0x63, 0xde, | ||
85 | 0xc5, 0xfe, 0x47, 0xe6, 0x52, 0xeb, 0xf3, 0x5d, | ||
86 | 0x53, 0xa8, 0xbf, 0x9d, 0xd6, 0x09, 0x6b, 0x5e, | ||
87 | 0x7f, 0xe0, 0x0d, 0x51, 0x30, 0x85, 0x6a, 0xda, | ||
88 | 0x68, 0x70, 0x85, 0xb0, 0xdb, 0x08, 0x0b, 0x83, | ||
89 | 0x2c, 0xef, 0x44, 0xe2, 0x36, 0x88, 0xee, 0x76, | ||
90 | 0x90, 0x6e, 0x7b, 0x50, 0x3e, 0x9a, 0xa0, 0xd6, | ||
91 | 0x3c, 0x34, 0xe3, 0x83, 0xe7, 0xd1, 0xbd, 0x9f, | ||
92 | 0x25, 0xa5, 0x03, 0x26, 0x01, 0x02, 0x20, 0x01, | ||
93 | 0x21, 0x58, 0x20, 0x17, 0x5b, 0x27, 0xa6, 0x56, | ||
94 | 0xb2, 0x26, 0x0c, 0x26, 0x0c, 0x55, 0x42, 0x78, | ||
95 | 0x17, 0x5d, 0x4c, 0xf8, 0xa2, 0xfd, 0x1b, 0xb9, | ||
96 | 0x54, 0xdf, 0xd5, 0xeb, 0xbf, 0x22, 0x64, 0xf5, | ||
97 | 0x21, 0x9a, 0xc6, 0x22, 0x58, 0x20, 0x87, 0x5f, | ||
98 | 0x90, 0xe6, 0xfd, 0x71, 0x27, 0x9f, 0xeb, 0xe3, | ||
99 | 0x03, 0x44, 0xbc, 0x8d, 0x49, 0xc6, 0x1c, 0x31, | ||
100 | 0x3b, 0x72, 0xae, 0xd4, 0x53, 0xb1, 0xfe, 0x5d, | ||
101 | 0xe1, 0x30, 0xfc, 0x2b, 0x1e, 0xd2, | ||
102 | }; | ||
103 | |||
104 | static const unsigned char x509[742] = { | ||
105 | 0x30, 0x82, 0x02, 0xe2, 0x30, 0x81, 0xcb, 0x02, | ||
106 | 0x01, 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, | ||
107 | 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, | ||
108 | 0x00, 0x30, 0x1d, 0x31, 0x1b, 0x30, 0x19, 0x06, | ||
109 | 0x03, 0x55, 0x04, 0x03, 0x13, 0x12, 0x59, 0x75, | ||
110 | 0x62, 0x69, 0x63, 0x6f, 0x20, 0x55, 0x32, 0x46, | ||
111 | 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, | ||
112 | 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x34, 0x30, 0x35, | ||
113 | 0x31, 0x35, 0x31, 0x32, 0x35, 0x38, 0x35, 0x34, | ||
114 | 0x5a, 0x17, 0x0d, 0x31, 0x34, 0x30, 0x36, 0x31, | ||
115 | 0x34, 0x31, 0x32, 0x35, 0x38, 0x35, 0x34, 0x5a, | ||
116 | 0x30, 0x1d, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x03, | ||
117 | 0x55, 0x04, 0x03, 0x13, 0x12, 0x59, 0x75, 0x62, | ||
118 | 0x69, 0x63, 0x6f, 0x20, 0x55, 0x32, 0x46, 0x20, | ||
119 | 0x54, 0x65, 0x73, 0x74, 0x20, 0x45, 0x45, 0x30, | ||
120 | 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, | ||
121 | 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, | ||
122 | 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, | ||
123 | 0x00, 0x04, 0xdb, 0x0a, 0xdb, 0xf5, 0x21, 0xc7, | ||
124 | 0x5c, 0xce, 0x63, 0xdc, 0xa6, 0xe1, 0xe8, 0x25, | ||
125 | 0x06, 0x0d, 0x94, 0xe6, 0x27, 0x54, 0x19, 0x4f, | ||
126 | 0x9d, 0x24, 0xaf, 0x26, 0x1a, 0xbe, 0xad, 0x99, | ||
127 | 0x44, 0x1f, 0x95, 0xa3, 0x71, 0x91, 0x0a, 0x3a, | ||
128 | 0x20, 0xe7, 0x3e, 0x91, 0x5e, 0x13, 0xe8, 0xbe, | ||
129 | 0x38, 0x05, 0x7a, 0xd5, 0x7a, 0xa3, 0x7e, 0x76, | ||
130 | 0x90, 0x8f, 0xaf, 0xe2, 0x8a, 0x94, 0xb6, 0x30, | ||
131 | 0xeb, 0x9d, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, | ||
132 | 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, | ||
133 | 0x00, 0x03, 0x82, 0x02, 0x01, 0x00, 0x95, 0x40, | ||
134 | 0x6b, 0x50, 0x61, 0x7d, 0xad, 0x84, 0xa3, 0xb4, | ||
135 | 0xeb, 0x88, 0x0f, 0xe3, 0x30, 0x0f, 0x2d, 0xa2, | ||
136 | 0x0a, 0x00, 0xd9, 0x25, 0x04, 0xee, 0x72, 0xfa, | ||
137 | 0x67, 0xdf, 0x58, 0x51, 0x0f, 0x0b, 0x47, 0x02, | ||
138 | 0x9c, 0x3e, 0x41, 0x29, 0x4a, 0x93, 0xac, 0x29, | ||
139 | 0x85, 0x89, 0x2d, 0xa4, 0x7a, 0x81, 0x32, 0x28, | ||
140 | 0x57, 0x71, 0x01, 0xef, 0xa8, 0x42, 0x88, 0x16, | ||
141 | 0x96, 0x37, 0x91, 0xd5, 0xdf, 0xe0, 0x8f, 0xc9, | ||
142 | 0x3c, 0x8d, 0xb0, 0xcd, 0x89, 0x70, 0x82, 0xec, | ||
143 | 0x79, 0xd3, 0xc6, 0x78, 0x73, 0x29, 0x32, 0xe5, | ||
144 | 0xab, 0x6c, 0xbd, 0x56, 0x9f, 0xd5, 0x45, 0x91, | ||
145 | 0xce, 0xc1, 0xdd, 0x8d, 0x64, 0xdc, 0xe9, 0x9c, | ||
146 | 0x1f, 0x5e, 0x3c, 0xd2, 0xaf, 0x51, 0xa5, 0x82, | ||
147 | 0x18, 0xaf, 0xe0, 0x37, 0xe7, 0x32, 0x9e, 0x76, | ||
148 | 0x05, 0x77, 0x02, 0x7b, 0xe6, 0x24, 0xa0, 0x31, | ||
149 | 0x56, 0x1b, 0xfd, 0x19, 0xc5, 0x71, 0xd3, 0xf0, | ||
150 | 0x9e, 0xc0, 0x73, 0x05, 0x4e, 0xbc, 0x85, 0xb8, | ||
151 | 0x53, 0x9e, 0xef, 0xc5, 0xbc, 0x9c, 0x56, 0xa3, | ||
152 | 0xba, 0xd9, 0x27, 0x6a, 0xbb, 0xa9, 0x7a, 0x40, | ||
153 | 0xd7, 0x47, 0x8b, 0x55, 0x72, 0x6b, 0xe3, 0xfe, | ||
154 | 0x28, 0x49, 0x71, 0x24, 0xf4, 0x8f, 0xf4, 0x20, | ||
155 | 0x81, 0xea, 0x38, 0xff, 0x7c, 0x0a, 0x4f, 0xdf, | ||
156 | 0x02, 0x82, 0x39, 0x81, 0x82, 0x3b, 0xca, 0x09, | ||
157 | 0xdd, 0xca, 0xaa, 0x0f, 0x27, 0xf5, 0xa4, 0x83, | ||
158 | 0x55, 0x6c, 0x9a, 0x39, 0x9b, 0x15, 0x3a, 0x16, | ||
159 | 0x63, 0xdc, 0x5b, 0xf9, 0xac, 0x5b, 0xbc, 0xf7, | ||
160 | 0x9f, 0xbe, 0x0f, 0x8a, 0xa2, 0x3c, 0x31, 0x13, | ||
161 | 0xa3, 0x32, 0x48, 0xca, 0x58, 0x87, 0xf8, 0x7b, | ||
162 | 0xa0, 0xa1, 0x0a, 0x6a, 0x60, 0x96, 0x93, 0x5f, | ||
163 | 0x5d, 0x26, 0x9e, 0x63, 0x1d, 0x09, 0xae, 0x9a, | ||
164 | 0x41, 0xe5, 0xbd, 0x08, 0x47, 0xfe, 0xe5, 0x09, | ||
165 | 0x9b, 0x20, 0xfd, 0x12, 0xe2, 0xe6, 0x40, 0x7f, | ||
166 | 0xba, 0x4a, 0x61, 0x33, 0x66, 0x0d, 0x0e, 0x73, | ||
167 | 0xdb, 0xb0, 0xd5, 0xa2, 0x9a, 0x9a, 0x17, 0x0d, | ||
168 | 0x34, 0x30, 0x85, 0x6a, 0x42, 0x46, 0x9e, 0xff, | ||
169 | 0x34, 0x8f, 0x5f, 0x87, 0x6c, 0x35, 0xe7, 0xa8, | ||
170 | 0x4d, 0x35, 0xeb, 0xc1, 0x41, 0xaa, 0x8a, 0xd2, | ||
171 | 0xda, 0x19, 0xaa, 0x79, 0xa2, 0x5f, 0x35, 0x2c, | ||
172 | 0xa0, 0xfd, 0x25, 0xd3, 0xf7, 0x9d, 0x25, 0x18, | ||
173 | 0x2d, 0xfa, 0xb4, 0xbc, 0xbb, 0x07, 0x34, 0x3c, | ||
174 | 0x8d, 0x81, 0xbd, 0xf4, 0xe9, 0x37, 0xdb, 0x39, | ||
175 | 0xe9, 0xd1, 0x45, 0x5b, 0x20, 0x41, 0x2f, 0x2d, | ||
176 | 0x27, 0x22, 0xdc, 0x92, 0x74, 0x8a, 0x92, 0xd5, | ||
177 | 0x83, 0xfd, 0x09, 0xfb, 0x13, 0x9b, 0xe3, 0x39, | ||
178 | 0x7a, 0x6b, 0x5c, 0xfa, 0xe6, 0x76, 0x9e, 0xe0, | ||
179 | 0xe4, 0xe3, 0xef, 0xad, 0xbc, 0xfd, 0x42, 0x45, | ||
180 | 0x9a, 0xd4, 0x94, 0xd1, 0x7e, 0x8d, 0xa7, 0xd8, | ||
181 | 0x05, 0xd5, 0xd3, 0x62, 0xcf, 0x15, 0xcf, 0x94, | ||
182 | 0x7d, 0x1f, 0x5b, 0x58, 0x20, 0x44, 0x20, 0x90, | ||
183 | 0x71, 0xbe, 0x66, 0xe9, 0x9a, 0xab, 0x74, 0x32, | ||
184 | 0x70, 0x53, 0x1d, 0x69, 0xed, 0x87, 0x66, 0xf4, | ||
185 | 0x09, 0x4f, 0xca, 0x25, 0x30, 0xc2, 0x63, 0x79, | ||
186 | 0x00, 0x3c, 0xb1, 0x9b, 0x39, 0x3f, 0x00, 0xe0, | ||
187 | 0xa8, 0x88, 0xef, 0x7a, 0x51, 0x5b, 0xe7, 0xbd, | ||
188 | 0x49, 0x64, 0xda, 0x41, 0x7b, 0x24, 0xc3, 0x71, | ||
189 | 0x22, 0xfd, 0xd1, 0xd1, 0x20, 0xb3, 0x3f, 0x97, | ||
190 | 0xd3, 0x97, 0xb2, 0xaa, 0x18, 0x1c, 0x9e, 0x03, | ||
191 | 0x77, 0x7b, 0x5b, 0x7e, 0xf9, 0xa3, 0xa0, 0xd6, | ||
192 | 0x20, 0x81, 0x2c, 0x38, 0x8f, 0x9d, 0x25, 0xde, | ||
193 | 0xe9, 0xc8, 0xf5, 0xdd, 0x6a, 0x47, 0x9c, 0x65, | ||
194 | 0x04, 0x5a, 0x56, 0xe6, 0xc2, 0xeb, 0xf2, 0x02, | ||
195 | 0x97, 0xe1, 0xb9, 0xd8, 0xe1, 0x24, 0x76, 0x9f, | ||
196 | 0x23, 0x62, 0x39, 0x03, 0x4b, 0xc8, 0xf7, 0x34, | ||
197 | 0x07, 0x49, 0xd6, 0xe7, 0x4d, 0x9a, | ||
198 | }; | ||
199 | |||
200 | const unsigned char sig[70] = { | ||
201 | 0x30, 0x44, 0x02, 0x20, 0x54, 0x92, 0x28, 0x3b, | ||
202 | 0x83, 0x33, 0x47, 0x56, 0x68, 0x79, 0xb2, 0x0c, | ||
203 | 0x84, 0x80, 0xcc, 0x67, 0x27, 0x8b, 0xfa, 0x48, | ||
204 | 0x43, 0x0d, 0x3c, 0xb4, 0x02, 0x36, 0x87, 0x97, | ||
205 | 0x3e, 0xdf, 0x2f, 0x65, 0x02, 0x20, 0x1b, 0x56, | ||
206 | 0x17, 0x06, 0xe2, 0x26, 0x0f, 0x6a, 0xe9, 0xa9, | ||
207 | 0x70, 0x99, 0x62, 0xeb, 0x3a, 0x04, 0x1a, 0xc4, | ||
208 | 0xa7, 0x03, 0x28, 0x56, 0x7c, 0xed, 0x47, 0x08, | ||
209 | 0x68, 0x73, 0x6a, 0xb6, 0x89, 0x0d, | ||
210 | }; | ||
211 | |||
212 | const unsigned char pubkey[64] = { | ||
213 | 0x17, 0x5b, 0x27, 0xa6, 0x56, 0xb2, 0x26, 0x0c, | ||
214 | 0x26, 0x0c, 0x55, 0x42, 0x78, 0x17, 0x5d, 0x4c, | ||
215 | 0xf8, 0xa2, 0xfd, 0x1b, 0xb9, 0x54, 0xdf, 0xd5, | ||
216 | 0xeb, 0xbf, 0x22, 0x64, 0xf5, 0x21, 0x9a, 0xc6, | ||
217 | 0x87, 0x5f, 0x90, 0xe6, 0xfd, 0x71, 0x27, 0x9f, | ||
218 | 0xeb, 0xe3, 0x03, 0x44, 0xbc, 0x8d, 0x49, 0xc6, | ||
219 | 0x1c, 0x31, 0x3b, 0x72, 0xae, 0xd4, 0x53, 0xb1, | ||
220 | 0xfe, 0x5d, 0xe1, 0x30, 0xfc, 0x2b, 0x1e, 0xd2, | ||
221 | }; | ||
222 | |||
223 | const unsigned char id[64] = { | ||
224 | 0x53, 0xfb, 0xdf, 0xaa, 0xce, 0x63, 0xde, 0xc5, | ||
225 | 0xfe, 0x47, 0xe6, 0x52, 0xeb, 0xf3, 0x5d, 0x53, | ||
226 | 0xa8, 0xbf, 0x9d, 0xd6, 0x09, 0x6b, 0x5e, 0x7f, | ||
227 | 0xe0, 0x0d, 0x51, 0x30, 0x85, 0x6a, 0xda, 0x68, | ||
228 | 0x70, 0x85, 0xb0, 0xdb, 0x08, 0x0b, 0x83, 0x2c, | ||
229 | 0xef, 0x44, 0xe2, 0x36, 0x88, 0xee, 0x76, 0x90, | ||
230 | 0x6e, 0x7b, 0x50, 0x3e, 0x9a, 0xa0, 0xd6, 0x3c, | ||
231 | 0x34, 0xe3, 0x83, 0xe7, 0xd1, 0xbd, 0x9f, 0x25, | ||
232 | }; | ||
233 | |||
234 | const char rp_id[] = "localhost"; | ||
235 | const char rp_name[] = "sweet home localhost"; | ||
236 | |||
237 | static void * | ||
238 | dummy_open(const char *path) | ||
239 | { | ||
240 | (void)path; | ||
241 | |||
242 | return (FAKE_DEV_HANDLE); | ||
243 | } | ||
244 | |||
245 | static void | ||
246 | dummy_close(void *handle) | ||
247 | { | ||
248 | assert(handle == FAKE_DEV_HANDLE); | ||
249 | } | ||
250 | |||
251 | static int | ||
252 | dummy_read(void *handle, unsigned char *buf, size_t len, int ms) | ||
253 | { | ||
254 | (void)handle; | ||
255 | (void)buf; | ||
256 | (void)len; | ||
257 | (void)ms; | ||
258 | |||
259 | abort(); | ||
260 | /* NOTREACHED */ | ||
261 | } | ||
262 | |||
263 | static int | ||
264 | dummy_write(void *handle, const unsigned char *buf, size_t len) | ||
265 | { | ||
266 | (void)handle; | ||
267 | (void)buf; | ||
268 | (void)len; | ||
269 | |||
270 | abort(); | ||
271 | /* NOTREACHED */ | ||
272 | } | ||
273 | |||
274 | static fido_cred_t * | ||
275 | alloc_cred(void) | ||
276 | { | ||
277 | fido_cred_t *c; | ||
278 | |||
279 | c = fido_cred_new(); | ||
280 | assert(c != NULL); | ||
281 | |||
282 | return (c); | ||
283 | } | ||
284 | |||
285 | static void | ||
286 | free_cred(fido_cred_t *c) | ||
287 | { | ||
288 | fido_cred_free(&c); | ||
289 | assert(c == NULL); | ||
290 | } | ||
291 | |||
292 | static fido_dev_t * | ||
293 | alloc_dev(void) | ||
294 | { | ||
295 | fido_dev_t *d; | ||
296 | |||
297 | d = fido_dev_new(); | ||
298 | assert(d != NULL); | ||
299 | |||
300 | return (d); | ||
301 | } | ||
302 | |||
303 | static void | ||
304 | free_dev(fido_dev_t *d) | ||
305 | { | ||
306 | fido_dev_free(&d); | ||
307 | assert(d == NULL); | ||
308 | } | ||
309 | |||
310 | static void | ||
311 | empty_cred(void) | ||
312 | { | ||
313 | fido_cred_t *c; | ||
314 | fido_dev_t *d; | ||
315 | fido_dev_io_t io_f; | ||
316 | |||
317 | c = alloc_cred(); | ||
318 | assert(fido_cred_authdata_len(c) == 0); | ||
319 | assert(fido_cred_authdata_ptr(c) == NULL); | ||
320 | assert(fido_cred_clientdata_hash_len(c) == 0); | ||
321 | assert(fido_cred_clientdata_hash_ptr(c) == NULL); | ||
322 | assert(fido_cred_flags(c) == 0); | ||
323 | assert(fido_cred_fmt(c) == NULL); | ||
324 | assert(fido_cred_id_len(c) == 0); | ||
325 | assert(fido_cred_id_ptr(c) == NULL); | ||
326 | assert(fido_cred_pubkey_len(c) == 0); | ||
327 | assert(fido_cred_pubkey_ptr(c) == NULL); | ||
328 | assert(fido_cred_rp_id(c) == NULL); | ||
329 | assert(fido_cred_rp_name(c) == NULL); | ||
330 | assert(fido_cred_sig_len(c) == 0); | ||
331 | assert(fido_cred_sig_ptr(c) == NULL); | ||
332 | assert(fido_cred_x5c_len(c) == 0); | ||
333 | assert(fido_cred_x5c_ptr(c) == NULL); | ||
334 | assert(fido_cred_verify(c) == FIDO_ERR_INVALID_ARGUMENT); | ||
335 | |||
336 | io_f.open = dummy_open; | ||
337 | io_f.close = dummy_close; | ||
338 | io_f.read = dummy_read; | ||
339 | io_f.write = dummy_write; | ||
340 | d = alloc_dev(); | ||
341 | |||
342 | fido_dev_force_u2f(d); | ||
343 | assert(fido_dev_set_io_functions(d, &io_f) == FIDO_OK); | ||
344 | assert(fido_dev_make_cred(d, c, NULL) == FIDO_ERR_INVALID_ARGUMENT); | ||
345 | assert(fido_dev_make_cred(d, c, "") == FIDO_ERR_UNSUPPORTED_OPTION); | ||
346 | assert(fido_cred_verify(c) == FIDO_ERR_INVALID_ARGUMENT); | ||
347 | |||
348 | fido_dev_force_fido2(d); | ||
349 | assert(fido_dev_set_io_functions(d, &io_f) == FIDO_OK); | ||
350 | assert(fido_dev_make_cred(d, c, NULL) == FIDO_ERR_INVALID_ARGUMENT); | ||
351 | assert(fido_dev_make_cred(d, c, "") == FIDO_ERR_INVALID_ARGUMENT); | ||
352 | assert(fido_cred_verify(c) == FIDO_ERR_INVALID_ARGUMENT); | ||
353 | |||
354 | free_cred(c); | ||
355 | free_dev(d); | ||
356 | } | ||
357 | |||
358 | static void | ||
359 | valid_cred(void) | ||
360 | { | ||
361 | fido_cred_t *c; | ||
362 | |||
363 | c = alloc_cred(); | ||
364 | assert(fido_cred_set_type(c, COSE_ES256) == FIDO_OK); | ||
365 | assert(fido_cred_set_clientdata_hash(c, cdh, sizeof(cdh)) == FIDO_OK); | ||
366 | assert(fido_cred_set_rp(c, rp_id, rp_name) == FIDO_OK); | ||
367 | assert(fido_cred_set_authdata(c, authdata, sizeof(authdata)) == FIDO_OK); | ||
368 | assert(fido_cred_set_rk(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
369 | assert(fido_cred_set_uv(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
370 | assert(fido_cred_set_x509(c, x509, sizeof(x509)) == FIDO_OK); | ||
371 | assert(fido_cred_set_sig(c, sig, sizeof(sig)) == FIDO_OK); | ||
372 | assert(fido_cred_set_fmt(c, "packed") == FIDO_OK); | ||
373 | assert(fido_cred_verify(c) == FIDO_OK); | ||
374 | assert(fido_cred_pubkey_len(c) == sizeof(pubkey)); | ||
375 | assert(memcmp(fido_cred_pubkey_ptr(c), pubkey, sizeof(pubkey)) == 0); | ||
376 | assert(fido_cred_id_len(c) == sizeof(id)); | ||
377 | assert(memcmp(fido_cred_id_ptr(c), id, sizeof(id)) == 0); | ||
378 | free_cred(c); | ||
379 | } | ||
380 | |||
381 | static void | ||
382 | no_cdh(void) | ||
383 | { | ||
384 | fido_cred_t *c; | ||
385 | |||
386 | c = alloc_cred(); | ||
387 | assert(fido_cred_set_type(c, COSE_ES256) == FIDO_OK); | ||
388 | assert(fido_cred_set_rp(c, rp_id, rp_name) == FIDO_OK); | ||
389 | assert(fido_cred_set_authdata(c, authdata, sizeof(authdata)) == FIDO_OK); | ||
390 | assert(fido_cred_set_rk(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
391 | assert(fido_cred_set_uv(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
392 | assert(fido_cred_set_x509(c, x509, sizeof(x509)) == FIDO_OK); | ||
393 | assert(fido_cred_set_sig(c, sig, sizeof(sig)) == FIDO_OK); | ||
394 | assert(fido_cred_set_fmt(c, "packed") == FIDO_OK); | ||
395 | assert(fido_cred_verify(c) == FIDO_ERR_INVALID_ARGUMENT); | ||
396 | assert(fido_cred_pubkey_len(c) == sizeof(pubkey)); | ||
397 | assert(memcmp(fido_cred_pubkey_ptr(c), pubkey, sizeof(pubkey)) == 0); | ||
398 | assert(fido_cred_id_len(c) == sizeof(id)); | ||
399 | assert(memcmp(fido_cred_id_ptr(c), id, sizeof(id)) == 0); | ||
400 | free_cred(c); | ||
401 | } | ||
402 | |||
403 | static void | ||
404 | no_rp_id(void) | ||
405 | { | ||
406 | fido_cred_t *c; | ||
407 | |||
408 | c = alloc_cred(); | ||
409 | assert(fido_cred_set_type(c, COSE_ES256) == FIDO_OK); | ||
410 | assert(fido_cred_set_clientdata_hash(c, cdh, sizeof(cdh)) == FIDO_OK); | ||
411 | assert(fido_cred_set_authdata(c, authdata, sizeof(authdata)) == FIDO_OK); | ||
412 | assert(fido_cred_set_rk(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
413 | assert(fido_cred_set_uv(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
414 | assert(fido_cred_set_x509(c, x509, sizeof(x509)) == FIDO_OK); | ||
415 | assert(fido_cred_set_sig(c, sig, sizeof(sig)) == FIDO_OK); | ||
416 | assert(fido_cred_set_fmt(c, "packed") == FIDO_OK); | ||
417 | assert(fido_cred_verify(c) == FIDO_ERR_INVALID_ARGUMENT); | ||
418 | assert(fido_cred_pubkey_len(c) == sizeof(pubkey)); | ||
419 | assert(memcmp(fido_cred_pubkey_ptr(c), pubkey, sizeof(pubkey)) == 0); | ||
420 | assert(fido_cred_id_len(c) == sizeof(id)); | ||
421 | assert(memcmp(fido_cred_id_ptr(c), id, sizeof(id)) == 0); | ||
422 | free_cred(c); | ||
423 | } | ||
424 | |||
425 | static void | ||
426 | no_rp_name(void) | ||
427 | { | ||
428 | fido_cred_t *c; | ||
429 | |||
430 | c = alloc_cred(); | ||
431 | assert(fido_cred_set_type(c, COSE_ES256) == FIDO_OK); | ||
432 | assert(fido_cred_set_rp(c, rp_id, NULL) == FIDO_OK); | ||
433 | assert(fido_cred_set_clientdata_hash(c, cdh, sizeof(cdh)) == FIDO_OK); | ||
434 | assert(fido_cred_set_authdata(c, authdata, sizeof(authdata)) == FIDO_OK); | ||
435 | assert(fido_cred_set_rk(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
436 | assert(fido_cred_set_uv(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
437 | assert(fido_cred_set_x509(c, x509, sizeof(x509)) == FIDO_OK); | ||
438 | assert(fido_cred_set_sig(c, sig, sizeof(sig)) == FIDO_OK); | ||
439 | assert(fido_cred_set_fmt(c, "packed") == FIDO_OK); | ||
440 | assert(fido_cred_verify(c) == FIDO_OK); | ||
441 | assert(fido_cred_pubkey_len(c) == sizeof(pubkey)); | ||
442 | assert(memcmp(fido_cred_pubkey_ptr(c), pubkey, sizeof(pubkey)) == 0); | ||
443 | assert(fido_cred_id_len(c) == sizeof(id)); | ||
444 | assert(memcmp(fido_cred_id_ptr(c), id, sizeof(id)) == 0); | ||
445 | free_cred(c); | ||
446 | } | ||
447 | |||
448 | static void | ||
449 | no_authdata(void) | ||
450 | { | ||
451 | fido_cred_t *c; | ||
452 | |||
453 | c = alloc_cred(); | ||
454 | assert(fido_cred_set_type(c, COSE_ES256) == FIDO_OK); | ||
455 | assert(fido_cred_set_clientdata_hash(c, cdh, sizeof(cdh)) == FIDO_OK); | ||
456 | assert(fido_cred_set_rp(c, rp_id, rp_name) == FIDO_OK); | ||
457 | assert(fido_cred_set_rk(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
458 | assert(fido_cred_set_uv(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
459 | assert(fido_cred_set_x509(c, x509, sizeof(x509)) == FIDO_OK); | ||
460 | assert(fido_cred_set_sig(c, sig, sizeof(sig)) == FIDO_OK); | ||
461 | assert(fido_cred_set_fmt(c, "packed") == FIDO_OK); | ||
462 | assert(fido_cred_verify(c) == FIDO_ERR_INVALID_ARGUMENT); | ||
463 | assert(fido_cred_pubkey_len(c) == 0); | ||
464 | assert(fido_cred_pubkey_ptr(c) == NULL); | ||
465 | assert(fido_cred_id_len(c) == 0); | ||
466 | assert(fido_cred_id_ptr(c) == NULL); | ||
467 | free_cred(c); | ||
468 | } | ||
469 | |||
470 | static void | ||
471 | no_x509(void) | ||
472 | { | ||
473 | fido_cred_t *c; | ||
474 | |||
475 | c = alloc_cred(); | ||
476 | assert(fido_cred_set_type(c, COSE_ES256) == FIDO_OK); | ||
477 | assert(fido_cred_set_clientdata_hash(c, cdh, sizeof(cdh)) == FIDO_OK); | ||
478 | assert(fido_cred_set_rp(c, rp_id, rp_name) == FIDO_OK); | ||
479 | assert(fido_cred_set_authdata(c, authdata, sizeof(authdata)) == FIDO_OK); | ||
480 | assert(fido_cred_set_rk(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
481 | assert(fido_cred_set_uv(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
482 | assert(fido_cred_set_sig(c, sig, sizeof(sig)) == FIDO_OK); | ||
483 | assert(fido_cred_set_fmt(c, "packed") == FIDO_OK); | ||
484 | assert(fido_cred_verify(c) == FIDO_ERR_INVALID_ARGUMENT); | ||
485 | assert(fido_cred_pubkey_len(c) == sizeof(pubkey)); | ||
486 | assert(memcmp(fido_cred_pubkey_ptr(c), pubkey, sizeof(pubkey)) == 0); | ||
487 | assert(fido_cred_id_len(c) == sizeof(id)); | ||
488 | assert(memcmp(fido_cred_id_ptr(c), id, sizeof(id)) == 0); | ||
489 | free_cred(c); | ||
490 | } | ||
491 | |||
492 | static void | ||
493 | no_sig(void) | ||
494 | { | ||
495 | fido_cred_t *c; | ||
496 | |||
497 | c = alloc_cred(); | ||
498 | assert(fido_cred_set_type(c, COSE_ES256) == FIDO_OK); | ||
499 | assert(fido_cred_set_clientdata_hash(c, cdh, sizeof(cdh)) == FIDO_OK); | ||
500 | assert(fido_cred_set_rp(c, rp_id, rp_name) == FIDO_OK); | ||
501 | assert(fido_cred_set_authdata(c, authdata, sizeof(authdata)) == FIDO_OK); | ||
502 | assert(fido_cred_set_rk(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
503 | assert(fido_cred_set_uv(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
504 | assert(fido_cred_set_x509(c, x509, sizeof(x509)) == FIDO_OK); | ||
505 | assert(fido_cred_set_fmt(c, "packed") == FIDO_OK); | ||
506 | assert(fido_cred_verify(c) == FIDO_ERR_INVALID_ARGUMENT); | ||
507 | assert(fido_cred_pubkey_len(c) == sizeof(pubkey)); | ||
508 | assert(memcmp(fido_cred_pubkey_ptr(c), pubkey, sizeof(pubkey)) == 0); | ||
509 | assert(fido_cred_id_len(c) == sizeof(id)); | ||
510 | assert(memcmp(fido_cred_id_ptr(c), id, sizeof(id)) == 0); | ||
511 | free_cred(c); | ||
512 | } | ||
513 | |||
514 | static void | ||
515 | no_fmt(void) | ||
516 | { | ||
517 | fido_cred_t *c; | ||
518 | |||
519 | c = alloc_cred(); | ||
520 | assert(fido_cred_set_type(c, COSE_ES256) == FIDO_OK); | ||
521 | assert(fido_cred_set_clientdata_hash(c, cdh, sizeof(cdh)) == FIDO_OK); | ||
522 | assert(fido_cred_set_rp(c, rp_id, rp_name) == FIDO_OK); | ||
523 | assert(fido_cred_set_authdata(c, authdata, sizeof(authdata)) == FIDO_OK); | ||
524 | assert(fido_cred_set_rk(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
525 | assert(fido_cred_set_uv(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
526 | assert(fido_cred_set_x509(c, x509, sizeof(x509)) == FIDO_OK); | ||
527 | assert(fido_cred_set_sig(c, sig, sizeof(sig)) == FIDO_OK); | ||
528 | assert(fido_cred_verify(c) == FIDO_ERR_INVALID_ARGUMENT); | ||
529 | assert(fido_cred_pubkey_len(c) == sizeof(pubkey)); | ||
530 | assert(memcmp(fido_cred_pubkey_ptr(c), pubkey, sizeof(pubkey)) == 0); | ||
531 | assert(fido_cred_id_len(c) == sizeof(id)); | ||
532 | assert(memcmp(fido_cred_id_ptr(c), id, sizeof(id)) == 0); | ||
533 | free_cred(c); | ||
534 | } | ||
535 | |||
536 | static void | ||
537 | wrong_options(void) | ||
538 | { | ||
539 | fido_cred_t *c; | ||
540 | |||
541 | c = alloc_cred(); | ||
542 | assert(fido_cred_set_type(c, COSE_ES256) == FIDO_OK); | ||
543 | assert(fido_cred_set_clientdata_hash(c, cdh, sizeof(cdh)) == FIDO_OK); | ||
544 | assert(fido_cred_set_rp(c, rp_id, rp_name) == FIDO_OK); | ||
545 | assert(fido_cred_set_authdata(c, authdata, sizeof(authdata)) == FIDO_OK); | ||
546 | assert(fido_cred_set_rk(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
547 | assert(fido_cred_set_uv(c, FIDO_OPT_TRUE) == FIDO_OK); | ||
548 | assert(fido_cred_set_x509(c, x509, sizeof(x509)) == FIDO_OK); | ||
549 | assert(fido_cred_set_sig(c, sig, sizeof(sig)) == FIDO_OK); | ||
550 | assert(fido_cred_set_fmt(c, "packed") == FIDO_OK); | ||
551 | assert(fido_cred_verify(c) == FIDO_ERR_INVALID_PARAM); | ||
552 | assert(fido_cred_pubkey_len(c) == sizeof(pubkey)); | ||
553 | assert(memcmp(fido_cred_pubkey_ptr(c), pubkey, sizeof(pubkey)) == 0); | ||
554 | assert(fido_cred_id_len(c) == sizeof(id)); | ||
555 | assert(memcmp(fido_cred_id_ptr(c), id, sizeof(id)) == 0); | ||
556 | free_cred(c); | ||
557 | } | ||
558 | |||
559 | static void | ||
560 | junk_cdh(void) | ||
561 | { | ||
562 | fido_cred_t *c; | ||
563 | unsigned char *junk; | ||
564 | |||
565 | junk = malloc(sizeof(cdh)); | ||
566 | assert(junk != NULL); | ||
567 | memcpy(junk, cdh, sizeof(cdh)); | ||
568 | junk[0] = ~junk[0]; | ||
569 | |||
570 | c = alloc_cred(); | ||
571 | assert(fido_cred_set_type(c, COSE_ES256) == FIDO_OK); | ||
572 | assert(fido_cred_set_clientdata_hash(c, junk, sizeof(cdh)) == FIDO_OK); | ||
573 | assert(fido_cred_set_rp(c, rp_id, rp_name) == FIDO_OK); | ||
574 | assert(fido_cred_set_authdata(c, authdata, sizeof(authdata)) == FIDO_OK); | ||
575 | assert(fido_cred_set_rk(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
576 | assert(fido_cred_set_uv(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
577 | assert(fido_cred_set_x509(c, x509, sizeof(x509)) == FIDO_OK); | ||
578 | assert(fido_cred_set_sig(c, sig, sizeof(sig)) == FIDO_OK); | ||
579 | assert(fido_cred_set_fmt(c, "packed") == FIDO_OK); | ||
580 | assert(fido_cred_verify(c) == FIDO_ERR_INVALID_SIG); | ||
581 | assert(fido_cred_pubkey_len(c) == sizeof(pubkey)); | ||
582 | assert(memcmp(fido_cred_pubkey_ptr(c), pubkey, sizeof(pubkey)) == 0); | ||
583 | assert(fido_cred_id_len(c) == sizeof(id)); | ||
584 | assert(memcmp(fido_cred_id_ptr(c), id, sizeof(id)) == 0); | ||
585 | free_cred(c); | ||
586 | free(junk); | ||
587 | } | ||
588 | |||
589 | static void | ||
590 | junk_rp_id(void) | ||
591 | { | ||
592 | fido_cred_t *c; | ||
593 | |||
594 | c = alloc_cred(); | ||
595 | assert(fido_cred_set_type(c, COSE_ES256) == FIDO_OK); | ||
596 | assert(fido_cred_set_clientdata_hash(c, cdh, sizeof(cdh)) == FIDO_OK); | ||
597 | assert(fido_cred_set_rp(c, "potato", rp_name) == FIDO_OK); | ||
598 | assert(fido_cred_set_authdata(c, authdata, sizeof(authdata)) == FIDO_OK); | ||
599 | assert(fido_cred_set_rk(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
600 | assert(fido_cred_set_uv(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
601 | assert(fido_cred_set_x509(c, x509, sizeof(x509)) == FIDO_OK); | ||
602 | assert(fido_cred_set_sig(c, sig, sizeof(sig)) == FIDO_OK); | ||
603 | assert(fido_cred_set_fmt(c, "packed") == FIDO_OK); | ||
604 | assert(fido_cred_verify(c) == FIDO_ERR_INVALID_PARAM); | ||
605 | assert(fido_cred_pubkey_len(c) == sizeof(pubkey)); | ||
606 | assert(memcmp(fido_cred_pubkey_ptr(c), pubkey, sizeof(pubkey)) == 0); | ||
607 | assert(fido_cred_id_len(c) == sizeof(id)); | ||
608 | assert(memcmp(fido_cred_id_ptr(c), id, sizeof(id)) == 0); | ||
609 | free_cred(c); | ||
610 | } | ||
611 | |||
612 | static void | ||
613 | junk_rp_name(void) | ||
614 | { | ||
615 | fido_cred_t *c; | ||
616 | |||
617 | c = alloc_cred(); | ||
618 | assert(fido_cred_set_type(c, COSE_ES256) == FIDO_OK); | ||
619 | assert(fido_cred_set_clientdata_hash(c, cdh, sizeof(cdh)) == FIDO_OK); | ||
620 | assert(fido_cred_set_rp(c, rp_id, "potato") == FIDO_OK); | ||
621 | assert(fido_cred_set_authdata(c, authdata, sizeof(authdata)) == FIDO_OK); | ||
622 | assert(fido_cred_set_rk(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
623 | assert(fido_cred_set_uv(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
624 | assert(fido_cred_set_x509(c, x509, sizeof(x509)) == FIDO_OK); | ||
625 | assert(fido_cred_set_sig(c, sig, sizeof(sig)) == FIDO_OK); | ||
626 | assert(fido_cred_set_fmt(c, "packed") == FIDO_OK); | ||
627 | assert(fido_cred_verify(c) == FIDO_OK); | ||
628 | assert(fido_cred_pubkey_len(c) == sizeof(pubkey)); | ||
629 | assert(memcmp(fido_cred_pubkey_ptr(c), pubkey, sizeof(pubkey)) == 0); | ||
630 | assert(fido_cred_id_len(c) == sizeof(id)); | ||
631 | assert(memcmp(fido_cred_id_ptr(c), id, sizeof(id)) == 0); | ||
632 | free_cred(c); | ||
633 | } | ||
634 | |||
635 | static void | ||
636 | junk_authdata(void) | ||
637 | { | ||
638 | fido_cred_t *c; | ||
639 | unsigned char *junk; | ||
640 | |||
641 | junk = malloc(sizeof(authdata)); | ||
642 | assert(junk != NULL); | ||
643 | memcpy(junk, authdata, sizeof(authdata)); | ||
644 | junk[0] = ~junk[0]; | ||
645 | |||
646 | c = alloc_cred(); | ||
647 | assert(fido_cred_set_authdata(c, junk, | ||
648 | sizeof(authdata)) == FIDO_ERR_INVALID_ARGUMENT); | ||
649 | assert(fido_cred_authdata_len(c) == 0); | ||
650 | assert(fido_cred_authdata_ptr(c) == NULL); | ||
651 | assert(fido_cred_flags(c) == 0); | ||
652 | assert(fido_cred_fmt(c) == NULL); | ||
653 | assert(fido_cred_id_len(c) == 0); | ||
654 | assert(fido_cred_id_ptr(c) == NULL); | ||
655 | assert(fido_cred_pubkey_len(c) == 0); | ||
656 | assert(fido_cred_pubkey_ptr(c) == NULL); | ||
657 | assert(fido_cred_rp_id(c) == NULL); | ||
658 | assert(fido_cred_rp_name(c) == NULL); | ||
659 | assert(fido_cred_sig_len(c) == 0); | ||
660 | assert(fido_cred_sig_ptr(c) == NULL); | ||
661 | assert(fido_cred_x5c_len(c) == 0); | ||
662 | assert(fido_cred_x5c_ptr(c) == NULL); | ||
663 | assert(fido_cred_verify(c) == FIDO_ERR_INVALID_ARGUMENT); | ||
664 | free_cred(c); | ||
665 | free(junk); | ||
666 | } | ||
667 | |||
668 | static void | ||
669 | junk_sig(void) | ||
670 | { | ||
671 | fido_cred_t *c; | ||
672 | unsigned char *junk; | ||
673 | |||
674 | junk = malloc(sizeof(sig)); | ||
675 | assert(junk != NULL); | ||
676 | memcpy(junk, sig, sizeof(sig)); | ||
677 | junk[0] = ~junk[0]; | ||
678 | |||
679 | c = alloc_cred(); | ||
680 | assert(fido_cred_set_type(c, COSE_ES256) == FIDO_OK); | ||
681 | assert(fido_cred_set_clientdata_hash(c, cdh, sizeof(cdh)) == FIDO_OK); | ||
682 | assert(fido_cred_set_rp(c, rp_id, rp_name) == FIDO_OK); | ||
683 | assert(fido_cred_set_authdata(c, authdata, sizeof(authdata)) == FIDO_OK); | ||
684 | assert(fido_cred_set_rk(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
685 | assert(fido_cred_set_uv(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
686 | assert(fido_cred_set_x509(c, x509, sizeof(x509)) == FIDO_OK); | ||
687 | assert(fido_cred_set_sig(c, junk, sizeof(sig)) == FIDO_OK); | ||
688 | assert(fido_cred_set_fmt(c, "packed") == FIDO_OK); | ||
689 | assert(fido_cred_verify(c) == FIDO_ERR_INVALID_SIG); | ||
690 | assert(fido_cred_pubkey_len(c) == sizeof(pubkey)); | ||
691 | assert(memcmp(fido_cred_pubkey_ptr(c), pubkey, sizeof(pubkey)) == 0); | ||
692 | assert(fido_cred_id_len(c) == sizeof(id)); | ||
693 | assert(memcmp(fido_cred_id_ptr(c), id, sizeof(id)) == 0); | ||
694 | free_cred(c); | ||
695 | free(junk); | ||
696 | } | ||
697 | |||
698 | static void | ||
699 | junk_x509(void) | ||
700 | { | ||
701 | fido_cred_t *c; | ||
702 | unsigned char *junk; | ||
703 | |||
704 | junk = malloc(sizeof(x509)); | ||
705 | assert(junk != NULL); | ||
706 | memcpy(junk, x509, sizeof(x509)); | ||
707 | junk[0] = ~junk[0]; | ||
708 | |||
709 | c = alloc_cred(); | ||
710 | assert(fido_cred_set_type(c, COSE_ES256) == FIDO_OK); | ||
711 | assert(fido_cred_set_clientdata_hash(c, cdh, sizeof(cdh)) == FIDO_OK); | ||
712 | assert(fido_cred_set_rp(c, rp_id, rp_name) == FIDO_OK); | ||
713 | assert(fido_cred_set_authdata(c, authdata, sizeof(authdata)) == FIDO_OK); | ||
714 | assert(fido_cred_set_rk(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
715 | assert(fido_cred_set_uv(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
716 | assert(fido_cred_set_x509(c, junk, sizeof(x509)) == FIDO_OK); | ||
717 | assert(fido_cred_set_sig(c, sig, sizeof(sig)) == FIDO_OK); | ||
718 | assert(fido_cred_set_fmt(c, "packed") == FIDO_OK); | ||
719 | assert(fido_cred_verify(c) == FIDO_ERR_INVALID_SIG); | ||
720 | assert(fido_cred_pubkey_len(c) == sizeof(pubkey)); | ||
721 | assert(memcmp(fido_cred_pubkey_ptr(c), pubkey, sizeof(pubkey)) == 0); | ||
722 | assert(fido_cred_id_len(c) == sizeof(id)); | ||
723 | assert(memcmp(fido_cred_id_ptr(c), id, sizeof(id)) == 0); | ||
724 | free_cred(c); | ||
725 | free(junk); | ||
726 | } | ||
727 | |||
728 | /* github issue #6 */ | ||
729 | static void | ||
730 | invalid_type(void) | ||
731 | { | ||
732 | fido_cred_t *c; | ||
733 | |||
734 | c = alloc_cred(); | ||
735 | assert(fido_cred_set_type(c, COSE_RS256) == FIDO_OK); | ||
736 | assert(fido_cred_set_clientdata_hash(c, cdh, sizeof(cdh)) == FIDO_OK); | ||
737 | assert(fido_cred_set_rp(c, rp_id, rp_name) == FIDO_OK); | ||
738 | assert(fido_cred_set_authdata(c, authdata, sizeof(authdata)) == FIDO_ERR_INVALID_ARGUMENT); | ||
739 | assert(fido_cred_set_rk(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
740 | assert(fido_cred_set_uv(c, FIDO_OPT_FALSE) == FIDO_OK); | ||
741 | assert(fido_cred_set_x509(c, x509, sizeof(x509)) == FIDO_OK); | ||
742 | assert(fido_cred_set_sig(c, sig, sizeof(sig)) == FIDO_OK); | ||
743 | assert(fido_cred_set_fmt(c, "packed") == FIDO_OK); | ||
744 | assert(fido_cred_verify(c) == FIDO_ERR_INVALID_ARGUMENT); | ||
745 | assert(fido_cred_pubkey_len(c) == 0); | ||
746 | assert(fido_cred_pubkey_ptr(c) == NULL); | ||
747 | assert(fido_cred_id_len(c) == 0); | ||
748 | assert(fido_cred_id_ptr(c) == NULL); | ||
749 | free_cred(c); | ||
750 | } | ||
751 | |||
752 | /* cbor_serialize_alloc misuse */ | ||
753 | static void | ||
754 | bad_cbor_serialize(void) | ||
755 | { | ||
756 | fido_cred_t *c; | ||
757 | |||
758 | c = alloc_cred(); | ||
759 | assert(fido_cred_set_type(c, COSE_ES256) == FIDO_OK); | ||
760 | assert(fido_cred_set_authdata(c, authdata, sizeof(authdata)) == FIDO_OK); | ||
761 | assert(fido_cred_authdata_len(c) == sizeof(authdata)); | ||
762 | free_cred(c); | ||
763 | } | ||
764 | |||
765 | static void | ||
766 | duplicate_keys(void) | ||
767 | { | ||
768 | fido_cred_t *c; | ||
769 | |||
770 | c = alloc_cred(); | ||
771 | assert(fido_cred_set_type(c, COSE_ES256) == FIDO_OK); | ||
772 | assert(fido_cred_set_authdata(c, authdata_dupkeys, | ||
773 | sizeof(authdata_dupkeys)) == FIDO_ERR_INVALID_ARGUMENT); | ||
774 | free_cred(c); | ||
775 | } | ||
776 | |||
777 | static void | ||
778 | unsorted_keys(void) | ||
779 | { | ||
780 | fido_cred_t *c; | ||
781 | |||
782 | c = alloc_cred(); | ||
783 | assert(fido_cred_set_type(c, COSE_ES256) == FIDO_OK); | ||
784 | assert(fido_cred_set_authdata(c, authdata_unsorted_keys, | ||
785 | sizeof(authdata_unsorted_keys)) == FIDO_ERR_INVALID_ARGUMENT); | ||
786 | free_cred(c); | ||
787 | } | ||
788 | |||
789 | int | ||
790 | main(void) | ||
791 | { | ||
792 | fido_init(0); | ||
793 | |||
794 | empty_cred(); | ||
795 | valid_cred(); | ||
796 | no_cdh(); | ||
797 | no_rp_id(); | ||
798 | no_rp_name(); | ||
799 | no_authdata(); | ||
800 | no_x509(); | ||
801 | no_sig(); | ||
802 | no_fmt(); | ||
803 | junk_cdh(); | ||
804 | junk_rp_id(); | ||
805 | junk_rp_name(); | ||
806 | junk_authdata(); | ||
807 | junk_x509(); | ||
808 | junk_sig(); | ||
809 | wrong_options(); | ||
810 | invalid_type(); | ||
811 | bad_cbor_serialize(); | ||
812 | duplicate_keys(); | ||
813 | unsorted_keys(); | ||
814 | |||
815 | exit(0); | ||
816 | } | ||