Returns the personal private key from the prefs.
public getPersonalPrivateKey ( integer $signkey = self::KEY_PRIMARY ) : string | ||
$signkey | integer | One of the IMP_Sime::KEY_* constants. |
Résultat | string | The personal S/MIME private key. |
/** * Parse enveloped (encrypted) data. * * @return mixed See self::_getEmbeddedMimeParts(). */ protected function _parseEnvelopedData() { $base_id = $this->_mimepart->getMimeId(); /* Initialize inline data. */ $status = new IMP_Mime_Status($this->_mimepart, _("The data in this part has been encrypted via S/MIME.")); $status->icon('mime/encryption.png', 'S/MIME'); $cache = $this->getConfigParam('imp_contents')->getViewCache(); $cache->smime[$base_id] = array('status' => $status, 'wrap' => ''); /* Is PGP active? */ $this->_initSmime(); if (empty($this->_impsmime)) { $status->addText(_("S/MIME support is not currently enabled so the data is unable to be decrypted.")); return null; } if (!$this->_impsmime->getPersonalPrivateKey()) { $status->addText(_("No personal private key exists so the data is unable to be decrypted.")); return null; } /* Make sure we have a passphrase. */ $passphrase = $this->_impsmime->getPassphrase(); if ($passphrase === false) { $imple = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create('IMP_Ajax_Imple_PassphraseDialog', array('type' => 'smimePersonal')); $status->addText(Horde::link('#', '', '', '', '', '', '', array('id' => $imple->getDomId())) . _("You must enter the passphrase for your S/MIME private key to view this data.") . '</a>'); return null; } $raw_text = $this->_getPartStream($this->_mimepart->getMimeId()); try { $decrypted_data = $this->_impsmime->decryptMessage($this->_mimepart->replaceEOL($raw_text, Horde_Mime_Part::RFC_EOL)); } catch (Horde_Exception $e) { $status->addText($e->getMessage()); return null; } $cache->smime[$base_id]['wrap'] = 'mimePartWrapValid'; $new_part = Horde_Mime_Part::parseMessage($decrypted_data, array('forcemime' => true)); switch ($new_part->getType()) { case 'application/pkcs7-mime': case 'application/x-pkcs7-mime': $signed_data = $this->_getSmimeType($new_part) === 'signed-data'; break; case 'multipart/signed': $signed_data = true; break; default: $signed_data = false; break; } if ($signed_data) { $hdrs = $this->getConfigParam('imp_contents')->getHeader(); $data = new Horde_Stream_Temp(); $data->add('From:' . $hdrs['From'] . "\n" . $decrypted_data); $new_part->setMetadata('imp-smime-decrypt', $data); $new_part->setContents($decrypted_data, array('encoding' => 'binary')); } return $new_part; }
/** */ protected function _init() { global $injector, $notification; $this->_smime = $injector->getInstance('IMP_Smime'); /* Run through the action handlers */ switch ($this->vars->actionID) { case 'import_public_key': $this->_importKeyDialog('process_import_public_key'); break; case 'process_import_public_key': try { $publicKey = $this->_getImportKey($this->vars->import_key); /* Add the public key to the storage system. */ $this->_smime->addPublicKey($publicKey); $notification->push(_("S/MIME public key successfully added."), 'horde.success'); $this->_reloadWindow(); } catch (Horde_Browser_Exception $e) { $notification->push(_("No S/MIME public key imported."), 'horde.error'); } catch (Horde_Exception $e) { $notification->push($e); } $this->vars->actionID = 'import_public_key'; $this->_importKeyDialog('process_import_public_key'); break; case 'view_public_key': case 'info_public_key': try { $key = $this->_smime->getPublicKey($this->vars->email); } catch (Horde_Exception $e) { $key = $e->getMessage(); } if ($this->vars->actionID == 'view_public_key') { $this->_textWindowOutput('S/MIME Public Key', $key); } $this->_printCertInfo($key); break; case 'view_personal_public_key': $this->_textWindowOutput('S/MIME Personal Public Key', $this->_smime->getPersonalPublicKey()); break; case 'info_personal_public_key': $this->_printCertInfo($this->_smime->getPersonalPublicKey()); break; case 'view_personal_private_key': $this->_textWindowOutput('S/MIME Personal Private Key', $this->_smime->getPersonalPrivateKey()); break; case 'import_personal_certs': $this->_importKeyDialog('process_import_personal_certs'); break; case 'process_import_personal_certs': try { $pkcs12 = $this->_getImportKey($this->vars->import_key); $this->_smime->addFromPKCS12($pkcs12, $this->vars->upload_key_pass, $this->vars->upload_key_pk_pass); $notification->push(_("S/MIME Public/Private Keypair successfully added."), 'horde.success'); $this->_reloadWindow(); } catch (Horde_Browser_Exception $e) { $notification->push(_("Personal S/MIME certificates NOT imported."), 'horde.error'); } catch (Horde_Exception $e) { $notification->push(_("Personal S/MIME certificates NOT imported: ") . $e->getMessage(), 'horde.error'); } $this->vars->actionID = 'import_personal_certs'; $this->_importKeyDialog('process_import_personal_certs'); break; } }
/** */ protected function _init() { global $injector, $notification; $this->_smime = $injector->getInstance('IMP_Smime'); /* Run through the action handlers */ switch ($this->vars->actionID) { case 'import_public_key': $this->_importKeyDialog('public'); break; case 'process_import_public_key': try { $publicKey = $this->_getImportKey('upload_key', $this->vars->import_key); /* Add the public key to the storage system. */ $this->_smime->addPublicKey($publicKey); $notification->push(_("S/MIME public key successfully added."), 'horde.success'); $this->_reloadWindow(); } catch (Horde_Browser_Exception $e) { $notification->push(_("No S/MIME public key imported."), 'horde.error'); } catch (Horde_Exception $e) { $notification->push($e); } $this->vars->actionID = 'import_public_key'; $this->_importKeyDialog('public'); break; case 'view_public_key': case 'info_public_key': try { $key = $this->_smime->getPublicKey($this->vars->email); } catch (Horde_Exception $e) { $key = $e->getMessage(); } if ($this->vars->actionID == 'view_public_key') { $this->_textWindowOutput('S/MIME Public Key', $key); } $this->_printCertInfo($key); break; case 'view_personal_public_key': case 'view_personal_public_sign_key': $this->_textWindowOutput('S/MIME Personal Public Key', $this->_smime->getPersonalPublicKey($this->vars->actionID == 'view_personal_public_sign_key')); break; case 'info_personal_public_key': case 'info_personal_public_sign_key': $this->_printCertInfo($this->_smime->getPersonalPublicKey($this->vars->actionID == 'info_personal_public_sign_key')); break; case 'view_personal_private_key': case 'view_personal_private_sign_key': $this->_textWindowOutput('S/MIME Personal Private Key', $this->_smime->getPersonalPrivateKey($this->vars->actionID == 'view_personal_private_sign_key')); break; case 'import_personal_certs': $this->_importKeyDialog('personal'); break; case 'process_import_personal_certs': $reload = false; $pkcs12_2nd = false; try { $pkcs12 = $this->_getImportKey('upload_key'); $this->_smime->addFromPKCS12($pkcs12, $this->vars->upload_key_pass, $this->vars->upload_key_pk_pass); $notification->push(_("S/MIME Public/Private Keypair successfully added."), 'horde.success'); if ($pkcs12_2nd = $this->_getSecondaryKey()) { $this->_smime->addFromPKCS12($pkcs12, $this->vars->upload_key_pass2, $this->vars->upload_key_pk_pass2, true); $notification->push(_("Secondary S/MIME Public/Private Keypair successfully added."), 'horde.success'); } $reload = true; } catch (Horde_Browser_Exception $e) { if ($e->getCode() != UPLOAD_ERR_NO_FILE || !($pkcs12_2nd = $this->_getSecondaryKey())) { $notification->push(_("Personal S/MIME certificates NOT imported."), 'horde.error'); } } catch (Horde_Exception $e) { $notification->push(_("Personal S/MIME certificates NOT imported: ") . $e->getMessage(), 'horde.error'); } if (!$reload && ($pkcs12_2nd || ($pkcs12_2nd = $this->_getSecondaryKey()))) { if (!$this->_smime->getPersonalPublicKey()) { $notification->push(_("Cannot import secondary personal S/MIME certificates without primary certificates."), 'horde.error'); } else { try { $this->_smime->addFromPKCS12($pkcs12_2nd, $this->vars->upload_key_pass2, $this->vars->upload_key_pk_pass2, true); $notification->push(_("Secondary S/MIME Public/Private Keypair successfully added."), 'horde.success'); $reload = true; } catch (Horde_Exception $e) { $notification->push(_("Personal S/MIME certificates NOT imported: ") . $e->getMessage(), 'horde.error'); } } } if ($reload) { $this->_reloadWindow(); } $this->vars->actionID = 'import_personal_certs'; $this->_importKeyDialog('personal'); break; } }