public AutenticationStatus Autenticate(string tokenInternalID, string password, string dataEntropy, out string newChallenge)
		{
			newChallenge = null;
			TokenCryptoData _tkCryptoData = new TokensDAO().loadTokenCryptoData(tokenInternalID);
			AutenticationStatus result;
			if (_tkCryptoData.ID == null)
			{
				result = AutenticationStatus.TokenNotFoundOrCanceled;
			}
			else
			{
				if (_tkCryptoData.TokenBaseParams.MovingFactorType != TokenMovingFactorType.TransactionAuthenticationNumber)
				{
					throw new Exception("Function not implemented for this type of token!!");
				}
				string currentChallenge = (string)new TokensChallengeRequestDAO().loadChallengeRequest(tokenInternalID);
				if (currentChallenge == null)
				{
					result = AutenticationStatus.InvalidDataOnPasswordValidation;
				}
				else
				{
					int iRequest = int.Parse(SAFConfiguration.readParameterExternal("TANRequestPositions"));
					int iDigitsByPos = int.Parse(SAFConfiguration.readParameterExternal("TANDigitsByPosition"));
					int iFixPosOnFaill = int.Parse(SAFConfiguration.readParameterExternal("TANFixedPosOnFail"));
					string _otp = string.Empty;
					byte[] _tkSeedOpen = _tkCryptoData.GetTokenSeed("");
					byte[] _dataEntropy = (dataEntropy == null || dataEntropy.Length < 1) ? new byte[0] : BaseFunctions.convertStringToByteArray(dataEntropy);
					string[] _arrayPosValid = currentChallenge.Split(new char[]
					{
						'|'
					});
					string[] _arrayChallenge = BaseFunctions.DecodeFrom64(_tkCryptoData.CryptoData.SupportCryptoData.Trim()).Split(new char[]
					{
						';'
					});
					for (int idx = 0; idx < _arrayPosValid.Length; idx++)
					{
						string[] _temp = _arrayPosValid[idx].Trim().Split(new char[]
						{
							';'
						});
						_tkCryptoData.ResetMovingFactor(long.Parse(_arrayChallenge[(int)checked((IntPtr)long.Parse(_temp[0]))]));
						_otp += HOTPPwdGenerator.generate(_tkCryptoData, _tkSeedOpen, _dataEntropy).Substring(int.Parse(_temp[1]), 1);
					}
					if (password.Trim() == _otp)
					{
						if (OperationResult.Success == new TokensChallengeRequestDAO().resetChallengeRequest(tokenInternalID))
						{
							result = AutenticationStatus.Success;
							return result;
						}
					}
					result = AutenticationStatus.TokenOrPasswordInvalid;
				}
			}
			return result;
		}
Ejemplo n.º 2
0
        public static OperationResult loadTokenKeyInformation(string tokenID, out string tokenKey)
        {
            OperationResult result = OperationResult.Error;
            tokenKey = null;
            TokenCryptoData tokenCryptoData2 = new TokensDAO().loadTokenCryptoData(tokenID);

            string masterKey = SF.Expand.SAF.Configuration.SAFConfiguration.readMasterKey();
            byte[] tokenSeed = tokenCryptoData2.GetTokenSeed(masterKey);
            if (tokenSeed != null)
            {
                Base32Encoder enc = new Base32Encoder();
                tokenKey = enc.Encode(tokenSeed);
                result = OperationResult.Success;
            }

            return result;
        }