Skip to content

Commit

Permalink
un-break certificate verification
Browse files Browse the repository at this point in the history
Commit 041d540 "Specify that we want to use the 'ldap' scheme to verify
certificates" unconditionally set IO:Socket::SSL's SSL_verify_cn_scheme
'ldap'.

In principle this is a good thing: it allows to verify whether the name of
the host we connect to matches the host name in the certificate presented.

But doing it unconditionally led to some trouble:
* it broke $ldap->start_tls() completely.
  see SSL_verifycn_name in IO::Socket::SSL(3) for why
* in the case of sslverify = 'none' it created a warning
  on every connect.

This commit fixes both issues.
  • Loading branch information
marschap committed Sep 7, 2011
1 parent 5ee91de commit a3c4f7f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/Net/LDAP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,18 @@ sub _SSL_context_init_args {
my $arg = shift;

my $verify = 0;
my %verifycn_ctx = ();
my ($clientcert,$clientkey,$passwdcb);

if (exists $arg->{'verify'}) {
my $v = lc $arg->{'verify'};
$verify = 0 + (exists $ssl_verify{$v} ? $ssl_verify{$v} : $verify);

if ($verify) {
$verifycn_ctx{SSL_verifycn_scheme} => "ldap";

This comment has been minimized.

Copy link
@gbarr

gbarr Sep 23, 2011

Thats a typo/copy & paste error. I have put a fix on my next branch, but can you test/verify it

This comment has been minimized.

Copy link
@marschap

marschap Sep 23, 2011

Author Owner

Ooops, sorry for the typo.

Tested: your changes

  • verify = none: connect if host names match & if host names don't match
  • verify = optional: connect if host names match, fail if host names don't match
  • verify = require: connect if host names match, fail if host names don't match
    with ldaps & ldap+start_tls.
    So, everything works as it should.

IMHO this is ready for 0.44 (or 0.4301 if you prefer ;-)

$verifycn_ctx{SSL_verifycn_name} = $arg->{'sslserver'}
if (defined $arg->{'sslserver'});
}
}

if (exists $arg->{'clientcert'}) {
Expand Down Expand Up @@ -230,7 +237,7 @@ sub _SSL_context_init_args {
SSL_verify_mode => $verify,
SSL_version => defined $arg->{'sslversion'} ? $arg->{'sslversion'} :
'sslv2/3',
SSL_verifycn_scheme => "ldap",
%verifycn_ctx,
);
}

Expand Down Expand Up @@ -1031,6 +1038,8 @@ sub start_tls {
delete $ldap->{net_ldap_root_dse};

$arg->{sslversion} = 'tlsv1' unless defined $arg->{sslversion};
$arg->{sslserver} = $ldap->{'net_ldap_host'} unless defined $arg->{sslserver};

IO::Socket::SSL::context_init( { _SSL_context_init_args($arg) } );
my $sock_class = ref($sock);

Expand Down

0 comments on commit a3c4f7f

Please sign in to comment.