From 89ee5268a99aac30dbdf36bc3a02074d34e653f2 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 15 Mar 2000 15:08:48 +0000 Subject: [PATCH] First stab at the ability to compile puttytel.exe, an SSH-free variant which is patent-safe in the US and legal in France and Russia. This is a horrible hack in some ways: it's shown up serious deficiencies in the module boundaries. Needs further work, probably once the SSH implementations are recombined. git-svn-id: svn://svn.tartarus.org/sgt/putty@410 cda61777-01e9-0310-a592-d414129be87e --- Makefile | 99 +++++++++++++++++++++++++++++++++++++++--------------------- be_all.c | 15 +++++++++ be_none.c | 13 ++++++++ be_nossh.c | 23 ++++++++++++++ nossh_res.rc | 3 ++ putty.h | 8 ++++- scpssh.c | 16 +++++++++- ssh.c | 16 +++++++++- win_res.rc | 2 ++ windlg.c | 38 +++++++++++------------ window.c | 22 ++++++++++++-- 11 files changed, 194 insertions(+), 61 deletions(-) create mode 100644 be_all.c create mode 100644 be_none.c create mode 100644 be_nossh.c create mode 100644 nossh_res.rc diff --git a/Makefile b/Makefile index c141399b..c54c5bad 100644 --- a/Makefile +++ b/Makefile @@ -37,23 +37,31 @@ CFLAGS = /nologo /W3 /YX /O2 /Yd /D_WINDOWS /DDEBUG /ML /Fd OBJ=obj RES=res +##-- objects putty puttytel +GOBJS1 = window.$(OBJ) windlg.$(OBJ) terminal.$(OBJ) telnet.$(OBJ) raw.$(OBJ) +GOBJS2 = xlat.$(OBJ) ldisc.$(OBJ) sizetip.$(OBJ) ##-- objects putty -POBJS1 = window.$(OBJ) windlg.$(OBJ) terminal.$(OBJ) telnet.$(OBJ) raw.$(OBJ) -POBJS2 = xlat.$(OBJ) ldisc.$(OBJ) sizetip.$(OBJ) ssh.$(OBJ) +POBJS = ssh.$(OBJ) be_all.$(OBJ) +##-- objects puttytel +TOBJS = be_nossh.$(OBJ) ##-- objects pscp -SOBJS = scp.$(OBJ) windlg.$(OBJ) scpssh.$(OBJ) +SOBJS = scp.$(OBJ) windlg.$(OBJ) scpssh.$(OBJ) be_none.$(OBJ) +##-- objects putty puttytel pscp +MOBJS = misc.$(OBJ) version.$(OBJ) ##-- objects putty pscp -OBJS1 = misc.$(OBJ) noise.$(OBJ) -OBJS2 = sshcrc.$(OBJ) sshdes.$(OBJ) sshmd5.$(OBJ) sshrsa.$(OBJ) sshrand.$(OBJ) -OBJS3 = sshsha.$(OBJ) sshblowf.$(OBJ) version.$(OBJ) +OBJS1 = sshcrc.$(OBJ) sshdes.$(OBJ) sshmd5.$(OBJ) sshrsa.$(OBJ) sshrand.$(OBJ) +OBJS2 = sshsha.$(OBJ) sshblowf.$(OBJ) noise.$(OBJ) ##-- resources putty PRESRC = win_res.$(RES) +##-- resources puttytel +TRESRC = nossh_res.$(RES) ##-- resources pscp SRESRC = scp.$(RES) ##-- ##-- gui-apps # putty +# puttytel ##-- console-apps # pscp ##-- @@ -61,34 +69,48 @@ SRESRC = scp.$(RES) LIBS1 = advapi32.lib user32.lib gdi32.lib LIBS2 = wsock32.lib comctl32.lib comdlg32.lib -all: putty.exe pscp.exe - -putty.exe: $(POBJS1) $(POBJS2) $(OBJS1) $(OBJS2) $(OBJS3) $(PRESRC) link.rsp - link /debug -out:putty.exe @link.rsp - -pscp.exe: $(SOBJS) $(OBJS1) $(OBJS2) $(OBJS3) $(SRESRC) scp.rsp - link /debug -out:pscp.exe @scp.rsp - -link.rsp: makefile - echo /nologo /subsystem:windows > link.rsp - echo $(POBJS1) >> link.rsp - echo $(POBJS2) >> link.rsp - echo $(OBJS1) >> link.rsp - echo $(OBJS2) >> link.rsp - echo $(OBJS3) >> link.rsp - echo $(PRESRC) >> link.rsp - echo $(LIBS1) >> link.rsp - echo $(LIBS2) >> link.rsp - -scp.rsp: makefile - echo /nologo /subsystem:console > scp.rsp - echo $(SOBJS) >> scp.rsp - echo $(OBJS1) >> scp.rsp - echo $(OBJS2) >> scp.rsp - echo $(OBJS3) >> scp.rsp - echo $(SRESRC) >> scp.rsp - echo $(LIBS1) >> scp.rsp - echo $(LIBS2) >> scp.rsp +all: putty.exe puttytel.exe pscp.exe + +putty.exe: $(GOBJS1) $(GOBJS2) $(POBJS) $(MOBJS) $(OBJS1) $(OBJS2) $(PRESRC) putty.rsp + link /debug -out:putty.exe @putty.rsp + +puttytel.exe: $(GOBJS1) $(GOBJS2) $(TOBJS) $(MOBJS) $(PRESRC) puttytel.rsp + link /debug -out:puttytel.exe @puttytel.rsp + +pscp.exe: $(SOBJS) $(OBJS1) $(OBJS2) $(OBJS3) $(SRESRC) pscp.rsp + link /debug -out:pscp.exe @pscp.rsp + +putty.rsp: makefile + echo /nologo /subsystem:windows > putty.rsp + echo $(GOBJS1) >> putty.rsp + echo $(GOBJS2) >> putty.rsp + echo $(POBJS) >> putty.rsp + echo $(MOBJS) >> putty.rsp + echo $(OBJS1) >> putty.rsp + echo $(OBJS2) >> putty.rsp + echo $(PRESRC) >> putty.rsp + echo $(LIBS1) >> putty.rsp + echo $(LIBS2) >> putty.rsp + +puttytel.rsp: makefile + echo /nologo /subsystem:windows > puttytel.rsp + echo $(GOBJS1) >> puttytel.rsp + echo $(GOBJS2) >> puttytel.rsp + echo $(TOBJS) >> puttytel.rsp + echo $(MOBJS) >> puttytel.rsp + echo $(TRESRC) >> puttytel.rsp + echo $(LIBS1) >> puttytel.rsp + echo $(LIBS2) >> puttytel.rsp + +pscp.rsp: makefile + echo /nologo /subsystem:console > pscp.rsp + echo $(SOBJS) >> pscp.rsp + echo $(MOBJS) >> pscp.rsp + echo $(OBJS1) >> pscp.rsp + echo $(OBJS2) >> pscp.rsp + echo $(SRESRC) >> pscp.rsp + echo $(LIBS1) >> pscp.rsp + echo $(LIBS2) >> pscp.rsp ##-- dependencies window.$(OBJ): window.c putty.h win_res.h @@ -112,6 +134,9 @@ sshblowf.$(OBJ): sshblowf.c ssh.h scp.$(OBJ): scp.c putty.h scp.h scpssh.$(OBJ): scpssh.c putty.h ssh.h scp.h version.$(OBJ): version.c +be_all.$(OBJ): be_all.c +be_nossh.$(OBJ): be_nossh.c +be_none.$(OBJ): be_none.c ##-- # Hack to force version.obj to be rebuilt always @@ -127,6 +152,12 @@ win_res.$(RES): rc $(FWHACK) $(RCFL) -r -DWIN32 -D_WIN32 -DWINVER=0x0400 win_res.rc ##-- dependencies +nossh_res.$(RES): nossh_res.rc win_res.h putty.ico +##-- +nossh_res.$(RES): + rc $(FWHACK) $(RCFL) -r -DWIN32 -D_WIN32 -DWINVER=0x0400 nossh_res.rc + +##-- dependencies scp.$(RES): scp.rc scp.ico ##-- scp.$(RES): diff --git a/be_all.c b/be_all.c new file mode 100644 index 00000000..69e44b76 --- /dev/null +++ b/be_all.c @@ -0,0 +1,15 @@ +/* + * Linking module for PuTTY proper: list the available backends + * including ssh. + */ + +#include +#include +#include "putty.h" + +struct backend_list backends[] = { + {PROT_SSH, "ssh", &ssh_backend}, + {PROT_TELNET, "telnet", &telnet_backend}, + {PROT_RAW, "raw", &raw_backend}, + {0, NULL} +}; diff --git a/be_none.c b/be_none.c new file mode 100644 index 00000000..0ec3a793 --- /dev/null +++ b/be_none.c @@ -0,0 +1,13 @@ +/* + * Linking module for PSCP: list no available backends. This is + * only present to satisfy linker requirements. I should really + * untangle the whole lot a bit better. + */ + +#include +#include +#include "putty.h" + +struct backend_list backends[] = { + {0, NULL} +}; diff --git a/be_nossh.c b/be_nossh.c new file mode 100644 index 00000000..2f8fa451 --- /dev/null +++ b/be_nossh.c @@ -0,0 +1,23 @@ +/* + * Linking module for PuTTYtel: list the available backends not + * including ssh. + */ + +#include +#include +#include "putty.h" + +struct backend_list backends[] = { + {PROT_TELNET, "telnet", &telnet_backend}, + {PROT_RAW, "raw", &raw_backend}, + {0, NULL} +}; + +/* + * Stub implementations of functions not used in non-ssh versions. + */ +void random_save_seed(void) { +} + +void noise_ultralight(DWORD data) { +} diff --git a/nossh_res.rc b/nossh_res.rc new file mode 100644 index 00000000..0e5a8018 --- /dev/null +++ b/nossh_res.rc @@ -0,0 +1,3 @@ +/* Stub rc file for the PuTTYtel ssh-free binary */ +#define NO_SSH +#include "win_res.rc" diff --git a/putty.h b/putty.h index 82170249..70122d05 100644 --- a/putty.h +++ b/putty.h @@ -104,6 +104,12 @@ typedef struct { GLOBAL Backend *back; +GLOBAL struct backend_list { + int protocol; + char *name; + Backend *backend; +} backends[]; + typedef struct { void (*send) (char *buf, int len); } Ldisc; @@ -215,7 +221,7 @@ void do_defaults (char *); void logevent (char *); void showeventlog (HWND); void showabout (HWND); -void verify_ssh_host_key(char *host, struct RSAKey *key); +void verify_ssh_host_key(char *host, char *keystr); void get_sesslist(int allocate); GLOBAL int nsessions; diff --git a/scpssh.c b/scpssh.c index 5db056a4..3c45c9ac 100644 --- a/scpssh.c +++ b/scpssh.c @@ -281,7 +281,21 @@ static void ssh_login(char *username, char *cmd) if (!rsabuf) fatalbox("Out of memory"); - verify_ssh_host_key(savedhost, &hostkey); + /* + * Verify the host key. + */ + { + /* + * First format the key into a string. + */ + int len = rsastr_len(&hostkey); + char *keystr = malloc(len); + if (!keystr) + fatalbox("Out of memory"); + rsastr_fmt(keystr, &hostkey); + verify_ssh_host_key(savedhost, keystr); + free(keystr); + } for (i=0; i<32; i++) { rsabuf[i] = session_key[i]; diff --git a/ssh.c b/ssh.c index caf98ce0..d31d823e 100644 --- a/ssh.c +++ b/ssh.c @@ -385,7 +385,21 @@ static void ssh_protocol(unsigned char *in, int inlen, int ispkt) { if (!rsabuf) fatalbox("Out of memory"); - verify_ssh_host_key(savedhost, &hostkey); + /* + * Verify the host key. + */ + { + /* + * First format the key into a string. + */ + int len = rsastr_len(&hostkey); + char *keystr = malloc(len); + if (!keystr) + fatalbox("Out of memory"); + rsastr_fmt(keystr, &hostkey); + verify_ssh_host_key(savedhost, keystr); + free(keystr); + } for (i=0; i<32; i++) { rsabuf[i] = session_key[i]; diff --git a/win_res.rc b/win_res.rc index fc400c2c..2c955015 100644 --- a/win_res.rc +++ b/win_res.rc @@ -75,8 +75,10 @@ BEGIN RTEXT "Protocol:", IDC0_PROTSTATIC, 3, 29, 52, 8 AUTORADIOBUTTON "&Raw", IDC0_PROTRAW, 61, 29, 33, 10, WS_GROUP AUTORADIOBUTTON "&Telnet", IDC0_PROTTELNET, 96, 29, 33, 10 +#ifndef NO_SSH AUTORADIOBUTTON "SS&H", IDC0_PROTSSH, 132, 29, 33, 10 #endif +#endif LTEXT "Stor&ed Sessions", IDC0_SESSSTATIC, 3, 40, 122, 8 EDITTEXT IDC0_SESSEDIT, 3, 48, 122, 12, ES_AUTOHSCROLL LISTBOX IDC0_SESSLIST, 3, 63, 122, 81, diff --git a/windlg.c b/windlg.c index 47a8690b..84dfa655 100644 --- a/windlg.c +++ b/windlg.c @@ -116,9 +116,13 @@ static void save_settings (char *section, int do_host) { if (do_host) { wpps (sesskey, "HostName", cfg.host); wppi (sesskey, "PortNumber", cfg.port); - wpps (sesskey, "Protocol", - cfg.protocol == PROT_SSH ? "ssh" : - cfg.protocol == PROT_TELNET ? "telnet" : "raw" ); + p = "raw"; + for (i = 0; backends[i].backend != NULL; i++) + if (backends[i].protocol == cfg.protocol) { + p = backends[i].name; + break; + } + wpps (sesskey, "Protocol", p); } wppi (sesskey, "CloseOnExit", !!cfg.close_on_exit); wppi (sesskey, "WarnOnClose", !!cfg.warn_on_close); @@ -235,15 +239,14 @@ static void load_settings (char *section, int do_host) { gpps (sesskey, "HostName", "", cfg.host, sizeof(cfg.host)); gppi (sesskey, "PortNumber", default_port, &cfg.port); + gpps (sesskey, "Protocol", "default", prot, 10); - if (!strcmp(prot, "ssh")) - cfg.protocol = PROT_SSH; - else if (!strcmp(prot, "telnet")) - cfg.protocol = PROT_TELNET; - else if (!strcmp(prot, "raw")) - cfg.protocol = PROT_RAW; - else - cfg.protocol = default_protocol; + cfg.protocol = default_protocol; + for (i = 0; backends[i].backend != NULL; i++) + if (!strcmp(prot, backends[i].name)) { + cfg.protocol = backends[i].protocol; + break; + } gppi (sesskey, "CloseOnExit", 1, &cfg.close_on_exit); gppi (sesskey, "WarnOnClose", 1, &cfg.warn_on_close); @@ -1433,19 +1436,12 @@ void showabout (HWND hwnd) { } } -void verify_ssh_host_key(char *host, struct RSAKey *key) { - char *keystr, *otherstr, *mungedhost; +void verify_ssh_host_key(char *host, char *keystr) { + char *otherstr, *mungedhost; int len; HKEY rkey; - /* - * Format the key into a string. - */ - len = rsastr_len(key); - keystr = malloc(len); - if (!keystr) - fatalbox("Out of memory"); - rsastr_fmt(keystr, key); + len = 1 + strlen(keystr); /* * Now read a saved key in from the registry and see what it diff --git a/window.c b/window.c index 3852d9eb..3e5f566d 100644 --- a/window.c +++ b/window.c @@ -186,9 +186,25 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) { } } - back = (cfg.protocol == PROT_SSH ? &ssh_backend : - cfg.protocol == PROT_TELNET ? &telnet_backend : - &raw_backend); + /* + * Select protocol. This is farmed out into a table in a + * separate file to enable an ssh-free variant. + */ + { + int i; + back = NULL; + for (i = 0; backends[i].backend != NULL; i++) + if (backends[i].protocol == cfg.protocol) { + back = backends[i].backend; + break; + } + if (back == NULL) { + MessageBox(NULL, "Unsupported protocol number found", + "PuTTY Internal Error", MB_OK | MB_ICONEXCLAMATION); + WSACleanup(); + return 1; + } + } ldisc = (cfg.ldisc_term ? &ldisc_term : &ldisc_simple); -- 2.11.0