Greenbone Vulnerability Management Libraries 22.32.0
passwordbasedauthentication_tests.c File Reference
#include "authutils.h"
#include "passwordbasedauthentication.c"
#include <cgreen/cgreen.h>
#include <cgreen/mocks.h>
#include <string.h>
Include dependency graph for passwordbasedauthentication_tests.c:

Go to the source code of this file.

Functions

 Describe (PBA)
 BeforeEach (PBA)
 AfterEach (PBA)
 Ensure (PBA, returns_false_on_not_phc_compliant_setting)
 Ensure (PBA, returns_true_on_phc_compliant_setting)
 Ensure (PBA, returns_NULL_on_unsupport_settings)
 Ensure (PBA, unique_hash_without_adding_used_pepper)
 Ensure (PBA, verify_hash)
 Ensure (PBA, verify_hash_returns_invalid_on_np_hash_np_password)
 Ensure (PBA, defaults)
 Ensure (PBA, initialization)
 Ensure (PBA, handle_md5_hash)
int main (int argc, char **argv)

Function Documentation

◆ AfterEach()

AfterEach ( PBA )

Definition at line 16 of file passwordbasedauthentication_tests.c.

17{
18}

◆ BeforeEach()

BeforeEach ( PBA )

Definition at line 13 of file passwordbasedauthentication_tests.c.

14{
15}

◆ Describe()

Describe ( PBA )

◆ Ensure() [1/9]

Ensure ( PBA ,
defaults  )

Definition at line 75 of file passwordbasedauthentication_tests.c.

76{
77 int i;
78 struct PBASettings *settings = pba_init (NULL, 0, 0, NULL);
79 assert_equal (settings->count, 20000);
80 for (i = 0; i < MAX_PEPPER_SIZE; i++)
81 assert_equal_with_message (settings->pepper[i], 0,
82 "init_without_pepper_should_not_have_pepper");
83 assert_string_equal (settings->prefix, "$6$");
84 pba_finalize (settings);
85}
void pba_finalize(struct PBASettings *settings)
Cleanup PBA settings.
struct PBASettings * pba_init(const char *pepper, unsigned int pepper_size, unsigned int count, char *prefix)
Init PBA.
#define MAX_PEPPER_SIZE
char pepper[MAX_PEPPER_SIZE]

References PBASettings::count, MAX_PEPPER_SIZE, pba_finalize(), pba_init(), PBASettings::pepper, and PBASettings::prefix.

Here is the call graph for this function:

◆ Ensure() [2/9]

Ensure ( PBA ,
handle_md5_hash  )

Definition at line 106 of file passwordbasedauthentication_tests.c.

107{
108 struct PBASettings *settings = pba_init (NULL, 0, 0, NULL);
109 char *hash;
110 assert_equal (gvm_auth_init (), 0);
111 hash = get_password_hashes ("admin");
112 assert_equal (pba_verify_hash (settings, hash, "admin"), UPDATE_RECOMMENDED);
113 pba_finalize (settings);
114 g_free (hash);
115}
int gvm_auth_init(void)
Initializes Gcrypt.
Definition authutils.c:109
gchar * get_password_hashes(const gchar *password)
Generate a pair of md5 hashes to be used in the "auth/hash" file for the user.
Definition authutils.c:210
enum pba_rc pba_verify_hash(const struct PBASettings *setting, const char *hash, const char *password)
Verify a password hash.

References get_password_hashes(), gvm_auth_init(), pba_finalize(), pba_init(), pba_verify_hash(), and UPDATE_RECOMMENDED.

Here is the call graph for this function:

◆ Ensure() [3/9]

Ensure ( PBA ,
initialization  )

Definition at line 86 of file passwordbasedauthentication_tests.c.

87{
88 int i;
89 struct PBASettings *settings = pba_init ("444", 3, 1, "$6$");
90 assert_equal (settings->count, 1);
91 for (i = 0; i < MAX_PEPPER_SIZE - 1; i++)
92 assert_equal_with_message (settings->pepper[i], '4',
93 "init_with_pepper_should_be_set");
94 assert_equal_with_message (settings->pepper[MAX_PEPPER_SIZE - 1], '\0',
95 "last_pepper_should_be_unset_by_pepper_3");
96 assert_string_equal (settings->prefix, "$6$");
97 pba_finalize (settings);
98 settings = pba_init ("444", MAX_PEPPER_SIZE + 1, 1, "$6$");
99 assert_equal_with_message (settings, NULL,
100 "should_fail_due_to_too_much_pepper");
101 settings = pba_init ("444", MAX_PEPPER_SIZE, 1, "$WALDFEE$");
102 assert_equal_with_message (settings, NULL,
103 "should_fail_due_to_unknown_prefix");
104}

