Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public CKdcToClientLogInData LogInApp(string userName)
        {
            if (users_list.ContainsKey(userName))
            {
                Console.WriteLine("you already logged");
                return(null);
            }

            Console.WriteLine("LOGIN: NAME {0} ", userName);

            CKdcToClientLogInData msgKdcToClientLoggin = new CKdcToClientLogInData();

            User retUserFromDB = m_DBservice.getUserByName(userName);

            if (retUserFromDB != null)
            {
                byte[] userSessionKey = CAes.NewKey();
                string challenge      = Path.GetRandomFileName();
                int    port           = 1100 + retUserFromDB.ID;
                byte[] localPortByte  = BitConverter.GetBytes(port);

                msgKdcToClientLoggin.m_username        = CAes.SimpleEncryptWithPassword(userName, retUserFromDB.PassWord);
                msgKdcToClientLoggin.m_kdcAsSessionKey = CAes.SimpleEncryptWithPassword(userSessionKey, retUserFromDB.PassWord);
                msgKdcToClientLoggin.m_challenge       = CAes.SimpleEncryptWithPassword(challenge, retUserFromDB.PassWord);
                msgKdcToClientLoggin.m_localPort       = CAes.SimpleEncryptWithPassword(localPortByte, retUserFromDB.PassWord);

                UserServiceData userServiceData = new UserServiceData(userSessionKey, OperationContext.Current.GetCallbackChannel <IClientKdcCallBack>());
                userServiceData.logginChallenge = challenge + challenge;
                users_list.Add(userName, userServiceData);
            }
            else
            {
                msgKdcToClientLoggin = null;
            }

            return(msgKdcToClientLoggin);
        }