Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed post 6.43 auth #4

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions lib/MikroTik/API.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ MikroTik::API - Client to MikroTik RouterOS API

=head1 VERSION

Version 1.0.4
Version 1.0.5

=cut

our $VERSION = '1.0.4';
our $VERSION = '1.0.5';


=head1 SYNOPSIS
Expand Down Expand Up @@ -150,26 +150,31 @@ sub login {
$self->connect();
}

# RouterOS post v6.43 has new authentication method, thus pushing login/pass in the very first request.
my @command = ('/login');
push( @command, '=name=' . $self->get_username() );
push( @command, '=password=' . $self->get_password() );
my ( $retval, @results ) = $self->talk( \@command );
my $challenge = pack("H*",$results[0]{'ret'});
my $md5 = Digest::MD5->new();
$md5->add( chr(0) );
$md5->add( $self->get_password() );
$md5->add( $challenge );

@command = ('/login');
push( @command, '=name=' . $self->get_username() );
push( @command, '=response=00' . $md5->hexdigest() );
( $retval, @results ) = $self->talk( \@command );
die 'disconnected while logging in' if !defined $retval;
# if we got "=ret=" in response - then assuming this is old style AUTH
if ( exists $results[0]{'ret'} ) {
my $challenge = pack("H*",$results[0]{'ret'});
my $md5 = Digest::MD5->new();
$md5->add( chr(0) );
$md5->add( $self->get_password() );
$md5->add( $challenge );

@command = ('/login');
push( @command, '=name=' . $self->get_username() );
push( @command, '=response=00' . $md5->hexdigest() );
( $retval, @results ) = $self->talk( \@command );
}
if ( $retval > 1 ) {
die $results[0]{'message'};
}
if ( $self->get_debug() > 0 ) {
print 'Logged in to '. $self->get_host() .' as '. $self->get_username() ."\n";
}

return $self;
}

Expand Down