|
6 | 6 | import unittest |
7 | 7 |
|
8 | 8 | sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) |
9 | | -from wolfclu_test import WOLFSSL_BIN, run_wolfssl, test_main |
| 9 | +from wolfclu_test import WOLFSSL_BIN, CERTS_DIR, run_wolfssl, test_main |
10 | 10 |
|
11 | 11 | # Files that tests may create; cleaned up by tearDownClass |
12 | 12 | _TEMP_FILES = [] |
@@ -385,12 +385,100 @@ def test_xmss_missing_height_value(self): |
385 | 385 | self._track("xmss-bad.priv", "xmss-bad.pub") |
386 | 386 | r = run_wolfssl("-genkey", "xmss", "-out", "xmss-bad", |
387 | 387 | "-outform", "raw", "-output", "KEYPAIR", "-height") |
388 | | - self.assertNotEqual(r.returncode, 0, |
389 | | - "expected failure for missing -height value") |
| 388 | + self.assertEqual(r.returncode, 0, |
| 389 | + "expected defalut value of 20 set for -hieght no " |
| 390 | + "crash") |
| 391 | + |
| 392 | + def test_xmss_missing_height_arg(self): |
| 393 | + self._track("xmss-bad.priv", "xmss-bad.pub") |
| 394 | + r = run_wolfssl("-genkey", "xmss", "-out", "xmss-bad", |
| 395 | + "-outform", "raw", "-output", "KEYPAIR") |
| 396 | + self.assertEqual(r.returncode, 0, |
| 397 | + "expected defalut value for -hieght no " |
| 398 | + "crash") |
| 399 | + |
| 400 | +@unittest.skipUnless(_has_algorithm("xmss"), "xmss not available") |
| 401 | +class XmssmtTest(_GenkeySignVerifyBase): |
| 402 | + |
| 403 | + def test_xmssmt_raw(self): |
| 404 | + # The XMSS^MT signer derives the parameter set from the key file name, |
| 405 | + # so the keybase must be a valid param string with '-' in place of '/' |
| 406 | + # (e.g. "XMSSMT-SHA2_20/2_256" -> "XMSSMT-SHA2_20-2_256"). -height 20 |
| 407 | + # defaults to layer 2, matching this name. |
| 408 | + keybase = "XMSSMT-SHA2_20-2_256" |
| 409 | + self._track(keybase + ".priv", keybase + ".pub") |
| 410 | + self._gen_sign_verify( |
| 411 | + "xmssmt", keybase, "xmss-signed.sig", "raw", |
| 412 | + extra_genkey_args=["-height", "20"], |
| 413 | + skip_priv_verify=True, use_output_flag=True) |
| 414 | + |
| 415 | + def test_xmss_missing_height_value(self): |
| 416 | + """-height with no value must fail gracefully (no crash).""" |
| 417 | + self._track("xmss-bad.priv", "xmss-bad.pub") |
| 418 | + r = run_wolfssl("-genkey", "xmssmt", "-out", "xmss-bad", |
| 419 | + "-outform", "raw", "-output", "KEYPAIR", "-height") |
| 420 | + self.assertEqual(r.returncode, 0, |
| 421 | + "expected defalut value of 20 set for -hieght no " |
| 422 | + "crash") |
| 423 | + |
| 424 | + def test_xmss_missing_height_arg(self): |
| 425 | + self._track("xmss-bad.priv", "xmss-bad.pub") |
| 426 | + r = run_wolfssl("-genkey", "xmssmt", "-out", "xmss-bad", |
| 427 | + "-outform", "raw", "-output", "KEYPAIR") |
| 428 | + self.assertEqual(r.returncode, 0, |
| 429 | + "expected defalut value for -hieght no " |
| 430 | + "crash") |
| 431 | + |
| 432 | + |
| 433 | +class SignVerifySetupArgsTest(unittest.TestCase): |
| 434 | + """Argument-parsing branches in clu_sign_verify_setup.c. |
| 435 | +
|
| 436 | + These exercise the legacy `-rsa`/`-ecc`/... sign & verify entry point |
| 437 | + (note the leading dash, which selects the legacy code path). |
| 438 | + """ |
| 439 | + |
| 440 | + SIGN_FILE = "svsetup-sign-this.txt" |
| 441 | + RSA_KEY = os.path.join(CERTS_DIR, "server-key.pem") |
| 442 | + ECC_KEY = os.path.join(CERTS_DIR, "ecc-key.pem") |
| 443 | + ECC_PUB = os.path.join(CERTS_DIR, "ecc-keyPub.pem") |
| 444 | + |
| 445 | + @classmethod |
| 446 | + def setUpClass(cls): |
| 447 | + config_log = os.path.join(".", "config.log") |
| 448 | + if os.path.isfile(config_log): |
| 449 | + with open(config_log, "r") as f: |
| 450 | + if "disable-filesystem" in f.read(): |
| 451 | + raise unittest.SkipTest("filesystem support disabled") |
| 452 | + with open(cls.SIGN_FILE, "w") as f: |
| 453 | + f.write("Sign this test data\n") |
| 454 | + |
| 455 | + @classmethod |
| 456 | + def tearDownClass(cls): |
| 457 | + _cleanup_files([cls.SIGN_FILE]) |
| 458 | + |
| 459 | + def test_sign_help(self): |
| 460 | + r = run_wolfssl("-rsa", "-sign", "-help") |
390 | 461 | self.assertGreaterEqual(r.returncode, 0, |
391 | | - "-height without value crashed with signal " |
| 462 | + "sign help crashed with signal " |
392 | 463 | "{}".format(r.returncode)) |
| 464 | + self.assertIn("RSA Sign", r.stdout + r.stderr) |
393 | 465 |
|
| 466 | + def test_verify_help(self): |
| 467 | + r = run_wolfssl("-rsa", "-verify", "-help") |
| 468 | + self.assertGreaterEqual(r.returncode, 0, |
| 469 | + "verify help crashed with signal " |
| 470 | + "{}".format(r.returncode)) |
| 471 | + self.assertIn("RSA Verify", r.stdout + r.stderr) |
| 472 | + |
| 473 | + def test_generic_help(self): |
| 474 | + """No -sign/-verify prints both the sign and verify help blocks.""" |
| 475 | + r = run_wolfssl("-ecc", "-help") |
| 476 | + self.assertGreaterEqual(r.returncode, 0, |
| 477 | + "generic help crashed with signal " |
| 478 | + "{}".format(r.returncode)) |
| 479 | + combined = r.stdout + r.stderr |
| 480 | + self.assertIn("ECC Sign", combined) |
| 481 | + self.assertIn("ECC Verify", combined) |
394 | 482 |
|
395 | 483 | class GenkeyArgvTest(unittest.TestCase): |
396 | 484 | """Argument-bounds checks for the genkey subcommand entry point.""" |
|
0 commit comments