Author: Chris Corbyn
Inheritance: extends Swift_Mime_CharsetObserver
Exemple #1
0
 public function setHeaders(Swift_Mime_HeaderSet $headers)
 {
     $bodyLen = $this->_bodyLen;
     if (is_bool($bodyLen)) {
         $bodyLen = -1;
     }
     $hash = $this->_hashAlgorithm == 'rsa-sha1' ? OpenDKIMSign::ALG_RSASHA1 : OpenDKIMSign::ALG_RSASHA256;
     $bodyCanon = $this->_bodyCanon == 'simple' ? OpenDKIMSign::CANON_SIMPLE : OpenDKIMSign::CANON_RELAXED;
     $headerCanon = $this->_headerCanon == 'simple' ? OpenDKIMSign::CANON_SIMPLE : OpenDKIMSign::CANON_RELAXED;
     $this->_dkimHandler = new OpenDKIMSign($this->_privateKey, $this->_selector, $this->_domainName, $headerCanon, $bodyCanon, $hash, $bodyLen);
     // Hardcode signature Margin for now
     $this->_dkimHandler->setMargin(78);
     if (!is_numeric($this->_signatureTimestamp)) {
         OpenDKIM::setOption(OpenDKIM::OPTS_FIXEDTIME, time());
     } else {
         if (!OpenDKIM::setOption(OpenDKIM::OPTS_FIXEDTIME, $this->_signatureTimestamp)) {
             throw new Swift_SwiftException('Unable to force signature timestamp [' . openssl_error_string() . ']');
         }
     }
     if (isset($this->_signerIdentity)) {
         $this->_dkimHandler->setSigner($this->_signerIdentity);
     }
     $listHeaders = $headers->listAll();
     foreach ($listHeaders as $hName) {
         // Check if we need to ignore Header
         if (!isset($this->_ignoredHeaders[strtolower($hName)])) {
             $tmp = $headers->getAll($hName);
             if ($headers->has($hName)) {
                 foreach ($tmp as $header) {
                     if ($header->getFieldBody() != '') {
                         $htosign = $header->toString();
                         $this->_dkimHandler->header($htosign);
                         $this->_signedHeaders[] = $header->getFieldName();
                     }
                 }
             }
         }
     }
     return $this;
 }
Exemple #2
0
 /**
  * Add the signature to the given Headers
  *
  * @param Swift_Mime_HeaderSet $headers
  * @return Swift_Signers_DKIMSigner
  */
 public function addSignature(Swift_Mime_HeaderSet $headers)
 {
     // Prepare the DKIM-Signature
     $params = array('v' => '1', 'a' => $this->_hashAlgorithm, 'bh' => base64_encode($this->_bodyHash), 'd' => $this->_domainName, 'h' => implode(': ', $this->_signedHeaders), 'i' => $this->_signerIdentity, 's' => $this->_selector);
     if ($this->_bodyCanon != 'simple') {
         $params['c'] = $this->_headerCanon . '/' . $this->_bodyCanon;
     } elseif ($this->_headerCanon != 'simple') {
         $params['c'] = $this->_headerCanon;
     }
     if ($this->_showLen) {
         $params['l'] = $this->_bodyLen;
     }
     if ($this->_signatureTimestamp === true) {
         $params['t'] = time();
         if ($this->_signatureExpiration !== false) {
             $params['x'] = $params['t'] + $this->_signatureExpiration;
         }
     } else {
         if ($this->_signatureTimestamp !== false) {
             $params['t'] = $this->_signatureTimestamp;
         }
         if ($this->_signatureExpiration !== false) {
             $params['x'] = $this->_signatureExpiration;
         }
     }
     if ($this->_debugHeaders) {
         $params['z'] = implode('|', $this->_debugHeadersData);
     }
     $string = '';
     foreach ($params as $k => $v) {
         $string .= $k . '=' . $v . '; ';
     }
     $string = trim($string);
     $headers->addTextHeader('DKIM-Signature', $string);
     // Add the last DKIM-Signature
     $tmp = $headers->getAll('DKIM-Signature');
     $this->_dkimHeader = end($tmp);
     $this->_addHeader(trim($this->_dkimHeader->toString()) . "\r\n b=", true);
     $this->_endOfHeaders();
     if ($this->_debugHeaders) {
         $headers->addTextHeader('X-DebugHash', base64_encode($this->_headerHash));
     }
     $this->_dkimHeader->setValue($string . " b=" . trim(chunk_split(base64_encode($this->_getEncryptedHash()), 73, " ")));
     return $this;
 }
 /**
  * Add the signature to the given Headers.
  *
  * @param Swift_Mime_HeaderSet $headers
  *
  * @return Swift_Signers_DomainKeySigner
  */
 public function addSignature(Swift_Mime_HeaderSet $headers)
 {
     // Prepare the DomainKey-Signature Header
     $params = array('a' => $this->_hashAlgorithm, 'b' => chunk_split(base64_encode($this->_getEncryptedHash()), 73, ' '), 'c' => $this->_canon, 'd' => $this->_domainName, 'h' => implode(': ', $this->_signedHeaders), 'q' => 'dns', 's' => $this->_selector);
     $string = '';
     foreach ($params as $k => $v) {
         $string .= $k . '=' . $v . '; ';
     }
     $string = trim($string);
     $headers->addTextHeader('DomainKey-Signature', $string);
     return $this;
 }
Exemple #4
0
 /**
  * Filter header set against a whitelist of regular expressions.
  *
  * @param Swift_Mime_HeaderSet $headerSet
  * @param string $type
  */
 private function _filterHeaderSet(Swift_Mime_HeaderSet $headerSet, $type)
 {
     foreach ($headerSet->getAll($type) as $headers) {
         $headers->setNameAddresses($this->_filterNameAddresses($headers->getNameAddresses()));
     }
 }