Skip to contentSkip to conversation

Pull request for branch yem-root-passwd

GIT PULL New Yann E. MORIN 2 participants 6 messages Dec 29, 2012 – Dec 30, 2012

lore
Share & tools
lore
#0 lore raw

Hello All!

This is iteration #4 for setting the root password from the configuration menu:
- first patch adds the basic functionality:
- plain text password in menuconfig
- MD5-encrypted in /etc/shadow
- second patch adds additional encryption methods

There has been previous review of this series by Arnout, who suggested dropping patch #2, and only use an MD5-encrypted password. Since MD5 is now considered to be a weak hash, stronger alternatives may be usefull for the security-conscious lurking among us. That's why I kept (resurrected) that second patch.

Arnout also objected to having the root password in clear in the .config, and recommended that the user enters the already-encrypted password. That has, IMHO, a few drawbacks, in that it requires the user actually reads the help text, switch to an alternate terminal, generates a password, and copy-pastes it back in the initial terminal with the menuconfig. OTOH, if the user forgets his/her password, he/she can recover it by looking at the .config file. That's why I still advocates for entering a clear-text password in the menuconfig.

Any more comments are welcome!

Changes v3 -> v4:
- fix the test for dependencies (Thomas)

The following changes since commit 14989d0be59762a354e7c5c15a2eeb4826d8040b:

package/tvheadend: new package (2012-12-28 23:40:26 +0100)

are available in the git repository at:
git://gitorious.org/buildroot/buildroot.git yem-root-passwd

Yann E. MORIN (2):
target: add option to set the root password
target: add different methods to encode the root password

 support/dependencies/dependencies.sh |    9 +++++
 system/Config.in                     |   67 ++++++++++++++++++++++++++++++++++
 system/system.mk                     |   15 ++++++++
 3 files changed, 91 insertions(+), 0 deletions(-)

Regards,
Yann E. MORIN

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#1 lore raw

PATCH 1/2 target: add option to set the root password

Add an option in the menuconfig to specify a root password.

If set to empty, no root password is created; otherwise, the password is encrypted using MD5 (MD5 is not the default for crypt(3), DES-56 is, but MD5 is widely available, not-so-strong, but not-so-weak either).

Add a check for 'mkpasswd' as a new dependency.

Cc Arnout Vandecappelle <[email protected]>
Cc Thomas Petazzoni <[email protected]>

---
Switched to using MD5 as per Arnout's suggestion:

    http://lists.busybox.net/pipermail/buildroot/2012-September/058712.html
---
 support/dependencies/dependencies.sh |    9 +++++++++
 system/Config.in                     |   21 +++++++++++++++++++++
 system/system.mk                     |   14 ++++++++++++++
 3 files changed, 44 insertions(+), 0 deletions(-)
support/dependencies/dependencies.sh +9 -0
index 7a02512..eb5a481 100755
@@ -158,6 +158,7 @@ if grep ^BR2_TOOLCHAIN_BUILDROOT=y $CONFIG_FILE > /dev/null && \
        exit 1 ;
    fi
 fi
+
 if grep -q ^BR2_PACKAGE_CLASSPATH=y $CONFIG_FILE ; then
     for prog in javac jar; do
 	if ! which $prog > /dev/null ; then
@@ -166,3 +167,11 @@ if grep -q ^BR2_PACKAGE_CLASSPATH=y $CONFIG_FILE ; then
 	fi
     done
 fi
+
+if grep -E '^BR2_TARGET_GENERIC_ROOT_PASSWD=".+"$' $CONFIG_FILE > /dev/null 2>&1; then
+    if ! which mkpasswd > /dev/null 2>&1; then
+        /bin/echo -e "\nYou need the 'mkpasswd' utility to set the root password\n"
+        /bin/echo -e "(in Debian/ubuntu, 'mkpasswd' provided by the whois package)\n"
+        exit 1
+    fi
+fi
system/Config.in +21 -0
index a557ea0..deead86 100644
@@ -12,6 +12,27 @@ config BR2_TARGET_GENERIC_ISSUE
        help
          Select system banner (/etc/issue) to be displayed at login.
 
+config BR2_TARGET_GENERIC_ROOT_PASSWD
+	string "root password"
+	default ""
+	help
+	  Set the initial root password (in clear). It will be md5-encrypted.
+	  
+	  If set to empty (the default), then no root password will be set,
+	  and root will need no password to log in.
+	  
+	  WARNING! WARNING!
+	  Although pretty strong, MD5 is now an old hash function, and
+	  suffers from som weaknesses, which makes it susceptible to attacks.
+	  It is showing its age, so this root password should not be trusted
+	  to properly secure any product that can be shipped to the wide,
+	  hostile world.
+	  
+	  WARNING! WARNING!
+	  The password appears in clear in the .config file, and may appear
+	  in the build log! Avoid using a valuable password if either the
+	  .config file or the build log may be distributed!
+
 choice
 	prompt "/dev management"
 	default BR2_ROOTFS_DEVICE_CREATION_STATIC
