| | |
| | | |
| | | function __construct($user) |
| | | { |
| | | $rcmail = rcmail::get_instance(); |
| | | $this->rc = $rcmail; |
| | | $this->rc = rcmail::get_instance(); |
| | | $this->user = $user; |
| | | } |
| | | |
| | |
| | | */ |
| | | function init() |
| | | { |
| | | $homedir = $this->rc->config->get('enigma_pgp_homedir', INSTALL_PATH . '/plugins/enigma/home'); |
| | | $homedir = $this->rc->config->get('enigma_pgp_homedir', INSTALL_PATH . 'plugins/enigma/home'); |
| | | |
| | | if (!$homedir) |
| | | return new enigma_error(enigma_error::E_INTERNAL, |
| | |
| | | try { |
| | | $this->gpg = new Crypt_GPG(array( |
| | | 'homedir' => $this->homedir, |
| | | // 'debug' => true, |
| | | // 'binary' => '/usr/bin/gpg2', |
| | | // 'debug' => true, |
| | | )); |
| | | } |
| | | catch (Exception $e) { |
| | |
| | | */ |
| | | } |
| | | |
| | | function decrypt($text, $key, $passwd) |
| | | /** |
| | | * Register private keys and passwords |
| | | * |
| | | * @param string Encrypted message |
| | | * @param array List of key-password mapping |
| | | */ |
| | | function decrypt($text, $keys = array()) |
| | | { |
| | | // $this->gpg->addDecryptKey($key, $passwd); |
| | | foreach ($keys as $key => $password) { |
| | | $this->gpg->addDecryptKey($key, $password); |
| | | } |
| | | |
| | | try { |
| | | $dec = $this->gpg->decrypt($text); |
| | | return $dec; |
| | |
| | | try { |
| | | $keys = $this->gpg->getKeys($pattern); |
| | | $result = array(); |
| | | //print_r($keys); |
| | | |
| | | foreach ($keys as $idx => $key) { |
| | | $result[] = $this->parse_key($key); |
| | | unset($keys[$idx]); |
| | | } |
| | | //print_r($result); |
| | | |
| | | return $result; |
| | | } |
| | | catch (Exception $e) { |
| | |
| | | { |
| | | } |
| | | |
| | | public function del_key($keyid) |
| | | public function delete_key($keyid) |
| | | { |
| | | // $this->get_key($keyid); |
| | | // delete public key |
| | | $result = $this->delete_pubkey($keyid); |
| | | |
| | | // if not found, delete private key |
| | | if ($result !== true && $result->getCode() == enigma_error::E_KEYNOTFOUND) { |
| | | $result = $this->delete_privkey($keyid); |
| | | } |
| | | |
| | | return $result; |
| | | } |
| | | |
| | | public function del_privkey($keyid) |
| | | public function delete_privkey($keyid) |
| | | { |
| | | try { |
| | | $this->gpg->deletePrivateKey($keyid); |
| | |
| | | } |
| | | } |
| | | |
| | | public function del_pubkey($keyid) |
| | | public function delete_pubkey($keyid) |
| | | { |
| | | try { |
| | | $this->gpg->deletePublicKey($keyid); |