-
Notifications
You must be signed in to change notification settings - Fork 696
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Review and update set_password_hashing_algorithm_libuserconf
Aligned to other rules related to hashing algorithm in order to use variable instead of a hardcoded sha512 value. Signed-off-by: Marcus Burghardt <[email protected]>
- Loading branch information
1 parent
ad33854
commit f3aed6e
Showing
7 changed files
with
45 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
.../set_password_hashing_algorithm/set_password_hashing_algorithm_libuserconf/bash/shared.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
# platform = multi_platform_rhel,multi_platform_fedora,multi_platform_ol,multi_platform_rhv,multi_platform_sle | ||
|
||
{{{ bash_instantiate_variables("var_password_hashing_algorithm_pam") }}} | ||
LIBUSER_CONF="/etc/libuser.conf" | ||
CRYPT_STYLE_REGEX='[[:space:]]*\[defaults](.*(\n)+)+?[[:space:]]*crypt_style[[:space:]]*' | ||
|
||
# Try find crypt_style in [defaults] section. If it is here, then change algorithm to sha512. | ||
# If it isn't here, then add it to [defaults] section. | ||
if grep -qzosP $CRYPT_STYLE_REGEX $LIBUSER_CONF ; then | ||
sed -i "s/\(crypt_style[[:space:]]*=[[:space:]]*\).*/\1sha512/g" $LIBUSER_CONF | ||
sed -i "s/\(crypt_style[[:space:]]*=[[:space:]]*\).*/\1$var_password_hashing_algorithm_pam/g" $LIBUSER_CONF | ||
elif grep -qs "\[defaults]" $LIBUSER_CONF ; then | ||
sed -i "/[[:space:]]*\[defaults]/a crypt_style = sha512" $LIBUSER_CONF | ||
sed -i "/[[:space:]]*\[defaults]/a crypt_style = $var_password_hashing_algorithm_pam" $LIBUSER_CONF | ||
else | ||
echo -e "[defaults]\ncrypt_style = sha512" >> $LIBUSER_CONF | ||
echo -e "[defaults]\ncrypt_style = $var_password_hashing_algorithm_pam" >> $LIBUSER_CONF | ||
fi |
26 changes: 17 additions & 9 deletions
26
...set_password_hashing_algorithm/set_password_hashing_algorithm_libuserconf/oval/shared.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
<def-group> | ||
<definition class="compliance" id="set_password_hashing_algorithm_libuserconf" version="1"> | ||
<definition class="compliance" id="{{{ rule_id }}}" version="1"> | ||
{{{ oval_metadata("The password hashing algorithm should be set correctly in /etc/libuser.conf.") }}} | ||
<criteria operator="AND"> | ||
<criterion test_ref="test_etc_libuser_conf_cryptstyle" /> | ||
<criterion test_ref="test_set_password_hashing_algorithm_libuserconf" /> | ||
</criteria> | ||
</definition> | ||
|
||
<ind:textfilecontent54_test check="all" check_existence="at_least_one_exists" | ||
comment="The password hashing algorithm should be set correctly in /etc/libuser.conf" | ||
id="test_etc_libuser_conf_cryptstyle" version="1"> | ||
<ind:object object_ref="object_etc_libuser_conf_cryptstyle" /> | ||
<ind:textfilecontent54_test id="test_set_password_hashing_algorithm_libuserconf" version="2" | ||
check="all" check_existence="at_least_one_exists" | ||
comment="check if /etc/libuser.conf hashing algorithm option is correct"> | ||
<ind:object object_ref="object_set_password_hashing_algorithm_libuserconf"/> | ||
<ind:state state_ref="state_set_password_hashing_algorithm_libuserconf"/> | ||
</ind:textfilecontent54_test> | ||
|
||
<ind:textfilecontent54_object comment="The password hashing algorithm should be set correctly in /etc/libuser.conf" | ||
id="object_etc_libuser_conf_cryptstyle" version="1"> | ||
<ind:textfilecontent54_object id="object_set_password_hashing_algorithm_libuserconf" version="2" | ||
comment="only one hashing algorithm option for pam_unix.so is found in /etc/pam.d/password-auth"> | ||
<ind:filepath>/etc/libuser.conf</ind:filepath> | ||
<ind:pattern operation="pattern match">^[\s]*crypt_style[\s]+=[\s]+(?i)sha512[\s]*$</ind:pattern> | ||
<ind:pattern operation="pattern match">^[\s]*crypt_style[\s]*=[\s]*(\w*)[\s]*$</ind:pattern> | ||
<ind:instance datatype="int">1</ind:instance> | ||
</ind:textfilecontent54_object> | ||
|
||
<ind:textfilecontent54_state id="state_set_password_hashing_algorithm_libuserconf" version="1"> | ||
<ind:subexpression operation="equals" datatype="string" var_ref="var_password_hashing_algorithm_pam"/> | ||
</ind:textfilecontent54_state> | ||
|
||
<external_variable id="var_password_hashing_algorithm_pam" datatype="string" version="1" | ||
comment="hashing algorithm for pam_unix.so"/> | ||
</def-group> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...ng_algorithm/set_password_hashing_algorithm_libuserconf/tests/correct_crypt_style.pass.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#!/bin/bash | ||
# variables = var_password_hashing_algorithm_pam=sha512 | ||
|
||
# example libuser.conf has set 'crypt_style = sha512' | ||
cp libuser.conf /etc/ |
1 change: 1 addition & 0 deletions
1
...hashing_algorithm/set_password_hashing_algorithm_libuserconf/tests/no_crypt_style.fail.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#!/bin/bash | ||
# variables = var_password_hashing_algorithm_pam=sha512 | ||
|
||
cp libuser.conf /etc/ | ||
sed -i "/crypt_style/d" /etc/libuser.conf |
1 change: 1 addition & 0 deletions
1
...hashing_algorithm/set_password_hashing_algorithm_libuserconf/tests/weak_algorithm.fail.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#!/bin/bash | ||
# variables = var_password_hashing_algorithm_pam=sha512 | ||
|
||
cp libuser.conf /etc/ | ||
sed -i "s/crypt_style = sha512/crypt_style = md5/" /etc/libuser.conf |