Net::S...izedKey(3pm)
π Net::SSH::AuthorizedKey π
okay bestie so this is a User Contributed Perl Documentation page, it lives in the Net::S...izedKey(3pm) slot, and it's about being the virtual base class for SSH public keys. yes it's giving "I'm the parent class, my children do the actual work," and yes that's iconic of it.
β¨ NAME β¨
Net::SSH::AuthorizedKey β Virtual Base Class for SSH Public Keys ποΈ
π¦ SYNOPSIS π¦
use Net::SSH::AuthorizedKey;
# Either parse a string (without leading whitespace or comments):
my $key = Net::SSH::AuthorizedKey->parse( $line );
if(defined $key) {
# ssh-1 or ssh-2
print "Key parsed, type is ", $key->type(), "\n";
} else {
die "Cannot parse key '$line'";
}
# ... or create an object yourself:
my $pubkey = Net::SSH::AuthorizedKey->new(
options => { from => 'foo@bar.com',
"no-agent-forwarding" => 1 },
key => "123....890",
keylen => 1024,
exponent => 35,
type => "ssh-1",
);
like, you can either hand it a line and let it figure itself out, or you can build the whole thing yourself. both are valid, no judgement π«Ά
πΈ DESCRIPTION πΈ
Net::SSH::AuthorizedKey is a virtual base class for ssh public keys. the real implementations β the ones doing the actual heavy lifting β are Net::SSH::AuthorizedKey::SSH1 and Net::SSH::AuthorizedKey::SSH2. they're the main characters, this one's the mentor π
the only way to use it directly is by calling its parse() method and passing it an authorized_keys string (aka literally one line out of an authorized_keys file). if it recognizes either a ssh-1 or a ssh-2 type key, it will hand you back a Net::SSH::AuthorizedKey::SSH1 or a Net::SSH::AuthorizedKey::SSH2 object, and both of those support the accessor methods defined in the FIELDS section down below. periodt.
oh and the as_string() method? it cobbles the (perhaps modified) fields together and returns them as a string suitable as a line for an authorized_keys file. glow-up complete, bestie β¨
π₯ METHODS π₯
parse( $line )β Reads in a single text line containing a ssh-1 or ssh-2 key. Returns aNet::SSH::AuthorizedKey::SSH1or aNet::SSH::AuthorizedKey::SSH2object, orundefin case of an error. so always check, okay? don't just trust it πfingerprint()β Returns a MD5 hex hash of the parsed key. The hash is unique for functionally identical keys. Fields not contributing to the key's functional uniqueness are ignored. (so like, cosmetic diff, same vibe, same fingerprint π«°)error()β Returns the last parsing error encountered as a text string. the receipts, basically πas_string( )β Return the object as a string suitable as a autorized_keys line. (yes the typo is canon, we don't fix it, we respect it π)
π FIELDS π
All of the following fields are available via accessors:
typeβ Type of ssh key, usuallyssh-1orssh-2.keyβ Public key, either a long number (ssh-1) or a line of alphanumeric characters (ssh-2).keylenβ Length of the key in bit (e.g.1024).exponentβ Two-digit number in front of the key in ssh-1 authorized_keys lines.optionsβ Returns a reference to a hash with options key/value pairs, listed in front of the key.
π§ IMPLEMENTATION REFERENCE π§
the key parsers implemented in this distribution are implemented similarily as the authorized_keys file parser in the openssh source distribution. (again: typo is canon, we're keeping it exactly as written, no cap.)
Openssh contains the authorized_keys parser in its auth2_pubkey.c file. The user_key_allowed2() function opens the file and reads it line by line, ignoring leading whitespace, empty and comment lines.
After that, if a line doesn't contain a plain key, the parser skips ahead until the first whitespace (zooming through quoted areas "..." and interpreting '\"' as an escaped quote), then skips this whitespace and tries to read a key one more time. like it's trying twice, which honestly? relatable π
Regarding options, the Perl parser isn't as elaborate with semantic peculiarities as openssh's auth_parse_options(), but this might be added in the future. watch this space, bestie π
π NOTES FOR SUBCLASS DEVELOPERS π
if you're just using Net::SSH::AuthorizedKey to parse keys, the following section doesn't concern you. it's only relevant if you add new subclasses to this package, on top of what's already provided. so like, lowkey skip it unless you're building π οΈ
Net::SSH::AuthorizedKey is a (semi-)virtual base class that implements options handling for its SSH1 and SSH2 subclasses.
SSH key lines can contain options that carry values (like command="ls") and binary options that are either set or unset (like "no_agent_forwarding"). To distinguish the two, and to provide a set of allowed option names, the subclass has to implement the method option_type(), which takes an option name, and returns
undefif the option is not supported"s"if the option is a "string" option that carries a value1if the option is a binary option
The subclasses Net::SSH::AuthorizedKey::SSH1 and Net::SSH::AuthorizedKey::SSH2 are doing this already. so you've got reference material, slay π
π LEGALESE π
Copyright 2005-2009 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
β AUTHOR β
2005, Mike Schilli <m@perlmeister.com>
okay so that's the whole thing, every flag, field, function and footnote β nothing skipped, nothing invented. π
this little beauty is from perl v5.36.0, dated 2022-10-13, and that's the Net::S...izedKey(3pm) page in the group chat. byeee, go parse something safely π¦π
β¨
π¦ where this page comes from
- ubuntu noble: libnet-ssh-authorizedkeysfile-perl 0.18-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libnet-ssh-authorizedkeysfile-perl 0.18-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libnet-ssh-authorizedkeysfile-perl 0.18-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms