rnpgp / rnp

@@ -5502,6 +5502,157 @@
Loading
5502 5502
    rnp_ffi_destroy(ffi);
5503 5503
}
5504 5504
5505 +
TEST_F(rnp_tests, test_ffi_malformed_keys_import)
5506 +
{
5507 +
    rnp_ffi_t   ffi = NULL;
5508 +
    rnp_input_t input = NULL;
5509 +
5510 +
    assert_rnp_success(rnp_ffi_create(&ffi, "GPG", "GPG"));
5511 +
    /* import keys with bad key0-uid0 certification, first without flag */
5512 +
    assert_rnp_success(
5513 +
      rnp_input_from_path(&input, "data/test_key_edge_cases/pubring-malf-cert.pgp"));
5514 +
    assert_rnp_failure(rnp_import_keys(ffi, input, RNP_LOAD_SAVE_PUBLIC_KEYS, NULL));
5515 +
    rnp_input_destroy(input);
5516 +
    size_t keycount = 255;
5517 +
    assert_rnp_success(rnp_get_public_key_count(ffi, &keycount));
5518 +
    assert_int_equal(keycount, 0);
5519 +
    /* now try with RNP_LOAD_SAVE_SKIP_BAD_PACKETS */
5520 +
    assert_rnp_success(
5521 +
      rnp_input_from_path(&input, "data/test_key_edge_cases/pubring-malf-cert.pgp"));
5522 +
    assert_rnp_success(rnp_import_keys(
5523 +
      ffi, input, RNP_LOAD_SAVE_PUBLIC_KEYS | RNP_LOAD_SAVE_SKIP_BAD_PACKETS, NULL));
5524 +
    rnp_input_destroy(input);
5525 +
    assert_rnp_success(rnp_get_public_key_count(ffi, &keycount));
5526 +
    assert_int_equal(keycount, 7);
5527 +
    rnp_key_handle_t key = NULL;
5528 +
    assert_rnp_success(rnp_locate_key(ffi, "keyid", "7bc6709b15c23a4a", &key));
5529 +
    assert_non_null(key);
5530 +
    size_t uidcount = 255;
5531 +
    assert_rnp_success(rnp_key_get_uid_count(key, &uidcount));
5532 +
    assert_int_equal(uidcount, 3);
5533 +
    size_t subcount = 255;
5534 +
    assert_rnp_success(rnp_key_get_subkey_count(key, &subcount));
5535 +
    assert_int_equal(subcount, 3);
5536 +
    assert_rnp_success(rnp_key_handle_destroy(key));
5537 +
    assert_rnp_success(rnp_locate_key(ffi, "keyid", "2fcadf05ffa501bb", &key));
5538 +
    assert_non_null(key);
5539 +
    assert_rnp_success(rnp_key_handle_destroy(key));
5540 +
5541 +
    /* import keys with bad key0-sub0 binding */
5542 +
    assert_rnp_success(rnp_unload_keys(ffi, RNP_KEY_UNLOAD_PUBLIC));
5543 +
    assert_rnp_success(rnp_get_public_key_count(ffi, &keycount));
5544 +
    assert_int_equal(keycount, 0);
5545 +
    assert_rnp_success(
5546 +
      rnp_input_from_path(&input, "data/test_key_edge_cases/pubring-malf-key0-sub0-bind.pgp"));
5547 +
    assert_rnp_success(rnp_import_keys(
5548 +
      ffi, input, RNP_LOAD_SAVE_PUBLIC_KEYS | RNP_LOAD_SAVE_SKIP_BAD_PACKETS, NULL));
5549 +
    rnp_input_destroy(input);
5550 +
    assert_rnp_success(rnp_get_public_key_count(ffi, &keycount));
5551 +
    assert_int_equal(keycount, 7);
5552 +
    assert_rnp_success(rnp_locate_key(ffi, "keyid", "7bc6709b15c23a4a", &key));
5553 +
    assert_non_null(key);
5554 +
    uidcount = 255;
5555 +
    assert_rnp_success(rnp_key_get_uid_count(key, &uidcount));
5556 +
    assert_int_equal(uidcount, 3);
5557 +
    subcount = 255;
5558 +
    assert_rnp_success(rnp_key_get_subkey_count(key, &subcount));
5559 +
    assert_int_equal(subcount, 3);
5560 +
    assert_rnp_success(rnp_key_handle_destroy(key));
5561 +
    assert_rnp_success(rnp_locate_key(ffi, "keyid", "2fcadf05ffa501bb", &key));
5562 +
    assert_non_null(key);
5563 +
    assert_rnp_success(rnp_key_handle_destroy(key));
5564 +
5565 +
    /* import keys with bad key0-sub0 packet */
5566 +
    assert_rnp_success(rnp_unload_keys(ffi, RNP_KEY_UNLOAD_PUBLIC));
5567 +
    assert_rnp_success(
5568 +
      rnp_input_from_path(&input, "data/test_key_edge_cases/pubring-malf-key0-sub0.pgp"));
5569 +
    assert_rnp_success(rnp_import_keys(
5570 +
      ffi, input, RNP_LOAD_SAVE_PUBLIC_KEYS | RNP_LOAD_SAVE_SKIP_BAD_PACKETS, NULL));
5571 +
    rnp_input_destroy(input);
5572 +
    assert_rnp_success(rnp_get_public_key_count(ffi, &keycount));
5573 +
    assert_int_equal(keycount, 6);
5574 +
    assert_rnp_success(rnp_locate_key(ffi, "keyid", "7bc6709b15c23a4a", &key));
5575 +
    assert_non_null(key);
5576 +
    uidcount = 255;
5577 +
    assert_rnp_success(rnp_key_get_uid_count(key, &uidcount));
5578 +
    assert_int_equal(uidcount, 3);
5579 +
    subcount = 255;
5580 +
    assert_rnp_success(rnp_key_get_subkey_count(key, &subcount));
5581 +
    assert_int_equal(subcount, 2);
5582 +
    assert_rnp_success(rnp_key_handle_destroy(key));
5583 +
    assert_rnp_success(rnp_locate_key(ffi, "keyid", "2fcadf05ffa501bb", &key));
5584 +
    assert_non_null(key);
5585 +
    assert_rnp_success(rnp_key_handle_destroy(key));
5586 +
5587 +
    /* import keys with bad key0 packet */
5588 +
    assert_rnp_success(rnp_unload_keys(ffi, RNP_KEY_UNLOAD_PUBLIC));
5589 +
    assert_rnp_success(
5590 +
      rnp_input_from_path(&input, "data/test_key_edge_cases/pubring-malf-key0.pgp"));
5591 +
    assert_rnp_success(rnp_import_keys(
5592 +
      ffi, input, RNP_LOAD_SAVE_PUBLIC_KEYS | RNP_LOAD_SAVE_SKIP_BAD_PACKETS, NULL));
5593 +
    rnp_input_destroy(input);
5594 +
    assert_rnp_success(rnp_get_public_key_count(ffi, &keycount));
5595 +
    assert_int_equal(keycount, 3);
5596 +
    assert_rnp_success(rnp_locate_key(ffi, "keyid", "7bc6709b15c23a4a", &key));
5597 +
    assert_null(key);
5598 +
    assert_rnp_success(rnp_locate_key(ffi, "keyid", "2fcadf05ffa501bb", &key));
5599 +
    assert_non_null(key);
5600 +
    assert_rnp_success(rnp_key_handle_destroy(key));
5601 +
5602 +
    /* import secret keys with bad key1 packet - public should be added as well */
5603 +
    assert_rnp_success(
5604 +
      rnp_input_from_path(&input, "data/test_key_edge_cases/secring-malf-key1.pgp"));
5605 +
    assert_rnp_success(rnp_import_keys(
5606 +
      ffi, input, RNP_LOAD_SAVE_SECRET_KEYS | RNP_LOAD_SAVE_SKIP_BAD_PACKETS, NULL));
5607 +
    rnp_input_destroy(input);
5608 +
    assert_rnp_success(rnp_get_public_key_count(ffi, &keycount));
5609 +
    assert_int_equal(keycount, 7);
5610 +
    assert_rnp_success(rnp_get_secret_key_count(ffi, &keycount));
5611 +
    assert_int_equal(keycount, 4);
5612 +
5613 +
    assert_rnp_success(rnp_locate_key(ffi, "keyid", "7bc6709b15c23a4a", &key));
5614 +
    assert_non_null(key);
5615 +
    bool secret = false;
5616 +
    assert_rnp_success(rnp_key_have_secret(key, &secret));
5617 +
    assert_true(secret);
5618 +
    assert_rnp_success(rnp_key_handle_destroy(key));
5619 +
    assert_rnp_success(rnp_locate_key(ffi, "keyid", "326ef111425d14a5", &key));
5620 +
    assert_non_null(key);
5621 +
    assert_rnp_success(rnp_key_have_secret(key, &secret));
5622 +
    assert_false(secret);
5623 +
    assert_rnp_success(rnp_key_handle_destroy(key));
5624 +
5625 +
    /* import secret keys with bad key0 packet */
5626 +
    assert_rnp_success(
5627 +
      rnp_input_from_path(&input, "data/test_key_edge_cases/secring-malf-key0.pgp"));
5628 +
    assert_rnp_success(rnp_import_keys(
5629 +
      ffi, input, RNP_LOAD_SAVE_SECRET_KEYS | RNP_LOAD_SAVE_SKIP_BAD_PACKETS, NULL));
5630 +
    rnp_input_destroy(input);
5631 +
    assert_rnp_success(rnp_get_public_key_count(ffi, &keycount));
5632 +
    assert_int_equal(keycount, 7);
5633 +
    assert_rnp_success(rnp_get_secret_key_count(ffi, &keycount));
5634 +
    assert_int_equal(keycount, 7);
5635 +
5636 +
    assert_rnp_success(rnp_locate_key(ffi, "keyid", "7bc6709b15c23a4a", &key));
5637 +
    assert_non_null(key);
5638 +
    assert_rnp_success(rnp_key_have_secret(key, &secret));
5639 +
    assert_true(secret);
5640 +
    assert_rnp_success(rnp_key_handle_destroy(key));
5641 +
    assert_rnp_success(rnp_locate_key(ffi, "userid", "key1-uid2", &key));
5642 +
    assert_non_null(key);
5643 +
    assert_rnp_success(rnp_key_have_secret(key, &secret));
5644 +
    assert_true(secret);
5645 +
    assert_rnp_success(rnp_key_handle_destroy(key));
5646 +
    assert_rnp_success(rnp_locate_key(ffi, "keyid", "326ef111425d14a5", &key));
5647 +
    assert_non_null(key);
5648 +
    assert_rnp_success(rnp_key_have_secret(key, &secret));
5649 +
    assert_true(secret);
5650 +
    assert_rnp_success(rnp_key_handle_destroy(key));
5651 +
5652 +
    /* cleanup */
5653 +
    rnp_ffi_destroy(ffi);
5654 +
}
5655 +
5505 5656
TEST_F(rnp_tests, test_ffi_stripped_keys_import)
5506 5657
{
5507 5658
    rnp_ffi_t   ffi = NULL;
Files Coverage
src 83.56%
include/rekey/rnp_key_store.h 100.00%
Project Totals (82 files) 83.56%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading