1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
|
Description: Switch from mcrypt to openssl
Author: Benjamin Zapiec <bzapiec@gonicus.de>
Abstract:
This patch includes the following gosa-core upstream commit:
.
commit 8a57db04f84337903f7de202e3c897d9b76d9b5f
Author: bzapiec <benjamin.zapiec@gonicus.de>
Date: Tue Feb 27 08:31:47 2018 +0100
.
(see #12)
add comment so the user know how and if to use the migration script
suppress openssl warning
execution right is revoked to avoid user to accidentally execute this script
.
commit 5f946bee9495db49bd718b8430eda2745adf8b3e
Author: bzapiec <benjamin.zapiec@gonicus.de>
Date: Tue Feb 27 08:25:21 2018 +0100
.
(see #12)
switch to ecb mode so we don't need to save the iv
add migration script
.
commit 374e19d8c7a915b8580caa1184a76240919f4f0d
Author: bzapiec <benjamin.zapiec@gonicus.de>
Date: Mon Feb 26 14:48:04 2018 +0100
.
remove gosa-si dependencies
.
commit df92dc9a0d5204825594986f78baf913167ca458
Author: bzapiec <benjamin.zapiec@gonicus.de>
Date: Fri Feb 23 15:37:19 2018 +0100
.
(see #12)
trim decoded value
.
commit db98333cf2a456d108939402efcffe129740463c
Author: bzapiec <benjamin.zapiec@gonicus.de>
Date: Fri Feb 23 14:48:05 2018 +0100
.
(see #12)
updated Socket_Client not to use mcrypt anymore
.
commit 22ed57eb75b1255f70ac1926824a8dc19edd2431
Author: bzapiec <benjamin.zapiec@gonicus.de>
Date: Fri Feb 23 14:09:00 2018 +0100
.
refs #12
first patchset to migrate from mcrypt to openssl encryption library
.
- use openssl library for password encryption in gosa.conf
@@ -1,12 +1,14 @@
#!/usr/bin/php
<?php
-function cred_encrypt($input, $password) {
-
- $size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
- $iv = mcrypt_create_iv($size, MCRYPT_DEV_RANDOM);
+function cred_encrypt($input, $password, $cipher = "aes-256-cbc") {
+ if (in_array($cipher, openssl_get_cipher_methods())) {
+ $ivlen = openssl_cipher_iv_length($cipher);
+ $iv = openssl_random_pseudo_bytes($ivlen);
+ return bin2hex(openssl_encrypt($input, $cipher, $password, OPENSSL_RAW_DATA, $iv));
+ }
- return bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $password, $input, MCRYPT_MODE_ECB, $iv));
+ return null;
}
@@ -68,7 +70,12 @@
$user = $referral->attributes->getNamedItem("adminDn");
echo "* encrypting GOsa password for: ".$user->nodeValue."\n";
$pw= $referral->attributes->getNamedItem("adminPassword");
- $pw->nodeValue= cred_encrypt($pw->nodeValue, $master_key);
+
+ $encryptedSecret = cred_encrypt($pw->nodeValue, $master_key);
+
+ if($encryptedSecret !== NULL) {
+ $pw->nodeValue = $encryptedSecret;
+ }
}
# Encrypt the snapshot passwords
@@ -78,7 +85,10 @@
$node = $location->attributes->getNamedItem("snapshotAdminPassword");
if($node->nodeValue){
echo "* encrypting snapshot pasword for location: ".$name->nodeValue."\n";
- $node->nodeValue = cred_encrypt($node->nodeValue, $master_key);;
+ $encryptedSecret = cred_encrypt($node->nodeValue, $master_key);
+ if($encryptedSecret !== NULL) {
+ $node->nodeValue = $encryptedSecret;
+ }
}
}
@@ -0,0 +1,109 @@
+#!/usr/bin/php
+<?php
+###################################################################
+# Migration script to migrate your gosa.conf
+# from mcrypt to openssl.
+#
+# If you already updated to openssl don't execute
+# this script again!
+# Your GOsa² installation will become unusable and you need
+# to revert the passwords manually.
+#
+# On new installations you don't need to execute this script.
+# Password encryption is done by gosa-encrypt-passwords
+###################################################################
+
+
+function cred_encrypt($input, $password, $cipher = "aes-256-ecb") {
+ if (in_array($cipher, openssl_get_cipher_methods())) {
+ $ivlen = openssl_cipher_iv_length($cipher);
+ $iv = openssl_random_pseudo_bytes($ivlen);
+ return bin2hex(openssl_encrypt($input, $cipher, $password, OPENSSL_RAW_DATA, $iv));
+ }
+
+ return null;
+}
+
+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 rtrim(@openssl_decrypt( pack("H*", $input), "aes-256-ecb" , $password, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv ), "\0\3\4\n");
+}
+
+
+# We need to have access to gosa.secrets
+if (posix_getuid() != 0){
+ die ("This program needs to be called by root!\n");
+}
+
+# Do we have a valid gosa.conf?
+if (!file_exists("/etc/gosa/gosa.conf")){
+ die ("Cannot find a valid /etc/gosa/gosa.conf!\n");
+}
+
+echo "Starting password encryption update\n";
+echo "* read master key from gosa.secrets\n";
+$master_key="";
+
+# Do we have a valid gosa.secrets, already?
+if (!file_exists("/etc/gosa/gosa.secrets")){
+ die ("There's no /etc/gosa/gosa.secrets. No need to update passwords\n");
+} else {
+ echo "* open /etc/gosa/gosa.secrets\n";
+ $content = file_get_contents("/etc/gosa/gosa.secrets");
+ $pos = strpos($content, "GOSAKEY");
+
+ if($pos !== NULL) {
+ $master_key = trim(substr($content, $pos + strlen("GOSAKEY")));
+ } else {
+ die ("/etc/gosa/gosa.secrets maulformed\n");
+ }
+}
+
+# Locate all passwords inside the gosa.conf
+echo "* loading /etc/gosa/gosa.conf\n";
+$conf = new DOMDocument();
+$conf->load("/etc/gosa/gosa.conf") or die ("Cannot read /etc/gosa/gosa.conf - aborted\n");
+$conf->encoding = 'UTF-8';
+$referrals= $conf->getElementsByTagName("referral");
+foreach($referrals as $referral){
+ $user = $referral->attributes->getNamedItem("adminDn");
+ echo "* encrypting GOsa password for: ".$user->nodeValue."\n";
+ $pw= $referral->attributes->getNamedItem("adminPassword");
+ $encryptedSecret = cred_encrypt(cred_decrypt($pw->nodeValue, $master_key), $master_key);
+
+ if($encryptedSecret !== NULL) {
+ $pw->nodeValue = $encryptedSecret;
+ }
+}
+
+# Encrypt the snapshot passwords
+$locations= $conf->getElementsByTagName("location");
+foreach($locations as $location){
+ $name = $location->attributes->getNamedItem("name");
+ $node = $location->attributes->getNamedItem("snapshotAdminPassword");
+ if($node->nodeValue){
+ echo "* encrypting snapshot pasword for location: ".$name->nodeValue."\n";
+ $encryptedSecret = cred_encrypt(cred_decrypt($node->nodeValue, $master_key), $master_key);
+ if($encryptedSecret !== NULL) {
+ $node->nodeValue = $encryptedSecret;
+ }
+ }
+}
+
+# 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";
+
+?>
@@ -1,51 +0,0 @@
-<?php
-/*
- * This code is part of GOsa (http://www.gosa-project.org)
- * Copyright (C) 2003-2008 GONICUS GmbH
- *
- * ID: $$Id: getbin.php 9255 2008-03-03 16:04:30Z cajus $$
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/* Basic setup, remove eventually registered sessions */
-@require_once ("../include/php_setup.inc");
-@require_once ("functions.inc");
-
-session_cache_limiter("private");
-session::start();
-session::global_set('errorsAlreadyPosted',array());
-
-/* Logged in? Simple security check */
-if (!session::global_is_set('ui')){
- new log("security","unknown","",array(),"Error: getFAIstatus.php called without session") ;
- header ("Location: index.php");
- exit;
-}
-
-/* There must be a mac address given */
-if(!isset($_GET['mac'])){
- return;
-}
-
-$config = session::global_get("config");
-$o = new gosaSupportDaemon();
-header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
-header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Datum in der Vergangenheit
-$res = $o->get_entries_by_mac(explode(",", $_GET['mac']));
-foreach($res as $entry){
- echo $entry['MACADDRESS']."|".$entry['PROGRESS']."\n";
-}
-?>
@@ -1626,20 +1626,7 @@
function renderDaemonMenu($separator)
{
- $result= "";
-
- // If there is a daemon registered, draw the menu entries
- if(class_available("DaemonEvent")){
- $events= DaemonEvent::get_event_types_by_category($this->categories);
- if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
- foreach($events['BY_CLASS'] as $name => $event){
- $result.= "<li$separator><a href='#' onClick='\$(\"act\").value=\"$name\";\$(\"exec_act\").click();'>".$event['MenuImage']." ".$event['s_Menu_Name']."</a></li>";
- $separator= "";
- }
- }
- }
-
- return $result;
+ return "";
}
@@ -35,10 +35,10 @@
private $b_encrypt = FALSE;
/* Crypto information */
- private $td= NULL;
private $ckey= "";
- private $ks;
private $iv;
+ private $openssl_cipher = "aes-256-cbc";
+ private $iv_len = -1;
public function __construct($host, $port, $connect = TRUE, $timeout = 3){
@@ -47,6 +47,8 @@
$this->timeout= $timeout;
$this->reset_error();
+ $this->iv_len = openssl_cipher_iv_length($openssl_cipher);
+
/* Connect if needed */
if($connect){
$this->open();
@@ -56,14 +58,8 @@
public function setEncryptionKey($key)
{
- if(!function_exists("mcrypt_get_iv_size")){
- $this->set_error(msgPool::missingext("mcrypt"));
- $this->ckey = "";
- $this->b_encrypt = FALSE;
- }
-
if ($this->connected()){
- $this->ckey = substr(md5($key), 0, $this->ks);
+ $this->ckey = md5($key);
$this->b_encrypt = TRUE;
}
@@ -74,8 +70,7 @@
private function encrypt($data)
{
if($this->b_encrypt){
- mcrypt_generic_init($this->td, $this->ckey, $this->iv);
- $data = base64_encode(mcrypt_generic($this->td, $data));
+ $data = base64_encode(openssl_encrypt($data, $this->openssl_cipher, $this->ckey, OPENSSL_RAW_DATA, $this->iv));
}
return($data);
}
@@ -85,9 +80,7 @@
{
/* decrypt data */
if($this->b_encrypt && strlen($data)){
- $data = base64_decode($data);
- mcrypt_generic_init($this->td, $this->ckey, $this->iv);
- $data = mdecrypt_generic($this->td, $data);
+ $data = openssl_decrypt(base64_decode($data), $this->openssl_cipher, $this->ckey, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $this->iv);
}
return($data);
}
@@ -109,12 +102,8 @@
}else{
$this->b_data_send = TRUE;
- /* Open the cipher */
- $this->td = mcrypt_module_open('rijndael-128', '', 'cbc', '');
-
/* Create the IV and determine the keysize length */
- $this->iv = substr(md5('GONICUS GmbH'),0, mcrypt_enc_get_iv_size($this->td));
- $this->ks = mcrypt_enc_get_key_size($this->td);
+ $this->iv = substr(md5('GONICUS GmbH'),0, $this->iv_len);
}
}
@@ -210,9 +199,6 @@
if($this->handle){
fclose($this->handle);
}
-
- /* Terminate decryption handle and close module */
- @mcrypt_generic_deinit($this->td);
}
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
@@ -3071,20 +3071,6 @@
return(array());
}
- }elseif ($config->get_cfg_value("core","gosaSupportURI") != ""){
-
- // Try using gosa-si
- $res= gosaSupportDaemon::send("gosa_gen_smb_hash", "GOSA", array("password" => $password), TRUE);
- if (isset($res['XML']['HASH'])){
- $hash= $res['XML']['HASH'];
- } else {
- $hash= "";
- }
-
- if ($hash == "") {
- msg_dialog::display(_("Configuration error"), _("Cannot generate SAMBA hash!"), ERROR_DIALOG);
- return ("");
- }
} else {
$password = addcslashes($password, '$'); // <- Escape "$" once to be able to use it in pw strings in Perl scripts
$tmp = $config->get_cfg_value("core",'sambaHashHook');
@@ -3322,24 +3308,26 @@
}
-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_encrypt($input, $password, $cipher = "aes-256-ecb") {
+ if (in_array($cipher, openssl_get_cipher_methods())) {
+ $ivlen = openssl_cipher_iv_length($cipher);
+ $iv = openssl_random_pseudo_bytes($ivlen);
+ return bin2hex(openssl_encrypt($input, $cipher, $password, OPENSSL_RAW_DATA, $iv));
+ }
+ return null;
}
+function cred_decrypt($input, $password, $cipher = "aes-256-ecb") {
+ if (in_array($cipher, openssl_get_cipher_methods())) {
+ $ivlen = openssl_cipher_iv_length($cipher);
+ $iv = openssl_random_pseudo_bytes($ivlen);
+ return rtrim(openssl_decrypt(pack("H*", $input), $cipher, $password, OPENSSL_RAW_DATA, $iv ), "\0\3\4\n");
+ }
-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 rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $password, pack("H*", $input), MCRYPT_MODE_ECB, $iv), "\0\3\4\n");
+ return null;
}
-
function get_object_info()
{
return(session::get('objectinfo'));
@@ -93,13 +93,6 @@
$msgs = $this->dialogObject->check();
if(count($msgs)){
msg_dialog::displayChecks($msgs);
- }else{
- $o_queue = new gosaSupportDaemon();
- $o_queue->append($this->dialogObject);
- if($o_queue->is_error()){
- msg_dialog::display(_("Infrastructure error"), msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
- }
- $this->closeDialogs();
}
}
@@ -118,16 +111,6 @@
$uids[] = $attrs['cn'][0];
}
}
- if(count($uids)){
- $events = DaemonEvent::get_event_types(USER_EVENT);
- $event = "DaemonEvent_notify";
- if(isset($events['BY_CLASS'][$event])){
- $type = $events['BY_CLASS'][$event];
- $this->dialogObject = new $type['CLASS_NAME']($this->config);
- $this->dialogObject->add_groups($uids);
- $this->dialogObject->set_type(SCHEDULED_EVENT);
- }
- }
}
@@ -108,13 +108,6 @@
$msgs = $this->dialogObject->check();
if(count($msgs)){
msg_dialog::displayChecks($msgs);
- }else{
- $o_queue = new gosaSupportDaemon();
- $o_queue->append($this->dialogObject);
- if($o_queue->is_error()){
- msg_dialog::display(_("Infrastructure error"), msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
- }
- $this->closeDialogs();
}
}
@@ -123,56 +116,7 @@
*/
function sendMessage($action="",$target=array(),$all=array())
{
-
- if(class_available("DaemonEvent_notify")){
-
- // Resolv targets
- $targets = array();
- $m_list = array();
- $ldap = $this->config->get_ldap_link();
-
- // Collect selected ogroups
- foreach($target as $dn){
- $ldap->cat($dn, array('member'));
- while ($entry = $ldap->fetch()) {
- $m_list[] = $entry;
- }
- }
-
- // Collect object group member dns
- foreach($m_list as $entry){
- $members = $entry['member'];
- for($i=0;$i<$members['count'];$i++) {
-
- // Fetch member object
- $ldap->cat($members[$i], array('uid','cn','objectClass'));
- if ($ldap->count() > 0) {
-
- // Determine which type the object has
- $attrs = $ldap->fetch();
- if (array_search('gosaAccount', $attrs['objectClass'])) {
- $uid = $attrs['uid'][0];
- $targets['USERS'][] = $uid;
- }elseif (array_search('posixGroup', $attrs['objectClass'])) {
- $group = $attrs['cn'][0];
- $targets['GROUPS'][] = $group;
- }
- }
- }
- }
-
- // We've at least one recipient
- if(count($targets)){
- $events = DaemonEvent::get_event_types(USER_EVENT);
- if(isset($events['BY_CLASS']['DaemonEvent_notify'])){
- $type = $events['BY_CLASS']['DaemonEvent_notify'];
- $this->dialogObject = new $type['CLASS_NAME']($this->config);
- $this->dialogObject->add_targets($targets);
- $this->dialogObject->set_type(TRIGGERED_EVENT);
- }
- }
-
- }
+ return;
}
static function filterProperties($row, $gosaGroupObjects)
@@ -163,28 +163,7 @@
*/
function sendMessage($action="",$target=array(),$all=array())
{
- if(class_available("DaemonEvent")){
- $uids = array();
- $ldap = $this->config->get_ldap_link();
- $ldap->cd($this->config->current['BASE']);
- foreach($target as $dn){
- $ldap->cat($dn,array('uid'));
- $attrs = $ldap->fetch();
- if(isset($attrs['uid'][0])){
- $uids[] = $attrs['uid'][0];
- }
- }
- if(count($uids)){
- $events = DaemonEvent::get_event_types(USER_EVENT);
- $event = "DaemonEvent_notify";
- if(isset($events['BY_CLASS'][$event])){
- $type = $events['BY_CLASS'][$event];
- $this->dialogObject = new $type['CLASS_NAME']($this->config);
- $this->dialogObject->add_users($uids);
- $this->dialogObject->set_type(SCHEDULED_EVENT);
- }
- }
- }
+ return;
}
@@ -196,13 +175,6 @@
$msgs = $this->dialogObject->check();
if(count($msgs)){
msg_dialog::displayChecks($msgs);
- }else{
- $o_queue = new gosaSupportDaemon();
- $o_queue->append($this->dialogObject);
- if($o_queue->is_error()){
- msg_dialog::display(_("Infrastructure error"), msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
- }
- $this->closeDialogs();
}
}
|