Ejemplo n.º 1
0
        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    = BaseFunctions.HexDecoder(_tkCryptoData.CryptoData.CryptoKey.Trim());
                    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 byte[] GetTokenSeed(string masterkey)
 {
     byte[] result;
     try
     {
         result = HOTPCipher.decryptData(BaseFunctions.HexDecoder(this._cryptoData.CryptoKey.Trim()), HOTPCipherInitialize.createCryptKey(BaseFunctions.HexDecoder(this._cryptoData.InternalSerialNumber.Trim()), (masterkey == null || masterkey.Length < 1) ? new byte[0] : BaseFunctions.convertStringToByteArray(masterkey)));
     }
     catch
     {
         result = null;
     }
     return(result);
 }
        public static OperationResult TokensImportNew(TokenTypeBaseParams tkTypeBaseParams, string masterKey, string vendorSerialNumber, string externalSeed, string pin, long movingFactor, out TokenCryptoData TokenCryptoData)
        {
            TokenCryptoData = new TokenCryptoData(null, null, new CryptoData(), new TokenTypeBaseParams());
            OperationResult result;

            try
            {
                if (tkTypeBaseParams.SeedType != TokenSeedType.Dynamic)
                {
                    throw new Exception("Invalid Seed type!");
                }
                if (tkTypeBaseParams.MovingFactorType != TokenMovingFactorType.EventBase || movingFactor < 1L)
                {
                    throw new Exception("Invalid MovingFactorType!");
                }
                byte[] tkserial = HOTPCipherInitialize.createSerialNumber((pin == null || pin.Length < 1) ? HOTPCipherInitialize.Generate4DigitsPin() : pin);
                byte[] tkseed   = HOTPCipher.encryptData(BaseFunctions.HexDecoder(externalSeed), HOTPCipherInitialize.createCryptKey(tkserial, (masterKey == null || masterKey.Length < 1) ? new byte[0] : BaseFunctions.convertStringToByteArray(masterKey)));
                TokenCryptoData = new TokenCryptoData(null, vendorSerialNumber, new CryptoData(movingFactor, BaseFunctions.HexEncoder(tkseed), BaseFunctions.HexEncoder(tkserial), ""), tkTypeBaseParams);
                TokenCryptoData.ResetMovingFactor(movingFactor);
                result = OperationResult.Success;
            }
            catch (Exception ex)
            {
                TokenCryptoData = new TokenCryptoData(null, null, new CryptoData(), new TokenTypeBaseParams());
                SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFCORE", new string[]
                {
                    "http://sfexpand.SAFCore.TokensBaseFunctions.softfinanca.com/",
                    Assembly.GetExecutingAssembly().FullName.ToString(),
                    ex.ToString()
                });
                result = OperationResult.Error;
            }
            finally
            {
            }
            return(result);
        }
