briandfoy / net-ssh-perl

Development on the Net::SSH::Perl module to support latest ciphers, key exchange mechanisms, etc.
Other
4 stars 1 forks source link

bug in write_private method #59

Open briandfoy opened 1 year ago

briandfoy commented 1 year ago

This ticket was imported from rt.cpan.org 122364

Hello, the documentation[1] says "If $file is not provided, returns the content that would have been written to the key file." But running this simple perl script returns the following error message :

hugo@brichemer:~$ cat test.pl use Net::SSH::Perl::Key; my $privkey = Net::SSH::Perl::Key->keygen("RSA",2048)->write_private(); hugo@brichemer:~$ perl test.pl Use of uninitialized value $key_file in open at /usr/local/lib/x86_64-linux-gnu/perl/5.22.1/Net/SSH/Perl/Key/RSA.pm line > 93. Use of uninitialized value $key_file in concatenation (.) or string at /usr/local/lib/x86_64-linux-gnu/perl/5.22.1/Net/SSH/Perl/Key/RSA.pm line 93. Can't write to : No such file or directory at test.pl line 2.

To fix this I added a line to handle the case where "$key_file" is empty, here is the diff between the original RSA.pm and the modified :

hugo@brichemer:~$ diff RSA.pm* 92a93,95

return $pem if(!$key_file);

I have checked some but not all perl modules file in 'perl/5.24.1/Net/SSH/Perl/Key/' for the function write_private and it seems they also need this modification.

Finally, here are some versions infos :

hugo@brichemer:~$ sudo cpanm --info Net::SSH::Perl::Key && uname -a && perl -v SCHWIGON/Net-SSH-Perl-2.12.tar.gz Linux brichemer 4.9.0-3-686-pae #1 SMP Debian 4.9.30-2+deb9u2 (2017-06-26) i686 GNU/Linux This is perl 5, version 24, subversion 1 (v5.24.1) built for i686-linux-gnu-thread-multi-64int

Thank you

[1] http://search.cpan.org/~schwigon/Net-SSH-Perl-2.12/lib/Net/SSH/Perl/Key.pm#$key-%3Ewrite_private([_$ ile[,$pass,$ciphername,$rounds]_])


gpg public key : https://ysengr.in/pubkey