30 public function __construct($privateKey, $domainName, $selector)
32 if (extension_loaded(
'opendkim')) {
33 $this->_peclLoaded =
true;
37 parent::__construct($privateKey, $domainName, $selector);
40 public static function newInstance($privateKey, $domainName, $selector)
42 return new static($privateKey, $domainName, $selector);
48 $headerVal = $this->_dkimHandler->getSignatureHeader();
52 $header->setValue($headerVal);
53 $headers->
set($header);
61 if (is_bool($bodyLen)) {
64 $hash = ($this->_hashAlgorithm ==
'rsa-sha1') ? OpenDKIMSign::ALG_RSASHA1 : OpenDKIMSign::ALG_RSASHA256;
65 $bodyCanon = ($this->_bodyCanon ==
'simple') ? OpenDKIMSign::CANON_SIMPLE : OpenDKIMSign::CANON_RELAXED;
66 $headerCanon = ($this->_headerCanon ==
'simple') ? OpenDKIMSign::CANON_SIMPLE : OpenDKIMSign::CANON_RELAXED;
67 $this->_dkimHandler =
new OpenDKIMSign($this->_privateKey, $this->_selector, $this->_domainName, $headerCanon, $bodyCanon, $hash, $bodyLen);
69 $this->_dkimHandler->setMargin(78);
71 if (!is_numeric($this->_signatureTimestamp)) {
72 OpenDKIM::setOption(OpenDKIM::OPTS_FIXEDTIME, time());
74 if (!OpenDKIM::setOption(OpenDKIM::OPTS_FIXEDTIME, $this->_signatureTimestamp)) {
75 throw new Swift_SwiftException(
'Unable to force signature timestamp ['.openssl_error_string().
']');
78 if (isset($this->_signerIdentity)) {
79 $this->_dkimHandler->setSigner($this->_signerIdentity);
81 $listHeaders = $headers->
listAll();
82 foreach ($listHeaders as $hName) {
84 if (!isset($this->_ignoredHeaders[strtolower($hName)])) {
85 $tmp = $headers->
getAll($hName);
86 if ($headers->
has($hName)) {
87 foreach ($tmp as $header) {
88 if ($header->getFieldBody() !=
'') {
89 $htosign = $header->toString();
90 $this->_dkimHandler->header($htosign);
91 $this->_signedHeaders[] = $header->getFieldName();
103 if (!$this->_peclLoaded) {
104 return parent::startBody();
106 $this->dropFirstLF =
true;
107 $this->_dkimHandler->eoh();
114 if (!$this->_peclLoaded) {
115 return parent::endBody();
117 $this->_dkimHandler->eom();
124 $this->_dkimHandler = null;
139 $this->_signatureTimestamp = $time;
153 $this->_signatureExpiration = $time;
167 $this->_debugHeaders = (bool) $debug;
176 if (!$this->_peclLoaded) {
177 return parent::_canonicalizeBody($string);
179 if (
false && $this->dropFirstLF ===
true) {
180 if ($string[0] ==
"\r" && $string[1] ==
"\n") {
181 $string = substr($string, 2);
184 $this->dropFirstLF =
false;
185 if (strlen($string)) {
186 $this->_dkimHandler->body($string);