Skip to content
Open
Show file tree
Hide file tree
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
18 changes: 15 additions & 3 deletions lib/Net/Netconf/Access/ssh.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,21 @@ sub start {
$self->trace("SSH connection succeeded!");

$self->trace("Performing SSH authentication");
$ssh2->auth(username => $self->{'login'},
password => $self->{'password'});
croak "SSH authentication failed" if(!$ssh2->auth_ok() or $ssh2->error());
if (exists $self->{'password'}) {
$self->trace("Using password");
$ssh2->auth(username => $self->{'login'},
password => $self->{'password'});
} elsif (exists $self->{'private_keyfile'} && exists $self->{'public_keyfile'}) {
$self->trace("Using private key " . $self->{'private_keyfile'} . " and public key " . $self->{'public_keyfile'});
$ssh2->auth(username => $self->{'login'},
privatekey => $self->{'private_keyfile'},
publickey => $self->{'public_keyfile'});
} elsif (exists $self->{'private_keyfile'}) {
$self->trace("Using ONLY private key " . $self->{'private_keyfile'});
$ssh2->auth(username => $self->{'login'},
privatekey => $self->{'private_keyfile'});
}
croak "SSH authentication failed " . $ssh2->error() if(!$ssh2->auth_ok() or $ssh2->error());
$self->trace("Authentication succeeded!");

$self->trace("Requesting SSH channel...");
Expand Down
11 changes: 10 additions & 1 deletion lib/Net/Netconf/Device.pm
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,14 @@ sub new
# Make sure we have 'login', 'hostname' and 'password'
croak 'missing information <hostname>' unless exists $args{'hostname'};
croak 'missing information <login>' unless exists $args{'login'};
croak 'missing information <password>' unless exists $args{'password'};
## Only die if password is unset and keyfile is unset...
if (!defined($args{'private_keyfile'})) { croak 'missing information <password>' unless exists $args{'password'} ; }

## Only die if keyfile is unset and password is unset...
if (!defined($args{'password'})) { croak 'missing information <private_keyfile>' unless exists $args{'private_keyfile'} ; }

## check to see if the keyfile actually exists
if (!defined($args{'password'})) { croak '<private_keyfile> not found in specified location' unless (-e $args{'private_keyfile'}); }

# SAX Parser
my $handler = new Net::Netconf::SAXHandler('ErrorContext' => 5);
Expand Down Expand Up @@ -704,6 +711,8 @@ It also does error handling.
'hostname' => 'routername',
'login' => 'loginname',
'password' => 'secret',
'private_key' => 'private_key_path',
'public_key' => 'public_key_path',
'access' => 'ssh',
'server' => 'netconf',
'debug_level' => 1,
Expand Down
2 changes: 2 additions & 0 deletions lib/Net/Netconf/Manager.pm
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ It also does error handling.
'hostname' => 'routername',
'login' => 'loginname',
'password' => 'secret',
'private_keyfile' => 'private_keyfile_path',
'public_keyfile' => 'public_keyfile_path',
'access' => 'ssh',
'server' => 'netconf',
'command' => 'junoscript netconf',
Expand Down