| 104 | | char cmd[MAXBUF+1]; |
|---|
| 105 | | |
|---|
| 106 | | // Create RSA test files |
|---|
| 107 | | |
|---|
| 108 | | create_testfile(filename_rsa_noarmour_nopassphrase); |
|---|
| 109 | | create_testfile(filename_rsa_armour_nopassphrase); |
|---|
| 110 | | create_testfile(filename_rsa_noarmour_passphrase); |
|---|
| 111 | | create_testfile(filename_rsa_armour_passphrase); |
|---|
| 112 | | |
|---|
| 113 | | /* |
|---|
| 114 | | * Now encrypt the test files with GPG |
|---|
| 115 | | * Note:: To make it do SE_IP packets, do NOT use --openpgp and DO use --force-mdc |
|---|
| 116 | | */ |
|---|
| 117 | | |
|---|
| 118 | | // default symmetric algorithm |
|---|
| 119 | | snprintf(cmd,sizeof cmd,"gpg --quiet --no-tty --homedir=%s --force-mdc --compress-level 0 --quiet --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase); |
|---|
| 120 | | if (system(cmd)) |
|---|
| 121 | | { |
|---|
| 122 | | return 1; |
|---|
| 123 | | } |
|---|
| 124 | | |
|---|
| 125 | | #ifndef OPENSSL_NO_IDEA |
|---|
| 126 | | // \todo write test which uses PGP2 instead of using gpg to test IDEA |
|---|
| 127 | | /* |
|---|
| 128 | | // IDEA |
|---|
| 129 | | snprintf(cmd,sizeof cmd,"gpg --quiet --no-tty --homedir=%s --cipher-algo \"IDEA\" --output=%s/IDEA_%s.gpg --force-mdc --compress-level 0 --quiet --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); |
|---|
| 130 | | if (system(cmd)) |
|---|
| 131 | | { |
|---|
| 132 | | return 1; |
|---|
| 133 | | } |
|---|
| 134 | | */ |
|---|
| 135 | | #endif |
|---|
| 136 | | |
|---|
| 137 | | // TripleDES |
|---|
| 138 | | snprintf(cmd,sizeof cmd,"gpg --quiet --no-tty --homedir=%s --cipher-algo \"3DES\" --output=%s/3DES_%s.gpg --force-mdc --compress-level 0 --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); |
|---|
| 139 | | if (system(cmd)) |
|---|
| 140 | | { |
|---|
| 141 | | return 1; |
|---|
| 142 | | } |
|---|
| 143 | | |
|---|
| 144 | | // Cast5 |
|---|
| 145 | | snprintf(cmd,sizeof cmd,"gpg --quiet --no-tty --homedir=%s --cipher-algo \"CAST5\" --output=%s/CAST5_%s.gpg --force-mdc --compress-level 0 --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); |
|---|
| 146 | | if (system(cmd)) |
|---|
| 147 | | { |
|---|
| 148 | | return 1; |
|---|
| 149 | | } |
|---|
| 150 | | |
|---|
| 151 | | // AES128 |
|---|
| 152 | | snprintf(cmd,sizeof cmd,"gpg --quiet --no-tty --homedir=%s --cipher-algo \"AES\" --output=%s/AES128_%s.gpg --force-mdc --compress-level 0 --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); |
|---|
| 153 | | if (system(cmd)) |
|---|
| 154 | | { |
|---|
| 155 | | return 1; |
|---|
| 156 | | } |
|---|
| 157 | | |
|---|
| 158 | | // AES256 |
|---|
| 159 | | snprintf(cmd,sizeof cmd,"gpg --quiet --no-tty --homedir=%s --cipher-algo \"AES256\" --output=%s/AES256_%s.gpg --force-mdc --compress-level 0 --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase, dir, filename_rsa_noarmour_nopassphrase); |
|---|
| 160 | | if (system(cmd)) |
|---|
| 161 | | { |
|---|
| 162 | | return 1; |
|---|
| 163 | | } |
|---|
| 164 | | |
|---|
| 165 | | // Armour, no passphrase |
|---|
| 166 | | snprintf(cmd,sizeof cmd,"gpg --quiet --no-tty --homedir=%s --force-mdc --compress-level 0 --personal-cipher-preferences='CAST5' --encrypt --armor --recipient Alpha %s/%s", dir, dir, filename_rsa_armour_nopassphrase); |
|---|
| 167 | | if (system(cmd)) |
|---|
| 168 | | { |
|---|
| 169 | | return 1; |
|---|
| 170 | | } |
|---|
| 171 | | |
|---|
| 172 | | // No armour, passphrase |
|---|
| 173 | | snprintf(cmd,sizeof cmd,"gpg --quiet --no-tty --homedir=%s --force-mdc --compress-level 0 --personal-cipher-preferences='CAST5' --encrypt --recipient Bravo %s/%s", dir, dir, filename_rsa_noarmour_passphrase); |
|---|
| 174 | | if (system(cmd)) |
|---|
| 175 | | { |
|---|
| 176 | | return 1; |
|---|
| 177 | | } |
|---|
| 178 | | |
|---|
| 179 | | // Armour, passphrase |
|---|
| 180 | | snprintf(cmd,sizeof cmd,"gpg --quiet --no-tty --homedir=%s --force-mdc --compress-level 0 --personal-cipher-preferences='CAST5' --encrypt --armor --recipient Bravo %s/%s", dir, dir, filename_rsa_armour_passphrase); |
|---|
| 181 | | if (system(cmd)) |
|---|
| 182 | | { |
|---|
| 183 | | return 1; |
|---|
| 184 | | } |
|---|
| 185 | | |
|---|
| 186 | | int level=0; |
|---|
| 187 | | int alg=0; |
|---|
| 188 | | for (level=0; level<=MAX_COMPRESS_LEVEL; level++) |
|---|
| 189 | | { |
|---|
| 190 | | for (alg=0; alg < n_algos; alg++) |
|---|
| 191 | | { |
|---|
| 192 | | char filename[MAXBUF+1]; |
|---|
| 193 | | |
|---|
| 194 | | // unarmoured |
|---|
| 195 | | snprintf(filename, sizeof filename, "%s_%s_%d.txt", |
|---|
| 196 | | filename_rsa_noarmour_compress_base, algos[alg], level); |
|---|
| 197 | | create_testfile(filename); |
|---|
| 198 | | |
|---|
| 199 | | snprintf(cmd,sizeof cmd,"gpg --quiet --no-tty --homedir=%s --cipher-algo \"CAST5\" --output=%s/%s.gpg --force-mdc --compress-algo \"%s\" --compress-level %d --encrypt --recipient Alpha %s/%s", dir, dir, filename, algos[alg], level, dir, filename); |
|---|
| 200 | | if (system(cmd)) |
|---|
| 201 | | { |
|---|
| 202 | | return 1; |
|---|
| 203 | | } |
|---|
| 204 | | |
|---|
| 205 | | // armoured |
|---|
| 206 | | snprintf(filename, sizeof filename, "%s_%s_%d.txt", |
|---|
| 207 | | filename_rsa_armour_compress_base, algos[alg], level); |
|---|
| 208 | | create_testfile(filename); |
|---|
| 209 | | |
|---|
| 210 | | snprintf(cmd,sizeof cmd,"gpg --quiet --no-tty --homedir=%s --cipher-algo \"CAST5\" --output=%s/%s.asc --force-mdc --compress-algo \"%s\" --compress-level %d --encrypt --armor --recipient Alpha %s/%s", dir, dir, filename, algos[alg], level, dir, filename); |
|---|
| 211 | | |
|---|
| 212 | | if (system(cmd)) |
|---|
| 213 | | { |
|---|
| 214 | | return 1; |
|---|
| 215 | | } |
|---|
| 216 | | } |
|---|
| 217 | | } |
|---|
| 218 | | |
|---|
| 292 | | test_rsa_decrypt(armour,passphrase,filename_rsa_noarmour_nopassphrase,NULL); |
|---|
| 293 | | } |
|---|
| 294 | | |
|---|
| 295 | | static void test_rsa_decrypt_noarmour_nopassphrase_3des(void) |
|---|
| 296 | | { |
|---|
| 297 | | CU_FAIL("3DES decryption not yet unimplemented"); |
|---|
| 298 | | |
|---|
| 299 | | /* |
|---|
| 300 | | int armour=0; |
|---|
| 301 | | int passphrase=0; |
|---|
| 302 | | test_rsa_decrypt(armour,passphrase,filename_rsa_noarmour_nopassphrase,"3DES"); |
|---|
| 303 | | */ |
|---|
| 304 | | } |
|---|
| 305 | | |
|---|
| 306 | | static void test_rsa_decrypt_noarmour_nopassphrase_cast5(void) |
|---|
| 307 | | { |
|---|
| 308 | | int armour=0; |
|---|
| 309 | | int passphrase=0; |
|---|
| 310 | | test_rsa_decrypt(armour,passphrase,filename_rsa_noarmour_nopassphrase,"CAST5"); |
|---|
| 311 | | } |
|---|
| 312 | | |
|---|
| 313 | | #ifdef TODO |
|---|
| 314 | | static void test_rsa_decrypt_armour_nopassphrase_cast5(void) |
|---|
| 315 | | { |
|---|
| 316 | | int armour=1; |
|---|
| 317 | | int passphrase=0; |
|---|
| 318 | | test_rsa_decrypt(armour,passphrase,filename_rsa_noarmour_nopassphrase,"CAST5"); |
|---|
| 319 | | } |
|---|
| 320 | | #endif |
|---|
| 321 | | |
|---|
| 322 | | static void test_rsa_decrypt_noarmour_nopassphrase_aes128(void) |
|---|
| 323 | | { |
|---|
| 324 | | int armour=0; |
|---|
| 325 | | int passphrase=0; |
|---|
| 326 | | test_rsa_decrypt(armour,passphrase,filename_rsa_noarmour_nopassphrase,"AES128"); |
|---|
| 327 | | } |
|---|
| 328 | | |
|---|
| 329 | | static void test_rsa_decrypt_noarmour_nopassphrase_aes256(void) |
|---|
| 330 | | { |
|---|
| 331 | | int armour=0; |
|---|
| 332 | | int passphrase=0; |
|---|
| 333 | | test_rsa_decrypt(armour,passphrase,filename_rsa_noarmour_nopassphrase,"AES256"); |
|---|
| 334 | | } |
|---|
| 335 | | |
|---|
| 336 | | // |
|---|
| 337 | | |
|---|
| 338 | | static void test_rsa_decrypt_armour_nopassphrase(void) |
|---|
| 339 | | { |
|---|
| 340 | | int armour=1; |
|---|
| 341 | | int passphrase=0; |
|---|
| 342 | | test_rsa_decrypt(armour,passphrase,filename_rsa_armour_nopassphrase,NULL); |
|---|
| 343 | | } |
|---|
| 344 | | |
|---|
| 345 | | static void test_rsa_decrypt_noarmour_passphrase(void) |
|---|
| 346 | | { |
|---|
| 347 | | int armour=0; |
|---|
| 348 | | int passphrase=1; |
|---|
| 349 | | test_rsa_decrypt(armour,passphrase,filename_rsa_noarmour_passphrase,NULL); |
|---|
| 350 | | } |
|---|
| 351 | | |
|---|
| 352 | | static void test_rsa_decrypt_armour_passphrase(void) |
|---|
| 353 | | { |
|---|
| 354 | | int armour=1; |
|---|
| 355 | | int passphrase=1; |
|---|
| 356 | | test_rsa_decrypt(armour,passphrase,filename_rsa_armour_passphrase,NULL); |
|---|
| 357 | | } |
|---|
| 358 | | |
|---|
| 359 | | static void test_rsa_decrypt_noarmour_compressed(void) |
|---|
| 360 | | { |
|---|
| 361 | | int armour=0; |
|---|
| 362 | | int passphrase=0; |
|---|
| 363 | | char filename[MAXBUF+1]; |
|---|
| 364 | | int level=0; |
|---|
| 365 | | int alg=0; |
|---|
| 366 | | for (level=1; level<=MAX_COMPRESS_LEVEL; level++) |
|---|
| | 178 | int compress_alg=0; |
|---|
| | 179 | int compress_lvl=0; |
|---|
| | 180 | |
|---|
| | 181 | for (compress_alg=0; compress_alg<n_compress_algos; compress_alg++) |
|---|
| 370 | | // unarmoured |
|---|
| 371 | | snprintf(filename, sizeof filename, "%s_%s_%d.txt", |
|---|
| 372 | | filename_rsa_noarmour_compress_base, algos[alg],level); |
|---|
| 373 | | test_rsa_decrypt(armour,passphrase,filename,NULL); |
|---|
| | 185 | for (armour=0; armour<=1; armour++) |
|---|
| | 186 | { |
|---|
| | 187 | char *armour_cmd= armour ? "--armor " : ""; |
|---|
| | 188 | char *suffix= armour ? "asc" : "gpg"; |
|---|
| | 189 | |
|---|
| | 190 | for (passphrase=0; passphrase<=1; passphrase++) |
|---|
| | 191 | { |
|---|
| | 192 | char *rcpt= passphrase ? "Bravo" : "Alpha"; |
|---|
| | 193 | |
|---|
| | 194 | // Create filename matching these params |
|---|
| | 195 | create_filename(&filename[0],sizeof filename, |
|---|
| | 196 | armour, passphrase, |
|---|
| | 197 | sym_alg, |
|---|
| | 198 | compress_algos[compress_alg], compress_lvl); |
|---|
| | 199 | |
|---|
| | 200 | // Create file with unique text matching this test |
|---|
| | 201 | create_testfile(filename); |
|---|
| | 202 | |
|---|
| | 203 | // Encrypt file using GPG |
|---|
| | 204 | snprintf(cmd,sizeof cmd,"gpg --quiet --no-tty --homedir=%s --cipher-algo \"%s\" --compress-algo \"%s\" --compress-level %d --output=%s/%s.%s --force-mdc --encrypt --recipient %s %s %s/%s", |
|---|
| | 205 | dir, //homedir |
|---|
| | 206 | sym_alg, |
|---|
| | 207 | compress_algos[compress_alg], |
|---|
| | 208 | compress_lvl, |
|---|
| | 209 | dir, filename, suffix, // for output file |
|---|
| | 210 | rcpt, |
|---|
| | 211 | armour_cmd, |
|---|
| | 212 | dir, filename); |
|---|
| | 213 | if (system(cmd)) |
|---|
| | 214 | { |
|---|
| | 215 | fprintf(stderr,"Err: cmd is %s\n", cmd); |
|---|
| | 216 | // return 1; |
|---|
| | 217 | } |
|---|
| | 218 | |
|---|
| | 219 | // Decrypt using OPS |
|---|
| | 220 | test_rsa_decrypt(armour,passphrase,filename); |
|---|
| | 221 | } |
|---|
| | 222 | } |
|---|
| 378 | | static void test_rsa_decrypt_armour_compressed(void) |
|---|
| 379 | | { |
|---|
| 380 | | int armour=1; |
|---|
| 381 | | int passphrase=0; |
|---|
| 382 | | char filename[MAXBUF+1]; |
|---|
| 383 | | int level=0; |
|---|
| 384 | | int alg=0; |
|---|
| 385 | | for (level=1; level<=MAX_COMPRESS_LEVEL; level++) |
|---|
| 386 | | { |
|---|
| 387 | | for (alg=0; alg<n_algos; alg++) |
|---|
| 388 | | { |
|---|
| 389 | | // unarmoured |
|---|
| 390 | | snprintf(filename, sizeof filename, "%s_%s_%d.txt", |
|---|
| 391 | | filename_rsa_armour_compress_base, algos[alg], level); |
|---|
| 392 | | test_rsa_decrypt(armour,passphrase,filename,NULL); |
|---|
| 393 | | } |
|---|
| 394 | | } |
|---|
| 395 | | } |
|---|
| | 227 | static void test_rsa_decrypt_cast5(void) |
|---|
| | 228 | { |
|---|
| | 229 | return test_rsa_decrypt_generic("cast5"); |
|---|
| | 230 | } |
|---|
| | 231 | |
|---|
| | 232 | static void test_rsa_decrypt_aes128(void) |
|---|
| | 233 | { |
|---|
| | 234 | return test_rsa_decrypt_generic("aes"); |
|---|
| | 235 | } |
|---|
| | 236 | |
|---|
| | 237 | static void test_rsa_decrypt_aes256(void) |
|---|
| | 238 | { |
|---|
| | 239 | return test_rsa_decrypt_generic("aes256"); |
|---|
| | 240 | } |
|---|
| | 241 | |
|---|
| | 242 | #ifdef FUTURE |
|---|
| | 243 | static void test_rsa_decrypt_3des(void) |
|---|
| | 244 | { |
|---|
| | 245 | return test_rsa_decrypt_generic("3des"); |
|---|
| | 246 | } |
|---|
| | 247 | #endif |
|---|
| | 248 | |
|---|
| | 249 | // |
|---|
| 410 | | if (NULL == CU_add_test(suite, "Unarmoured, no passphrase (Default)", test_rsa_decrypt_noarmour_nopassphrase)) |
|---|
| 411 | | return 0; |
|---|
| 412 | | |
|---|
| 413 | | if (NULL == CU_add_test(suite, "Unarmoured, no passphrase (CAST5)", test_rsa_decrypt_noarmour_nopassphrase_cast5)) |
|---|
| 414 | | return 0; |
|---|
| 415 | | |
|---|
| 416 | | if (NULL == CU_add_test(suite, "Unarmoured, no passphrase (AES128)", test_rsa_decrypt_noarmour_nopassphrase_aes128)) |
|---|
| 417 | | return 0; |
|---|
| 418 | | |
|---|
| 419 | | if (NULL == CU_add_test(suite, "Unarmoured, no passphrase (AES256)", test_rsa_decrypt_noarmour_nopassphrase_aes256)) |
|---|
| 420 | | return 0; |
|---|
| 421 | | |
|---|
| 422 | | if (NULL == CU_add_test(suite, "Unarmoured, no passphrase (3DES)", test_rsa_decrypt_noarmour_nopassphrase_3des)) |
|---|
| 423 | | return 0; |
|---|
| 424 | | |
|---|
| 425 | | if (NULL == CU_add_test(suite, "Unarmoured, passphrase", test_rsa_decrypt_noarmour_passphrase)) |
|---|
| 426 | | return 0; |
|---|
| 427 | | |
|---|
| 428 | | if (NULL == CU_add_test(suite, "Armoured, no passphrase", test_rsa_decrypt_armour_nopassphrase)) |
|---|
| 429 | | return 0; |
|---|
| 430 | | |
|---|
| 431 | | if (NULL == CU_add_test(suite, "Armoured, passphrase", test_rsa_decrypt_armour_passphrase)) |
|---|
| 432 | | return 0; |
|---|
| 433 | | |
|---|
| 434 | | if (NULL == CU_add_test(suite, "Unarmoured, compressed", test_rsa_decrypt_noarmour_compressed)) |
|---|
| 435 | | return 0; |
|---|
| 436 | | |
|---|
| 437 | | if (NULL == CU_add_test(suite, "Armoured, compressed", test_rsa_decrypt_armour_compressed)) |
|---|
| 438 | | return 0; |
|---|
| 439 | | |
|---|
| | 262 | if (NULL == CU_add_test(suite, "CAST5", test_rsa_decrypt_cast5)) |
|---|
| | 263 | return 0; |
|---|
| | 264 | |
|---|
| | 265 | if (NULL == CU_add_test(suite, "AES128", test_rsa_decrypt_aes128)) |
|---|
| | 266 | return 0; |
|---|
| | 267 | |
|---|
| | 268 | if (NULL == CU_add_test(suite, "AES256", test_rsa_decrypt_aes256)) |
|---|
| | 269 | return 0; |
|---|
| | 270 | |
|---|
| | 271 | #ifdef FUTURE |
|---|
| | 272 | if (NULL == CU_add_test(suite, "3DES", test_rsa_decrypt_3des)) |
|---|
| | 273 | return 0; |
|---|
| | 274 | #endif |
|---|
| | 275 | |
|---|