{"id":1537,"date":"2016-01-22T22:42:30","date_gmt":"2016-01-23T04:42:30","guid":{"rendered":"http:\/\/blografia.net\/vicm3\/?p=1537"},"modified":"2016-08-27T00:40:00","modified_gmt":"2016-08-27T05:40:00","slug":"bits-of-code-php-and-self-signed-cert-on-moodle","status":"publish","type":"post","link":"https:\/\/blografia.net\/vicm3\/2016\/01\/bits-of-code-php-and-self-signed-cert-on-moodle\/","title":{"rendered":"Bits of code, php and self signed cert on Moodle"},"content":{"rendered":"<p>And a hack, if you happen to have a Moodle 2.6.x with phpmailer old library and you had php5.6.x you may find if you use ssl\/tls to send mail that now php is strictier with self signed certificates, well there are good documentation on php.net about [1] and [2] but not really a clue on what you need to do exactly, for that serverfault offered a better answer [3], not to mention that toke me like 2 hours of reading logs, my own doc on changes, receive a call from my co admin at work for Moodle as he received a lot of mail asking why things where broken, mostly lost|forgotten passwords. At last thinking on the way Moodle uses mail got with the right file, now search how to implement after tried to modify directly, got more time to read and found where it connects finally, so there also exists $options variable to add well options, so I did.<br \/>\n<code><br \/>\n$git diff class.phpmailer.php<br \/>\ndiff --git a\/lib\/phpmailer\/class.phpmailer.php b\/lib\/phpmailer\/class.phpmailer.php<br \/>\nindex fe37a93..414d2e8 100644<br \/>\n--- a\/lib\/phpmailer\/class.phpmailer.php<br \/>\n+++ b\/lib\/phpmailer\/class.phpmailer.php<br \/>\n@@ -1222,7 +1222,12 @@ class PHPMailer<br \/>\n* @throws phpmailerException<br \/>\n* @return bool<br \/>\n*\/<br \/>\n- public function smtpConnect($options = array())<br \/>\n+ public function smtpConnect($options = array(<br \/>\n+ 'ssl'=&gt;array(<br \/>\n+ 'verify_peer' =&gt; false,<br \/>\n+ 'verify_peer_name' =&gt; false,<br \/>\n+ 'allow_self_signed' =&gt; true)<br \/>\n+ ))<br \/>\n{<br \/>\nif (is_null($this-&gt;smtp)) {<br \/>\n$this-&gt;smtp = $this-&gt;getSMTPInstance();<\/code><\/p>\n<p>And voila, we are live again, if you wonder why we need to send mail via tls from another host, well is a long history, but made short Azure not providing reverse resolution from their web panel [4] or from their powershell implementation on Linux also our contact in .mx where unable to provide, info|fix|doc|options to get our mail not marked as bulk from no other that outlook.com go figure.<\/p>\n<p>Had to admit that I was planning to begin the weekend very different <del>doing something really different<\/del> :\/ but as this early morning update our production server with the well tested config on our dev machine&#8230; that don&#8217;t need to send mail :P at least wasn&#8217;t tomorrow, that a large course with self enrolment begins, that will have been overkill and not nice.<\/p>\n<p>Update 26\/8\/2016: We have migrated to Moodle 3.1, is not their problem it&#8217;s PHP no longer accepting self signed certs, new diff, same file:<\/p>\n<p><code>diff --git a\/lib\/phpmailer\/class.phpmailer.php b\/lib\/phpmailer\/class.phpmailer.php<br \/>\nindex e4dd00b..5db0de9 100644<br \/>\n--- a\/lib\/phpmailer\/class.phpmailer.php<br \/>\n+++ b\/lib\/phpmailer\/class.phpmailer.php<br \/>\n@@ -269,7 +269,12 @@ class PHPMailer<br \/>\n* Options array passed to stream_context_create when connecting via SMTP.<br \/>\n* @var array<br \/>\n*\/<br \/>\n- public $SMTPOptions = array();<br \/>\n+ public $SMTPOptions = array(<br \/>\n+ 'ssl'=&gt;array(<br \/>\n+ 'verify_peer' =&gt; false,<br \/>\n+ 'verify_peer_name' =&gt; false,<br \/>\n+ 'allow_self_signed' =&gt; true)<br \/>\n+ );<\/code><\/p>\n<p>\/**<br \/>\n* SMTP username.<\/p>\n<p>It&#8217;s needed to get working again.<br \/>\n[1]\u00a0<a href=\"http:\/\/php.net\/manual\/en\/migration56.openssl.php\">http:\/\/php.net\/manual\/en\/migration56.openssl.php<\/a><br \/>\n[2]\u00a0<a href=\"http:\/\/php.net\/manual\/en\/context.ssl.php\">http:\/\/php.net\/manual\/en\/context.ssl.php<\/a><br \/>\n[3]\u00a0<a href=\"http:\/\/serverfault.com\/questions\/660241\/postfix-tls-error\">http:\/\/serverfault.com\/questions\/660241\/postfix-tls-error<\/a><br \/>\n[4]\u00a0<a href=\"https:\/\/azure.microsoft.com\/en-us\/blog\/announcing-reverse-dns-for-azure-cloud-services\/\">https:\/\/azure.microsoft.com\/en-us\/blog\/announcing-reverse-dns-for-azure-cloud-services\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>And a hack, if you happen to have a Moodle 2.6.x with phpmailer old library and you had php5.6.x you may find if you use ssl\/tls to send mail that now php is strictier with self signed certificates, well there &hellip; <a href=\"https:\/\/blografia.net\/vicm3\/2016\/01\/bits-of-code-php-and-self-signed-cert-on-moodle\/\">Sigue leyendo <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[9,3,10,8,6,7],"tags":[567,333,653,50,654,569,652,655,568],"class_list":["post-1537","post","type-post","status-publish","format-standard","hentry","category-educacion","category-general","category-planetalinux","category-sysadmin","category-trabajo","category-web","tag-fix","tag-hack","tag-mail","tag-moodle","tag-mx","tag-php-5-6","tag-phpmailer","tag-postfix","tag-self-signed-cert"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":2141,"url":"https:\/\/blografia.net\/vicm3\/2019\/12\/allow-wordpress-to-use-a-relay-smtp-with-self-signed-cert\/","url_meta":{"origin":1537,"position":0},"title":"Allow WordPress to use a relay smtp with self signed cert","author":"vicm3","date":"10 diciembre, 2019","format":false,"excerpt":"271 \/** 272 * Options array passed to stream_context_create when connecting via SMTP. 273 * @var array 274 *\/ 275 public $SMTPOptions = array( 276 'ssl' => array( 277 'verify_peer' => false, 278 'verify_peer_name' => false, 279 'allow_self_signed' => true 280 ) 281 ); Around line 271 on wp-includes\/class-phpmailer.php ,or\u2026","rel":"","context":"En \u00abDebraye\u00bb","block_context":{"text":"Debraye","link":"https:\/\/blografia.net\/vicm3\/category\/debraye\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1029,"url":"https:\/\/blografia.net\/vicm3\/2013\/03\/arcane-solution-to-new-problems\/","url_meta":{"origin":1537,"position":1},"title":"Arcane solution to new problems","author":"vicm3","date":"19 marzo, 2013","format":false,"excerpt":"Well as the title says as google has not provided a solution to use self signed certs on gmail I begin to change my habits on reading mail, returned to use mutt (and my mutt-fu skills are very rusted) keep using thunderbird at home, and worse Dreamhost still has not\u2026","rel":"","context":"En \u00abDebraye\u00bb","block_context":{"text":"Debraye","link":"https:\/\/blografia.net\/vicm3\/category\/debraye\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1670,"url":"https:\/\/blografia.net\/vicm3\/2016\/08\/php-y-certificados-firmados-por-uno-mismo-el-caso-de-moodle\/","url_meta":{"origin":1537,"position":2},"title":"PHP y certificados firmados por uno mismo el caso de Moodle","author":"vicm3","date":"29 agosto, 2016","format":false,"excerpt":"Ya lo puse en gran medida en ingles en enero de este a\u00f1o que actualizamos la mayor\u00eda de nuestros servidores a php > 5.6 y empezamos a tener problemas al mandar correo desde el mismo via SSL\/TLS entonces lo documento ac\u00e1 de nuevo pero en espa\u00f1ol, porque no se me\u2026","rel":"","context":"En \u00abEducaci\u00f3n\u00bb","block_context":{"text":"Educaci\u00f3n","link":"https:\/\/blografia.net\/vicm3\/category\/educacion\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":922,"url":"https:\/\/blografia.net\/vicm3\/2012\/06\/the-sorry-state-of-moodle-on-debian\/","url_meta":{"origin":1537,"position":3},"title":"The sorry state of Moodle on Debian","author":"vicm3","date":"7 junio, 2012","format":false,"excerpt":"Well, yes I know, for starters i would be involved on the -team for Moodle, but it bug me out that the important security fixes takes really time to get out to stable, yes I know some are not that severe, but also 1.9.x that is currently on Stable (squeezy)\u2026","rel":"","context":"En \u00abEducaci\u00f3n\u00bb","block_context":{"text":"Educaci\u00f3n","link":"https:\/\/blografia.net\/vicm3\/category\/educacion\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":752,"url":"https:\/\/blografia.net\/vicm3\/2010\/10\/on-the-debian-upgrade-for-moodle-to-1-8-13-miss-profile-pics-i-found-this\/","url_meta":{"origin":1537,"position":4},"title":"Miss the profile pics when upgrading Moodle to 1.8.13 on Debian?  I found this","author":"vicm3","date":"12 octubre, 2010","format":false,"excerpt":"On the upgrade from 1.8.2 to 1.8.13 the way \/var\/lib\/moodle profile pics where handle changed in a subtle way. From users\/x to user\/0 user\/1000 user\/2000 this is a very good idea, but I can't find info about it on README.Debian or any other documentation, would be nice to add to\u2026","rel":"","context":"En \u00abEducaci\u00f3n\u00bb","block_context":{"text":"Educaci\u00f3n","link":"https:\/\/blografia.net\/vicm3\/category\/educacion\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1691,"url":"https:\/\/blografia.net\/vicm3\/2016\/11\/automagic-moodle-update\/","url_meta":{"origin":1537,"position":5},"title":"Automagic Moodle update","author":"vicm3","date":"14 noviembre, 2016","format":false,"excerpt":"Well its monday so semi auto magic roll of patches on CentOS via yum-cron on Debian broken for some dumb and strong firewall rules but applied via unattended updates now done through a ssh tunnel using tsocks, been thinking on create a permanent tunnel or one based on apt.conf and\u2026","rel":"","context":"En \u00abDebraye\u00bb","block_context":{"text":"Debraye","link":"https:\/\/blografia.net\/vicm3\/category\/debraye\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/blografia.net\/vicm3\/wp-json\/wp\/v2\/posts\/1537","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blografia.net\/vicm3\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blografia.net\/vicm3\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blografia.net\/vicm3\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blografia.net\/vicm3\/wp-json\/wp\/v2\/comments?post=1537"}],"version-history":[{"count":0,"href":"https:\/\/blografia.net\/vicm3\/wp-json\/wp\/v2\/posts\/1537\/revisions"}],"wp:attachment":[{"href":"https:\/\/blografia.net\/vicm3\/wp-json\/wp\/v2\/media?parent=1537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blografia.net\/vicm3\/wp-json\/wp\/v2\/categories?post=1537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blografia.net\/vicm3\/wp-json\/wp\/v2\/tags?post=1537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}