master
1#***************************************************************************
2# _ _ ____ _
3# Project ___| | | | _ \| |
4# / __| | | | |_) | |
5# | (__| |_| | _ <| |___
6# \___|\___/|_| \_\_____|
7#
8# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21# SPDX-License-Identifier: curl
22#
23#***************************************************************************
25package sshhelp;
27use strict;
28use warnings;
30BEGIN {
31 use base qw(Exporter);
33 our @EXPORT_OK = qw(
34 $sshdexe
35 $sshexe
36 $sftpsrvexe
37 $sftpexe
38 $sshkeygenexe
39 $sshdconfig
40 $sshconfig
41 $sftpconfig
42 $knownhosts
43 $sshdlog
44 $sshlog
45 $sftplog
46 $sftpcmds
47 $hstprvkeyf
48 $hstpubkeyf
49 $hstpubmd5f
50 $hstpubsha256f
51 $cliprvkeyf
52 $clipubkeyf
53 display_file_top
54 display_sshdconfig
55 display_sshconfig
56 display_sftpconfig
57 display_sshdlog
58 display_sshlog
59 display_sftplog
60 dump_array
61 find_sshd
62 find_ssh
63 find_sftpsrv
64 find_sftp
65 find_sshkeygen
66 find_httptlssrv
67 sshversioninfo
68 );
69}
71use File::Spec;
73use pathhelp qw(
74 exe_ext
75 );
77#***************************************************************************
78# Global variables initialization
79#
80our $sshdexe = 'sshd' .exe_ext('SSH'); # base name and ext of ssh daemon
81our $sshexe = 'ssh' .exe_ext('SSH'); # base name and ext of ssh client
82our $sftpsrvexe = 'sftp-server' .exe_ext('SSH'); # base name and ext of sftp-server
83our $sftpexe = 'sftp' .exe_ext('SSH'); # base name and ext of sftp client
84our $sshkeygenexe = 'ssh-keygen' .exe_ext('SSH'); # base name and ext of ssh-keygen
85our $httptlssrvexe = 'gnutls-serv' .exe_ext('SSH'); # base name and ext of gnutls-serv
86our $sshdconfig = 'curl_sshd_config'; # ssh daemon config file
87our $sshconfig = 'curl_ssh_config'; # ssh client config file
88our $sftpconfig = 'curl_sftp_config'; # sftp client config file
89our $sshdlog = undef; # ssh daemon log file
90our $sshlog = undef; # ssh client log file
91our $sftplog = undef; # sftp client log file
92our $sftpcmds = 'curl_sftp_cmds'; # sftp client commands batch file
93our $knownhosts = 'curl_client_knownhosts'; # ssh knownhosts file
94our $hstprvkeyf = 'curl_host_key'; # host private key file
95our $hstpubkeyf = 'curl_host_key.pub'; # host public key file
96our $hstpubmd5f = 'curl_host_key.pub_md5'; # md5 hash of host public key
97our $hstpubsha256f = 'curl_host_key.pub_sha256'; # sha256 hash of host public key
98our $cliprvkeyf = 'curl_client_key'; # client private key file
99our $clipubkeyf = 'curl_client_key.pub'; # client public key file
101#***************************************************************************
102# Absolute paths where to look for sftp-server plugin, when not in PATH
103#
104our @sftppath = qw(
105 /usr/lib/openssh
106 /usr/libexec/openssh
107 /usr/libexec
108 /usr/local/libexec
109 /opt/local/libexec
110 /usr/lib/ssh
111 /usr/libexec/ssh
112 /usr/sbin
113 /usr/lib
114 /usr/lib/ssh/openssh
115 /usr/lib64/ssh
116 /usr/lib64/misc
117 /usr/lib/misc
118 /usr/local/sbin
119 /usr/freeware/bin
120 /usr/freeware/sbin
121 /usr/freeware/libexec
122 /opt/ssh/sbin
123 /opt/ssh/libexec
124 );
126#***************************************************************************
127# Absolute paths where to look for httptlssrv (gnutls-serv), when not in PATH
128#
129our @httptlssrvpath = qw(
130 /usr/sbin
131 /usr/libexec
132 /usr/lib
133 /usr/lib/misc
134 /usr/lib64/misc
135 /usr/local/bin
136 /usr/local/sbin
137 /usr/local/libexec
138 /opt/local/bin
139 /opt/local/sbin
140 /opt/local/libexec
141 /usr/freeware/bin
142 /usr/freeware/sbin
143 /usr/freeware/libexec
144 /opt/gnutls/bin
145 /opt/gnutls/sbin
146 /opt/gnutls/libexec
147 );
149#***************************************************************************
150# Create or overwrite the given file with lines from an array of strings
151#
152sub dump_array {
153 my ($filename, @arr) = @_;
154 my $error;
156 if(!$filename) {
157 $error = 'Error: Missing argument 1 for dump_array()';
158 }
159 elsif(open(my $textfh, ">", $filename)) {
160 foreach my $line (@arr) {
161 $line .= "\n" if($line !~ /\n$/);
162 print $textfh $line;
163 }
164 if(!close($textfh)) {
165 $error = "Error: cannot close file $filename";
166 }
167 }
168 else {
169 $error = "Error: cannot write file $filename";
170 }
171 return $error;
172}
174#***************************************************************************
175# Display contents of the given file
176#
177sub display_file {
178 my $filename = $_[0];
179 print "=== Start of file $filename\n";
180 if(open(my $displayfh, "<", $filename)) {
181 while(my $line = <$displayfh>) {
182 print $line;
183 }
184 close $displayfh;
185 }
186 print "=== End of file $filename\n";
187}
189#***************************************************************************
190# Display first line of the given file
191#
192sub display_file_top {
193 my $filename = $_[0];
194 print "=== Top of file $filename\n";
195 if(open(my $displayfh, "<", $filename)) {
196 my $line = <$displayfh>;
197 print $line;
198 close $displayfh;
199 }
200 print "=== End of file $filename\n";
201}
203#***************************************************************************
204# Display contents of the ssh daemon config file
205#
206sub display_sshdconfig {
207 display_file($sshdconfig);
208}
210#***************************************************************************
211# Display contents of the ssh client config file
212#
213sub display_sshconfig {
214 display_file($sshconfig);
215}
217#***************************************************************************
218# Display contents of the sftp client config file
219#
220sub display_sftpconfig {
221 display_file($sftpconfig);
222}
224#***************************************************************************
225# Display contents of the ssh daemon log file
226#
227sub display_sshdlog {
228 die "error: \$sshdlog uninitialized" if(not defined $sshdlog);
229 display_file($sshdlog);
230}
232#***************************************************************************
233# Display contents of the ssh client log file
234#
235sub display_sshlog {
236 die "error: \$sshlog uninitialized" if(not defined $sshlog);
237 display_file($sshlog);
238}
240#***************************************************************************
241# Display contents of the sftp client log file
242#
243sub display_sftplog {
244 die "error: \$sftplog uninitialized" if(not defined $sftplog);
245 display_file($sftplog);
246}
248#***************************************************************************
249# Find a file somewhere in the given path
250#
251sub find_file {
252 my $fn = $_[0];
253 shift;
254 my @path = @_;
255 foreach (@path) {
256 my $file = File::Spec->catfile($_, $fn);
257 if(-e $file && ! -d $file) {
258 return $file;
259 }
260 }
261 return "";
262}
264#***************************************************************************
265# Find an executable file somewhere in the given path
266#
267sub find_exe_file {
268 my $fn = $_[0];
269 shift;
270 my @path = @_;
271 my $xext = exe_ext('SSH');
272 foreach (@path) {
273 my $file = File::Spec->catfile($_, $fn);
274 if(-e $file && ! -d $file) {
275 return $file if(-x $file);
276 return $file if(($xext) && (lc($file) =~ /\Q$xext\E$/));
277 }
278 }
279 return "";
280}
282#***************************************************************************
283# Find a file in environment path or in our sftppath
284#
285sub find_file_spath {
286 my $filename = $_[0];
287 my @spath;
288 push(@spath, File::Spec->path());
289 push(@spath, @sftppath);
290 return find_file($filename, @spath);
291}
293#***************************************************************************
294# Find an executable file in environment path or in our httptlssrvpath
295#
296sub find_exe_file_hpath {
297 my $filename = $_[0];
298 my @hpath;
299 push(@hpath, File::Spec->path());
300 push(@hpath, @httptlssrvpath);
301 return find_exe_file($filename, @hpath);
302}
304#***************************************************************************
305# Find ssh daemon and return canonical filename
306#
307sub find_sshd {
308 return find_file_spath($sshdexe);
309}
311#***************************************************************************
312# Find ssh client and return canonical filename
313#
314sub find_ssh {
315 return find_file_spath($sshexe);
316}
318#***************************************************************************
319# Find sftp-server plugin and return canonical filename
320#
321sub find_sftpsrv {
322 return find_file_spath($sftpsrvexe);
323}
325#***************************************************************************
326# Find sftp client and return canonical filename
327#
328sub find_sftp {
329 return find_file_spath($sftpexe);
330}
332#***************************************************************************
333# Find ssh-keygen and return canonical filename
334#
335sub find_sshkeygen {
336 return find_file_spath($sshkeygenexe);
337}
339#***************************************************************************
340# Find httptlssrv (gnutls-serv) and return canonical filename
341#
342sub find_httptlssrv {
343 my $p = find_exe_file_hpath($httptlssrvexe);
344 if($p) {
345 my @o = qx("$p" -l);
346 my $found;
347 for(@o) {
348 if(/Key exchange: SRP/) {
349 $found = 1;
350 last;
351 }
352 }
353 return $p if($found);
354 }
355 return "";
356}
358#***************************************************************************
359# Return version info for the given ssh client or server binaries
360#
361sub sshversioninfo {
362 my $sshbin = $_[0]; # canonical filename
363 my $major;
364 my $minor;
365 my $patch;
366 my $sshid;
367 my $versnum;
368 my $versstr;
369 my $error;
371 if(!$sshbin) {
372 $error = 'Error: Missing argument 1 for sshversioninfo()';
373 }
374 elsif(! -x $sshbin) {
375 $error = "Error: cannot read or execute $sshbin";
376 }
377 else {
378 my $cmd = ($sshbin =~ /$sshdexe$/) ? "\"$sshbin\" -?" : "\"$sshbin\" -V";
379 $error = "$cmd\n";
380 foreach my $tmpstr (qx($cmd 2>&1)) {
381 if($tmpstr =~ /OpenSSH[_-](\d+)\.(\d+)(\.(\d+))*/i) {
382 $major = $1;
383 $minor = $2;
384 $patch = $4 ? $4 : 0;
385 $sshid = 'OpenSSH';
386 $versnum = (100 * $major) + (10 * $minor) + $patch;
387 $versstr = "$sshid $major.$minor.$patch";
388 $error = undef;
389 last;
390 }
391 if($tmpstr =~ /OpenSSH[_-]for[_-]Windows[_-](\d+)\.(\d+)(\.(\d+))*/i) {
392 $major = $1;
393 $minor = $2;
394 $patch = $4 ? $4 : 0;
395 $sshid = 'OpenSSH-Windows';
396 $versnum = (100 * $major) + (10 * $minor) + $patch;
397 $versstr = "$sshid $major.$minor.$patch";
398 $error = undef;
399 last;
400 }
401 if($tmpstr =~ /Sun[_-]SSH[_-](\d+)\.(\d+)(\.(\d+))*/i) {
402 $major = $1;
403 $minor = $2;
404 $patch = $4 ? $4 : 0;
405 $sshid = 'SunSSH';
406 $versnum = (100 * $major) + (10 * $minor) + $patch;
407 $versstr = "$sshid $major.$minor.$patch";
408 $error = undef;
409 last;
410 }
411 $error .= $tmpstr;
412 }
413 chomp $error if($error);
414 }
415 return ($sshid, $versnum, $versstr, $error);
416}
418#***************************************************************************
419# End of library
4201;
Diagnostics4 git calls · 56 ms
CallStatusSizeTime056 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit19 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=19 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2002.9 KiB · hit34 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=34 git.response.bytes=2964 git.response.cache=HIT git.response.duration_ms=34 git.fetch.wants=84c9a8513fbaf11c0238a16e337a904b37b642c5 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=2964 git.pkt.payload.max=2943 git.sideband.band1.bytes=2942 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e22cbeccf4a594
- Request
- ffa22d8b…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format