Файловый менеджер - Редактировать - /home/wuectly/www/03cbe/keychain.php.tar
Назад
home/wuectly/www/bin/keychain.php 0000604 00000020313 15245561041 0013066 0 ustar 00 #!/usr/bin/env php <?php /** * @package Joomla.Platform * * @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt * */ // @deprecated 4.0 Deprecated without replacement // We are a valid entry point. define('_JEXEC', 1); // Load system defines if (file_exists(dirname(__DIR__) . '/defines.php')) { require_once dirname(__DIR__) . '/defines.php'; } if (!defined('_JDEFINES')) { define('JPATH_BASE', dirname(__DIR__)); require_once JPATH_BASE . '/includes/defines.php'; } // Get the framework. require_once JPATH_LIBRARIES . '/import.legacy.php'; // Bootstrap the CMS libraries. require_once JPATH_LIBRARIES . '/cms.php'; // Import the configuration. require_once JPATH_CONFIGURATION . '/configuration.php'; // System configuration. $config = new JConfig; // Configure error reporting to maximum for CLI output. error_reporting(E_ALL); ini_set('display_errors', 1); /** * Keychain Manager. * * @since 3.1.4 */ class KeychainManager extends JApplicationCli { /** * @var boolean A flag if the keychain has been updated to trigger saving the keychain * @since 3.1.4 */ protected $updated = false; /** * @var JKeychain The keychain object being manipulated. * @since 3.1.4 */ protected $keychain = null; /** * Execute the application * * @return void * * @since 3.1.4 */ public function execute( ) { if (!count($this->input->args)) { // Check if they passed --help in otherwise display short usage summary if ($this->input->get('help', false) === false) { $this->out("usage: {$this->input->executable} [options] [command] [<args>]"); exit(1); } else { $this->displayHelp(); exit(0); } } // For all tasks but help and init we use the keychain if (!in_array($this->input->args[0], array('help', 'init'))) { $this->loadKeychain(); } switch ($this->input->args[0]) { case 'init': $this->initPassphraseFile(); break; case 'list': $this->listEntries(); break; case 'create': $this->create(); break; case 'change': $this->change(); break; case 'delete': $this->delete(); break; case 'read': $this->read(); break; case 'help': $this->displayHelp(); break; default: $this->out('Invalid command.'); break; } if ($this->updated) { $this->saveKeychain(); } exit(0); } /** * Load the keychain from a file. * * @return void * * @since 3.1.4 */ protected function loadKeychain() { $keychain = $this->input->get('keychain', '', 'raw'); $publicKeyFile = $this->input->get('public-key', '', 'raw'); $passphraseFile = $this->input->get('passphrase', '', 'raw'); $this->keychain = new JKeychain; if (file_exists($keychain)) { if (file_exists($publicKeyFile)) { $this->keychain->loadKeychain($keychain, $passphraseFile, $publicKeyFile); } else { $this->out('Public key not specified or missing!'); exit(1); } } } /** * Save this keychain to a file. * * @return void * * @since 3.1.4 */ protected function saveKeychain() { $keychain = $this->input->get('keychain', '', 'raw'); $publicKeyFile = $this->input->get('public-key', '', 'raw'); $passphraseFile = $this->input->get('passphrase', '', 'raw'); if (!file_exists($publicKeyFile)) { $this->out("Public key file specified doesn't exist: $publicKeyFile"); exit(1); } $this->keychain->saveKeychain($keychain, $passphraseFile, $publicKeyFile); } /** * Initialise a new passphrase file. * * @return void * * @since 3.1.4 */ protected function initPassphraseFile() { $keychain = new JKeychain; $passphraseFile = $this->input->get('passphrase', '', 'raw'); $privateKeyFile = $this->input->get('private-key', '', 'raw'); if (!strlen($passphraseFile)) { $this->out('A passphrase file must be specified with --passphrase'); exit(1); } if (!file_exists($privateKeyFile)) { $this->out("protected key file specified doesn't exist: $privateKeyFile"); exit(1); } $this->out('Please enter the new passphrase:'); $passphrase = $this->in(); $this->out('Please enter the passphrase for the protected key:'); $privateKeyPassphrase = $this->in(); $keychain->createPassphraseFile($passphrase, $passphraseFile, $privateKeyFile, $privateKeyPassphrase); } /** * Create a new entry * * @return void * * @since 3.1.4 */ protected function create() { if (count($this->input->args) != 3) { $this->out("usage: {$this->input->executable} [options] create entry_name entry_value"); exit(1); } if ($this->keychain->exists($this->input->args[1])) { $this->out('error: entry already exists. To change this entry, use "change"'); exit(1); } $this->change(); } /** * Change an existing entry to a new value or create an entry if missing. * * @return void * * @since 3.1.4 */ protected function change() { if (count($this->input->args) != 3) { $this->out("usage: {$this->input->executable} [options] change entry_name entry_value"); exit(1); } $this->updated = true; $this->keychain->setValue($this->input->args[1], $this->input->args[2]); } /** * Read an entry from the keychain * * @return void * * @since 3.1.4 */ protected function read() { if (count($this->input->args) != 2) { $this->out("usage: {$this->input->executable} [options] read entry_name"); exit(1); } $key = $this->input->args[1]; $this->out($key . ': ' . $this->dumpVar($this->keychain->get($key))); } /** * Get the string from var_dump * * @param mixed $var The variable you want to have dumped. * * @return string The result of var_dump * * @since 3.1.4 */ private function dumpVar($var) { ob_start(); var_dump($var); $result = trim(ob_get_contents()); ob_end_clean(); return $result; } /** * Delete an entry from the keychain * * @return void * * @since 3.1.4 */ protected function delete() { if (count($this->input->args) != 2) { $this->out("usage: {$this->input->executable} [options] delete entry_name"); exit(1); } $this->updated = true; $this->keychain->deleteValue($this->input->args[1]); } /** * List entries in the keychain * * @return void * * @since 3.1.4 */ protected function listEntries() { foreach ($this->keychain->toArray() as $key => $value) { $line = $key; if ($this->input->get('print-values')) { $line .= ': ' . $this->dumpVar($value); } $this->out($line); } } /** * Display the help information * * @return void * * @since 3.1.4 */ protected function displayHelp() { /* COMMANDS - list - create entry_name entry_value - change entry_name entry_value - delete entry_name - read entry_name */ $help = <<<HELP Keychain Management Utility usage: {$this->input->executable} [--keychain=/path/to/keychain] [--passphrase=/path/to/passphrase.dat] [--public-key=/path/to/public.pem] [command] [<args>] OPTIONS --keychain=/path/to/keychain Path to a keychain file to manipulate. --passphrase=/path/to/passphrase.dat Path to a passphrase file containing the encryption/decryption key. --public-key=/path/to/public.pem Path to a public key file to decrypt the passphrase file. COMMANDS list: Usage: list [--print-values] Lists all entries in the keychain. Optionally pass --print-values to print the values as well. create: Usage: create entry_name entry_value Creates a new entry in the keychain called "entry_name" with the plaintext value "entry_value". NOTE: This is an alias for change. change: Usage: change entry_name entry_value Updates the keychain entry called "entry_name" with the value "entry_value". delete: Usage: delete entry_name Removes an entry called "entry_name" from the keychain. read: Usage: read entry_name Outputs the plaintext value of "entry_name" from the keychain. init: Usage: init Creates a new passphrase file and prompts for a new passphrase. HELP; $this->out($help); } } try { JApplicationCli::getInstance('KeychainManager')->execute(); } catch (Exception $e) { echo $e->getMessage() . "\n"; exit(1); } home/wuectly/www/libraries/joomla/keychain/keychain.php 0000604 00000012600 15245570526 0017356 0 ustar 00 <?php /** * @package Joomla.Platform * @subpackage Keychain * * @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE */ defined('JPATH_PLATFORM') or die; /** * Keychain Class * * @since 3.1.4 * @deprecated 4.0 Deprecated without replacement */ class JKeychain extends \Joomla\Registry\Registry { /** * @var string Method to use for encryption. * @since 3.1.4 */ public $method = 'aes-128-cbc'; /** * @var string Initialisation vector for encryption method. * @since 3.1.4 */ public $iv = '1234567890123456'; /** * Create a passphrase file * * @param string $passphrase The passphrase to store in the passphrase file. * @param string $passphraseFile Path to the passphrase file to create. * @param string $privateKeyFile Path to the private key file to encrypt the passphrase file. * @param string $privateKeyPassphrase The passphrase for the private key. * * @return boolean Result of writing the passphrase file to disk. * * @since 3.1.4 * @throws RuntimeException */ public function createPassphraseFile($passphrase, $passphraseFile, $privateKeyFile, $privateKeyPassphrase) { $privateKey = openssl_get_privatekey(file_get_contents($privateKeyFile), $privateKeyPassphrase); if (!$privateKey) { throw new RuntimeException('Failed to load private key.'); } $crypted = ''; if (!openssl_private_encrypt($passphrase, $crypted, $privateKey)) { throw new RuntimeException('Failed to encrypt data using private key.'); } return file_put_contents($passphraseFile, $crypted); } /** * Delete a registry value (very simple method) * * @param string $path Registry Path (e.g. joomla.content.showauthor) * * @return mixed Value of old value or boolean false if operation failed * * @since 3.1.4 */ public function deleteValue($path) { $result = null; // Explode the registry path into an array $nodes = explode('.', $path); if ($nodes) { // Initialize the current node to be the registry root. $node = $this->data; // Traverse the registry to find the correct node for the result. for ($i = 0, $n = count($nodes) - 1; $i < $n; $i++) { if (!isset($node->{$nodes[$i]}) && ($i != $n)) { $node->{$nodes[$i]} = new stdClass; } $node = $node->{$nodes[$i]}; } // Get the old value if exists so we can return it $result = $node->{$nodes[$i]}; unset($node->{$nodes[$i]}); } return $result; } /** * Load a keychain file into this object. * * @param string $keychainFile Path to the keychain file. * @param string $passphraseFile The path to the passphrase file to decript the keychain. * @param string $publicKeyFile The file containing the public key to decrypt the passphrase file. * * @return boolean Result of loading the object. * * @since 3.1.4 * @throws RuntimeException */ public function loadKeychain($keychainFile, $passphraseFile, $publicKeyFile) { if (!file_exists($keychainFile)) { throw new RuntimeException('Attempting to load non-existent keychain file'); } $passphrase = $this->getPassphraseFromFile($passphraseFile, $publicKeyFile); $cleartext = openssl_decrypt(file_get_contents($keychainFile), $this->method, $passphrase, true, $this->iv); if ($cleartext === false) { throw new RuntimeException('Failed to decrypt keychain file'); } return $this->loadObject(json_decode($cleartext)); } /** * Save this keychain to a file. * * @param string $keychainFile The path to the keychain file. * @param string $passphraseFile The path to the passphrase file to encrypt the keychain. * @param string $publicKeyFile The file containing the public key to decrypt the passphrase file. * * @return boolean Result of storing the file. * * @since 3.1.4 * @throws RuntimeException */ public function saveKeychain($keychainFile, $passphraseFile, $publicKeyFile) { $passphrase = $this->getPassphraseFromFile($passphraseFile, $publicKeyFile); $data = $this->toString('JSON'); $encrypted = @openssl_encrypt($data, $this->method, $passphrase, true, $this->iv); if ($encrypted === false) { throw new RuntimeException('Unable to encrypt keychain'); } return file_put_contents($keychainFile, $encrypted); } /** * Get the passphrase for this keychain * * @param string $passphraseFile The file containing the passphrase to encrypt and decrypt. * @param string $publicKeyFile The file containing the public key to decrypt the passphrase file. * * @return string The passphrase in from passphraseFile * * @since 3.1.4 * @throws RuntimeException */ protected function getPassphraseFromFile($passphraseFile, $publicKeyFile) { if (!file_exists($publicKeyFile)) { throw new RuntimeException('Missing public key file'); } $publicKey = openssl_get_publickey(file_get_contents($publicKeyFile)); if (!$publicKey) { throw new RuntimeException('Failed to load public key.'); } if (!file_exists($passphraseFile)) { throw new RuntimeException('Missing passphrase file'); } $passphrase = ''; if (!openssl_public_decrypt(file_get_contents($passphraseFile), $passphrase, $publicKey)) { throw new RuntimeException('Failed to decrypt passphrase file'); } return $passphrase; } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.34 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка