| 1 | use strict; | ||
| 2 | use warnings; | ||
| 3 | package Net::SSLGlue::LDAP; | ||
| 4 | our $VERSION = '1.01'; | ||
| 5 | use Net::LDAP; | ||
| 6 | use IO::Socket::SSL 1.19; | ||
| 7 | |||
| 8 | # can be reset with local | ||
| 9 | our %SSLopts; | ||
| 10 | |||
| 11 | # add SSL_verifycn_scheme to the SSL CTX args returned by | ||
| 12 | # Net::LDAP::_SSL_context_init_args | ||
| 13 | |||
| 14 | my $old = defined &Net::LDAP::_SSL_context_init_args | ||
| 15 | && \&Net::LDAP::_SSL_context_init_args | ||
| 16 | || die "cannot find Net::LDAP::_SSL_context_init_args"; | ||
| 17 | no warnings 'redefine'; | ||
| 18 | *Net::LDAP::_SSL_context_init_args = sub { | ||
| 19 | my %arg = $old->(@_); | ||
| 20 | $arg{SSL_verifycn_scheme} ||= 'ldap' if $arg{SSL_verify_mode}; | ||
| 21 | while ( my ($k,$v) = each %SSLopts ) { | ||
| 22 | $arg{$k} = $v; | ||
| 23 | } | ||
| 24 | return %arg; | ||
| 25 | }; | ||
| 26 | |||
| 27 | 1; | ||
| 28 | |||
| 29 | =head1 NAME | ||
| 30 | |||
| 31 | Net::SSLGlue::LDAP - proper certificate checking for ldaps in Net::LDAP | ||
| 32 | |||
| 33 | =head1 SYNOPSIS | ||
| 34 | |||
| 35 | use Net::SSLGlue::LDAP; | ||
| 36 | local %Net::SSLGlue::LDAP = ( SSL_verifycn_name => $hostname_in_cert ); | ||
| 37 | my $ldap = Net::LDAP->new( $hostname, capath => ... ); | ||
| 38 | $ldap->start_tls; | ||
| 39 | |||
| 40 | |||
| 41 | =head1 DESCRIPTION | ||
| 42 | |||
| 43 | L<Net::SSLGlue::LDAP> modifies L<Net::LDAP> so that it does proper certificate | ||
| 44 | checking using the C<ldap> SSL_verify_scheme from L<IO::Socket::SSL>. | ||
| 45 | |||
| 46 | Because L<Net::LDAP> does not have a mechanism to forward arbitrary parameters for | ||
| 47 | the construction of the underlying socket these parameters can be set globally | ||
| 48 | when including the package, or with local settings of the | ||
| 49 | C<%Net::SSLGlue::LDAP::SSLopts> variable. | ||
| 50 | |||
| 51 | All of the C<SSL_*> parameters from L<IO::Socket::SSL> can be used; the | ||
| 52 | following parameter is especially useful: | ||
| 53 | |||
| 54 | =over 4 | ||
| 55 | |||
| 56 | =item SSL_verifycn_name | ||
| 57 | |||
| 58 | Usually the name given as the hostname in the constructor is used to verify the | ||
| 59 | identity of the certificate. If you want to check the certificate against | ||
| 60 | another name you can specify it with this parameter. | ||
| 61 | |||
| 62 | =back | ||
| 63 | |||
| 64 | C<SSL_ca_path>, C<SSL_ca_file> for L<IO::Socket::SSL> can be set with the | ||
| 65 | C<capath> and C<cafile> parameters of L<Net::LDAP::new> and C<SSL_verify_mode> | ||
| 66 | can be set with C<verify>, but the meaning of the values differs (C<none> is 0, | ||
| 67 | e.g. disable certificate verification). | ||
| 68 | |||
| 69 | =head1 SEE ALSO | ||
| 70 | |||
| 71 | IO::Socket::SSL, LWP, Net::LDAP | ||
| 72 | |||
| 73 | =head1 COPYRIGHT | ||
| 74 | |||
| 75 | This module is copyright (c) 2008, Steffen Ullrich. | ||
| 76 | All Rights Reserved. | ||
| 77 | This module is free software. It may be used, redistributed and/or modified | ||
| 78 | under the same terms as Perl itself. | ||
| 79 |