public static OperationResult Generate(string masterKey, string pin, TokenTypeBaseParams tokenTypeBaseParams, out byte[] tkseed, out byte[] tkserial, out long tkmovFactor)
        {
            OperationResult result;

            try
            {
                if (tokenTypeBaseParams.SeedType != TokenSeedType.Dynamic)
                {
                    throw new Exception("Invalid token info!");
                }
                tkserial = HOTPCipherInitialize.createSerialNumber((pin == null || pin.Length < 1) ? HOTPCipherInitialize.Generate4DigitsPin() : pin);
                byte[] data = HOTPCipherInitialize.createSeed((masterKey == null || masterKey.Length < 1) ? new byte[0] : BaseFunctions.convertStringToByteArray(masterKey));
                tkseed = HOTPCipher.encryptData(data, HOTPCipherInitialize.createCryptKey(tkserial, (masterKey == null || masterKey.Length < 1) ? new byte[0] : BaseFunctions.convertStringToByteArray(masterKey)));
                if (tokenTypeBaseParams.MovingFactorType == TokenMovingFactorType.EventBase)
                {
                    tkmovFactor = HOTPCipherInitialize.createSequenceNumber();
                }
                else
                {
                    tkmovFactor = -1L;
                }
                result = OperationResult.Success;
            }
            catch
            {
                tkseed      = null;
                tkserial    = null;
                tkmovFactor = -1L;
                result      = OperationResult.Error;
            }
            return(result);
        }
