Skip to content

Commit

Permalink
First stab at the ability to compile puttytel.exe, an SSH-free
Browse files Browse the repository at this point in the history
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.

[originally from svn r410]
  • Loading branch information
sgtatham committed Mar 15, 2000
1 parent 7aa84c2 commit 96dbf9c
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 61 deletions.
99 changes: 65 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,58 +37,80 @@ 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
##--

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
Expand All @@ -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
Expand All @@ -126,6 +151,12 @@ win_res.$(RES): win_res.rc win_res.h putty.ico
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
##--
Expand Down
15 changes: 15 additions & 0 deletions be_all.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Linking module for PuTTY proper: list the available backends
* including ssh.
*/

#include <windows.h>
#include <stdio.h>
#include "putty.h"

struct backend_list backends[] = {
{PROT_SSH, "ssh", &ssh_backend},
{PROT_TELNET, "telnet", &telnet_backend},
{PROT_RAW, "raw", &raw_backend},
{0, NULL}
};
13 changes: 13 additions & 0 deletions be_none.c
Original file line number Diff line number Diff line change
@@ -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 <windows.h>
#include <stdio.h>
#include "putty.h"

struct backend_list backends[] = {
{0, NULL}
};
23 changes: 23 additions & 0 deletions be_nossh.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Linking module for PuTTYtel: list the available backends not
* including ssh.
*/

#include <windows.h>
#include <stdio.h>
#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) {
}
3 changes: 3 additions & 0 deletions nossh_res.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* Stub rc file for the PuTTYtel ssh-free binary */
#define NO_SSH
#include "win_res.rc"
8 changes: 7 additions & 1 deletion putty.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 15 additions & 1 deletion scpssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
16 changes: 15 additions & 1 deletion ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 2 additions & 0 deletions win_res.rc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ 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
Expand Down
38 changes: 17 additions & 21 deletions windlg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
22 changes: 19 additions & 3 deletions window.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 96dbf9c

Please sign in to comment.