Ejemplo n.º 4
0
        public bool Export(string pin, string deviceType, string masterKey, TokenCryptoData tokenCryptoData, out string tokenBlob)
        {
            tokenBlob = null;
            bool result;

            try
            {
                if (pin == null || pin.Length < 4 || deviceType == null || deviceType.Length != 2)
                {
                    result = false;
                }
                else
                {
                    byte[] blob        = new byte[114];
                    byte[] cryptoBlock = new byte[48];
                    byte[] _oTPOffSet  = new byte[]
                    {
                        (byte)tokenCryptoData.TokenBaseParams.OTPOffSet
                    };
                    byte[] _oTPTotalDigits = new byte[]
                    {
                        (byte)tokenCryptoData.TokenBaseParams.OTPTotalDigits
                    };
                    byte[] _movingFactorType = new byte[]
                    {
                        (byte)tokenCryptoData.TokenBaseParams.MovingFactorType
                    };
                    byte[] _hOTPMovingFactorDrift = new byte[]
                    {
                        (byte)tokenCryptoData.TokenBaseParams.HOTPMovingFactorDrift
                    };
                    byte[] _dvType = new byte[]
                    {
                        (char.Parse(deviceType.Substring(0, 1)) <= '9' && char.Parse(deviceType.Substring(0, 1)) >= '0') ? byte.Parse(deviceType.Substring(0, 1)) : ((byte)char.Parse(deviceType.Substring(0, 1))),
                        (char.Parse(deviceType.Substring(1, 1)) <= '9' && char.Parse(deviceType.Substring(1, 1)) >= '0') ? byte.Parse(deviceType.Substring(1, 1)) : ((byte)char.Parse(deviceType.Substring(1, 1)))
                    };
                    byte[] _pin          = HashBaseFunction.createBinaryHash(BaseFunctions.convertStringToByteArray(pin));
                    byte[] _movingFactor = BitConverter.GetBytes(tokenCryptoData.CryptoData.MovingFactor);
                    byte[] _serialNumber = BaseFunctions.HexDecoder(tokenCryptoData.CryptoData.InternalSerialNumber);
                    byte[] _internalKey  = tokenCryptoData.GetTokenSeed(masterKey);
                    Buffer.BlockCopy(_internalKey, 0, cryptoBlock, 0, 32);
                    Buffer.BlockCopy(_movingFactor, 0, cryptoBlock, 32, 8);
                    Buffer.BlockCopy(_oTPTotalDigits, 0, cryptoBlock, 40, 1);
                    Buffer.BlockCopy(_oTPOffSet, 0, cryptoBlock, 41, 1);
                    Buffer.BlockCopy(_movingFactorType, 0, cryptoBlock, 42, 1);
                    Buffer.BlockCopy(_hOTPMovingFactorDrift, 0, cryptoBlock, 43, 1);
                    Buffer.BlockCopy(_dvType, 0, blob, 0, 2);
                    Buffer.BlockCopy(_pin, 0, blob, 2, 32);
                    Buffer.BlockCopy(_serialNumber, 0, blob, 34, 32);
                    Buffer.BlockCopy(HOTPCipher.encrypt(cryptoBlock, HOTPCipherInitialize.createCryptKey(_serialNumber, pin)), 0, blob, 66, 48);
                    tokenBlob = BaseFunctions.HexEncoder(blob);
                    result    = true;
                }
            }
            catch (Exception ex)
            {
                SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFCORE", new string[]
                {
                    "http://sfexpand.SAFCore.BLOBStructInfSrv.softfinanca.com/",
                    Assembly.GetExecutingAssembly().FullName.ToString(),
                    ex.ToString()
                });
                tokenBlob = null;
                result    = false;
            }
            return(result);
        }
