コード例 #1
0
ファイル: MainWin.xaml.cs プロジェクト: lioris/KdcChat
        // requst to connect to Ftp service
        private void getSessionKeyForFtpWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            clientPrivateData clientData = ClientAllData.Instance.getMyClient();

            //send requst for Auth
            FtpKeyRequst ftpKeyRequst = new FtpKeyRequst(clientData.username);

            FtpTicketResponse ftpTicketResponse = kdcProxy.RequstSessionKeyForFtpConnection(ftpKeyRequst); // blocking

            if (ftpTicketResponse == null)
            {
                return;
            }

            byte[] sessionKey = CAes.SimpleDecrypt(ftpTicketResponse.SessionKeyClientFTPEncryptedForClient, clientData.m_kdcAsSessionKey, clientData.m_kdcAsSessionKey);

            ClientAllData.Instance.getMyClient().m_ftpSessionKey = sessionKey;

            FtpTicketRequst ftpTicketRequst = new FtpTicketRequst();

            ftpTicketRequst.UserNameencryptedForFtpWithFtpKey  = ftpTicketResponse.UserNameencryptedForFtpWithFtpKey;
            ftpTicketRequst.SessionKeyClientFTPEncryptedForFTP = ftpTicketResponse.SessionKeyClientFTPEncryptedForFTP;

            ftpTicketRequst.UserNameencryptedForFtpWithSessionKey = CAes.SimpleEncrypt(clientData.username, sessionKey, sessionKey);
            ftpProxy.requstForConnectionWithSessionKey(ftpTicketRequst); // non blocking

            //TODO: should set timer for time out
        }
コード例 #2
0
        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);
        }