Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - procedure TfrmSecureBridgeTest.ResetProps;
 - begin
 - ScSSHClient1.HostName := '';
 - ScSSHClient1.User := '';
 - ScSSHClient1.Password := '';
 - ScSSHClient1.HostKeyName := '';
 - end;
 - procedure TfrmSecureBridgeTest.InitConnection;
 - var
 - aKey : TscKey;
 - const
 - KEY_FILE_NAME: string = '.\emsb2.ppk';
 - begin
 - ResetProps;
 - ScSSHClient1.HostName := edthostName.text;
 - ScSSHClient1.User := edtUsername.Text; // need a valid username, but no password
 - aKey := ScFileStorage1.Keys.FindKey('emsb2');
 - if not assigned(aKey) or (not aKey.Ready) then
 - begin
 - aKey := TscKey.Create;
 - aKey.KeyName := 'emsb2';
 - aKey.ImportFrom(KEY_FILE_NAME);
 - ScFileStorage1.Keys.Add(aKey);
 - end else
 - aKey.ImportFrom(KEY_FILE_NAME);
 - ScSSHClient1.PrivateKeyName := aKey.KeyName;
 - ScSSHClient1.Authentication := atPublicKey;
 - ScSSHClient1.Connect; // fails here.
 - Log('SSH Client connected');
 - ScSSHChannel1.DestHost := ScSSHClient1.HostName;
 - ScSSHChannel1.DestPort := 3306;
 - ScSSHChannel1.Connect;
 - Log('Channel port 3306 connected');
 - end;
 - procedure TfrmSecureBridgeTest.ScSSHClient1ServerKeyValidate(Sender: TObject; NewServerKey: TScKey; var Accept: Boolean);
 - var
 - CurHostKeyName: string;
 - begin
 - if ScSSHClient1.HostKeyName = EmptyStr then
 - CurHostKeyName := ScSSHClient1.HostName
 - else
 - CurHostKeyName := ScSSHClient1.HostKeyName;
 - DoServerKeyValidate(ScSSHClient1.KeyStorage as TscFileStorage, CurHostKeyName, NewServerKey, Accept);
 - end;
 - procedure TfrmSecureBridgeTest.DoServerKeyValidate(FileStorage: TscFileStorage; const HostKeyName: string; NewServerKey: TscKey; var Accept: boolean);
 - var
 - Key: TscKey;
 - fp: string; // fingerprint
 - msg: string;
 - begin
 - Key := FileStorage.Keys.FindKey(HostKeyName);
 - if (not assigned(Key)) or (not Key.Ready) or ((not assigned(key)) and not NewServerKey.Equals(Key)) then
 - begin
 - NewServerKey.GetFingerprint(haMD5, fp);
 - log('New server ident');
 - log('Fingerprint = ' + fp);
 - log('Key Length = ' + IntToStr(NewServerKey.BitCount) + ' bits');
 - log('HostKeyName = ' + HostKeyName);
 - Key := TscKey.Create(nil);
 - try
 - Key.assign(NewServerKey);
 - Key.Keyname := HostKeyName;
 - FileStorage.Keys.Add(Key);
 - Accept := TRUE;
 - except
 - key.free;
 - raise;
 - end;
 - end;
 - end;
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment