public static function beforeSend(\GO\Email\Controller\MessageController $controller, array &$response, \GO\Base\Mail\SmimeMessage $message, \GO\Base\Mail\Mailer $mailer, \GO\Email\Model\Account $account, \GO\Email\Model\Alias $alias, $params) { if (!empty($params['sign_smime'])) { //$password = trim(file_get_contents("/home/mschering/password.txt")); $password = GO::session()->values['smime']['passwords'][$account->id]; $cert = Model\Certificate::model()->findByPk($account->id); $message->setSignParams($cert->cert, $password); } if (!empty($params['encrypt_smime'])) { if (!isset($cert)) { $cert = Model\Certificate::model()->findByPk($account->id); } $password = GO::session()->values['smime']['passwords'][$account->id]; openssl_pkcs12_read($cert->cert, $certs, $password); if (!isset($certs['cert'])) { throw new \Exception("Failed to get your public key for encryption"); } $to = $message->getTo(); $cc = $message->getCc(); $bcc = $message->getBcc(); if (is_array($cc)) { $to = array_merge($to, $cc); } if (is_array($bcc)) { $to = array_merge($to, $bcc); } //lookup all recipients $failed = array(); $publicCerts = array($certs['cert']); foreach ($to as $email => $name) { $pubCert = Model\PublicCertificate::model()->findSingleByAttributes(array('user_id' => GO::user()->id, 'email' => $email)); if (!$pubCert) { $failed[] = $email; } else { $publicCerts[] = $pubCert->cert; } } if (count($failed)) { throw new \Exception(sprintf(GO::t('noPublicCertForEncrypt', 'smime'), implode(', ', $failed))); } $message->setEncryptParams($publicCerts); } }
private function _savePublicCertificate($certData, $emails) { $findParams = \GO\Base\Db\FindParams::newInstance()->single(); $findParams->getCriteria()->addInCondition('email', $emails)->addCondition('user_id', \GO::user()->id); $cert = \GO\Smime\Model\PublicCertificate::model()->find($findParams); if (!$cert) { $cert = new \GO\Smime\Model\PublicCertificate(); $cert->email = $emails[0]; $cert->user_id = \GO::user()->id; } $cert->cert = $certData; $cert->save(); }