system/system.mk +14 -0
index 353d0ba..a23feef 100644
@@ -1,5 +1,6 @@
 TARGET_GENERIC_HOSTNAME:=$(call qstrip,$(BR2_TARGET_GENERIC_HOSTNAME))
 TARGET_GENERIC_ISSUE:=$(call qstrip,$(BR2_TARGET_GENERIC_ISSUE))
+TARGET_GENERIC_ROOT_PASSWD:=$(call qstrip,$(BR2_TARGET_GENERIC_ROOT_PASSWD))
 TARGET_GENERIC_GETTY:=$(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT))
 TARGET_GENERIC_GETTY_BAUDRATE:=$(call qstrip,$(BR2_TARGET_GENERIC_GETTY_BAUDRATE))
 TARGET_GENERIC_GETTY_TERM:=$(call qstrip,$(BR2_TARGET_GENERIC_GETTY_TERM))
@@ -14,6 +15,13 @@ target-generic-issue:
 	mkdir -p $(TARGET_DIR)/etc
 	echo "$(TARGET_GENERIC_ISSUE)" > $(TARGET_DIR)/etc/issue
 
+target-no-root-passwd:
+	$(SED) "s/^root:[^:]*:/root::/" $(TARGET_DIR)/etc/shadow
+
+target-root-passwd:
+	root_passwd="$$( mkpasswd -m md5 "$(TARGET_GENERIC_ROOT_PASSWD)" )"; \
+	$(SED) "s,^root::,root:$${root_passwd}:," $(TARGET_DIR)/etc/shadow
+
 target-generic-getty-busybox:
 	$(SED) '/# GENERIC_SERIAL$$/s~^.*#~$(TARGET_GENERIC_GETTY)::respawn:/sbin/getty -L $(TARGET_GENERIC_GETTY) $(TARGET_GENERIC_GETTY_BAUDRATE) $(TARGET_GENERIC_GETTY_TERM) #~' \
 		$(TARGET_DIR)/etc/inittab
@@ -40,6 +48,12 @@ ifneq ($(TARGET_GENERIC_ISSUE),)
 TARGETS += target-generic-issue
 endif
 
+ifneq ($(TARGET_GENERIC_ROOT_PASSWD),)
+TARGETS += target-root-passwd
+else
+TARGETS += target-no-root-passwd
+endif
+
 ifeq ($(BR2_ROOTFS_SKELETON_DEFAULT),y)
 ifeq ($(BR2_PACKAGE_SYSVINIT),y)
 TARGETS += target-generic-getty-sysvinit
Signature · 1 line
1.7.2.5
#3 lore raw

PATCH 2/2 target: add different methods to encode the root password

In reply to Yann E. MORIN

The password can be encoded in different ways (from the weakest to the strongest): des, md5, sha-256, sha-512

Add a choice entry to select the method, defaulting to 'md5'.

---
 system/Config.in |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 system/system.mk |    3 ++-
 2 files changed, 48 insertions(+), 1 deletions(-)
system/Config.in +46 -0
index deead86..2c90e8a 100644
@@ -34,6 +34,52 @@ config BR2_TARGET_GENERIC_ROOT_PASSWD
 	  .config file or the build log may be distributed!
 
 choice
+	bool "root password encoding"
+	depends on BR2_TARGET_GENERIC_ROOT_PASSWD != ""
+	default BR2_TARGET_GENERIC_ROOT_PASSWD_MD5
+
+config BR2_TARGET_GENERIC_ROOT_PASSWD_DES
+	bool "des"
+	help
+	  Use standard 56-bit DES-based crypt(3).
+	  
+	  Old, wildly available, but also the weakest.
+
+config BR2_TARGET_GENERIC_ROOT_PASSWD_MD5
+	bool "md5"
+	help
+	  Use MD5 to encode the password.
+	  
+	  The default, wildly available, and pretty good.
+
+config BR2_TARGET_GENERIC_ROOT_PASSWD_SHA256
+	bool "sha-256"
+	help
+	  Use SHA256 to encode the password.
+	  
+	  Very strong, but not ubiquitous, although available in glibc
+	  for some time now. Choose only if you are sure your C library
+	  understands SHA256 passwords.
+
+config BR2_TARGET_GENERIC_ROOT_PASSWD_SHA512
+	bool "sha-512"
+	help
+	  Use SHA512 to encode the password.
+	  
+	  Extremely strong, but not ubiquitous, although available in glibc
+	  for some time now. Choose only if you are sure your C library
+	  understands SHA512 passwords.
+
+endchoice # root passwd encoding
+
+config BR2_TARGET_GENERIC_ROOT_PASSWD_METHOD
+	string
+	default "des"       if BR2_TARGET_GENERIC_ROOT_PASSWD_DES
+	default "md5"       if BR2_TARGET_GENERIC_ROOT_PASSWD_MD5
+	default "sha-256"   if BR2_TARGET_GENERIC_ROOT_PASSWD_SHA256
+	default "sha-512"   if BR2_TARGET_GENERIC_ROOT_PASSWD_SHA512
+
+choice
 	prompt "/dev management"
 	default BR2_ROOTFS_DEVICE_CREATION_STATIC
 
