From: Tony Caduto |
|
Subject: anyone interested in helping with a SSH port forwarding prog |
NewsGroup: borland.public.delphi.internet.winsock |
Date Posted: 11-Apr-2005 at 20:0:32 PST |
I have a sort of working demo built with the latest Synapse which has
support for Cryptlib, which has built in SSH capabilites(very cool by
the way).
I have it sort of working, but only with a sleep placed after a write
operation in the while select loop.
Here is the link if anyone is interested in helping:
http://www.amsoftwaredesign.com/downloads/synapse_ssh_test.zip
there is a listener thread that listens on localhost and a clientthread
that connects to the ssh server, both are implemented in their own units
(makes it easier to follow)
I just want to get it working, I don't care what happens to the code,
feel free to download and take a look. With a little work it could make
a nice SSH forwarding component. If it does get working I would like to
give it back to the synapse project as a demo.
You will also need the cryptlib dll from here:
http://www.ararat.cz/synapse/files/crypt/cryptlib-3.1.1-beta1.zip
and the latest synasnap (synapse snapshot)
http://www.ararat.cz/synapse/files/synasnap.zip
The problem seems to occur in the relaytcp function when two sockets
become ready to read at the same time.
I have never used select before and it's taking me forever to get this
working.
Any help would be apppreciated.
Thanks,
Tony
|
From: Stig Johansen |
|
Subject: Re: Working SSH port forwarding demo |
NewsGroup: borland.public.delphi.internet.winsock |
Date Posted: 16-Apr-2005 at 6:12:17 PST |
Tony Caduto wrote:
> Just uploaded it again, this time it's the new one for sure.
Sorry Tony, but when i open the zip file, it is still the old version.
All files are dated apr. 8.
Is the URL correct?
I would like to try your demo with K3/Linux.
--
Best regards
Stig Johansen
|
From: Tony Caduto |
|
Subject: Re: Working SSH port forwarding demo |
NewsGroup: borland.public.delphi.internet.winsock |
Date Posted: 15-Apr-2005 at 8:15:42 PST |
Just uploaded it again, this time it's the new one for sure.
>
> It looks like the same version as in your original post.
> Have you updated the zip file?
>
|
From: Tony Caduto |
|
Subject: Re: Working SSH port forwarding demo |
NewsGroup: borland.public.delphi.internet.winsock |
Date Posted: 14-Apr-2005 at 0:22:10 PST |
hmmm, I thought I did. I will double check.
Tony
>
> It looks like the same version as in your original post.
> Have you updated the zip file?
>
|
From: Stig Johansen |
|
Subject: Re: Working SSH port forwarding demo |
NewsGroup: borland.public.delphi.internet.winsock |
Date Posted: 14-Apr-2005 at 5:32:37 PST |
tony wrote:
> Here is the working demo
>
> http://www.amsoftwaredesign.com/downloads/synapse_ssh_test.zip
It looks like the same version as in your original post.
Have you updated the zip file?
--
Best regards
Stig Johansen
|
From: Tony |
|
Subject: Working SSH port forwarding demo |
NewsGroup: borland.public.delphi.internet.winsock |
Date Posted: 13-Apr-2005 at 14:33:19 PST |
Here is the working demo
http://www.amsoftwaredesign.com/downloads/synapse_ssh_test.zip
Thanks Stig :-)
Threads drop off when either side disconnects and does not use a lot of CPU.
This would make a nice component if someone was inclined to do so :-)
Tony
|
From: Tony |
|
Subject: Re: anyone interested in helping with a SSH port forwarding |
NewsGroup: borland.public.delphi.internet.winsock |
Date Posted: 13-Apr-2005 at 11:58:26 PST |
Stig,
I plugged in your functions with a couple of small changes (i.e. setting a cont for cMaxBuffer)
and it works perfectly :-) It was faster than Putty.
I will do some more hacking so I can understand how it works and I will post a link to the code.
Thanks Again,
Tony
Stig Johansen wrote:
> Tony Caduto wrote:
>
>
>>Thanks Stig,
>>I will check it out, looks pretty impressive for untested :-)
>
>
> You're welcome.
> Well, i have to admit, that there is some copy/paste from one of my own
> Linux deamon's using Synapse.
>
|
From: Stig Johansen |
|
Subject: Re: anyone interested in helping with a SSH port forwarding |
NewsGroup: borland.public.delphi.internet.winsock |
Date Posted: 13-Apr-2005 at 7:14:3 PST |
Tony Caduto wrote:
> Thanks Stig,
> I will check it out, looks pretty impressive for untested :-)
You're welcome.
Well, i have to admit, that there is some copy/paste from one of my own
Linux deamon's using Synapse.
--
Best regards
Stig Johansen
|
From: Tony Caduto |
|
Subject: Re: anyone interested in helping with a SSH port forwarding |
NewsGroup: borland.public.delphi.internet.winsock |
Date Posted: 12-Apr-2005 at 23:58:48 PST |
Thanks Stig,
I will check it out, looks pretty impressive for untested :-)
I will also ensure all contributions are noted in the source.
Tony
Stig Johansen wrote:
>
> I have made a (untested,uncompiled,no warranty etc.) suggestion as follows:
>
> In your clientthread unit, implement a procedure as:
>
> PROCEDURE DoTransfer(FromSocket : TTCPBlockSocket ; ToSocket :
> TTCPBlockSocket );
> VAR
> Buff : ARRAY[0..cMaxBuffer-1] OF CHAR ;
> BuffLen : INTEGER ;
> P : Pchar ;
> Total : INTEGER ;
> Delta : INTEGER ;
> Count : INTEGER ;
>
> BEGIN
> BuffLen := SIZEOF(Buff);
> BuffLen := FromSocket.recvBuffer(@Buff, BuffLen);
> IF FromSocket.LastError = 0 THEN BEGIN
> Total := 0 ;
> Delta := 0 ;
> P := Buff ;
> Count := BuffLen;
> WHILE Total < Count DO BEGIN
> TRY
> Delta := Count - Total ;
> IF Delta > cMaxBuffer THEN
> Delta := cMaxBuffer ;
> Delta := ToSocket.SendBuffer(P,Delta);
> EXCEPT
> BREAK ;
> END ;
> INC(P,Delta);
> INC(Total,Delta);
> END ;
> END ELSE BEGIN
> BREAK;
> END;
> END;
>
> and change your RelayTCP function as:
>
> function RelayTCP(const fsock, dsock: TTCPBlockSocket;timeout:integer):
> boolean;
> var
> FDSet: TFDSet;
> FDSetSave: TFDSet;
> TimeVal: PTimeVal;
> TimeV: TTimeVal;
> begin
> result := false;
> //buffer maybe contains some pre-readed datas...
> if fsock.LineBuffer <> '' then
> begin
> buf := fsock.RecvPacket(timeout);
> if fsock.LastError <> 0 then
> Exit;
> dsock.SendString(buf);
> end;
> //begin relaying of TCP
> try
> TimeV.tv_usec := (Timeout mod 1000) * 1000;
> TimeV.tv_sec := Timeout div 1000;
> TimeVal := @TimeV;
> if Timeout = -1 then
> TimeVal := nil;
> FD_ZERO(FDSetSave);
> FD_SET(fsock.Socket, FDSetSave);
> FD_SET(dsock.Socket, FDSetSave);
> FDSet := FDSetSave;
> while synsock.Select(65535, @FDSet, nil, nil, TimeVal) > 0 do
> begin
> if FD_ISSET(dsock.Socket, FDSet) then
> DoTransfer(dsock,fsock);
> if FD_ISSET(fsock.Socket, FDSet) then
> DoTransfer(fsock,dsock);
> FDSet := FDSetSave;
> end;
> finally
> end;
> result := true;
> end;
>
>
|
From: Stig Johansen |
|
Subject: Re: anyone interested in helping with a SSH port forwarding |
NewsGroup: borland.public.delphi.internet.winsock |
Date Posted: 13-Apr-2005 at 4:21:51 PST |
Tony Caduto wrote:
> I have a sort of working demo built with the latest Synapse which has
> support for Cryptlib, which has built in SSH capabilites(very cool by
> the way).
>
> I have it sort of working, but only with a sleep placed after a write
> operation in the while select loop.
>
> Here is the link if anyone is interested in helping:
>
> http://www.amsoftwaredesign.com/downloads/synapse_ssh_test.zip
I have made a (untested,uncompiled,no warranty etc.) suggestion as follows:
In your clientthread unit, implement a procedure as:
PROCEDURE DoTransfer(FromSocket : TTCPBlockSocket ; ToSocket :
TTCPBlockSocket );
VAR
Buff : ARRAY[0..cMaxBuffer-1] OF CHAR ;
BuffLen : INTEGER ;
P : Pchar ;
Total : INTEGER ;
Delta : INTEGER ;
Count : INTEGER ;
BEGIN
BuffLen := SIZEOF(Buff);
BuffLen := FromSocket.recvBuffer(@Buff, BuffLen);
IF FromSocket.LastError = 0 THEN BEGIN
Total := 0 ;
Delta := 0 ;
P := Buff ;
Count := BuffLen;
WHILE Total < Count DO BEGIN
TRY
Delta := Count - Total ;
IF Delta > cMaxBuffer THEN
Delta := cMaxBuffer ;
Delta := ToSocket.SendBuffer(P,Delta);
EXCEPT
BREAK ;
END ;
INC(P,Delta);
INC(Total,Delta);
END ;
END ELSE BEGIN
BREAK;
END;
END;
and change your RelayTCP function as:
function RelayTCP(const fsock, dsock: TTCPBlockSocket;timeout:integer):
boolean;
var
FDSet: TFDSet;
FDSetSave: TFDSet;
TimeVal: PTimeVal;
TimeV: TTimeVal;
begin
result := false;
//buffer maybe contains some pre-readed datas...
if fsock.LineBuffer <> '' then
begin
buf := fsock.RecvPacket(timeout);
if fsock.LastError <> 0 then
Exit;
dsock.SendString(buf);
end;
//begin relaying of TCP
try
TimeV.tv_usec := (Timeout mod 1000) * 1000;
TimeV.tv_sec := Timeout div 1000;
TimeVal := @TimeV;
if Timeout = -1 then
TimeVal := nil;
FD_ZERO(FDSetSave);
FD_SET(fsock.Socket, FDSetSave);
FD_SET(dsock.Socket, FDSetSave);
FDSet := FDSetSave;
while synsock.Select(65535, @FDSet, nil, nil, TimeVal) > 0 do
begin
if FD_ISSET(dsock.Socket, FDSet) then
DoTransfer(dsock,fsock);
if FD_ISSET(fsock.Socket, FDSet) then
DoTransfer(fsock,dsock);
FDSet := FDSetSave;
end;
finally
end;
result := true;
end;
--
Best regards
Stig Johansen
|
From: Tony |
|
Subject: Re: Working SSH port forwarding demo |
NewsGroup: borland.public.delphi.internet.winsock |
Date Posted: 19-Apr-2005 at 12:2:15 PST |
Your correct, I accidentily uploaded it to the wrong directory.
The date now shows the April 19th
Sorry about that :-(
Stig Johansen wrote:
> Tony Caduto wrote:
>
>
>>Just uploaded it again, this time it's the new one for sure.
>
>
> Sorry Tony, but when i open the zip file, it is still the old version.
> All files are dated apr. 8.
> Is the URL correct?
> I would like to try your demo with K3/Linux.
>
|