Ejemplo n.º 5
0
        public static string processRequest(string httpParamters)
        {
            string appBase64Data            = null;
            string appContentType           = null;
            string _deployProcessorTypeName = null;
            long   requestDeployEventID     = 0L;

            string[] _inParams = httpParamters.Split(new char[]
            {
                '|'
            });
            string result;

            if (_inParams.Length % 2 != 0 || _inParams.Length < 4)
            {
                result = null;
            }
            else
            {
                DataTable _dTableEvent;
                if (OperationResult.Error == new TokensBusinessEventsDAO().loadDeployEventInfo(_inParams[1], out _dTableEvent))
                {
                    result = null;
                }
                else
                {
                    if (_dTableEvent.Rows.Count != 1)
                    {
                        result = null;
                    }
                    else
                    {
                        TokenCryptoData _tokenCryptoData = new TokensDAO().loadTokenCryptoData(_dTableEvent.Rows[0][0].ToString());
                        if (_tokenCryptoData.ID == null)
                        {
                            result = null;
                        }
                        else
                        {
                            if (OperationResult.Success != HttpDeployProcessor._processTokenEvents(_dTableEvent.Rows[0][0].ToString(), _dTableEvent.Rows[0][2].ToString(), httpParamters, out requestDeployEventID))
                            {
                                result = null;
                            }
                            else
                            {
                                new DeployTokenDAO().loadDeployProcessor(_dTableEvent.Rows[0][1].ToString(), _inParams[3].Trim(), out _deployProcessorTypeName);
                                if (_deployProcessorTypeName == null)
                                {
                                    new TokensBusinessEventsDAO().updateEventStatus(requestDeployEventID.ToString(), 1);
                                    result = null;
                                }
                                else
                                {
                                    try
                                    {
                                        IDeployToken _deployProcessor = DeployTokenFactory.LoadAssembly(_deployProcessorTypeName);
                                        if (OperationResult.Success == _deployProcessor.AssembleTokenApplication(BaseFunctions.HexDecoder(_tokenCryptoData.CryptoData.SupportCryptoData), out appContentType, out appBase64Data))
                                        {
                                            if (OperationResult.Success == SAFBaseFunctions.tokenEnable(_dTableEvent.Rows[0][2].ToString(), _dTableEvent.Rows[0][0].ToString(), null))
                                            {
                                                result = appContentType + "|" + appBase64Data;
                                                return(result);
                                            }
                                        }
                                        new TokensBusinessEventsDAO().updateEventStatus(requestDeployEventID.ToString(), 1);
                                        result = null;
                                    }
                                    catch (Exception ex)
                                    {
                                        SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFBUSINESSDEPLOY", new string[]
                                        {
                                            "http://sfexpand.SAFDeploy.DEPLOYJ1JAVAINFOSRV.softfinanca.com/",
                                            Assembly.GetExecutingAssembly().FullName.ToString(),
                                            ex.ToString()
                                        });
                                        new TokensBusinessEventsDAO().updateEventStatus(requestDeployEventID.ToString(), 1);
                                        result = null;
                                    }
                                    finally
                                    {
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 6
0
 public static byte[] decryptData(byte[] data, byte[] key)
 {
     return(BaseFunctions.HexDecoder(BaseFunctions.convertByteArrayToString(HOTPCipher.decrypt(data, key))));
 }
        /// <summary>
        /// </summary>
        /// <param name="httpParamters"></param>
        /// <returns></returns>
        public static string processRequest(string httpParamters)
        {
            string appBase64Data            = null;
            string appContentType           = null;
            string _deployProcessorTypeName = null;
            long   requestDeployEventID     = 0;

            DataTable    _dTableEvent;
            IDeployToken _deployProcessor = null;

            string[] _inParams = httpParamters.Split(new char[] { '|' });
            if (_inParams.Length % 2 != 0 || _inParams.Length < 4)
            {
                return(null);
            }

            if (OperationResult.Error == new TokensBusinessEventsDAO().loadDeployEventInfo(_inParams[1], out _dTableEvent))
            {
                return(null);
            }
            if (_dTableEvent.Rows.Count != 1)
            {
                return(null);
            }
            TokenCryptoData _tokenCryptoData = new TokensDAO().loadTokenCryptoData(_dTableEvent.Rows[0][0].ToString());

            if (_tokenCryptoData.ID == null)
            {
                return(null);
            }
            if (OperationResult.Success != _processTokenEvents(_dTableEvent.Rows[0][0].ToString(), _dTableEvent.Rows[0][2].ToString(), httpParamters, out requestDeployEventID))
            {
                return(null);
            }
            new DeployTokenDAO().loadDeployProcessor(_dTableEvent.Rows[0][1].ToString(), _inParams[3].Trim(), out _deployProcessorTypeName);
            if (_deployProcessorTypeName == null)
            {
                new TokensBusinessEventsDAO().updateEventStatus(requestDeployEventID.ToString(), (byte)1);
                return(null);
            }
            try
            {
                _deployProcessor = DeployTokenFactory.LoadAssembly(_deployProcessorTypeName);
                if (OperationResult.Success == _deployProcessor.AssembleTokenApplication(BaseFunctions.HexDecoder(_tokenCryptoData.CryptoData.SupportCryptoData), out appContentType, out appBase64Data))
                {
                    if (OperationResult.Success == SAFBaseFunctions.tokenEnable(_dTableEvent.Rows[0][2].ToString(), _dTableEvent.Rows[0][0].ToString(), null))
                    {
                        return(appContentType + "|" + appBase64Data);
                    }
                }

                new TokensBusinessEventsDAO().updateEventStatus(requestDeployEventID.ToString(), (byte)1);
                return(null);
            }
            catch
            {
                new TokensBusinessEventsDAO().updateEventStatus(requestDeployEventID.ToString(), (byte)1);
                return(null);
            }
            finally
            {
                _deployProcessor = null;
            }
        }