Bug 743715

Summary: Password Encryption: Yast Add User Uses MD5, Initial System Config Used SHA512
Product: [openSUSE] openSUSE 12.1 Reporter: andrew cooke <andrew>
Component: YaST2Assignee: Jiří Suchomel <jsuchome>
Status: RESOLVED FIXED QA Contact: Jiri Srain <jsrain>
Severity: Normal    
Priority: P5 - None CC: bruno
Version: Final   
Target Milestone: ---   
Hardware: x86-64   
OS: SUSE Other   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Attachments: Default values on a 12.1 system
Full var/log/YaST2 just after a Factory 12.2 installation

Description andrew cooke 2012-01-27 00:06:46 UTC
User-Agent:       Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7

I just (re-)installed OpenSuse 12.1.  When I added the initial user and root the default setting was SHA512, and that checks with the entries in /etc/shadow ($6$ prefix,  as documented in man crypt).

However, I then added another user via Yast, and that user was added with an MD5 ($1$ prefix).

It's not clear to me whether this is a problem or not.  MD5 isn't that great a choice these days and I would have expected SHA512 to be used consistently, if it was selected during install.

As far as I know I haven't changed any settings (I cannot find anywhere in sysconfig that specified this; nor can I find anything in Yast that can change what is used when a new user is added).

Reproducible: Always

Steps to Reproduce:
1. Install with default settings and note the $6$ prefixes in /etc/shadow
2. Add a new user with Yast and see the $1$ prefix
3. Profit!
Actual Results:  
Here are relevant entries from my system.  I've replaced some values with Xs.  "andrew" was added during install; "test" was added afterwards.

andrew:$6$XXXXXXXXXXXXXXXXXXX/XXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:15365:0:99999:7:::
test:$1$XXXXXXXXXXXXXXXXXX:15365:0:99999:7:::


Expected Results:  
I'd expect both lines to contain $6$.
Comment 1 Bruno Friedmann 2012-01-27 12:23:53 UTC
It's not only YaST : simple command line tools like useradd/passwd didn't setup the SHA512 encrypted password

To reproduce, install 12.1 ensure that SHA512 is used.
Setup a different normal user & root password

check result

userdel user
useraadd user
passwd user

expected $6$xxxx found $1$1
Comment 2 Bruno Friedmann 2012-01-27 12:28:11 UTC
Created attachment 473006 [details]
Default values on a 12.1 system

Default values are not setup correctly in /etc/default/passwd
Comment 3 Bruno Friedmann 2012-01-27 12:31:38 UTC
rpm -qf /etc/default/passwd 
pwdutils-3.2.17-6.1.2.x86_64
c-3po:/etc/pam.d # rpm -q --changelog pwdutils-3.2.17-6.1.2.x86_64
* Mon Aug 29 2011 crrodriguez@opensuse.org
-  Fix build with new gnu LD.

* Thu Jul 14 2011 lnussel@suse.de
* add support for sha512
  * use implicit defaults in /etc/default/passwd
  * use glibc's crypt_gensalt if available

* Mon May 16 2011 kukuk@suse.de
- Fix syntax errors in useradd.local

