#include <stdint.h>
#include <yaca_key.h>
+#include <yaca_types.h>
#include <yaca_error.h>
#include "yaca-test-common.h"
{
YACA_INVALID_PARAM(yaca_key_generate(key_type, key_bit_len, key));
- YACA_ASSERT_MSG(key == NULL || *key == YACA_KEY_NULL,
+ YACA_ASSERT_MSG(key == nullptr || *key == YACA_KEY_NULL,
"Non-empty key returned from a function that failed");
}
RUNNER_TEST_GROUP_INIT(T4000_YACA_KEY);
-RUNNER_TEST(T4002_yaca_key_import)
-{
-}
-
-RUNNER_TEST(T4003_yaca_key_export)
-{
-}
-
RUNNER_TEST(T4006_yaca_key_free)
{
}
YACA_INVALID_PARAM(yaca_key_get_bit_length(key_ptr.get(), nullptr));
}
+
+RUNNER_TEST(T4220_yaca_key_export_invalid_param, YacaTest)
+{
+ KeyPtr key_sym = generate_key(YACA_KEY_TYPE_SYMMETRIC, 1024);
+ KeyPtr key_rsa = generate_key(YACA_KEY_TYPE_RSA_PRIV, 1024);
+ char *data;
+ size_t data_len;
+
+ YACA_INVALID_PARAM(yaca_key_export(nullptr,
+ YACA_KEY_FORMAT_DEFAULT,
+ YACA_KEY_FILE_FORMAT_BASE64,
+ nullptr, &data, &data_len));
+
+ YACA_INVALID_PARAM(yaca_key_export(key_sym.get(),
+ YACA_KEY_FORMAT_DEFAULT,
+ YACA_KEY_FILE_FORMAT_BASE64,
+ nullptr, nullptr, &data_len));
+ YACA_INVALID_PARAM(yaca_key_export(key_sym.get(),
+ YACA_KEY_FORMAT_DEFAULT,
+ YACA_KEY_FILE_FORMAT_BASE64,
+ nullptr, &data, nullptr));
+
+ YACA_INVALID_PARAM(yaca_key_export(key_sym.get(),
+ YACA_KEY_FORMAT_DEFAULT,
+ YACA_KEY_FILE_FORMAT_BASE64,
+ "pass", &data, &data_len));
+ YACA_INVALID_PARAM(yaca_key_export(key_sym.get(),
+ static_cast<yaca_key_format_e>(-1),
+ YACA_KEY_FILE_FORMAT_BASE64,
+ nullptr, &data, &data_len));
+ YACA_INVALID_PARAM(yaca_key_export(key_sym.get(),
+ YACA_KEY_FORMAT_DEFAULT,
+ static_cast<yaca_key_file_format_e>(-1),
+ nullptr, &data, &data_len));
+ YACA_INVALID_PARAM(yaca_key_export(key_sym.get(),
+ YACA_KEY_FORMAT_DEFAULT,
+ YACA_KEY_FILE_FORMAT_PEM,
+ nullptr, &data, &data_len));
+ YACA_INVALID_PARAM(yaca_key_export(key_sym.get(),
+ YACA_KEY_FORMAT_DEFAULT,
+ YACA_KEY_FILE_FORMAT_DER,
+ nullptr, &data, &data_len));
+ YACA_INVALID_PARAM(yaca_key_export(key_sym.get(),
+ YACA_KEY_FORMAT_PKCS8,
+ YACA_KEY_FILE_FORMAT_PEM,
+ nullptr, &data, &data_len));
+
+ YACA_INVALID_PARAM(yaca_key_export(key_rsa.get(),
+ static_cast<yaca_key_format_e>(-1),
+ YACA_KEY_FILE_FORMAT_PEM,
+ nullptr, &data, &data_len));
+ YACA_INVALID_PARAM(yaca_key_export(key_rsa.get(),
+ YACA_KEY_FORMAT_DEFAULT,
+ static_cast<yaca_key_file_format_e>(-1),
+ nullptr, &data, &data_len));
+ YACA_INVALID_PARAM(yaca_key_export(key_rsa.get(),
+ YACA_KEY_FORMAT_DEFAULT,
+ YACA_KEY_FILE_FORMAT_BASE64,
+ nullptr, &data, &data_len));
+ YACA_INVALID_PARAM(yaca_key_export(key_rsa.get(),
+ YACA_KEY_FORMAT_DEFAULT,
+ YACA_KEY_FILE_FORMAT_RAW,
+ nullptr, &data, &data_len));
+}
+
+RUNNER_TEST(T4220_yaca_key_import_invalid_param, YacaTest)
+{
+ KeyPtr key_sym = generate_key(YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_LENGTH_256BIT);
+ size_t key_sym_data_len;
+ BufPtr key_sym_data = export_key(key_sym, YACA_KEY_FORMAT_DEFAULT,
+ YACA_KEY_FILE_FORMAT_BASE64,
+ nullptr, &key_sym_data_len);
+
+ KeyPtr key_rsa = generate_key(YACA_KEY_TYPE_RSA_PRIV, YACA_KEY_LENGTH_1024BIT);
+ size_t key_rsa_data_len;
+ BufPtr key_rsa_data = export_key(key_rsa, YACA_KEY_FORMAT_DEFAULT,
+ YACA_KEY_FILE_FORMAT_DER,
+ nullptr, &key_rsa_data_len);
+
+ const char *inv_data1 = "qwertyuiopasdfghjklzxcvbnmqwerty";
+ size_t inv_data1_len = strlen(inv_data1);
+ const char *inv_data2 = "--------qwertyuiopasdfghjklzxcvbnm";
+ size_t inv_data2_len = strlen(inv_data2);
+ yaca_key_h out;
+
+ YACA_INVALID_PARAM(yaca_key_import(static_cast<yaca_key_type_e>(-1), nullptr,
+ key_sym_data.get(), key_sym_data_len, &out));
+ YACA_INVALID_PARAM(yaca_key_import(YACA_KEY_TYPE_SYMMETRIC, "pass",
+ key_sym_data.get(), key_sym_data_len, &out));
+ YACA_INVALID_PARAM(yaca_key_import(YACA_KEY_TYPE_SYMMETRIC, nullptr,
+ nullptr, key_sym_data_len, &out));
+ YACA_INVALID_PARAM(yaca_key_import(YACA_KEY_TYPE_SYMMETRIC, nullptr,
+ key_sym_data.get(), 0, &out));
+ YACA_INVALID_PARAM(yaca_key_import(YACA_KEY_TYPE_DES, nullptr,
+ key_sym_data.get(), key_sym_data_len, &out));
+ YACA_INVALID_PARAM(yaca_key_import(YACA_KEY_TYPE_SYMMETRIC, nullptr,
+ inv_data2, SIZE_MAX / 2, &out));
+
+ YACA_INVALID_PARAM(yaca_key_import(YACA_KEY_TYPE_RSA_PUB, nullptr,
+ key_rsa_data.get(), key_rsa_data_len, &out));
+ YACA_INVALID_PARAM(yaca_key_import(YACA_KEY_TYPE_DSA_PRIV, nullptr,
+ key_rsa_data.get(), key_rsa_data_len, &out));
+ YACA_INVALID_PARAM(yaca_key_import(YACA_KEY_TYPE_RSA_PRIV, nullptr,
+ key_rsa_data.get(), key_rsa_data_len - 1, &out));
+ YACA_INVALID_PARAM(yaca_key_import(YACA_KEY_TYPE_RSA_PRIV, nullptr,
+ inv_data1, inv_data1_len, &out));
+ YACA_INVALID_PARAM(yaca_key_import(YACA_KEY_TYPE_RSA_PRIV, nullptr,
+ inv_data2, inv_data2_len, &out));
+
+ /* implementation specific tests, might go away at some point */
+ YACA_INVALID_PARAM(yaca_key_import(YACA_KEY_TYPE_RSA_PRIV, nullptr,
+ key_rsa_data.get(), static_cast<size_t>(INT_MAX) + 1, &out));
+ YACA_INVALID_PARAM(yaca_key_import(YACA_KEY_TYPE_RSA_PRIV, nullptr,
+ key_rsa_data.get(), 3, &out));
+}