system/system.mk +2 -1
index a23feef..f5a8310 100644
@@ -1,6 +1,7 @@
 TARGET_GENERIC_HOSTNAME:=$(call qstrip,$(BR2_TARGET_GENERIC_HOSTNAME))
 TARGET_GENERIC_ISSUE:=$(call qstrip,$(BR2_TARGET_GENERIC_ISSUE))
 TARGET_GENERIC_ROOT_PASSWD:=$(call qstrip,$(BR2_TARGET_GENERIC_ROOT_PASSWD))
+TARGET_GENERIC_ROOT_PASSWD_METHOD:=$(call qstrip,$(BR2_TARGET_GENERIC_ROOT_PASSWD_METHOD))
 TARGET_GENERIC_GETTY:=$(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT))
 TARGET_GENERIC_GETTY_BAUDRATE:=$(call qstrip,$(BR2_TARGET_GENERIC_GETTY_BAUDRATE))
 TARGET_GENERIC_GETTY_TERM:=$(call qstrip,$(BR2_TARGET_GENERIC_GETTY_TERM))
@@ -19,7 +20,7 @@ target-no-root-passwd:
 	$(SED) "s/^root:[^:]*:/root::/" $(TARGET_DIR)/etc/shadow
 
 target-root-passwd:
-	root_passwd="$$( mkpasswd -m md5 "$(TARGET_GENERIC_ROOT_PASSWD)" )"; \
+	root_passwd="$$( mkpasswd -m "$(TARGET_GENERIC_ROOT_PASSWD_METHOD)" "$(TARGET_GENERIC_ROOT_PASSWD)" )"; \
 	$(SED) "s,^root::,root:$${root_passwd}:," $(TARGET_DIR)/etc/shadow
 
 target-generic-getty-busybox:
Signature · 1 line
1.7.2.5
#2 lore raw

PATCH 1/2 target: add option to set the root password

In reply to Yann E. MORIN
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Yann" == Yann E MORIN <[email protected]> writes:

Yann> Add an option in the menuconfig to specify a root password. Yann> If set to empty, no root password is created; otherwise, the password is Yann> encrypted using MD5 (MD5 is not the default for crypt(3), DES-56 is, but Yann> MD5 is widely available, not-so-strong, but not-so-weak either).

Yann> Add a check for 'mkpasswd' as a new dependency.

Yann> Signed-off-by: "Yann E. MORIN" <[email protected]> Yann> Cc: Arnout Vandecappelle <[email protected]>
Yann> Cc: Thomas Petazzoni <[email protected]>

Yann> +config BR2_TARGET_GENERIC_ROOT_PASSWD
Yann> + string "root password"

The rest of the options here are capitilized, so I've done that as well here.

Yann> + default ""
Yann> + help
Yann> + Set the initial root password (in clear). It will be md5-encrypted.
Yann> +
Yann> + If set to empty (the default), then no root password will be set,
Yann> + and root will need no password to log in.
Yann> +

 Yann> +	  WARNING! WARNING!
 Yann> +	  Although pretty strong, MD5 is now an old hash function, and
 Yann> +	  suffers from som weaknesses, which makes it susceptible to attacks.

s/som/some/

Yann> +target-no-root-passwd:
Yann> + $(SED) "s/^root:[^:]*:/root::/" $(TARGET_DIR)/etc/shadow
Yann> +
Yann> +target-root-passwd:
Yann> + root_passwd="$$( mkpasswd -m md5 "$(TARGET_GENERIC_ROOT_PASSWD)" )"; \
Yann> + $(SED) "s,^root::,root:$${root_passwd}:," $(TARGET_DIR)/etc/shadow
Yann> +

The 2nd sed only applies if the root passwd isn't set (E.G. running make menuconfig and changing password + make doesn't work), so I've simplified the two cases together to simply replace root:[^:]*: with root:$(TARGET_GENERIC_ROOT_PASSWD_HASH): which is either the empty string or the mkpasswd -m md5 output.

Signature · 1 line
Bye, Peter Korsgaard
#4 lore raw

PATCH 2/2 target: add different methods to encode the root password

In reply to Yann E. MORIN
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Yann" == Yann E MORIN <[email protected]> writes:

Yann> The password can be encoded in different ways (from the weakest Yann> to the strongest): des, md5, sha-256, sha-512

Yann> Add a choice entry to select the method, defaulting to 'md5'.

Care to respin this on top of mainline (E.G. after I changed the logic)?

Signature · 1 line
Bye, Peter Korsgaard
#5 lore raw

PATCH 2/2 target: add different methods to encode the root password

Peter, All,

Quoted 8 lines · On Sunday 30 December 2012 Peter Korsgaard wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Yann" == Yann E MORIN <[email protected]> writes:

Yann> The password can be encoded in different ways (from the weakest Yann> to the strongest): des, md5, sha-256, sha-512

Yann> Add a choice entry to select the method, defaulting to 'md5'.

Care to respin this on top of mainline (E.G. after I changed the logic)?

Yes, I'll do.
Thanks!

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'