1Net::SSH::Perl::Util(3)User Contributed Perl DocumentatioNnet::SSH::Perl::Util(3)
2
3
4
6 Net::SSH::Perl::Util - Shared utility functions
7
9 use Net::SSH::Perl::Util qw( ... );
10
12 Net::SSH::Perl::Util contains a variety of exportable utility functions
13 used by the various Net::SSH::Perl modules. These range from hostfile
14 routines, to RSA encryption routines, etc.
15
16 None of the routines are actually stored in the Util module itself;
17 they are contained within sub-modules that are loaded on demand by the
18 parent Util module, which contains a table mapping function names to
19 sub-module names. The "on demand" is done by including either a func‐
20 tion name, or a tag name (see below), in your use line.
21 Net::SSH::Perl::Util will take care of loading the sub-module and
22 importing the requested function(s) into your namespace.
23
24 The routines are exportable by themselves, ie.
25
26 use Net::SSH::Perl::Util qw( routine_name );
27
28 In addition, some of the routines are grouped into bundles that you can
29 pull in by export tag, ie.
30
31 use Net::SSH::Perl::Util qw( :bundle );
32
33 The groups are:
34
35 * hosts
36 Routines associated with hostfile-checking, addition, etc. Con‐
37 tains "_check_host_in_hostfile" and "_add_host_to_hosfile".
38
39 * rsa
40 Routines associated with RSA encryption, decryption, and authenti‐
41 cation. Contains "_rsa_public_encrypt", "_rsa_private_decrypt", and
42 "_respond_to_rsa_challenge".
43
44 * ssh1mp
45 Routines associated with multiple-precision integers and the gener‐
46 ation and manipulation of same. Contains "_mp_linearize" and "_com‐
47 pute_session_id".
48
49 Because the SSH1 implementation uses Math::GMP for its big inte‐
50 gers, the functions in ssh1mp all deal with Math::GMP objects.
51
52 * ssh2mp
53 Routines associated with SSH2 big integers, which are Math::Pari
54 objects. Contains "bitsize", "bin2mp", and "mp2bin".
55
56 * authfile
57 Routines associated with loading of RSA SSH1 keys (both public and
58 private) from keyfiles. Contains "_load_public_key", "_load_pri‐
59 vate_key", and "_save_private_key".
60
61 Note that this interface is deprecated in favor of the
62 Net::SSH::Perl::Key interface to loading keys.
63
64 * all
65 All routines. Contains all of the routines listed below.
66
68 _crc32($data)
69
70 Returns a CRC32 checksum of $data. This uses String::CRC32 internally
71 to do its magic, with the caveat that the "init state" of the checksum
72 is 0xFFFFFFFF, and the result is xor-ed with 0xFFFFFFFF.
73
74 This is used in SSH1.
75
76 _compute_session_id($check_bytes, $host_key, $public_key)
77
78 Given the check bytes ($check_bytes) and the server host and public
79 keys ($host_key and $public_key, respectively), computes the session ID
80 that is then used to uniquely identify the session between the server
81 and client.
82
83 $host_key and $public_key should be Net::SSH::Perl::Key::RSA1 objects;
84 $check_bytes is an 8-byte string.
85
86 Returns the session ID.
87
88 _mp_linearize($int)
89
90 Converts a multiple-precision integer $int into a byte string. $int
91 should be a Math::GMP object.
92
93 Returns the byte string.
94
95 bitsize($int)
96
97 Returns the number of bits in $int, which should be a Math::Pari
98 object.
99
100 bin2mp($octet_string)
101
102 Treats $octet_string as a representation of a big integer in base 256,
103 and converts the string into that integer. Returns the integer, a
104 Math::Pari object.
105
106 mp2bin($int)
107
108 Converts $int, a Math::Pari object, into an octet string (ie. the
109 reverse of "bin2mp"). Returns the octet string.
110
111 _check_host_in_hostfile($host, $host_file, $host_key)
112
113 Looks up $host in $host_file and checks the stored host key against
114 $host_key to determine the status of the host.
115
116 $host_key should be an object of some subclass of Net::SSH::Perl::Key;
117 in particular, it must support the extract_public class method and the
118 equal object method.
119
120 If the host is not found, returns HOST_NEW.
121
122 If the host is found, and the keys match, returns HOST_OK.
123
124 If the host is found, and the keys don't match, returns HOST_CHANGED,
125 which generally indicates a security problem (ie. man-in-the-middle
126 attack).
127
128 _add_host_to_hostfile($host, $host_file, $host_key)
129
130 Opens up the known hosts file $host_file and adds an entry for $host
131 with host key $host_key. Dies if $host_file can't be opened for writ‐
132 ing.
133
134 $host_key should be an object of some subclass of Net::SSH::Perl::Key;
135 in particular, it must support the dump_public object method.
136
137 _load_public_key($key_file)
138
139 Given the location of a public key file $key_file, reads the RSA public
140 key from that file.
141
142 If called in list context, returns the key and the comment associated
143 with the key. If called in scalar context, returns only the key.
144
145 Dies if: the key file $key_file can't be opened for reading; or the key
146 file is "bad" (the ID string in the file doesn't match the PRI‐
147 VATE_KEY_ID_STRING constant).
148
149 Returns the RSA key (a Net::SSH::Perl::Key::RSA1 object).
150
151 _load_private_key($key_file [, $passphrase ])
152
153 Given the location of a private key file $key_file, and an optional
154 passphrase to decrypt the key, reads the private key from that file. If
155 $passphrase is not supplied, an empty passphrase (the empty string) is
156 tried instead.
157
158 If called in list context, returns the key and the comment associated
159 with the key. If called in scalar context, returns only the key.
160
161 Dies if: the key file $key_file can't be opened for reading; the key
162 file is "bad" (the ID string in the file doesn't match the PRI‐
163 VATE_KEY_ID_STRING constant); the file is encrypted using an unsup‐
164 ported encryption cipher; or the passphrase $passphrase is incorrect.
165
166 Returns the RSA key (a Net::SSH::Perl::Key::RSA1 object).
167
168 _save_private_key($key_file, $key, [ $passphrase [, $comment ]])
169
170 Given a private key $key, and the location of the private key file
171 $key_file, writes out an SSH1 RSA key file to $key_file.
172
173 If $passphrase is supplied, the private key portion of the file is
174 encrypted with 3DES encryption, using the passphrase $passphrase. If
175 the passphrase is not supplied, an empty passphrase will be used
176 instead. This is useful when using RSA authentication in a non-interac‐
177 tive process, for example.
178
179 $comment is an optional string that, if supplied, is inserted into the
180 key file and can be used by clients when prompting for the passphrase
181 upon loading the private key, etc. It should be somewhat descriptive of
182 this key file.
183
184 $key should be a Net::SSH::Perl::Key::RSA1 object.
185
186 _prompt($prompt [, $default [, $echo ]])
187
188 Emits an interactive prompt $prompt with an optional default $default.
189 If $echo is true, reads normally from STDIN; if $echo is false, calls
190 _read_passphrase internally to read sensitive information with echo
191 off.
192
193 Returns the user's answer to the prompt, $default if no answer was pro‐
194 vided.
195
196 _read_passphrase($prompt)
197
198 Uses Term::ReadKey with echo off to read a passphrase, after issuing
199 the prompt $prompt. Echo is restored once the passphrase has been read.
200
201 _read_yes_or_no($prompt)
202
203 Issues the prompt $prompt, which should be a yes/no question; then
204 reads the response, and returns true if the response is yes (or rather,
205 anything starting with 'y', case insensitive).
206
207 _respond_to_rsa_challenge($ssh, $challenge, $key)
208
209 Decrypts the RSA challenge $challenge using $key, then the response
210 (MD5 of decrypted challenge and session ID) to the server, using the
211 $ssh object, in an RSA response packet.
212
213 _rsa_public_encrypt($data, $key)
214
215 Encrypts the multiple-precision integer $data (a Math::GMP object)
216 using $key.
217
218 Returns the encrypted data, also a Math::GMP object.
219
220 _rsa_private_decrypt($data, $key)
221
222 Decrypts the multiple-precision integer $data (a Math::GMP object)
223 using $key.
224
225 Returns the decrypted data, also a Math::GMP object.
226
228 Please see the Net::SSH::Perl manpage for author, copyright, and
229 license information.
230
231
232
233perl v5.8.8 2003-12-03 Net::SSH::Perl::Util(3)