Authen-NTLM-HTTP
view release on metacpan or search on metacpan
lib/Authen/NTLM/HTTP.pm view on Meta::CPAN
# Stolen from Crypt::DES.
sub usage {
my ($package, $filename, $line, $subr) = caller (1);
$Carp::CarpLevel = 2;
croak "Usage: $subr (@_)";
}
# Flags to indicate whether we are talking to web server or proxy
use constant NTLMSSP_HTTP_WWW => "WWW";
use constant NTLMSSP_HTTP_PROXY => "Proxy";
# These constants are stolen from samba-2.2.4 and other sources
use constant NTLMSSP_SIGNATURE => 'NTLMSSP';
# NTLMSSP Message Types
use constant NTLMSSP_NEGOTIATE => 1;
use constant NTLMSSP_CHALLENGE => 2;
use constant NTLMSSP_AUTH => 3;
use constant NTLMSSP_UNKNOWN => 4;
lib/Authen/NTLM/HTTP.pm view on Meta::CPAN
# domain, user name and workstation name are in ASCII format and not in #
# UNICODE format. #
###########################################################################
sub http_auth($$$)
{
my $self = shift;
my $nonce = shift;
my $flags = shift;
my $str = encode_base64($self->SUPER::auth_msg($nonce, $flags));
$str =~ s/\s//g;;
if ($self->{'type'} eq NTLMSSP_HTTP_PROXY) {
return "Proxy-Authorization: NTLM " . $str;
}
else {
return "Authorization: NTLM " . $str;
}
}
###########################################################################
# http_parse_auth parses the NTLM-over-HTTP authentication tag line and #
# return a list of NTLM Negotiation Flags, LM response, NT response, User #
# Domain, User Name, User Machine Name and Session Key. #
###########################################################################
sub http_parse_auth($$)
{
my ($self, $pkt) = @_;
if ($self->{'type'} eq NTLMSSP_HTTP_PROXY) {
$pkt =~ s/Proxy-Authorization: NTLM //;
}
else {
$pkt =~ s/Authorization: NTLM //;
}
my $str = decode_base64($pkt);
return $self->SUPER::parse_auth($str);
}
1;
lib/Authen/NTLM/HTTP.pm view on Meta::CPAN
6: C <-- S 200 Ok
=head1 SYNOPSIS
use Authen::NTLM (nt_hash lm_hash);
use Authen::NTLM::HTTP;
$my_pass = "mypassword";
# Note: To instantiate a client talking to a proxy, do
# $client = new_client Authen::NTLM::HTTP(lm_hash($my_pass), nt_hash($my_pass), Authen::NTLM::HTTP::NTLMSSP_HTTP_PROXY);
$client = new_client Authen::NTLM::HTTP(lm_hash($my_pass), nt_hash($my_pass));
# Stage 3 scenario: creates NTLM negotiate message and then
# append $negotiate_msg to one of the tag lines in your HTTP
# request header
# To compose a NTLM Negotiate Packet
$flags = Authen::NTLM::NTLMSSP_NEGOTIATE_ALWAYS_SIGN
| Authen::NTLM::NTLMSSP_NEGOTIATE_OEM_DOMAIN_SUPPLIED
| Authen::NTLM::NTLMSSP_NEGOTIATE_OEM_WORKSTATION_SUPPLIED
lib/Authen/NTLM/HTTP.pm view on Meta::CPAN
$negotiate_msg = $client->http_negotiate($flags);
# Stage 4 scenario: extract the line contains "Authorization: NTLM "
# in the HTTP header.
# Parses NTLM negotiate message and then generates
# the NTLM challenge message.
# To instantiate a server to parse a NTLM negotiation
# and compose a NTLM challenge
# Note: To instantiate a proxy, do
# $server = new_server Authen::NTLM::HTTP(Authen::NTLM::HTTP::NTLMSSP_HTTP_PROXY);
$server = new_server Authen::NTLM::HTTP;
($flags, $domain, $machine) =
$server->http_parse_negotiate($negotiate_msg);
$flags = Authen::NTLM::NTLMSSP_NEGOTIATE_ALWAYS_SIGN
| Authen::NTLM::NTLMSSP_NEGOTIATE_NTLM
| Authen::NTLM::NTLMSSP_NEGOTIATE_UNICODE;
$challenge_msg = $server->http_challenge($flags);
( run in 1.375 second using v1.01-cache-2.11-cpan-71847e10f99 )