| 1 | ########################################### | ||||||||||||||
| 2 | package Net::SSH::AuthorizedKey::SSH2; | ||||||||||||||
| 3 | ########################################### | ||||||||||||||
| 4 | 11 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 11 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 11 | ▶ | use Net::SSH::AuthorizedKey::Base; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 11 | ▶ | use base qw(Net::SSH::AuthorizedKey::Base); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 11 | ▶ | use Log::Log4perl qw(:easy); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | # No additional options, only global ones | ||||||||||||||
| 11 | 11 | our %VALID_OPTIONS = (); | |||||||||||||
| 12 | |||||||||||||||
| 13 | 11 | our $KEYTYPE_REGEX = qr/rsa|dsa|ssh-rsa|ssh-dss|ecdsa-\S+/; | |||||||||||||
| 14 | |||||||||||||||
| 15 | 11 | our @REQUIRED_FIELDS = qw( | |||||||||||||
| 16 | encryption | ||||||||||||||
| 17 | ); | ||||||||||||||
| 18 | |||||||||||||||
| 19 | 11 | __PACKAGE__->make_accessor( $_ ) for | |||||||||||||
| 20 | (@REQUIRED_FIELDS); | ||||||||||||||
| 21 | |||||||||||||||
| 22 | ########################################### | ||||||||||||||
| 23 | sub new { | ||||||||||||||
| 24 | ########################################### | ||||||||||||||
| 25 | 34 | ▶ | my($class, %options) = @_; | ||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 26 | |||||||||||||||
| 27 | 34 | return $class->SUPER::new( %options, type => "ssh-2" ); | |||||||||||||
| 28 | } | ||||||||||||||
| 29 | |||||||||||||||
| 30 | ########################################### | ||||||||||||||
| 31 | sub as_string { | ||||||||||||||
| 32 | ########################################### | ||||||||||||||
| 33 | 46 | ▶ | my($self) = @_; | ||||||||||||
|
Subroutine
as_string: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||
| 34 | |||||||||||||||
| 35 | 46 | my $string = $self->options_as_string(); | |||||||||||||
| 36 | 46 | ▶ | $string .= " " if length $string; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 37 | |||||||||||||||
| 38 | 46 | $string .= "$self->{encryption} $self->{key}"; | |||||||||||||
| 39 | 46 | ▶ | $string .= " $self->{email}" if length $self->{email}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 40 | |||||||||||||||
| 41 | 46 | return $string; | |||||||||||||
| 42 | } | ||||||||||||||
| 43 | |||||||||||||||
| 44 | ########################################### | ||||||||||||||
| 45 | sub parse_multi_line { | ||||||||||||||
| 46 | ########################################### | ||||||||||||||
| 47 | 0 | ▶ | my($self, $string) = @_; | ||||||||||||
|
Subroutine
parse_multi_line: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||
| 48 | |||||||||||||||
| 49 | 0 | my @fields = (); | |||||||||||||
| 50 | |||||||||||||||
| 51 | 0 | ▶ | while($string =~ s/^(.*):\s+(.*)//gm) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 52 | 0 | my($field, $value) = ($1, $2); | |||||||||||||
| 53 | # remove quotes | ||||||||||||||
| 54 | 0 | $value =~ s/^"(.*)"$/$1/; | |||||||||||||
| 55 | 0 | push @fields, $field, $value; | |||||||||||||
| 56 | 0 | my $lcfield = lc $field; | |||||||||||||
| 57 | |||||||||||||||
| 58 | 0 | ▶ | if( $self->accessor_exists( $lcfield ) ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 59 | 0 | $self->$lcfield( $value ); | |||||||||||||
| 60 | } else { | ||||||||||||||
| 61 | 0 | WARN "Ignoring unknown field '$field'"; | |||||||||||||
| 62 | } | ||||||||||||||
| 63 | } | ||||||||||||||
| 64 | |||||||||||||||
| 65 | # Rest is the key, split across several lines | ||||||||||||||
| 66 | 0 | $string =~ s/\n//g; | |||||||||||||
| 67 | 0 | $self->key( $string ); | |||||||||||||
| 68 | 0 | $self->type( "ssh-2" ); | |||||||||||||
| 69 | |||||||||||||||
| 70 | # Comment: "rsa-key-20090703" | ||||||||||||||
| 71 | 0 | ▶ | if($self->comment() =~ /\b(.*?)-key/) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 72 | 0 | $self->encryption( "ssh-" . $1 ); | |||||||||||||
| 73 | } elsif( ! $self->{strict} ) { | ||||||||||||||
| 74 | 0 | WARN "Unknown encryption [", $self->comment(), | |||||||||||||
| 75 | "] fixed to ssh-rsa"; | ||||||||||||||
| 76 | 0 | $self->encryption( "ssh-rsa" ); | |||||||||||||
| 77 | } | ||||||||||||||
| 78 | } | ||||||||||||||
| 79 | |||||||||||||||
| 80 | ########################################### | ||||||||||||||
| 81 | sub key_read { | ||||||||||||||
| 82 | ############################################ | ||||||||||||||
| 83 | 91 | ▶ | my($class, $line) = @_; | ||||||||||||
|
Subroutine
key_read: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||
| 84 | |||||||||||||||
| 85 | 91 | ▶ | if($line !~ s/^($KEYTYPE_REGEX)\s*//) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 86 | 57 | DEBUG "No SSH2 keytype found"; | |||||||||||||
| 87 | 57 | return undef; | |||||||||||||
| 88 | } | ||||||||||||||
| 89 | |||||||||||||||
| 90 | 34 | my $encryption = $1; | |||||||||||||
| 91 | 34 | DEBUG "Parsed encryption $encryption"; | |||||||||||||
| 92 | |||||||||||||||
| 93 | 34 | ▶ | if($line !~ s/^(\S+)\s*//) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 94 | 0 | DEBUG "No SSH2 key found"; | |||||||||||||
| 95 | 0 | return undef; | |||||||||||||
| 96 | } | ||||||||||||||
| 97 | |||||||||||||||
| 98 | 34 | my $key = $1; | |||||||||||||
| 99 | 34 | DEBUG "Parsed key $key"; | |||||||||||||
| 100 | |||||||||||||||
| 101 | 34 | my $email = $line; | |||||||||||||
| 102 | |||||||||||||||
| 103 | 34 | my $obj = __PACKAGE__->new(); | |||||||||||||
| 104 | 34 | $obj->encryption( $encryption ); | |||||||||||||
| 105 | 34 | $obj->key( $key ); | |||||||||||||
| 106 | 34 | $obj->email( $email ); | |||||||||||||
| 107 | 34 | $obj->comment( $email ); | |||||||||||||
| 108 | |||||||||||||||
| 109 | 34 | return $obj; | |||||||||||||
| 110 | } | ||||||||||||||
| 111 | |||||||||||||||
| 112 | ########################################### | ||||||||||||||
| 113 | sub sanity_check { | ||||||||||||||
| 114 | ########################################### | ||||||||||||||
| 115 | 2 | ▶ | my($self) = @_; | ||||||||||||
|
Subroutine
sanity_check: called CC=3 SCAR=12.5
Pod
undocumented
| |||||||||||||||
| 116 | |||||||||||||||
| 117 | 2 | for my $field (@REQUIRED_FIELDS) { | |||||||||||||
| 118 | 2 | ▶ | if(! length $self->$field()) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 119 | 0 | WARN "ssh-2 sanity check failed '$field' requirement"; | |||||||||||||
| 120 | 0 | return undef; | |||||||||||||
| 121 | } | ||||||||||||||
| 122 | } | ||||||||||||||
| 123 | |||||||||||||||
| 124 | 2 | return 1; | |||||||||||||
| 125 | } | ||||||||||||||
| 126 | |||||||||||||||
| 127 | ########################################### | ||||||||||||||
| 128 | sub option_type { | ||||||||||||||
| 129 | ########################################### | ||||||||||||||
| 130 | 0 | ▶ | my($self, $option) = @_; | ||||||||||||
|
Subroutine
option_type: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 131 | |||||||||||||||
| 132 | 0 | ▶ | if(exists $VALID_OPTIONS{ $option }) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 133 | 0 | return $VALID_OPTIONS{ $option }; | |||||||||||||
| 134 | } | ||||||||||||||
| 135 | |||||||||||||||
| 136 | 0 | return undef; | |||||||||||||
| 137 | } | ||||||||||||||
| 138 | |||||||||||||||
| 139 | 11 | 1; | |||||||||||||
| 140 | |||||||||||||||
| 141 | __END__ | ||||||||||||||
| 142 | |||||||||||||||
| 143 | =head1 NAME | ||||||||||||||
| 144 | |||||||||||||||
| 145 | Net::SSH::AuthorizedKey::SSH2 - Net::SSH::AuthorizedKey subclass for ssh-2 | ||||||||||||||
| 146 | |||||||||||||||
| 147 | =head1 DESCRIPTION | ||||||||||||||
| 148 | |||||||||||||||
| 149 | See Net::SSH::AuthorizedKey. | ||||||||||||||
| 150 | |||||||||||||||
| 151 | =head1 LEGALESE | ||||||||||||||
| 152 | |||||||||||||||
| 153 | Copyright 2005 by Mike Schilli, all rights reserved. | ||||||||||||||
| 154 | This program is free software, you can redistribute it and/or | ||||||||||||||
| 155 | modify it under the same terms as Perl itself. | ||||||||||||||
| 156 | |||||||||||||||
| 157 | =head1 AUTHOR | ||||||||||||||
| 158 | |||||||||||||||
| 159 | 2005, Mike Schilli <m@perlmeister.com> | ||||||||||||||