Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit 7cbd5da

Browse files
committed
Pass session credentials to command line via ENV variable.
Generate a unique secret key at install for tokenisation of CLI calls instead of using default one.
1 parent 3ad3263 commit 7cbd5da

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

core/src/cmd.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,17 @@
6868
} else {
6969
// Consider "u" is a crypted version of u:p
7070
$optToken = $options["t"];
71-
$optUser = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($optToken."\1CDAFx¨op#"), base64_decode($optUser), MCRYPT_MODE_ECB), "\0");
71+
$cKey = ConfService::getCoreConf("AJXP_CLI_SECRET_KEY", "conf");
72+
if(empty($cKey)) $cKey = "\1CDAFx¨op#";
73+
$optUser = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($optToken.$cKey), base64_decode($optUser), MCRYPT_MODE_ECB), "\0");
74+
$env = getenv("AJXP_SAFE_CREDENTIALS");
75+
if(!empty($env)){
76+
$array = AJXP_Safe::getCredentialsFromEncodedString($env);
77+
if(isSet($array["user"]) && $array["user"] == $optUser){
78+
unset($optToken);
79+
$optPass = $array["password"];
80+
}
81+
}
7282
}
7383
if (strpos($optUser,",") !== false) {
7484
$originalOptUser = $optUser;

core/src/core/classes/class.AJXP_Controller.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,11 @@ public static function applyActionInBackground($currentRepositoryId, $actionName
331331
else $user = "shared";
332332
}
333333
if (AuthService::usersEnabled()) {
334-
$user = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($token."\1CDAFx¨op#"), $user, MCRYPT_MODE_ECB));
334+
$cKey = ConfService::getCoreConf("AJXP_CLI_SECRET_KEY", "conf");
335+
if(empty($cKey)){
336+
$cKey = "\1CDAFx¨op#";
337+
}
338+
$user = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($token.$cKey), $user, MCRYPT_MODE_ECB));
335339
}
336340
$robustInstallPath = str_replace("/", DIRECTORY_SEPARATOR, AJXP_INSTALL_PATH);
337341
$cmd = ConfService::getCoreConf("CLI_PHP")." ".$robustInstallPath.DIRECTORY_SEPARATOR."cmd.php -u=$user -t=$token -a=$actionName -r=$currentRepositoryId";
@@ -355,7 +359,21 @@ public static function applyActionInBackground($currentRepositoryId, $actionName
355359
}
356360
}
357361

358-
return self::runCommandInBackground($cmd, $logFile);
362+
$repoObject = ConfService::getRepository();
363+
$clearEnv = false;
364+
if($repoObject->getOption("USE_SESSION_CREDENTIALS")){
365+
$encodedCreds = AJXP_Safe::getEncodedCredentialString();
366+
if(!empty($encodedCreds)){
367+
putenv("AJXP_SAFE_CREDENTIALS=".$encodedCreds);
368+
$clearEnv = "AJXP_SAFE_CREDENTIALS";
369+
}
370+
}
371+
372+
$res = self::runCommandInBackground($cmd, $logFile);
373+
if(!empty($clearEnv)){
374+
putenv($clearEnv);
375+
}
376+
return $res;
359377
}
360378

361379
/**

core/src/plugins/boot.conf/class.BootConfLoader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ public function applyInstallerForm($action, $httpVars, $fileVars)
143143
$this->_loadPluginConfig("core.auth", $coreAuth);
144144
if(!isSet($coreConf["UNIQUE_INSTANCE_CONFIG"])) $coreConf["UNIQUE_INSTANCE_CONFIG"] = array();
145145
if(!isSet($coreAuth["MASTER_INSTANCE_CONFIG"])) $coreAuth["MASTER_INSTANCE_CONFIG"] = array();
146+
$coreConf["AJXP_CLI_SECRET_KEY"] = AJXP_Utils::generateRandomString(24, true);
146147

147148
$storageType = $data["STORAGE_TYPE"]["type"];
148149
if ($storageType == "db") {

0 commit comments

Comments
 (0)