public FtpTicketResponse RequstSessionKeyForFtpConnection(FtpKeyRequst ftpKeyRequst) { if (!users_list.ContainsKey(ftpKeyRequst.UserName)) { return(null); } // get users from the data base KdcFtpKey retKeyFromDB = m_FtpDBservice.getKdcFtpKey("KDC"); // check validity if (retKeyFromDB == null) { Console.Write("no key exist in DB"); return(null); } // genrate new session key for CLIENT - FTP byte[] sessiomKey = CAes.NewKey(); FtpTicketResponse ftpTicketResponse = new FtpTicketResponse(); ftpTicketResponse.SessionKeyClientFTPEncryptedForFTP = CAes.SimpleEncryptWithPassword(sessiomKey, retKeyFromDB.PassWord); ftpTicketResponse.UserNameencryptedForFtpWithFtpKey = CAes.SimpleEncryptWithPassword(ftpKeyRequst.UserName, retKeyFromDB.PassWord); ftpTicketResponse.SessionKeyClientFTPEncryptedForClient = CAes.SimpleEncrypt(sessiomKey, users_list[ftpKeyRequst.UserName].SessionKey, users_list[ftpKeyRequst.UserName].SessionKey); return(ftpTicketResponse); }
public KdcFtpKey getKdcFtpKey(string name) { try { KdcFtpKey exsistUser = kdcFtpdbContext.KdcFtpKeys.Single(user => user.Name == name); Console.WriteLine("user with name " + name + " is exsists"); return(exsistUser); } catch { Console.WriteLine("user with name " + name + " not exsists"); return(null); } }
public static Dictionary <string, UserFtpServiceData> users_list = new Dictionary <string, UserFtpServiceData>(); // user, key_S public void requstForConnectionWithSessionKey(FtpTicketRequst ftpTicketRequst) { IClientFtpCallBack iClientFtpCallBack = OperationContext.Current.GetCallbackChannel <IClientFtpCallBack>(); KdcFtpKey retKeyFromDB = m_FtpDBservice.getKdcFtpKey("KDC"); if (retKeyFromDB == null) { iClientFtpCallBack.finishRequstConnectionProcess(null); return; } byte[] sessionKey = CAes.SimpleDecryptWithPassword(ftpTicketRequst.SessionKeyClientFTPEncryptedForFTP, retKeyFromDB.PassWord); string usenameDecryptedWithFtpKdcKey = CAes.SimpleDecryptWithPassword(ftpTicketRequst.UserNameencryptedForFtpWithFtpKey, retKeyFromDB.PassWord); string usenameDecryptedWithSessionKey = CAes.SimpleDecrypt(ftpTicketRequst.UserNameencryptedForFtpWithSessionKey, sessionKey, sessionKey); if (usenameDecryptedWithFtpKdcKey == usenameDecryptedWithSessionKey) // OK { UserFtpServiceData userData = new UserFtpServiceData(sessionKey, iClientFtpCallBack); users_list.Add(usenameDecryptedWithFtpKdcKey, userData); string fileNameResult; string[] filesPaths = Directory.GetFiles("..\\..\\files\\", "*.*", SearchOption.AllDirectories); List <string> newFilesNames = new List <string>(); // Display all the files. foreach (string path in filesPaths) { fileNameResult = Path.GetFileName(path); string fileNameResultString = CAes.SimpleEncrypt(fileNameResult, sessionKey, sessionKey); newFilesNames.Add(fileNameResultString); } iClientFtpCallBack.finishRequstConnectionProcess(newFilesNames); return; } iClientFtpCallBack.finishRequstConnectionProcess(null); }