References PBASettings::count, MAX_PEPPER_SIZE, pba_finalize(), pba_init(), PBASettings::pepper, and PBASettings::prefix.

Here is the call graph for this function:

◆ Ensure() [4/9]

Ensure ( PBA ,
returns_false_on_not_phc_compliant_setting  )

Definition at line 20 of file passwordbasedauthentication_tests.c.

21{
22 assert_false (pba_is_phc_compliant ("$"));
23 assert_false (pba_is_phc_compliant ("password"));
24}
static int pba_is_phc_compliant(const char *setting)
Check if a PBA settings is PHC compliant.

References pba_is_phc_compliant().

Here is the call graph for this function:

◆ Ensure() [5/9]

Ensure ( PBA ,
returns_NULL_on_unsupport_settings  )

Definition at line 29 of file passwordbasedauthentication_tests.c.

30{
31 struct PBASettings setting = {"0000", 20000, "$6$"};
32 assert_false (pba_hash (NULL, "*password"));
33 assert_false (pba_hash (&setting, NULL));
34 setting.prefix = "$1$";
35 assert_false (pba_hash (&setting, "*password"));
36}
char * pba_hash(struct PBASettings *setting, const char *password)
Create a password hash.

References pba_hash(), and PBASettings::prefix.

Here is the call graph for this function:

◆ Ensure() [6/9]

Ensure ( PBA ,
returns_true_on_phc_compliant_setting  )

Definition at line 25 of file passwordbasedauthentication_tests.c.

26{
27 assert_true (pba_is_phc_compliant ("$password"));
28}

References pba_is_phc_compliant().

Here is the call graph for this function:

◆ Ensure() [7/9]

Ensure ( PBA ,
unique_hash_without_adding_used_pepper  )

Definition at line 37 of file passwordbasedauthentication_tests.c.

38{
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);
46 free (hash);
47 free (cmp_hash);
48}

References pba_hash(), and PBASettings::pepper.

Here is the call graph for this function:

◆ Ensure() [8/9]

Ensure ( PBA ,
verify_hash  )

Definition at line 49 of file passwordbasedauthentication_tests.c.

50{
51 struct PBASettings setting = {"4242", 20000, "$6$"};
52 char *hash;
53 hash = pba_hash (&setting, "*password");
54 assert_not_equal (hash, NULL);
55 assert_equal (pba_verify_hash (&setting, hash, "*password"), VALID);
56 assert_equal (pba_verify_hash (&setting, hash, "*password1"), INVALID);
57 free (hash);
58 struct PBASettings setting_wo_pepper = {"\0\0\0\0", 20000, "$6$"};
59 hash = pba_hash (&setting_wo_pepper, "*password");
60 assert_equal (pba_verify_hash (&setting_wo_pepper, hash, "*password"), VALID);
61 free (hash);
62}

References INVALID, pba_hash(), pba_verify_hash(), and VALID.

Here is the call graph for this function:

◆ Ensure() [9/9]

Ensure ( PBA ,
verify_hash_returns_invalid_on_np_hash_np_password  )

Definition at line 64 of file passwordbasedauthentication_tests.c.

65{
66 struct PBASettings setting = {"4242", 20000, "$6$"};
67 char *hash;
68 hash = pba_hash (&setting, "*password");
69 assert_not_equal (hash, NULL);
70 assert_equal (pba_verify_hash (&setting, NULL, "*password"), INVALID);
71 assert_equal (pba_verify_hash (&setting, hash, NULL), INVALID);
72 free (hash);
73}

References INVALID, pba_hash(), and pba_verify_hash().

Here is the call graph for this function:

◆ main()

int main ( int argc,
char ** argv )

Definition at line 118 of file passwordbasedauthentication_tests.c.

119{
120 int ret;
121 TestSuite *suite;
122
123 suite = create_test_suite ();
124
125 add_test_with_context (suite, PBA,
126 returns_false_on_not_phc_compliant_setting);
127 add_test_with_context (suite, PBA, returns_true_on_phc_compliant_setting);
128 add_test_with_context (suite, PBA, returns_NULL_on_unsupport_settings);
129 add_test_with_context (suite, PBA, unique_hash_without_adding_used_pepper);
130 add_test_with_context (suite, PBA, verify_hash);
131 add_test_with_context (suite, PBA,
132 verify_hash_returns_invalid_on_np_hash_np_password);
133 add_test_with_context (suite, PBA, handle_md5_hash);
134 add_test_with_context (suite, PBA, defaults);
135 add_test_with_context (suite, PBA, initialization);
136
137 if (argc > 1)
138 ret = run_single_test (suite, argv[1], create_text_reporter ());
139 else
140 ret = run_test_suite (suite, create_text_reporter ());
141
142 destroy_test_suite (suite);
143
144 return ret;
145}