Example #2
0
        public TokenTypeBaseParams loadTokenBaseParams(string tokenParamsID)
        {
            IDataReader         dataReader = null;
            IDbCommand          dbCommand  = null;
            TokenTypeBaseParams result;

            try
            {
                base.ConnectionString = DBConnectionString.ExpandSAFCore();
                dbCommand             = base.CreateCommand("GetTokenBaseParams", CommandType.StoredProcedure);
                dbCommand.Parameters.Add(base.AddParameter("@Param1", tokenParamsID));
                base.Connection.Open();
                dataReader = dbCommand.ExecuteReader(CommandBehavior.CloseConnection);
                dataReader.Read();
                result = new TokenTypeBaseParams((int)((byte)dataReader[0]), (int)((byte)dataReader[1]), (int)dataReader[2], (long)dataReader[3], (TokenSeedType)((byte)dataReader[4]), (TokenMovingFactorType)((byte)dataReader[5]), (long)((int)dataReader[6]), tokenParamsID, (int)dataReader[7]);
            }
            catch (Exception ex)
            {
                LOGGER.Write(LOGGER.LogCategory.ERROR, "SF.Expand.SAF.Core.TokenParamsDAO::loadTokenBaseParams[]\r\n" + ex.Message, null);
                result = default(TokenTypeBaseParams);
            }
            finally
            {
                if (dataReader != null)
                {
                    dataReader.Dispose();
                }
                if (dbCommand != null)
                {
                    dbCommand.Dispose();
                }
                base.CloseConnection();
            }
            return(result);
        }
        private static void buildSeeds(object _params)
        {
            string          sVendorSerial    = null;
            long            _ntotalCreated   = 0;
            int             seed             = RandomGen.Next();
            InMemoryLogging loggerMatrixFile = null;
            long            _nRequest        = (long)((object[])_params)[1];
            string          _nSerie          = (string)((object[])_params)[2];
            string          _outInf          = "/Process:" + Thread.CurrentThread.GetHashCode().ToString() + " /thread:" + ((string)((object[])_params)[3]).Trim() + " /processing:" + _nRequest.ToString().Trim() + "/{0} ";
            ArrayList       _vSm             = (ArrayList)((object[])_params)[4];
            string          _masterKey       = SAFConfiguration.readMasterKey();

            TokenCryptoData     _TokenCryptoData;
            TokenTypeBaseParams _tkParams = (TokenTypeBaseParams)((object[])_params)[0];
            InMemoryLogging     logger    = InMemoryLogging.GetLogString(cBASE_FILE_NAME + "." + ((string)((object[])_params)[3]).PadLeft(3, '0'), false);

            logger.MaxChars = -1;


            if (_tkParams.MovingFactorType == TokenMovingFactorType.TransactionAuthenticationNumber)
            {
                loggerMatrixFile          = InMemoryLogging.GetLogString(cBASE_FILE_NAME_MATRIX + "." + ((string)((object[])_params)[3]).PadLeft(3, '0'), false);
                loggerMatrixFile.MaxChars = -1;
            }

            for (int i = 0; i < _nRequest; i++)
            {
                while (true)
                {
                    sVendorSerial = new Random(seed++).NextDouble().ToString();
                    sVendorSerial = sVendorSerial.Substring(sVendorSerial.Length - 12);

                    lock (_vSm)
                    {
                        if (!_vSm.Contains((object)sVendorSerial))
                        {
                            _vSm.Add((object)sVendorSerial);
                            break;
                        }
                    }
                }

                if (OperationResult.Success == TokensBaseFunctions.TokensCreateNew(_tkParams, _masterKey, sVendorSerial, "", out _TokenCryptoData))
                {
                    logger.Add(BaseImportExportTokens.Export(_TokenCryptoData, _nSerie));
                    if (_tkParams.MovingFactorType == TokenMovingFactorType.TransactionAuthenticationNumber)
                    {
                        loggerMatrixFile.Add(sVendorSerial + ";" + string.Join(";", TokensBaseFunctions.tokenTANMatrixArrayFetch(_TokenCryptoData, _masterKey, "")));
                    }
                    _ntotalCreated += 1;
                }
            }
            logger.Persist();
            if (loggerMatrixFile != null)
            {
                loggerMatrixFile.Persist();
            }
        }
        public static OperationResult tokenTANFetchMatrixValues(LoteType loteType, string lotID, string TokenVendorID)
        {
            DataTable           _dt           = null;
            TokenTypeBaseParams _tkBaseParams = default(TokenTypeBaseParams);
            string            _masterKey      = SAFConfiguration.readMasterKey();
            string            _exportFilePath = SAFConfiguration.readParameterExternal("ExportFilePath");
            SAFLOGGERInMEMORY logger          = SAFLOGGERInMEMORY.GetLogString(_exportFilePath + "\\" + lotID.Trim() + ".DAT", false);

            logger.Clear();
            OperationResult result;

            try
            {
                _tkBaseParams = new TokenParamsDAO().loadTokenBaseParams(TokenVendorID);
                if (_tkBaseParams.TokenTypeBaseParamsID == null || _tkBaseParams.MovingFactorType != TokenMovingFactorType.TransactionAuthenticationNumber)
                {
                    result = OperationResult.Error;
                }
                else
                {
                    if (OperationResult.Error == new TokensDAO().loadTableWithTokensLot(loteType, lotID, TokenVendorID, TokenMovingFactorType.TransactionAuthenticationNumber, out _dt))
                    {
                        result = OperationResult.Error;
                    }
                    else
                    {
                        foreach (DataRow row in _dt.Rows)
                        {
                            TokenCryptoData _tkCryptoData = new TokenCryptoData(row[5].ToString(), row[0].ToString(), new CryptoData((long)row[1], row[2].ToString().Trim(), row[3].ToString().Trim(), (row[6] != null) ? row[6].ToString().Trim() : string.Empty), _tkBaseParams);
                            logger.Add(_tkCryptoData.SupplierSerialNumber + ";" + string.Join(";", TokensBaseFunctions.tokenTANMatrixArrayFetch(_tkCryptoData, _masterKey, null)));
                        }
                        logger.Persist();
                        result = OperationResult.Success;
                    }
                }
            }
            catch (Exception ex)
            {
                SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFCORE", new string[]
                {
                    "http://sfexpand.SAFCore.TokensBaseFunctions.softfinanca.com/",
                    Assembly.GetExecutingAssembly().FullName.ToString(),
                    ex.ToString()
                });
                result = OperationResult.Error;
            }
            finally
            {
                _dt = null;
                //TokenCryptoData _tkCryptoData = default(TokenCryptoData);
                _tkBaseParams = default(TokenTypeBaseParams);
            }
            return(result);
        }
