9#include <cgreen/cgreen.h>
10#include <cgreen/mocks.h>
20Ensure (PBA, returns_false_on_not_phc_compliant_setting)
25Ensure (PBA, returns_true_on_phc_compliant_setting)
29Ensure (PBA, returns_NULL_on_unsupport_settings)
31 struct PBASettings setting = {
"0000", 20000,
"$6$"};
32 assert_false (
pba_hash (NULL,
"*password"));
33 assert_false (
pba_hash (&setting, NULL));
35 assert_false (
pba_hash (&setting,
"*password"));
37Ensure (PBA, unique_hash_without_adding_used_pepper)
39 struct PBASettings setting = {
"4242", 20000,
"$6$"};
40 char *cmp_hash, *hash;
41 hash =
pba_hash (&setting,
"*password");
42 assert_not_equal (hash, NULL);
43 assert_false (string_contains (hash, setting.
pepper));
44 cmp_hash =
pba_hash (&setting,
"*password");
45 assert_string_not_equal (hash, cmp_hash);
51 struct PBASettings setting = {
"4242", 20000,
"$6$"};
53 hash =
pba_hash (&setting,
"*password");
54 assert_not_equal (hash, NULL);
58 struct PBASettings setting_wo_pepper = {
"\0\0\0\0", 20000,
"$6$"};
59 hash =
pba_hash (&setting_wo_pepper,
"*password");
64Ensure (PBA, verify_hash_returns_invalid_on_np_hash_np_password)
66 struct PBASettings setting = {
"4242", 20000,
"$6$"};
68 hash =
pba_hash (&setting,
"*password");
69 assert_not_equal (hash, NULL);
78 assert_equal (settings->
count, 20000);
80 assert_equal_with_message (settings->
pepper[i], 0,
81 "init_without_pepper_should_not_have_pepper");
82 assert_string_equal (settings->
prefix,
"$6$");
89 assert_equal (settings->
count, 1);
91 assert_equal_with_message (settings->
pepper[i],
'4',
92 "init_with_pepper_should_be_set");
94 "last_pepper_should_be_unset_by_pepper_3");
95 assert_string_equal (settings->
prefix,
"$6$");
98 assert_equal_with_message (settings, NULL,
99 "should_fail_due_to_too_much_pepper");
101 assert_equal_with_message (settings, NULL,
102 "should_fail_due_to_unknown_prefix");
120 suite = create_test_suite ();
122 add_test_with_context (suite, PBA,
123 returns_false_on_not_phc_compliant_setting);
124 add_test_with_context (suite, PBA, returns_true_on_phc_compliant_setting);
125 add_test_with_context (suite, PBA, returns_NULL_on_unsupport_settings);
126 add_test_with_context (suite, PBA, unique_hash_without_adding_used_pepper);
127 add_test_with_context (suite, PBA, verify_hash);
128 add_test_with_context (suite, PBA,
129 verify_hash_returns_invalid_on_np_hash_np_password);
130 add_test_with_context (suite, PBA, handle_md5_hash);
131 add_test_with_context (suite, PBA, defaults);
132 add_test_with_context (suite, PBA, initialization);
134 return run_single_test (suite, argv[1], create_text_reporter ());
135 return run_test_suite (suite, create_text_reporter ());
int gvm_auth_init(void)
Initializes Gcrypt.
gchar * get_password_hashes(const gchar *password)
Generate a pair of md5 hashes to be used in the "auth/hash" file for the user.
Authentication mechanism(s).
static int pba_is_phc_compliant(const char *setting)
void pba_finalize(struct PBASettings *settings)
char * pba_hash(struct PBASettings *setting, const char *password)
struct PBASettings * pba_init(const char *pepper, unsigned int pepper_size, unsigned int count, char *prefix)
enum pba_rc pba_verify_hash(const struct PBASettings *setting, const char *hash, const char *password)
Ensure(PBA, returns_false_on_not_phc_compliant_setting)
int main(int argc, char **argv)
char pepper[MAX_PEPPER_SIZE]