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