Skip to content

Commit

Permalink
Added test case with low-level botan calls, reproducing windows crash…
Browse files Browse the repository at this point in the history
… issue.
  • Loading branch information
ni4 committed Nov 24, 2023
1 parent e75fc49 commit 8c08edc
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions src/tests/cipher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,3 +1137,108 @@ TEST_F(rnp_tests, test_brainpool_enabled)
assert_false(supported);
#endif
}

#if defined(CRYPTO_BACKEND_BOTAN)
TEST_F(rnp_tests, test_windows_botan_crash)

Check warning

Code scanning / CodeQL

Poorly documented large function Warning test

Poorly documented function: fewer than 2% comments for a function of 102 lines.
{
struct botan_cipher_struct *cipher = NULL;
assert_int_equal(botan_cipher_init(&cipher, "AES-128/OCB", BOTAN_CIPHER_INIT_FLAG_DECRYPT),
0);

const char *key1 = "c78a5d2cbcfc00f557c6193141115abe";
uint8_t bufbin[32768] = {0};
assert_int_equal(rnp::hex_decode(key1, bufbin, 16), 16);
assert_int_equal(botan_cipher_set_key(cipher, bufbin, 16), 0);

const char *ad1 = "c3050702";
assert_int_equal(rnp::hex_decode(ad1, bufbin, 4), 4);
assert_int_equal(botan_cipher_set_associated_data(cipher, bufbin, 4), 0);

const char *nonce1 = "7122c391f2b5327292523ce1cb6a69";
assert_int_equal(rnp::hex_decode(nonce1, bufbin, 15), 15);
assert_int_equal(botan_cipher_start(cipher, bufbin, 15), 0);

auto data = file_to_vec("data/test_messages/message.aead-windows-issue-botan");
size_t idx = 0;
uint8_t outbuf[32768] = {0};
size_t written = 0;
size_t read = 0;
assert_int_equal(botan_cipher_update(cipher,
BOTAN_CIPHER_UPDATE_FLAG_FINAL,
outbuf,
sizeof(outbuf),
&written,
data.data(),
32,
&read),
0);
assert_int_equal(written, 16);
assert_int_equal(read, 32);
idx += read;
assert_int_equal(botan_cipher_reset(cipher), 0);
assert_int_equal(botan_cipher_destroy(cipher), 0);

assert_int_equal(botan_cipher_init(&cipher, "AES-128/OCB", BOTAN_CIPHER_INIT_FLAG_DECRYPT),
0);

const char *key2 = "417835a476bc5958b18d41fb00cf682d";
assert_int_equal(rnp::hex_decode(key2, bufbin, 16), 16);
assert_int_equal(botan_cipher_set_key(cipher, bufbin, 16), 0);

const char *ad2 = "d40107020c0000000000000000";
assert_int_equal(rnp::hex_decode(ad2, bufbin, 13), 13);
assert_int_equal(botan_cipher_set_associated_data(cipher, bufbin, 13), 0);

const char *nonce2 = "005dbbbe0088f9d17ca2d8d464920f";
assert_int_equal(rnp::hex_decode(nonce2, bufbin, 15), 15);
assert_int_equal(botan_cipher_start(cipher, bufbin, 15), 0);

assert_int_equal(
botan_cipher_update(
cipher, 0, outbuf, sizeof(outbuf), &written, data.data() + idx, 32736, &read),
0);
assert_int_equal(written, 32736);
assert_int_equal(read, 32736);
idx += read;

assert_int_equal(
botan_cipher_update(
cipher, 0, outbuf, sizeof(outbuf), &written, data.data() + idx, 32736, &read),
0);
assert_int_equal(written, 32736);
assert_int_equal(read, 32736);
idx += read;

assert_int_equal(
botan_cipher_update(
cipher, 0, outbuf, sizeof(outbuf), &written, data.data() + idx, 32736, &read),
0);
assert_int_equal(written, 32736);
assert_int_equal(read, 32736);
idx += read;

assert_int_equal(
botan_cipher_update(
cipher, 0, outbuf, sizeof(outbuf), &written, data.data() + idx, 32736, &read),
0);
assert_int_equal(written, 32736);
assert_int_equal(read, 32736);
idx += read;

assert_int_equal(botan_cipher_update(cipher,
BOTAN_CIPHER_UPDATE_FLAG_FINAL,
outbuf,
sizeof(outbuf),
&written,
data.data() + idx,
25119,
&read),
0);
assert_int_equal(written, 25119 - 16);
assert_int_equal(read, 25119);
idx += read;

assert_int_equal(botan_cipher_reset(cipher), 0);
assert_int_equal(botan_cipher_destroy(cipher), 0);
}
#endif
Binary file not shown.

0 comments on commit 8c08edc

Please sign in to comment.