Example #5
0
        public static OperationResult TokensCreateNew(TokenTypeBaseParams tkTypeBaseParams, string masterKey, string vendorSerialNumber, string dataEntropy, out TokenCryptoData tokenCryptoData)
        {
            OperationResult result;

            try
            {
                byte[] data;
                byte[] data2;
                long   movingFactor;
                if (OperationResult.Error == HOTPCryptoData.Generate(masterKey, null, tkTypeBaseParams, out data, out data2, out movingFactor))
                {
                    tokenCryptoData = new TokenCryptoData(null, null, default(CryptoData), default(TokenTypeBaseParams));
                    result          = OperationResult.Error;
                }
                else
                {
                    TokenCryptoData tokenCryptoData2 = new TokenCryptoData(null, vendorSerialNumber, new CryptoData(movingFactor, BaseFunctions.HexEncoder(data), BaseFunctions.HexEncoder(data2), ""), tkTypeBaseParams);
                    tokenCryptoData2.ResetMovingFactor(HOTPCipherInitialize.createSequenceNumber());

                    /*--------------------------*/
                    byte[]        tokenSeed = tokenCryptoData2.GetTokenSeed(masterKey);
                    string        x         = Encoding.ASCII.GetString(tokenSeed);
                    Base32Encoder enc       = new Base32Encoder();
                    string        y         = enc.Encode(tokenSeed);


                    /*--------------------------*/


                    if (tkTypeBaseParams.MovingFactorType == TokenMovingFactorType.TransactionAuthenticationNumber)
                    {
                        string value;
                        if (OperationResult.Error == TokensBaseFunctions.tokenTANMatrixIntegrityCheck(tokenCryptoData2, tokenCryptoData2.GetTokenSeed(masterKey), (dataEntropy == null || dataEntropy.Length < 1) ? new byte[0] : BaseFunctions.convertStringToByteArray(dataEntropy), out value))
                        {
                            tokenCryptoData = new TokenCryptoData(null, null, default(CryptoData), default(TokenTypeBaseParams));
                            result          = OperationResult.Error;
                            return(result);
                        }
                        tokenCryptoData2.ResetSupportCryptoData(value);
                    }
                    tokenCryptoData = tokenCryptoData2;
                    result          = OperationResult.Success;
                }
            }
            catch
            {
                LOGGER.Write(LOGGER.LogCategory.ERROR, "SF.Expand.SAF.Core::TokensCreateNew[]", null);
                tokenCryptoData = new TokenCryptoData(null, null, default(CryptoData), default(TokenTypeBaseParams));
                result          = OperationResult.Error;
            }
            return(result);
        }
        public static OperationResult tokenTANFetchSupplierSerialNumber(LoteType loteType, string lotID, string TokenVendorID)
        {
            DataTable           _dt           = null;
            TokenTypeBaseParams _tkBaseParams = default(TokenTypeBaseParams);
            string            _exportFilePath = SAFConfiguration.readParameterExternal("ExportFilePath");
            SAFLOGGERInMEMORY logger          = SAFLOGGERInMEMORY.GetLogString(_exportFilePath + "\\" + lotID.Trim() + "SerialNumbers.TXT", false);

            logger.Clear();
            OperationResult result;

            try
            {
                _tkBaseParams = new TokenParamsDAO().loadTokenBaseParams(TokenVendorID);
                if (_tkBaseParams.TokenTypeBaseParamsID == null || _tkBaseParams.MovingFactorType != TokenMovingFactorType.TransactionAuthenticationNumber)
                {
                    result = OperationResult.Error;
                }
                else
                {
                    if (OperationResult.Error == new TokensDAO().tokenSupplierSerialNumbersByLot(loteType, lotID, out _dt))
                    {
                        result = OperationResult.Error;
                    }
                    else
                    {
                        foreach (DataRow row in _dt.Rows)
                        {
                            logger.Add(row[0].ToString().Trim());
                        }
                        logger.Persist();
                        result = OperationResult.Success;
                    }
                }
            }
            catch (Exception ex)
            {
                SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFCORE", new string[]
                {
                    "http://sfexpand.SAFCore.TokensBaseFunctions.softfinanca.com/",
                    Assembly.GetExecutingAssembly().FullName.ToString(),
                    ex.ToString()
                });
                result = OperationResult.Error;
            }
            finally
            {
                _dt           = null;
                logger        = null;
                _tkBaseParams = default(TokenTypeBaseParams);
            }
            return(result);
        }
        public static OperationResult TokensCreateNew(TokenTypeBaseParams tkTypeBaseParams, string masterKey, string vendorSerialNumber, string dataEntropy, out TokenCryptoData tokenCryptoData)
        {
            OperationResult result;

            try
            {
                byte[] tkseed;
                byte[] tkserial;
                long   tkmovFactor;
                if (OperationResult.Error == HOTPCryptoData.Generate(masterKey, null, tkTypeBaseParams, out tkseed, out tkserial, out tkmovFactor))
                {
                    tokenCryptoData = new TokenCryptoData(null, null, new CryptoData(), new TokenTypeBaseParams());
                    result          = OperationResult.Error;
                }
                else
                {
                    TokenCryptoData _tkCryptoData = new TokenCryptoData(null, vendorSerialNumber, new CryptoData(tkmovFactor, BaseFunctions.HexEncoder(tkseed), BaseFunctions.HexEncoder(tkserial), ""), tkTypeBaseParams);
                    _tkCryptoData.ResetMovingFactor(HOTPCipherInitialize.createSequenceNumber());
                    if (tkTypeBaseParams.MovingFactorType == TokenMovingFactorType.TransactionAuthenticationNumber)
                    {
                        string supportCryptoData;
                        if (OperationResult.Error == TokensBaseFunctions.tokenTANMatrixIntegrityCheck(_tkCryptoData, _tkCryptoData.GetTokenSeed(masterKey), (dataEntropy == null || dataEntropy.Length < 1) ? new byte[0] : BaseFunctions.convertStringToByteArray(dataEntropy), out supportCryptoData))
                        {
                            tokenCryptoData = new TokenCryptoData(null, null, new CryptoData(), new TokenTypeBaseParams());
                            result          = OperationResult.Error;
                            return(result);
                        }
                        _tkCryptoData.ResetSupportCryptoData(supportCryptoData);
                    }
                    tokenCryptoData = _tkCryptoData;
                    result          = OperationResult.Success;
                }
            }
            catch (Exception ex)
            {
                tokenCryptoData = new TokenCryptoData(null, null, default(CryptoData), default(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
            {
                // byte[] tkseed = null;
                // byte[] tkserial = null;
            }
            return(result);
        }
Example #8
0
        public static TokenCryptoData ParseFileInputLine(string tokenData, TokenTypeBaseParams tokenTypeBaseParams)
        {
            TokenCryptoData result;

            try
            {
                string[] _flds = tokenData.Split(new char[]
                {
                    '\a'
                });
                if (_flds.Length != 5)
                {
                    result = default(TokenCryptoData);
                }
                else
                {
                    if (_flds[1].Length < 1 || _flds[2].Length < 1 || _flds[3].Length < 1)
                    {
                        result = default(TokenCryptoData);
                    }
                    else
                    {
                        if (tokenTypeBaseParams.MovingFactorType == TokenMovingFactorType.TransactionAuthenticationNumber && (_flds[0].Length < 1 || _flds[4].Length < 1))
                        {
                            result = default(TokenCryptoData);
                        }
                        else
                        {
                            result = new TokenCryptoData(null, _flds[0], new CryptoData(long.Parse(_flds[2]), _flds[3], _flds[1], _flds[4]), tokenTypeBaseParams);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFCORE", new string[]
                {
                    "http://sfexpand.SAFCore.PREProcessorTokens.softfinanca.com/",
                    Assembly.GetExecutingAssembly().FullName.ToString(),
                    ex.ToString()
                });
                result = default(TokenCryptoData);
            }
            return(result);
        }
Example #9
0
        public static OperationResult tokenTANFetchMatrixValues(LoteType loteType, string lotID, string TokenVendorID)
        {
            DataTable           dataTable           = null;
            TokenTypeBaseParams tokenTypeBaseParams = default(TokenTypeBaseParams);
            string          str       = SAFConfiguration.readParameterExternal("ExportFilePath");
            InMemoryLogging logString = InMemoryLogging.GetLogString(str + "\\" + lotID.TrimEnd(new char[]
            {
                ' '
            }) + ".DAT", false);
            string          masterKey = SAFConfiguration.readMasterKey();
            OperationResult result;

            try
            {
                tokenTypeBaseParams = new TokenParamsDAO().loadTokenBaseParams(TokenVendorID);
                if (tokenTypeBaseParams.TokenTypeBaseParamsID == null || tokenTypeBaseParams.MovingFactorType != TokenMovingFactorType.TransactionAuthenticationNumber)
                {
                    result = OperationResult.Error;
                }
                else
                {
                    if (OperationResult.Error == new TokensDAO().loadTableWithTokensLot(loteType, lotID, TokenVendorID, TokenMovingFactorType.TransactionAuthenticationNumber, out dataTable))
                    {
                        result = OperationResult.Error;
                    }
                    else
                    {
                        foreach (DataRow dataRow in dataTable.Rows)
                        {
                            TokenCryptoData tokenCryptoData = new TokenCryptoData(dataRow[5].ToString(), dataRow[0].ToString(), new CryptoData((long)dataRow[1], dataRow[2].ToString().Trim(), dataRow[3].ToString().Trim(), (dataRow[6] != null) ? dataRow[6].ToString().Trim() : string.Empty), tokenTypeBaseParams);
                            logString.Add(tokenCryptoData.SupplierSerialNumber + ";" + string.Join(";", TokensBaseFunctions.tokenTANMatrixArrayFetch(tokenCryptoData, masterKey, null)));
                        }
                        logString.Persist();
                        result = OperationResult.Success;
                    }
                }
            }
            catch (Exception logObject)
            {
                LOGGER.Write(LOGGER.LogCategory.ERROR, "SF.Expand.SAF.Core::tokenTANFetchMatcrixValues[]", logObject);
                result = OperationResult.Error;
            }
            return(result);
        }
        public static OperationResult Generate(string masterKey, string pin, TokenTypeBaseParams tokenTypeBaseParams, out byte[] tkseed, out byte[] tkserial, out long tkmovFactor)
        {
            OperationResult result;

            try
            {
                if (tokenTypeBaseParams.SeedType != TokenSeedType.Dynamic)
                {
                    throw new Exception("Invalid token info!");
                }
                tkserial = HOTPCipherInitialize.createSerialNumber((pin == null || pin.Length < 1) ? HOTPCipherInitialize.Generate4DigitsPin() : pin);
                byte[] buffOPSeed = HOTPCipherInitialize.createSeed((masterKey == null || masterKey.Length < 1) ? new byte[0] : BaseFunctions.convertStringToByteArray(masterKey));
                tkseed = HOTPCipher.encryptData(buffOPSeed, HOTPCipherInitialize.createCryptKey(tkserial, (masterKey == null || masterKey.Length < 1) ? new byte[0] : BaseFunctions.convertStringToByteArray(masterKey)));
                if (tokenTypeBaseParams.MovingFactorType == TokenMovingFactorType.EventBase)
                {
                    tkmovFactor = HOTPCipherInitialize.createSequenceNumber();
                }
                else
                {
                    tkmovFactor = -1L;
                }
                result = OperationResult.Success;
            }
            catch (Exception ex)
            {
                tkseed      = null;
                tkserial    = null;
                tkmovFactor = -1L;
                SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFCORE", new string[]
                {
                    "http://sfexpand.SAFCore.HOTPCryptoData.softfinanca.com/",
                    Assembly.GetExecutingAssembly().FullName.ToString(),
                    ex.ToString()
                });
                result = OperationResult.Error;
            }
            finally
            {
            }
            return(result);
        }
Example #11
0
        public TokenTypeBaseParams loadTokenBaseParams(string tokenParamsID)
        {
            IDataReader         _rd  = null;
            IDbCommand          _cmd = null;
            TokenTypeBaseParams result;

            try
            {
                base.ConnectionString = DBConnectionString.ExpandSAFCore();
                _cmd = base.CreateCommand("GetTokenBaseParams", CommandType.StoredProcedure);
                _cmd.Parameters.Add(base.AddParameter("@Param1", tokenParamsID));
                base.Connection.Open();
                _rd = _cmd.ExecuteReader(CommandBehavior.CloseConnection);
                _rd.Read();
                result = new TokenTypeBaseParams((int)((byte)_rd[0]), (int)((byte)_rd[1]), (int)_rd[2], (long)_rd[3], (TokenSeedType)((byte)_rd[4]), (TokenMovingFactorType)((byte)_rd[5]), (long)((int)_rd[6]), tokenParamsID, (int)_rd[7]);
            }
            catch (Exception ex)
            {
                SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFCORE", new string[]
                {
                    "http://sfexpand.SAFCore.TokenParamsDAO.softfinanca.com/",
                    Assembly.GetExecutingAssembly().FullName.ToString(),
                    ex.ToString()
                });
                result = default(TokenTypeBaseParams);
            }
            finally
            {
                if (_rd != null)
                {
                    _rd.Dispose();
                }
                if (_cmd != null)
                {
                    _cmd.Dispose();
                }
                base.CloseConnection();
            }
            return(result);
        }
        public static TokenCryptoData ParseFileInputLine(string tokenData, TokenTypeBaseParams tokenTypeBaseParams)
        {
            TokenCryptoData result;

            try
            {
                string[] array = tokenData.Split(new char[]
                {
                    '\a'
                });
                if (array.Length != 5)
                {
                    result = default(TokenCryptoData);
                }
                else
                {
                    if (array[1].Length < 1 || array[2].Length < 1 || array[3].Length < 1)
                    {
                        result = default(TokenCryptoData);
                    }
                    else
                    {
                        if (tokenTypeBaseParams.MovingFactorType == TokenMovingFactorType.TransactionAuthenticationNumber && (array[0].Length < 1 || array[4].Length < 1))
                        {
                            result = default(TokenCryptoData);
                        }
                        else
                        {
                            result = new TokenCryptoData(null, array[0], new CryptoData(long.Parse(array[2]), array[3], array[1], array[4]), tokenTypeBaseParams);
                        }
                    }
                }
            }
            catch
            {
                result = default(TokenCryptoData);
            }
            return(result);
        }
Example #13
0
        public static OperationResult tokenTANFetchSupplierSerialNumber(LoteType loteType, string lotID, string TokenVendorID)
        {
            DataTable           dataTable           = null;
            TokenTypeBaseParams tokenTypeBaseParams = default(TokenTypeBaseParams);
            InMemoryLogging     logString           = InMemoryLogging.GetLogString(lotID.Trim() + "SerialNumbers.TXT", false);
            OperationResult     result;

            try
            {
                tokenTypeBaseParams = new TokenParamsDAO().loadTokenBaseParams(TokenVendorID);
                if (tokenTypeBaseParams.TokenTypeBaseParamsID == null || tokenTypeBaseParams.MovingFactorType != TokenMovingFactorType.TransactionAuthenticationNumber)
                {
                    result = OperationResult.Error;
                }
                else
                {
                    if (OperationResult.Error == new TokensDAO().tokenSupplierSerialNumbersByLot(loteType, lotID, out dataTable))
                    {
                        result = OperationResult.Error;
                    }
                    else
                    {
                        foreach (DataRow dataRow in dataTable.Rows)
                        {
                            logString.Add(dataRow[0].ToString().Trim());
                        }
                        logString.Persist();
                        result = OperationResult.Success;
                    }
                }
            }
            catch
            {
                LOGGER.Write(LOGGER.LogCategory.ERROR, "SF.Expand.SAF.Core::tokenTANFetchSupplierSerialNumber[]", null);
                result = OperationResult.Error;
            }
            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);
        }
Example #15
0
        private static void buildSeeds(object _params)
        {
            string          text            = null;
            long            num             = 0L;
            int             num2            = RandomGen.Next();
            InMemoryLogging inMemoryLogging = null;
            long            num3            = (long)((object[])_params)[1];
            string          loteID          = (string)((object[])_params)[2];

            string.Concat(new string[]
            {
                "/Process:",
                Thread.CurrentThread.GetHashCode().ToString(),
                " /thread:",
                ((string)((object[])_params)[3]).Trim(),
                " /processing:",
                num3.ToString().Trim(),
                "/{0} "
            });
            ArrayList           arrayList        = (ArrayList)((object[])_params)[4];
            string              masterKey        = SAFConfiguration.readMasterKey();
            TokenTypeBaseParams tkTypeBaseParams = (TokenTypeBaseParams)((object[])_params)[0];
            InMemoryLogging     logString        = InMemoryLogging.GetLogString("seedsThread." + ((string)((object[])_params)[3]).PadLeft(3, '0'), false);

            logString.MaxChars = -1;
            if (tkTypeBaseParams.MovingFactorType == TokenMovingFactorType.TransactionAuthenticationNumber)
            {
                inMemoryLogging          = InMemoryLogging.GetLogString("seedsThreadMatrix." + ((string)((object[])_params)[3]).PadLeft(3, '0'), false);
                inMemoryLogging.MaxChars = -1;
            }
            int num4 = 0;

            while ((long)num4 < num3)
            {
                while (true)
                {
                    text = new Random(num2++).NextDouble().ToString();
                    text = text.Substring(text.Length - 12);
                    ArrayList obj;
                    Monitor.Enter(obj = arrayList);
                    try
                    {
                        if (arrayList.Contains(text))
                        {
                            continue;
                        }
                        arrayList.Add(text);
                    }
                    finally
                    {
                        Monitor.Exit(obj);
                    }
                    break;
                }
                TokenCryptoData tokenCryptoData;
                if (TokensBaseFunctions.TokensCreateNew(tkTypeBaseParams, masterKey, text, "", out tokenCryptoData) == OperationResult.Success)
                {
                    logString.Add(BaseImportExportTokens.Export(tokenCryptoData, loteID));
                    if (tkTypeBaseParams.MovingFactorType == TokenMovingFactorType.TransactionAuthenticationNumber)
                    {
                        inMemoryLogging.Add(text + ";" + string.Join(";", TokensBaseFunctions.tokenTANMatrixArrayFetch(tokenCryptoData, masterKey, "")));
                    }
                    num += 1L;
                }
                num4++;
            }
            logString.Persist();
            if (inMemoryLogging != null)
            {
                inMemoryLogging.Persist();
            }
        }