1 # $NetBSD: t_cgdconfig.sh,v 1.4 2022/08/13 17:46:26 hannken Exp $ 2 # 3 # Copyright (c) 2022 The NetBSD Foundation, Inc. 4 # All rights reserved. 5 # 6 # Redistribution and use in source and binary forms, with or without 7 # modification, are permitted provided that the following conditions 8 # are met: 9 # 1. Redistributions of source code must retain the above copyright 10 # notice, this list of conditions and the following disclaimer. 11 # 2. Redistributions in binary form must reproduce the above copyright 12 # notice, this list of conditions and the following disclaimer in the 13 # documentation and/or other materials provided with the distribution. 14 # 15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 # POSSIBILITY OF SUCH DAMAGE. 26 # 27 28 COUNTKEY=$(atf_get_srcdir)/h_countkey 29 30 atf_test_case storedkey 31 storedkey_head() 32 { 33 atf_set descr "Test key generation with storedkey" 34 } 35 storedkey_body() 36 { 37 cat <<EOF >params 38 algorithm adiantum; 39 iv-method encblkno1; 40 keylength 256; 41 verify_method none; 42 keygen storedkey key AAABAJtnmp3XZspMBAFpCYnB8Hekn0 \ 43 gj5cDVngslfGLSqwcy; 44 EOF 45 atf_check -o inline:'m2eanddmykwEAWkJicHwd6SfSCPlwNWeCyV8YtKrBzI=\n' \ 46 cgdconfig -t params 47 } 48 49 atf_test_case storedkeys 50 storedkeys_head() 51 { 52 atf_set descr "Test multiple stored keys with cgd.conf" 53 } 54 storedkeys_body() 55 { 56 cat <<EOF >dska 57 algorithm adiantum; 58 iv-method encblkno1; 59 keylength 256; 60 verify_method none; 61 keygen storedkey key AAABAJtnmp3XZspMBAFpCYnB8Hekn0 \ 62 gj5cDVngslfGLSqwcy; 63 EOF 64 cat <<EOF >dskb 65 algorithm adiantum; 66 iv-method encblkno1; 67 keylength 256; 68 verify_method none; 69 keygen storedkey key AAABAK1pbgIayXftX0RQ3AaMK4YEd/ \ 70 fowKwQbENxpu3o1k9m; 71 EOF 72 cat <<EOF >cgd.conf 73 cgd0 /dev/dska dska 74 cgd1 /dev/dskb dskb 75 EOF 76 cat <<EOF >expected 77 /dev/dska: m2eanddmykwEAWkJicHwd6SfSCPlwNWeCyV8YtKrBzI= 78 /dev/dskb: rWluAhrJd+1fRFDcBowrhgR39+jArBBsQ3Gm7ejWT2Y= 79 EOF 80 atf_check -o file:expected cgdconfig -T -f cgd.conf 81 } 82 83 atf_test_case storedkey2a 84 storedkey2a_head() 85 { 86 atf_set descr "Test key generation with combined storedkeys" 87 } 88 storedkey2a_body() 89 { 90 cat <<EOF >params 91 algorithm adiantum; 92 iv-method encblkno1; 93 keylength 256; 94 verify_method none; 95 keygen storedkey key AAABAJtnmp3XZspMBAFpCYnB8Hekn0 \ 96 gj5cDVngslfGLSqwcy; 97 keygen storedkey key AAABAK1pbgIayXftX0RQ3AaMK4YEd/ \ 98 fowKwQbENxpu3o1k9m; 99 EOF 100 atf_check -o inline:'Ng70n82vvaFbRTnVj03b8aDov8slbMXySFTajzp9SFQ=\n' \ 101 cgdconfig -t params 102 } 103 104 atf_test_case storedkey2b 105 storedkey2b_head() 106 { 107 atf_set descr "Test key generation with combined storedkeys, reversed" 108 } 109 storedkey2b_body() 110 { 111 cat <<EOF >params 112 algorithm adiantum; 113 iv-method encblkno1; 114 keylength 256; 115 verify_method none; 116 keygen storedkey key AAABAK1pbgIayXftX0RQ3AaMK4YEd/ \ 117 fowKwQbENxpu3o1k9m; 118 keygen storedkey key AAABAJtnmp3XZspMBAFpCYnB8Hekn0 \ 119 gj5cDVngslfGLSqwcy; 120 EOF 121 atf_check -o inline:'Ng70n82vvaFbRTnVj03b8aDov8slbMXySFTajzp9SFQ=\n' \ 122 cgdconfig -t params 123 } 124 125 atf_test_case sharedstoredkey10 126 sharedstoredkey10_head() 127 { 128 atf_set descr "Test shared key generation from storedkey, 10-byte info" 129 } 130 sharedstoredkey10_body() 131 { 132 cat <<EOF >params 133 algorithm adiantum; 134 iv-method encblkno1; 135 keylength 256; 136 verify_method none; 137 keygen storedkey { 138 key AAABAAd3CTYsLjLfDdw/DcR7umOQtsc7tQ+cMSLshErXwrPl; 139 shared "helloworld" algorithm hkdf-hmac-sha256 \ 140 subkey AAAAUPDx8vP09fb3+Pk=; 141 }; 142 EOF 143 atf_check -o inline:'PLJfJfqs1XqQQ09k0DYvKi0tCpDPGlpMXbAtVuzExb8=\n' \ 144 cgdconfig -t params 145 } 146 147 atf_test_case sharedstoredkey80 148 sharedstoredkey80_head() 149 { 150 atf_set descr "Test shared key generation from storedkey, 80-byte info" 151 } 152 sharedstoredkey80_body() 153 { 154 cat <<EOF >params 155 algorithm adiantum; 156 iv-method encblkno1; 157 keylength 256; 158 verify_method none; 159 keygen storedkey { 160 key AAABAAamuIxYUzYaBhBMnOs1tFzvdgAUkEZxAUoZP0DBX8JE; 161 shared "helloworld" algorithm hkdf-hmac-sha256 \ 162 subkey AAACgLCxsrO0tba3uLm6u7y9vr/AwcLDxMXGx8jJ \ 163 ysvMzc7P0NHS09TV1tfY2drb3N3e3+Dh4uPk5ebn \ 164 6Onq6+zt7u/w8fLz9PX29/j5+vv8/f7/; 165 }; 166 EOF 167 atf_check -o inline:'sR45jcgDJ6HI5/eMWWpJNE8BLtotTvrYoFDMTBmvqXw=\n' \ 168 cgdconfig -t params 169 } 170 171 atf_test_case sharedstoredkeys 172 sharedstoredkeys_head() 173 { 174 atf_set descr "Test multiple shared key generations from stored keys" 175 } 176 sharedstoredkeys_body() 177 { 178 cat <<EOF >dska 179 algorithm adiantum; 180 iv-method encblkno1; 181 keylength 256; 182 verify_method none; 183 keygen storedkey { 184 key AAABAAd3CTYsLjLfDdw/DcR7umOQtsc7tQ+cMSLshErXwrPl; 185 shared "helloworld" algorithm hkdf-hmac-sha256 \ 186 subkey AAAAUPDx8vP09fb3+Pk=; 187 }; 188 EOF 189 cat <<EOF >dskb 190 algorithm adiantum; 191 iv-method encblkno1; 192 keylength 256; 193 verify_method none; 194 keygen storedkey { 195 key AAABAAd3CTYsLjLfDdw/DcR7umOQtsc7tQ+cMSLshErXwrPl; 196 shared "helloworld" algorithm hkdf-hmac-sha256 \ 197 subkey AAAAQMxUtCBh7ha6mUU=; 198 }; 199 EOF 200 cat <<EOF >cgd.conf0 201 cgd0 /dev/dska dska 202 cgd1 /dev/dskb dskb 203 EOF 204 cat <<EOF >expected0 205 /dev/dska: PLJfJfqs1XqQQ09k0DYvKi0tCpDPGlpMXbAtVuzExb8= 206 /dev/dskb: ADxn574yb7sVdxHphNRRdObZxntMJA/ssMuUX6SXgEY= 207 EOF 208 cat <<EOF >cgd.conf1 209 cgd0 /dev/dskb dskb 210 cgd1 /dev/dska dska 211 EOF 212 cat <<EOF >expected1 213 /dev/dskb: ADxn574yb7sVdxHphNRRdObZxntMJA/ssMuUX6SXgEY= 214 /dev/dska: PLJfJfqs1XqQQ09k0DYvKi0tCpDPGlpMXbAtVuzExb8= 215 EOF 216 atf_check -o file:expected0 cgdconfig -T -f cgd.conf0 217 atf_check -o file:expected1 cgdconfig -T -f cgd.conf1 218 } 219 220 atf_test_case sharedshellkeys 221 sharedshellkeys_head() 222 { 223 atf_set descr "Test multiple shared key generations from shell_cmd" 224 } 225 sharedshellkeys_body() 226 { 227 cat <<EOF >dska 228 algorithm adiantum; 229 iv-method encblkno1; 230 keylength 256; 231 verify_method none; 232 keygen shell_cmd { 233 cmd "${COUNTKEY} n B3cJNiwuMt8N3D8NxHu6Y5C2xzu1D5wxIuyEStfCs+U="; 234 shared "helloworld" algorithm hkdf-hmac-sha256 \ 235 subkey AAAAUPDx8vP09fb3+Pk=; 236 }; 237 EOF 238 cat <<EOF >dskb 239 algorithm adiantum; 240 iv-method encblkno1; 241 keylength 256; 242 verify_method none; 243 keygen shell_cmd { 244 cmd "${COUNTKEY} n B3cJNiwuMt8N3D8NxHu6Y5C2xzu1D5wxIuyEStfCs+U="; 245 shared "helloworld" algorithm hkdf-hmac-sha256 \ 246 subkey AAAAQMxUtCBh7ha6mUU=; 247 }; 248 EOF 249 cat <<EOF >cgd.conf0 250 cgd0 /dev/dska dska 251 cgd1 /dev/dskb dskb 252 EOF 253 cat <<EOF >expected0 254 /dev/dska: PLJfJfqs1XqQQ09k0DYvKi0tCpDPGlpMXbAtVuzExb8= 255 /dev/dskb: ADxn574yb7sVdxHphNRRdObZxntMJA/ssMuUX6SXgEY= 256 EOF 257 cat <<EOF >cgd.conf1 258 cgd0 /dev/dskb dskb 259 cgd1 /dev/dska dska 260 EOF 261 cat <<EOF >expected1 262 /dev/dskb: ADxn574yb7sVdxHphNRRdObZxntMJA/ssMuUX6SXgEY= 263 /dev/dska: PLJfJfqs1XqQQ09k0DYvKi0tCpDPGlpMXbAtVuzExb8= 264 EOF 265 atf_check -o file:expected0 cgdconfig -T -f cgd.conf0 266 atf_check -o inline:'1\n' cat n 267 atf_check -o file:expected1 cgdconfig -T -f cgd.conf1 268 atf_check -o inline:'2\n' cat n 269 } 270 271 atf_init_test_cases() 272 { 273 atf_add_test_case sharedshellkeys 274 atf_add_test_case sharedstoredkey10 275 atf_add_test_case sharedstoredkey80 276 atf_add_test_case sharedstoredkeys 277 atf_add_test_case storedkey 278 atf_add_test_case storedkey2a 279 atf_add_test_case storedkey2b 280 atf_add_test_case storedkeys 281 } 282