summaryrefslogtreecommitdiff
path: root/tests/dev/cgd/t_cgdconfig.sh
blob: cd6661a0f98e5f0b78c1dce4af90d3f10ab7b45b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#	$NetBSD: t_cgdconfig.sh,v 1.4 2022/08/13 17:46:26 hannken Exp $
#
# Copyright (c) 2022 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

COUNTKEY=$(atf_get_srcdir)/h_countkey

atf_test_case storedkey
storedkey_head()
{
	atf_set descr "Test key generation with storedkey"
}
storedkey_body()
{
	cat <<EOF >params
algorithm adiantum;
iv-method encblkno1;
keylength 256;
verify_method none;
keygen storedkey key AAABAJtnmp3XZspMBAFpCYnB8Hekn0 \
                     gj5cDVngslfGLSqwcy;
EOF
	atf_check -o inline:'m2eanddmykwEAWkJicHwd6SfSCPlwNWeCyV8YtKrBzI=\n' \
	    cgdconfig -t params
}

atf_test_case storedkeys
storedkeys_head()
{
	atf_set descr "Test multiple stored keys with cgd.conf"
}
storedkeys_body()
{
	cat <<EOF >dska
algorithm adiantum;
iv-method encblkno1;
keylength 256;
verify_method none;
keygen storedkey key AAABAJtnmp3XZspMBAFpCYnB8Hekn0 \
                     gj5cDVngslfGLSqwcy;
EOF
	cat <<EOF >dskb
algorithm adiantum;
iv-method encblkno1;
keylength 256;
verify_method none;
keygen storedkey key AAABAK1pbgIayXftX0RQ3AaMK4YEd/ \
                     fowKwQbENxpu3o1k9m;
EOF
	cat <<EOF >cgd.conf
cgd0	/dev/dska	dska
cgd1	/dev/dskb	dskb
EOF
	cat <<EOF >expected
/dev/dska: m2eanddmykwEAWkJicHwd6SfSCPlwNWeCyV8YtKrBzI=
/dev/dskb: rWluAhrJd+1fRFDcBowrhgR39+jArBBsQ3Gm7ejWT2Y=
EOF
	atf_check -o file:expected cgdconfig -T -f cgd.conf
}

atf_test_case storedkey2a
storedkey2a_head()
{
	atf_set descr "Test key generation with combined storedkeys"
}
storedkey2a_body()
{
	cat <<EOF >params
algorithm adiantum;
iv-method encblkno1;
keylength 256;
verify_method none;
keygen storedkey key AAABAJtnmp3XZspMBAFpCYnB8Hekn0 \
                     gj5cDVngslfGLSqwcy;
keygen storedkey key AAABAK1pbgIayXftX0RQ3AaMK4YEd/ \
                     fowKwQbENxpu3o1k9m;
EOF
	atf_check -o inline:'Ng70n82vvaFbRTnVj03b8aDov8slbMXySFTajzp9SFQ=\n' \
	    cgdconfig -t params
}

atf_test_case storedkey2b
storedkey2b_head()
{
	atf_set descr "Test key generation with combined storedkeys, reversed"
}
storedkey2b_body()
{
	cat <<EOF >params
algorithm adiantum;
iv-method encblkno1;
keylength 256;
verify_method none;
keygen storedkey key AAABAK1pbgIayXftX0RQ3AaMK4YEd/ \
                     fowKwQbENxpu3o1k9m;
keygen storedkey key AAABAJtnmp3XZspMBAFpCYnB8Hekn0 \
                     gj5cDVngslfGLSqwcy;
EOF
	atf_check -o inline:'Ng70n82vvaFbRTnVj03b8aDov8slbMXySFTajzp9SFQ=\n' \
	    cgdconfig -t params
}

atf_test_case sharedstoredkey10
sharedstoredkey10_head()
{
	atf_set descr "Test shared key generation from storedkey, 10-byte info"
}
sharedstoredkey10_body()
{
	cat <<EOF >params
algorithm adiantum;
iv-method encblkno1;
keylength 256;
verify_method none;
keygen storedkey {
        key AAABAAd3CTYsLjLfDdw/DcR7umOQtsc7tQ+cMSLshErXwrPl;
        shared "helloworld" algorithm hkdf-hmac-sha256 \
            subkey AAAAUPDx8vP09fb3+Pk=;
};
EOF
	atf_check -o inline:'PLJfJfqs1XqQQ09k0DYvKi0tCpDPGlpMXbAtVuzExb8=\n' \
	    cgdconfig -t params
}

atf_test_case sharedstoredkey80
sharedstoredkey80_head()
{
	atf_set descr "Test shared key generation from storedkey, 80-byte info"
}
sharedstoredkey80_body()
{
	cat <<EOF >params
algorithm adiantum;
iv-method encblkno1;
keylength 256;
verify_method none;
keygen storedkey {
        key AAABAAamuIxYUzYaBhBMnOs1tFzvdgAUkEZxAUoZP0DBX8JE;
        shared "helloworld" algorithm hkdf-hmac-sha256 \
            subkey AAACgLCxsrO0tba3uLm6u7y9vr/AwcLDxMXGx8jJ \
                   ysvMzc7P0NHS09TV1tfY2drb3N3e3+Dh4uPk5ebn \
                   6Onq6+zt7u/w8fLz9PX29/j5+vv8/f7/;
};
EOF
	atf_check -o inline:'sR45jcgDJ6HI5/eMWWpJNE8BLtotTvrYoFDMTBmvqXw=\n' \
	    cgdconfig -t params
}

