From: cajus Date: Mon, 5 May 2008 15:19:46 +0000 (+0000) Subject: Added support for master-key encrypted passwords in gosa.conf X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4db036c45428d85fa3f9a2ed9377b7c601bdfdf9;p=gosa.git Added support for master-key encrypted passwords in gosa.conf git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@10767 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/bin/gosa-encrypt-passwords b/bin/gosa-encrypt-passwords new file mode 100755 index 000000000..0f8c5ada1 --- /dev/null +++ b/bin/gosa-encrypt-passwords @@ -0,0 +1,114 @@ +#!/usr/bin/php +load("/etc/gosa/gosa.conf") or die ("Cannot read /etc/gosa/gosa.conf - aborted\n"); +$conf->encoding = 'UTF-8'; +$referrals= $conf->getElementsByTagName("referral"); +echo "* encrypting existent passwords with master key\n"; +foreach($referrals as $referral){ + $pw= $referral->attributes->getNamedItem("password"); + $pw->nodeValue= cred_encrypt($pw->nodeValue, $master_key); +} + +# Move original gosa.conf out of the way and make it unreadable for the web user +echo "* creating backup in /etc/gosa/gosa.conf.orig\n"; +rename("/etc/gosa/gosa.conf", "/etc/gosa/gosa.conf.orig"); +chmod("/etc/gosa/gosa.conf.orig", 0600); +chown ("/etc/gosa/gosa.conf.orig", "root"); +chgrp ("/etc/gosa/gosa.conf.orig", "root"); + +# Save new passwords +echo "* saving modified /etc/gosa/gosa.conf\n"; +$conf->save("/etc/gosa/gosa.conf") or die("Cannot write modified /etc/gosa/gosa.conf - aborted\n"); +chmod("/etc/gosa/gosa.conf", 0640); +chown ("/etc/gosa/gosa.conf", "root"); +chgrp ("/etc/gosa/gosa.conf", "www-data"); +echo "OK\n\n"; + +# Print reminder +echo<< + php_admin_flag engine on + php_admin_value open_basedir "/etc/gosa/:/usr/share/gosa/:/var/cache/gosa/:/var/spool/gosa/" + php_admin_flag register_globals off + php_admin_flag allow_call_time_pass_reference off + php_admin_flag expose_php off + php_admin_flag zend.ze1_compatibility_mode off + php_admin_flag register_long_arrays off + php_admin_flag magic_quotes_gpc on + include /etc/gosa/gosa.secrets + + + +Please reload your httpd configuration after you've modified anything. + + +EOF; +?> diff --git a/debian/README.debian b/debian/README.debian index 9f57efc87..99dd917a2 100644 --- a/debian/README.debian +++ b/debian/README.debian @@ -70,6 +70,11 @@ an important LDAP password as the www-data user. If you allow other people to have i.e. public html directories, they will be able to read this configuration as well - if you don't take steps against it. +As a simple solution, you can pass a master password via request headers. +This can be achieved by running: + +# a2enmod headers +# gosa-encrypt-passwords ---- Cajus Pollmeier Fri 02 Jun 2006 16:23:50 +0200 diff --git a/debian/changelog b/debian/changelog index 1c2f0e74a..8de28da29 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,6 +4,7 @@ gosa (2.5.16-1) unstable; urgency=low * Fixed problem with broken characters in the password fields (Closes #470303) * Added apache configuration advisory to the README.debian * Removed additional bashisms from the rules file (Closes #478388) + * Add a root-readable master key for passwords in gosa.conf (Closes #402010) -- Cajus Pollmeier Fri, 04 Apr 2008 09:03:52 +0200 diff --git a/include/class_config.inc b/include/class_config.inc index 887288feb..270f1e256 100644 --- a/include/class_config.inc +++ b/include/class_config.inc @@ -179,16 +179,21 @@ class config { $this->level--; } + + function get_credentials($creds) + { + if (isset($_SERVER['HTTP_GOSA_KEY'])){ + return (cred_decrypt($creds, $_SERVER['HTTP_GOSA_KEY'])); + } + return ($creds); + } + + function get_ldap_link($sizelimit= FALSE) { -# Reuse same handle ldap handle. -# Disabled due to unpredictable results -# -# if($this->ldap === NULL || !is_resource($this->ldap->cid)){ -# /* Build new connection */ $this->ldap= ldap_init ($this->current['SERVER'], $this->current['BASE'], - $this->current['ADMIN'], $this->current['PASSWORD']); + $this->current['ADMIN'], $this->get_credentials($this->current['PASSWORD'])); /* Check for connection */ if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){ diff --git a/include/functions.inc b/include/functions.inc index 70ab363ac..cebbb4a3f 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -2643,6 +2643,23 @@ function remove_objectClass($classes, &$attrs) } +function cred_encrypt($input, $password) { + + $size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); + $iv = mcrypt_create_iv($size, MCRYPT_DEV_RANDOM); + + return bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $password, $input, MCRYPT_MODE_ECB, $iv)); +} + + +function cred_decrypt($input,$password) { + $size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); + $iv = mcrypt_create_iv($size, MCRYPT_DEV_RANDOM); + + return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $password, pack("H*", $input), MCRYPT_MODE_ECB, $iv); +} + + /* Returns contents of the given POST variable and check magic quotes settings */ function get_post($name) {