<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Mike B</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/mike_b/" />
    <link rel="self" type="application/atom+xml" href="http://blogs.perl.org/users/mike_b/atom.xml" />
    <id>tag:blogs.perl.org,2009-11-03:/users/mike_b//986</id>
    <updated>2013-05-17T07:31:54Z</updated>
    <subtitle>A blog about the Perl programming language</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Pro 4.38</generator>

<entry>
    <title>POP3 with TLS in Perl</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/mike_b/2013/05/pop3-with-tls-in-perl.html" />
    <id>tag:blogs.perl.org,2013:/users/mike_b//986.4684</id>

    <published>2013-05-16T18:14:57Z</published>
    <updated>2013-05-17T07:31:54Z</updated>

    <summary>The famous libnet modules provide Perl programmers with a low level interface to POP3 and SMTP servers, among others. This works fine in general but over the past years most mail servers stopped offering &apos;plain&apos; SMTP and POP3 access, but...</summary>
    <author>
        <name>Mike B</name>
        
    </author>
    
    <category term="pop3libnettlsssl" label="pop3 libnet tls ssl" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/mike_b/">
        <![CDATA[<p>The famous <a href="https://metacpan.org/release/libnet">libnet</a> modules provide Perl programmers with a low level interface to POP3 and SMTP servers, among others.</p>

<p>This works fine in general but over the past years most mail servers stopped offering 'plain' SMTP and POP3 access, but use either SSL or TLS encryption. This has lead to a plethora of modules on CPAN to support SMTP via SSL or TLS and also for POP3 via SSL. Until recently this was not the case for POP3 using TLS security. But earlier this week Steffen Ullrich, the maintainer of IO::Socket::SSL, released a new version of <a href="https://metacpan.org/module/Net::SSLGlue">Net::SSLGlue</a> that also allows for connecting to POP3 over TLS. And as opposed to many of the other modules, it also allows to verify the SSL certificate on the remote server for extra security. Net::SSLGlue works for Net::SMTP, Net::POP3, Net::LDAP, and LWP.</p>

<p>Here is an example of how you can connect to a POP3 mail server over TLS:</p>
]]>
        <![CDATA[<pre><code>#!/usr/bin/env perl

use strict;
use warnings;

use Net::SSLGlue::POP3;

my $host  = 'pop.aol.com';
my $login = 'myusername@aol.com';
my $pass  = '4Radfsai8fsfd9sdf9sdf';

my $pop3 = Net::POP3-&gt;new( $host) || die "Can't connect to $host: $!";
# no SSL verification: vulnerable for Man in the Middle attack
$pop3-&gt;starttls( SSL_verify_mode =&gt; 0 ) || die "Can't perform starttls: $!";

my $messages = $pop3-&gt;login( $login, $pass ) || die "Failed to authenticate login $login on $host: $!";

print "There are $messages messages on $host for $login.\n";
</code></pre>

<p>This would give you all the safety of SSL encryption, so no-one can eavesdrop on your communication; but you still have not verified the remote certificate. So in theory, people could set up a server impersonating the mail server and poison DNS. You connect to their mail server nice and securely, thinking it is the original mail server, and you tell them your password. This is called a "<a href="http://en.wikipedia.org/wiki/Man-in-the-middle_attack">Man in the Middle-attack</a>". Luckily Net::SSLGlue also exposes the internals of <a href="https://metacpan.org/module/IO::Socket::SSL">IO::Socket::SSL</a>. This is no coincidence because they both have the same maintainer. Read the module documentation for the fine details; if you do not have OpenSSL installed or certificate bundles at hand a convenient way is to use the certificates of <a href="https://metacpan.org/module/Mozilla::CA">Mozilla::CA</a> as in the code example below.</p>

<pre><code>#!/usr/bin/env perl

use strict;
use warnings;

use Net::SSLGlue::POP3;
use Mozilla::CA;

my $host  = 'pop.aol.com';
my $login = 'myusername@aol.com';
my $pass  = '4Radfsai8fsfd9sdf9sdf';

my $pop3 = Net::POP3-&gt;new( $host) || die "Can't connect to $host: $!";
$pop3-&gt;starttls(
    SSL_verify_mode =&gt; 1,
    SSL_ca_file =&gt; Mozilla::CA::SSL_ca_file(),
) || die "Can't perform starttls: $!";

my $messages = $pop3-&gt;login( $login, $pass ) || die "Failed to authenticate login $login on $host: $!";

print "There are $messages messages on $host for $login.\n";
</code></pre>

<p>Thanks to Steffen for an awesome module!</p>
]]>
    </content>
</entry>

<entry>
    <title>On Unicode and Sorting</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/mike_b/2011/08/on-unicode-and-sorting.html" />
    <id>tag:blogs.perl.org,2011:/users/mike_b//986.2152</id>

    <published>2011-08-31T20:54:35Z</published>
    <updated>2011-09-01T07:48:46Z</updated>

    <summary>Tom Christiansen published an article on Perl.com on the topic of sorting and unicode. It&apos;s good and it explains a little bit about why Unicode is so difficult and why sorting Unicode (or even ascii) is even more difficult, mainly...</summary>
    <author>
        <name>Mike B</name>
        
    </author>
    
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/mike_b/">
        <![CDATA[<p>Tom Christiansen <a href="http://www.perl.com/pub/2011/08/whats-wrong-with-sort-and-how-to-fix-it.html">published an article on Perl.com on the topic of sorting and unicode</a>.</p>

<p>It's good and it explains a little bit about why Unicode is so difficult and why sorting Unicode (or even ascii) is even more difficult, mainly because it depends on your local definitions what results you expect from a sorting operation.</p>

<p>It might be nice to point out that the modules he proposes on using, <a href="https://metacpan.org/module/Unicode::Collate">Unicode::Collate</a>, and <a href="https://metacpan.org/module/Unicode::Collate::Locale">Unicode::Collate::Locale</a>, have been in core perl since 5.8 and 5.14, respectively.</p>

<p>Happy sorting!</p>]]>
        
    </content>
</entry>

</feed>