atf_test_case sharedstoredkeys
sharedstoredkeys_head()
{
	atf_set descr "Test multiple shared key generations from stored keys"
}
sharedstoredkeys_body()
{
	cat <<EOF >dska
algorithm adiantum;
iv-method encblkno1;
keylength 256;
verify_method none;
keygen storedkey {
        key AAABAAd3CTYsLjLfDdw/DcR7umOQtsc7tQ+cMSLshErXwrPl;
        shared "helloworld" algorithm hkdf-hmac-sha256 \
            subkey AAAAUPDx8vP09fb3+Pk=;
};
EOF
	cat <<EOF >dskb
algorithm adiantum;
iv-method encblkno1;
keylength 256;
verify_method none;
keygen storedkey {
        key AAABAAd3CTYsLjLfDdw/DcR7umOQtsc7tQ+cMSLshErXwrPl;
        shared "helloworld" algorithm hkdf-hmac-sha256 \
            subkey AAAAQMxUtCBh7ha6mUU=;
};
EOF
	cat <<EOF >cgd.conf0
cgd0	/dev/dska	dska
cgd1	/dev/dskb	dskb
EOF
	cat <<EOF >expected0
/dev/dska: PLJfJfqs1XqQQ09k0DYvKi0tCpDPGlpMXbAtVuzExb8=
/dev/dskb: ADxn574yb7sVdxHphNRRdObZxntMJA/ssMuUX6SXgEY=
EOF
	cat <<EOF >cgd.conf1
cgd0	/dev/dskb	dskb
cgd1	/dev/dska	dska
EOF
	cat <<EOF >expected1
/dev/dskb: ADxn574yb7sVdxHphNRRdObZxntMJA/ssMuUX6SXgEY=
/dev/dska: PLJfJfqs1XqQQ09k0DYvKi0tCpDPGlpMXbAtVuzExb8=
EOF
	atf_check -o file:expected0 cgdconfig -T -f cgd.conf0
	atf_check -o file:expected1 cgdconfig -T -f cgd.conf1
}

atf_test_case sharedshellkeys
sharedshellkeys_head()
{
	atf_set descr "Test multiple shared key generations from shell_cmd"
}
sharedshellkeys_body()
{
	cat <<EOF >dska
algorithm adiantum;
iv-method encblkno1;
keylength 256;
verify_method none;
keygen shell_cmd {
        cmd "${COUNTKEY} n B3cJNiwuMt8N3D8NxHu6Y5C2xzu1D5wxIuyEStfCs+U=";
        shared "helloworld" algorithm hkdf-hmac-sha256 \
            subkey AAAAUPDx8vP09fb3+Pk=;
};
EOF
	cat <<EOF >dskb
algorithm adiantum;
iv-method encblkno1;
keylength 256;
verify_method none;
keygen shell_cmd {
        cmd "${COUNTKEY} n B3cJNiwuMt8N3D8NxHu6Y5C2xzu1D5wxIuyEStfCs+U=";
        shared "helloworld" algorithm hkdf-hmac-sha256 \
            subkey AAAAQMxUtCBh7ha6mUU=;
};
EOF
	cat <<EOF >cgd.conf0
cgd0	/dev/dska	dska
cgd1	/dev/dskb	dskb
EOF
	cat <<EOF >expected0
/dev/dska: PLJfJfqs1XqQQ09k0DYvKi0tCpDPGlpMXbAtVuzExb8=
/dev/dskb: ADxn574yb7sVdxHphNRRdObZxntMJA/ssMuUX6SXgEY=
EOF
	cat <<EOF >cgd.conf1
cgd0	/dev/dskb	dskb
cgd1	/dev/dska	dska
EOF
	cat <<EOF >expected1
/dev/dskb: ADxn574yb7sVdxHphNRRdObZxntMJA/ssMuUX6SXgEY=
/dev/dska: PLJfJfqs1XqQQ09k0DYvKi0tCpDPGlpMXbAtVuzExb8=
EOF
	atf_check -o file:expected0 cgdconfig -T -f cgd.conf0
	atf_check -o inline:'1\n' cat n
	atf_check -o file:expected1 cgdconfig -T -f cgd.conf1
	atf_check -o inline:'2\n' cat n
}

atf_init_test_cases()
{
	atf_add_test_case sharedshellkeys
	atf_add_test_case sharedstoredkey10
	atf_add_test_case sharedstoredkey80
	atf_add_test_case sharedstoredkeys
	atf_add_test_case storedkey
	atf_add_test_case storedkey2a
	atf_add_test_case storedkey2b
	atf_add_test_case storedkeys
}