* Wed May 11 2011 kukuk@suse.de
- Update to pwdutils version 3.2.16
  - sha512 new default password hash [FATE#312321].
  - newgrp: honour dynamically assigned groups [bnc#680833].
- Don't link against libxcrypt
Comment 4 Jiří Suchomel 2012-01-30 10:40:08 UTC
what does your /var/lib/YaST2/users_first_stage.ycp say?
Comment 5 andrew cooke 2012-01-30 11:02:06 UTC
> cat /var/lib/YaST2/users_first_stage.ycp
$[
  "after_auth" : "users",
  "autologin_user" : "",
  "encryption_method" : "sha512",
  "root_alias" : "andrew",
  "root_password_written" : "1",
  "run_krb_config" : "0",
  "users_written" : 1
]
Comment 6 andrew cooke 2012-01-30 11:02:25 UTC
removing NEEDINFO
Comment 7 Bruno Friedmann 2012-01-30 11:09:29 UTC
on a 12.1 updated from 11.4 

cat /var/lib/YaST2/users_first_stage.ycp
$[
  "after_auth" : "users",
  "autologin_user" : "",
  "encryption_method" : "blowfish",
  "root_alias" : "",
  "root_password_written" : "1",
  "run_krb_config" : "0",
  "users_written" : 1
]

on a 12.1 first installation
$[
  "after_auth" : "users",
  "autologin_user" : "",
  "encryption_method" : "sha512",
  "root_alias" : "",
  "root_password_written" : "1",
  "run_krb_config" : "0",
  "users_written" : 1
]
Comment 8 Jiří Suchomel 2012-01-30 12:14:02 UTC
Do you have YaST log files from the installation?

(see http://en.opensuse.org/openSUSE:Bugreport_YaST)
Comment 9 andrew cooke 2012-01-30 12:47:45 UTC
don't you have a 12.1 of your own you can take these from?  it was just a standard install.

the entire log dump appears to contain a lot of information.  i am not going to make a pile of unchecked info public.  if you want one particular file i can read it and supply it.
Comment 10 Bruno Friedmann 2012-01-30 13:27:50 UTC
Okay this can also be reproduced on a pure factory 12.2 stock installation.
Remove the use automatic setup
enter a user with a password, then another passwd for root 

after the first reboot 
check cat /etc/password
usertest:$6$JFXfHX77$LbUQdSJtjJVysC97vgpuEsNReS8JVYoerKsV5m4cGMk2Hp3ZzRTFG86Q9bmFXEFCxHnYvCChoUR4.AcOZX4/d/:15369:0:99999:7:::

issue passwd usertest as root, then recheck shadow.
usertest:$1$sjdNwIef$y3QkcSWoBVQMbzlq4iwiK1:15369:0:99999:7:::

As I've just installed this vm this morning, I will add as attachement the whole var/log/YaST folder
Comment 11 Bruno Friedmann 2012-01-30 13:31:08 UTC
Created attachment 473259 [details]
Full var/log/YaST2 just after a Factory 12.2 installation
Comment 12 andrew cooke 2012-01-30 13:39:19 UTC
thanks (sorry for being so paranoid - but then, if i wasn't, perhaps i would not have found the bug :o).
Comment 13 Jiří Suchomel 2012-01-30 14:15:26 UTC
Thanks.
Comment 14 Bernhard Wiedemann 2012-01-31 15:00:08 UTC
This is an autogenerated message for OBS integration:
This bug (743715) was mentioned in
https://build.opensuse.org/request/show/102239 Factory / yast2-pam
https://build.opensuse.org/request/show/102240 Factory / yast2-security
https://build.opensuse.org/request/show/102243 Factory / yast2-security
Comment 15 Jiří Suchomel 2012-01-31 15:07:09 UTC
So, I've sent a fix to Factory (and 12.2). 

For 12.1, we cannot fix installation process anyway. Does it work for you when you change encryption method (at running system) from yast2 users or yast2 security?
Comment 16 Bernhard Wiedemann 2012-01-31 16:00:13 UTC
This is an autogenerated message for OBS integration:
This bug (743715) was mentioned in
https://build.opensuse.org/request/show/102267 Factory / yast2-users
Comment 17 andrew cooke 2012-01-31 16:10:12 UTC
@Jiri - sorry, I don't understand what you want me to do.  Where should I specify the encryption method?

currently, /etc/default/passwd has

  CRYPT=

so i assume it should use the default.  but according to the post above the default should be sha512.  so it is already configured correctly.
Comment 18 Jiří Suchomel 2012-01-31 16:25:26 UTC
I'm asking if the encryption can be changed using YaST. It could be done from YaST Users or YaST Security module.

If there were bug also here, we'd need to release update, that's why I ask.
Comment 19 Bruno Friedmann 2012-01-31 16:44:58 UTC
Jiri, it seems to work manually under a 12.1, once in Yast2 security center -> password you set SHA512 
then the /etc/default/passwd contain this
cat /etc/default/passwd 
# This file contains some information for
# the passwd (1) command and other tools
# creating or modifying passwords.

# Define default crypt hash.
# CRYPT={des,md5,blowfish,sha256,sha512}
CRYPT=

# Use another crypt hash for group passwords.
# This is used by gpasswd, fallback is the CRYPT entry.
# GROUP_CRYPT=des


# We can override the default for a specific service
# by appending the service name (FILES, YP, NISPLUS, LDAP)

# for local files, use a more secure hash. We
# don't need to be portable here:
# CRYPT_FILES=sha512
#
# For NIS, we should always use DES:
# CRYPT_YP=des

# We can override the default for a special service
# by appending the service name (FILES, YP, NISPLUS, LDAP)

# for local files, use a more secure hash. We
# don't need to be portable here:
# CRYPT_FILES=blowfish

# sometimes we need to specify special options for a hash (variable
# is prepended by the name of the crypt hash). In case of blowfish
# and sha* this is the number of rounds
# blowfish: 4-31
# BLOWFISH_CRYPT_FILES=5
# sha256/sha512: 1000-9999999
# SHA512_CRYPT_FILES=1000

# In June 2011 it was discovered that the Linux crypt_blowfish
# implementation contained a bug that made passwords with non-ASCII
# characters easier to crack (CVE-2011-2483). Affected passwords are
# also incompatible with the original, correct OpenBSD
# implementation. Therefore the $2a hash identifier previously used
# for blowfish now is ambiguous as it could mean the hash was
# generated with the correct implementation on OpenBSD or the buggy
# one on Linux. To avoid the ambiguity two new identifier were
# introduced. $2x now explicitly identifies hashes that were
# generated with the buggy algorithm while $2y is used for hashes
# generated with the correct algorithm. New passwords are now
# generated with the $2y identifier.
#
# Setting the following option to "yes" tells the sytem that $2a
# hashes are to be treated as generated with the buggy algorithm.
BLOWFISH_2A2X=
CRYPT_FILES=sha512

then using Yast or useradd/usermod/passwd for users change the password for the desired format $6$

But any users, that have been created, need to change its actual password so it become re-encoded with the new format. That must be write in CAPITALS during the update.

For 12.1 update, perhaps the script could check if 
CRYPT_FILES=md5
then replace it by 
CRYPT_FILES=sha512
? Don't know if it's a good idea or not, +adding a comment #bnc743715
Comment 20 andrew cooke 2012-01-31 18:17:01 UTC
OK, so just in case anyone else reading this doesn't understand what is happening - it's clearer when you read all the comments in /etc/default/passwd.  There the CRYPT variable is the default, but different services can be over-ridden.  In this case, CRYPT_FILES, which is for "files" service (ie, shadow file)  was being set to "md5" during install, which is the root cause of the bug.  You can edit this by hand or via Yast's "security centre" - changing the default there changes the CRYPT_FILES value in default/passwd to "sha512".
Comment 21 Jiří Suchomel 2012-01-31 20:15:26 UTC
(In reply to comment #19)
> Jiri, it seems to work manually under a 12.1, once in Yast2 security center ->
> password you set SHA512 
> then the /etc/default/passwd contain this

> CRYPT_FILES=sha512

So this is correct and YaST works as it should on installed system.

> For 12.1 update, perhaps the script could check if 
> CRYPT_FILES=md5
> then replace it by 
> CRYPT_FILES=sha512
> ? Don't know if it's a good idea or not, +adding a comment #bnc743715

No, that would not be good, as we could not know in script if the value is there by error or on purpose.

So I think I can close it now: for 12.1, users can change the encryption value from YaST, and for next release, it should work well from the beginning.