BinkP server updates

This commit is contained in:
mysticbbs 2013-08-25 05:06:19 -04:00
parent ce54792ee4
commit da18bf9218
1 changed files with 67 additions and 26 deletions

View File

@ -100,8 +100,8 @@ Type
SetBlockSize : Word; SetBlockSize : Word;
SetOutPath : String; SetOutPath : String;
SetTimeOut : Word; SetTimeOut : Word;
InAddress : String; HaveNode : Boolean;
EchoNode : RecEchoMailNode;
Client : TIOSocket; Client : TIOSocket;
IsClient : Boolean; IsClient : Boolean;
UseMD5 : Boolean; UseMD5 : Boolean;
@ -122,7 +122,10 @@ Type
Constructor Create (Var C: TIOSocket; Var FL: TProtocolQueue; IsCli: Boolean; TOV: Word); Constructor Create (Var C: TIOSocket; Var FL: TProtocolQueue; IsCli: Boolean; TOV: Word);
Destructor Destroy; Override; Destructor Destroy; Override;
// TO BE REWRITTEN/MOVED/REMOVED
Procedure RemoveFilesFromFLO (FN: String); Procedure RemoveFilesFromFLO (FN: String);
Function FindNodeByAddress (AddrList: String) : Boolean;
Function GetDataStr : String; Function GetDataStr : String;
Procedure SendFrame (CmdType: Byte; CmdData: String); Procedure SendFrame (CmdType: Byte; CmdData: String);
Procedure SendDataFrame (Var Buf; BufSize: Word); Procedure SendDataFrame (Var Buf; BufSize: Word);
@ -143,7 +146,7 @@ Begin
Client := C; Client := C;
FileList := FL; FileList := FL;
IsClient := IsCli; IsClient := IsCli;
UseMD5 := False; UseMD5 := True;
ForceMD5 := False; ForceMD5 := False;
RxBufSize := 0; RxBufSize := 0;
RxState := RxNone; RxState := RxNone;
@ -152,7 +155,7 @@ Begin
NeedHeader := True; NeedHeader := True;
HaveHeader := False; HaveHeader := False;
MD5Challenge := ''; MD5Challenge := '';
InAddress := ''; HaveNode := False;
AuthState := SendWelcome; AuthState := SendWelcome;
If Not IsClient and UseMD5 Then If Not IsClient and UseMD5 Then
@ -164,6 +167,31 @@ Begin
Inherited Destroy; Inherited Destroy;
End; End;
Function TBinkP.FindNodeByAddress (AddrList: String) : Boolean;
Var
F : File;
Begin
Result := False;
Assign (F, bbsConfig.DataPath + 'echonode.dat');
If Not ioReset(F, SizeOf(RecEchoMailNode), fmRWDN) Then Exit;
While Not Eof(F) Do Begin
ioRead(F, EchoNode);
// cycle through addrList and find a match.
// If EchoNode.Address = InAddress Then Begin
// Result := True;
// Break;
// End;
End;
Close (F);
End;
Procedure TBinkP.RemoveFilesFromFLO (FN: String); Procedure TBinkP.RemoveFilesFromFLO (FN: String);
Var Var
Str : String; Str : String;
@ -231,7 +259,7 @@ Begin
If RxBufSize > 255 Then If RxBufSize > 255 Then
SZ := 255 SZ := 255
Else Else
SZ := RxBufSize; SZ := RxBufSize - 1;
Move (RxBuffer[1], Result[1], SZ); Move (RxBuffer[1], Result[1], SZ);
@ -345,11 +373,14 @@ Begin
// WriteLn ('AuthState: ', Ord(AuthState), ', HasHeader: ', HaveHeader, ' Data: ', GetDataStr); // WriteLn ('AuthState: ', Ord(AuthState), ', HasHeader: ', HaveHeader, ' Data: ', GetDataStr);
//waitms(100); //waitms(100);
Case AuthState of Case AuthState of
SendChallenge : Begin // Send MD5 digest SendChallenge : Begin
// generate value into md5challenge For Count := 1 to 16 Do
MD5Challenge := ''; Str[Count] := Char(Random(255));
SendFrame (M_NUL, 'MD5-' + MD5Challenge);
// ^^ double check format MD5Challenge := Digest2String(Str);
SendFrame (M_NUL, 'OPT MD5-' + MD5Challenge);
AuthState := SendWelcome; AuthState := SendWelcome;
End; End;
SendWelcome : Begin SendWelcome : Begin
@ -374,14 +405,12 @@ Begin
If IsClient Then If IsClient Then
AuthState := SendPassword AuthState := SendPassword
Else Begin Else Begin
// if use MD5 then sendchallenge else...
// note: right now create statys with sendchallenge
HaveHeader := False; HaveHeader := False;
NeedHeader := True; NeedHeader := True;
AuthState := WaitAddress; AuthState := WaitAddress;
End; End;
End; End;
SendPassword : If HaveHeader Then Begin // wait for header to see if we support CRAMMD5 SendPassword : If HaveHeader Then Begin
If UseMD5 And (MD5Challenge <> '') Then Begin If UseMD5 And (MD5Challenge <> '') Then Begin
MD5Challenge := Digest2String(HMAC_MD5(String2Digest(MD5Challenge), SetPassword)); MD5Challenge := Digest2String(HMAC_MD5(String2Digest(MD5Challenge), SetPassword));
@ -407,26 +436,38 @@ Begin
// Client did not send ADR // Client did not send ADR
AuthState := AuthFailed; AuthState := AuthFailed;
End Else Begin End Else Begin
InAddress := GetDataStr; HaveNode := FindNodeByAddress(GetDataStr);
AuthState := WaitPassword; AuthState := WaitPassword;
NeedHeader := True;
HaveHeader := False;
End; End;
End; End;
// End Else
// NeedHeader := True;
WaitPassword : If HaveHeader Then Begin WaitPassword : If HaveHeader Then Begin
If RxCommand <> M_PWD Then AuthState := AuthFailed;
AuthState := AuthFailed
Else Begin If (RxCommand = M_PWD) And HaveNode Then Begin
Str := GetDataStr; Str := GetDataStr;
If Pos('CRAM-MD5-', Str) > 0 Then Begin If Pos('CRAM-MD5-', Str) > 0 Then Begin
// check address Delete(Str, 1, Pos('CRAM-MD5-', Str) + 8);
// generate hash and check for a match
// if match send M_OK, state pass else authfailed MD5Challenge := Digest2String(HMAC_MD5(String2Digest(MD5Challenge), EchoNode.binkPass));
If Str = MD5Challenge Then Begin
SendFrame (M_OK, '');
AuthState := AuthOK;
End;
End Else Begin End Else Begin
// if forced MD5 then error If ForceMD5 Then
// check address and password SendFrame (M_ERR, 'Required CRAM-MD5 authentication')
// if match send M_OK, state pass else authfailed Else Begin
If Str = EchoNode.binkPass Then Begin
SendFrame (M_OK, '');
AuthState := AuthOK;
End;
End;
End; End;
End; End;
End; End;