Diff

Differences From Artifact [e7ed5104c9]:

To Artifact [14c737bfe0]:


1706
1707
1708
1709
1710
1711
1712

1713
1714
1715
1716
1717
1718
1719
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720







+







{
    static int vslen;
    static char version[10];
    static char *vstring;
    static int vstrsize;
    static char *vlog;
    static int i;
    static int proto1, proto2;

    crBegin;

    /* Search for the string "SSH-" in the input. */
    i = 0;
    while (1) {
	static const int transS[] = { 1, 2, 2, 1 };
1762
1763
1764
1765
1766
1767
1768
1769
1770

1771


1772














1773
1774

1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794

1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1763
1764
1765
1766
1767
1768
1769


1770
1771
1772
1773

1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788

1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808

1809
1810
1811
1812
1813
1814
1815
1816
1817





1818
1819
1820
1821
1822
1823
1824







-
-
+

+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+



















-
+








-
-
-
-
-







    vstring[strcspn (vstring, "\r\n")] = '\0'; /* remove end-of-line chars */
    sprintf(vlog, "Server version: %s", vstring);
    logevent(vlog);
    ssh_detect_bugs(vstring);
    sfree(vlog);

    /*
     * Server version "1.99" means we can choose whether we use v1
     * or v2 protocol. Choice is based on cfg.sshprot.
     * Decide which SSH protocol version to support.
     */

    /* Anything strictly below "2.0" means protocol 1 is supported. */
    if (ssh_versioncmp(version, cfg.sshprot == 1 ? "2.0" : "1.99") >= 0) {
    proto1 = ssh_versioncmp(version, "2.0") < 0;
    /* Anything greater or equal to "1.99" means protocol 2 is supported. */
    proto2 = ssh_versioncmp(version, "1.99") > 0;

    if (cfg.sshprot == 0 && !proto1) {
	bombout(("SSH protocol version 1 required by user but not provided by server"));
	crReturn(0);
    }
    if (cfg.sshprot == 3 && !proto2) {
	bombout(("SSH protocol version 2 required by user but not provided by server"));
	crReturn(0);
    }

    if (proto2 && (cfg.sshprot == 2 || !proto1)) {
	/*
	 * This is a v2 server. Begin v2 protocol.
	 * Use v2 protocol.
	 */
	char verstring[80], vlog[100];
	sprintf(verstring, "SSH-2.0-%s", sshver);
	SHA_Init(&exhashbase);
	/*
	 * Hash our version string and their version string.
	 */
	sha_string(&exhashbase, verstring, strlen(verstring));
	sha_string(&exhashbase, vstring, strcspn(vstring, "\r\n"));
	sprintf(vlog, "We claim version: %s", verstring);
	logevent(vlog);
	strcat(verstring, "\n");
	logevent("Using SSH protocol version 2");
	sk_write(s, verstring, strlen(verstring));
	ssh_protocol = ssh2_protocol;
	ssh_version = 2;
	s_rdpkt = ssh2_rdpkt;
    } else {
	/*
	 * This is a v1 server. Begin v1 protocol.
	 * Use v1 protocol.
	 */
	char verstring[80], vlog[100];
	sprintf(verstring, "SSH-%s-%s",
		(ssh_versioncmp(version, "1.5") <= 0 ? version : "1.5"),
		sshver);
	sprintf(vlog, "We claim version: %s", verstring);
	logevent(vlog);
	strcat(verstring, "\n");
	
	if (cfg.sshprot == 3) {
	    bombout(("SSH protocol version 2 required by user but not provided by server"));
	    crReturn(0);
	}

	logevent("Using SSH protocol version 1");
	sk_write(s, verstring, strlen(verstring));
	ssh_protocol = ssh1_protocol;
	ssh_version = 1;
	s_rdpkt = ssh1_rdpkt;
    }