/// <summary> /// </summary> /// <param name="context"></param> /// <returns></returns> public static string processRequest(object httpContext) { String[] _confServerVarsKeys = null; StringBuilder _inputParameters = new StringBuilder(); if ((httpContext == null) || (httpContext.GetType() != typeof(HttpContext))) { throw new Exception("Object type not supported"); } try { HttpContext context = (HttpContext)httpContext; _inputParameters.AppendFormat("ID|{0}", context.Request.QueryString.Get(SAFConfiguration.readParameterExternal(cTOKENDEPLOY_SERVICE_PUBLICNAME))); _confServerVarsKeys = SAFConfiguration.readParameterExternal(cHTTPREQUEST_SERVER_KEYS).Split('|'); for (int i = 0; i < _confServerVarsKeys.Length; i++) { _inputParameters.AppendFormat("|{0}|{1}", _confServerVarsKeys[i], context.Request.ServerVariables.Get(_confServerVarsKeys[i])); } return(processRequest(_inputParameters.ToString())); } catch { return(null); } finally { _confServerVarsKeys = null; _inputParameters = null; } }
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); }
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(); } }
/// <summary></summary> /// <returns></returns> private string _getTemplateFile() { string _fTemplateLocation = SAFConfiguration.readParameterExternal(cTEMPLATE_LOCATION); if (!File.Exists(_fTemplateLocation)) { return(null); } return(_fTemplateLocation); }
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); }
public static string ExpandSecureDeployTokens() { try { return(SAFConfiguration.readConnectionStringBusiness()); } catch (Exception ex) { LOGGER.Write(LOGGER.LogCategory.ERROR, _baseName + NEW_LINE + ex.Message, null); return(null); } }
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); }
private string _getTemplateFile() { string _fTemplateLocation = SAFConfiguration.readParameterExternal("DEPLOYJ1WINMOBILEINFOSRV"); string result; if (!File.Exists(_fTemplateLocation)) { result = null; } else { result = _fTemplateLocation; } return(result); }
public static string ExpandSAFCore() { string result; try { string cipherString = SAFConfiguration.readConnectionStringCoreEncrypted(); string text = CryptorEngineTripleDES.Decrypt(cipherString, SAFSecurityKeys.getSecurityInfoFromWConfig(), true); result = text; } catch (Exception ex) { LOGGER.Write(LOGGER.LogCategory.ERROR, "SF.Expand.SAF.Core.DBConnectionString::ExpandSAFCore[]\r\n" + ex.Message, null); result = null; } return(result); }
/// <summary> /// </summary> /// <returns></returns> private string _getTempFolder() { string _fBaseFolder = SAFConfiguration.readParameterExternal(cTEMPWORKFOLDER); if (_fBaseFolder == null || _fBaseFolder.Length < 2) { _fBaseFolder = Path.GetTempPath(); } string _fTempFolder = _fBaseFolder + (!_fBaseFolder.EndsWith(@"\") ? @"\" : "") + Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + @"\"; if (!Directory.Exists(_fTempFolder)) { Directory.CreateDirectory(_fTempFolder); return(_fTempFolder); } return(null); }
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 string ExpandSAFCore() { string result; try { result = CryptorEngineTripleDES.Decrypt(SAFConfiguration.readConnectionStringCoreEncrypted(), new SecurityInfo(SAFConfiguration.readMasterKey(), SAFConfiguration.readInfoKey(), SAFConfiguration.readInfoIV()), true); } catch (Exception ex) { SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFCORE", new string[] { "http://sfexpand.SAFCore.dbConnectionString.softfinanca.com/", Assembly.GetExecutingAssembly().FullName.ToString(), ex.ToString() }); result = null; } return(result); }
public static string ExpandSecureBusiness() { string result; try { result = SAFConfiguration.readConnectionStringBusiness(); } catch (Exception ex) { SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFBUSINESS", new string[] { "http://sfexpand.SAFBusiness.DBConnectionString.softfinanca.com/", Assembly.GetExecutingAssembly().FullName.ToString(), ex.ToString() }); result = null; } return(result); }
private string _getTempFolder() { string _fBaseFolder = SAFConfiguration.readParameterExternal("DEPLOYJ1WINMOBILEINFOSRV_TEMPFOLDER"); if (_fBaseFolder == null || _fBaseFolder.Length < 2) { _fBaseFolder = Path.GetTempPath(); } string _fTempFolder = _fBaseFolder + ((!_fBaseFolder.EndsWith("\\")) ? "\\" : "") + Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + "\\"; string result; if (!Directory.Exists(_fTempFolder)) { Directory.CreateDirectory(_fTempFolder); result = _fTempFolder; } else { result = null; } return(result); }
public static string processRequest(object httpContext) { StringBuilder _inputParameters = new StringBuilder(); if (httpContext == null || httpContext.GetType() != typeof(HttpContext)) { throw new Exception("Object type not supported"); } string result; try { HttpContext context = (HttpContext)httpContext; _inputParameters.AppendFormat("ID|{0}", context.Request.QueryString.Get(SAFConfiguration.readParameterExternal("TOKENDEPLOY_SERVICE_PUBLICNAME"))); string[] _confServerVarsKeys = SAFConfiguration.readParameterExternal("HTTPREQUEST_SERVER_KEYS").Split(new char[] { '|' }); for (int i = 0; i < _confServerVarsKeys.Length; i++) { _inputParameters.AppendFormat("|{0}|{1}", _confServerVarsKeys[i], context.Request.ServerVariables.Get(_confServerVarsKeys[i])); } result = HttpDeployProcessor.processRequest(_inputParameters.ToString()); } catch (Exception ex) { SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFBUSINESSDEPLOY", new string[] { "http://sfexpand.SAFDeploy.DEPLOYJ1JAVAINFOSRV.softfinanca.com/", Assembly.GetExecutingAssembly().FullName.ToString(), ex.ToString() }); result = null; } finally { } return(result); }
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(); } }
public static void Export(string eventHandlerTypeName, APPEVENTSDeff appeventDeff, int appEventID, string appMODName, string[] appMessages) { object retVAL = null; try { ISAFEvents safEvents = SAFEventsFactory.LoadAssembly((eventHandlerTypeName == null || eventHandlerTypeName.Length < 1) ? SAFConfiguration.readParameterExternal("SAFAPPEventHandler") : eventHandlerTypeName); if (safEvents != null) { safEvents.Export(appeventDeff, appEventID, appMODName, appMessages, out retVAL); } } finally { } }
public static void Export(APPEVENTSDeff appeventDeff, int appEventID, string appMODName, string[] appMessages) { SAFInternalEvents.Export(SAFConfiguration.readParameterExternal(appeventDeff.ToString()), appeventDeff, appEventID, appMODName, appMessages); }
public OperationResult AfterCreate(string applicationUser, string applicationUseruserPhone, string applicationEmail, string tokenVendorID, string expirationDate, string supplierSerialNumber, string creationLotID, string pin, string baseNotifyMessage, int tokenInternalID, long businessEventID, TokenStatus tokenStatus) { TokenInfo tokenInfo = new TokenInfo(); OperationResult operationResult = OperationResult.Error; TokenInfo[] array = new TokenBusinessDAO().loadTokenUserByType(applicationUser, tokenVendorID); OperationResult result; if (array == null) { result = OperationResult.PostValidationRulesFail; } else { for (int i = 0; i < array.Length; i++) { if (tokenInternalID == array[i].tokenInfoCore.InternalID) { tokenInfo = array[i]; operationResult = OperationResult.Success; } else { switch (array[i].tokenInfoCore.TypeID) { case 1: if (array[i].Status == TokenStatus.Enabled) { operationResult = SAFBaseFunctions.tokenDisable(array[i].ApplicationUser, array[i].tokenInfoCore.InternalID.ToString(), string.Empty); } break; case 2: if (array[i].Status == TokenStatus.Enabled || array[i].Status == TokenStatus.Disabled) { operationResult = SAFBaseFunctions.tokenCancel(array[i].ApplicationUser, array[i].tokenInfoCore.InternalID.ToString(), string.Empty); } break; case 3: if (array[i].Status == TokenStatus.Enabled || array[i].Status == TokenStatus.Disabled) { operationResult = SAFBaseFunctions.tokenCancel(array[i].ApplicationUser, array[i].tokenInfoCore.InternalID.ToString(), string.Empty); } break; } } } if (operationResult != OperationResult.Success) { result = operationResult; } else { string text = SAFConfiguration.readParameterExternal((tokenStatus == TokenStatus.ReadyToDeploy) ? "OP.SMS.NOTIFY.ON.CREATE.DEPLOY" : "OP.SMS.NOTIFY.ON.CREATE"); text = ((text.Trim().Length < 1) ? null : text.Trim()); string smsMessage; if (0 >= (text ?? "").IndexOf("[0]")) { smsMessage = (((baseNotifyMessage ?? "").Length > 1) ? baseNotifyMessage : text).Replace("{dt}", DateTime.Now.ToShortDateString()).Replace("{tm}", DateTime.Now.ToShortTimeString()).Replace("{dpl}", businessEventID.ToString().Trim()); } else { smsMessage = ((text != null) ? string.Format(text, baseNotifyMessage.Split(new char[] { '|' })) : string.Join("", baseNotifyMessage.Split(new char[] { '|' })).Trim()); } result = SMSSender.Send(tokenInfo.ApplicationUser, tokenInfo.tokenInfoCore.InternalID.ToString(), tokenInfo.PhoneNumberUser, smsMessage); } } return(result); }
public override void ProcessMessage(SoapMessage message) { try { if (message.Stage == SoapMessageStage.AfterDeserialize) { string _mtd = this._processSoap(message); string _userExecute = string.Format("USERID '{0}' ", "unknown"); foreach (SoapHeader header in message.Headers) { if (header is AuthHeader) { AuthHeader credentials = (AuthHeader)header; try { switch (credentials.CryptoAlgorithm) { case AuthHeader.CryptoAlgorithmEnum.NONE: _userExecute = string.Format("USERID '{0}' ", credentials.AuthKey.Split(new char[] { '|' })[0]); break; case AuthHeader.CryptoAlgorithmEnum.TRIPLEDES: _userExecute = string.Format("USERID '{0}' ", CryptorEngineTripleDES.Decrypt(SAFConfiguration.readConnectionStringCoreEncrypted(), new SecurityInfo(SAFConfiguration.readMasterKey(), SAFConfiguration.readInfoKey(), SAFConfiguration.readInfoIV()), true).Split(new char[] { '|' })[0]); break; } } catch (SoapException ex) { SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFAPILOGGER", new string[] { "http://sfexpand.SAFBusiness.AuthExtension.softfinanca.com/", ex.ToString() }); } } } SAFLOGGER.dump(SAFLOGGER.LOGGEREventID.INFORMATION, "SAFAPILOGGER", new string[] { _userExecute + _mtd }); } } catch { } }
public OperationResult AfterStartServerAuthentication(string applicationUser, string tokenID, string baseNotifyMessage, string newPassword, TokenMovingFactorType tokenMovingFactorType, TokenSeedType tokenSeedType) { string[] _arrayNotifMsg = (baseNotifyMessage ?? "").Split(new char[] { '|' }); string[] _params = new string[_arrayNotifMsg.Length - 1]; Array.Copy(_arrayNotifMsg, 1, _params, 0, _params.Length); string notifMsg = ((_arrayNotifMsg[0] ?? "").Length > 1) ? _arrayNotifMsg[0] : SAFConfiguration.readParameterExternal("SMS.TEMPLATE.ON.STARTSERVERAUTH"); notifMsg = string.Format(notifMsg.Replace("{tm}", DateTime.Now.ToShortDateString()).Replace("{dt}", DateTime.Now.ToShortTimeString()), _params); return(SMSSender.Send(applicationUser, tokenID, null, notifMsg)); }
public OperationResult AfterCreate(string applicationUser, string applicationUseruserPhone, string applicationEmail, string tokenVendorID, string expirationDate, string supplierSerialNumber, string creationLotID, string pin, string baseNotifyMessage, int tokenInternalID, long businessEventID, TokenStatus tokenStatus) { TokenInfo _lastInsertedToken = new TokenInfo(); OperationResult _hResult = OperationResult.Error; TokenInfo[] _tkInfo = new TokenBusinessDAO().loadTokenUserByType(applicationUser, tokenVendorID); OperationResult result; if (_tkInfo == null) { result = OperationResult.PostValidationRulesFail; } else { for (int i = 0; i < _tkInfo.Length; i++) { if (tokenInternalID == _tkInfo[i].tokenInfoCore.InternalID) { _lastInsertedToken = _tkInfo[i]; _hResult = OperationResult.Success; } else { switch (_tkInfo[i].tokenInfoCore.TypeID) { case 1: if (_tkInfo[i].Status == TokenStatus.Enabled) { _hResult = SAFBaseFunctions.tokenDisable(_tkInfo[i].ApplicationUser, _tkInfo[i].tokenInfoCore.InternalID.ToString(), string.Empty); } break; case 2: if (_tkInfo[i].Status == TokenStatus.Enabled || _tkInfo[i].Status == TokenStatus.Disabled || _tkInfo[i].Status == TokenStatus.ReadyToDeploy || _tkInfo[i].Status == TokenStatus.DeployCompleted) { _hResult = SAFBaseFunctions.tokenCancel(_tkInfo[i].ApplicationUser, _tkInfo[i].tokenInfoCore.InternalID.ToString(), string.Empty); } break; case 3: if (_tkInfo[i].Status == TokenStatus.Enabled || _tkInfo[i].Status == TokenStatus.Disabled) { _hResult = SAFBaseFunctions.tokenCancel(_tkInfo[i].ApplicationUser, _tkInfo[i].tokenInfoCore.InternalID.ToString(), string.Empty); } break; } } } if (_hResult != OperationResult.Success) { result = _hResult; } else { string[] _arrayNotifMsg = (baseNotifyMessage ?? "").Split(new char[] { '|' }); string[] _params = new string[_arrayNotifMsg.Length - 1]; Array.Copy(_arrayNotifMsg, 1, _params, 0, _params.Length); string notifMsg = ((_arrayNotifMsg[0] ?? "").Length > 1) ? _arrayNotifMsg[0] : SAFConfiguration.readParameterExternal((tokenStatus == TokenStatus.ReadyToDeploy) ? "SMS.TEMPLATE.ON.CREATE.DEPLOY" : "SMS.TEMPLATE.ON.CREATE"); notifMsg = string.Format(notifMsg.Replace("{tm}", DateTime.Now.ToShortDateString()).Replace("{dt}", DateTime.Now.ToShortTimeString()), _params); result = SMSSender.Send(_lastInsertedToken.ApplicationUser, _lastInsertedToken.tokenInfoCore.InternalID.ToString(), _lastInsertedToken.PhoneNumberUser, notifMsg); } } return(result); }
public OperationResult ChallengeRequest(string tokenInternalID, string dataEntropy, out string newChallenge) { TokenCryptoData _tkCryptoData = new TokensDAO().loadTokenCryptoData(tokenInternalID); OperationResult result; if (_tkCryptoData.ID == null) { newChallenge = null; result = OperationResult.Error; } else { if (_tkCryptoData.TokenBaseParams.MovingFactorType != TokenMovingFactorType.TransactionAuthenticationNumber && _tkCryptoData.TokenBaseParams.MovingFactorType != TokenMovingFactorType.EventBase && _tkCryptoData.TokenBaseParams.SeedType == TokenSeedType.ActivactionKey) { throw new Exception("Function not implemented for this type of token!!"); } string currentChallenge = (string)new TokensChallengeRequestDAO().loadChallengeRequest(tokenInternalID); if (currentChallenge != null) { newChallenge = this.formatChallenge(currentChallenge.Trim()); result = OperationResult.Success; } else { int _idx = 0; int iRequest = int.Parse(SAFConfiguration.readParameterExternal("TANRequestPositions")); int iDigitsByPos = int.Parse(SAFConfiguration.readParameterExternal("TANDigitsByPosition")); int[] _array = new int[iRequest]; string _lastRequest = string.Empty; DateTime _lastRequestValidThru = (_tkCryptoData.TokenBaseParams.ChallengeRequestValidUntil > 0) ? DateTime.Now.AddSeconds((double)_tkCryptoData.TokenBaseParams.ChallengeRequestValidUntil) : DateTime.MaxValue; while (_idx != iRequest) { bool _flag; do { _flag = false; Random rndArray = new Random(); _array[_idx] = rndArray.Next(0, _tkCryptoData.TokenBaseParams.OTPValidationWindow); for (int _idx2 = 0; _idx2 < _idx; _idx2++) { if (_array[_idx] == _array[_idx2]) { _flag = true; break; } } }while (_flag); Random rndPos = new Random(); string text = _lastRequest; _lastRequest = string.Concat(new string[] { text, _array[_idx].ToString().Trim(), ";", rndPos.Next(0, _tkCryptoData.TokenBaseParams.OTPTotalDigits).ToString().Trim(), "|" }); _idx++; } newChallenge = this.formatChallenge(_lastRequest.Substring(0, _lastRequest.Length - 1).Trim()); result = new TokensChallengeRequestDAO().persistChallengeRequest(tokenInternalID, _lastRequest.Substring(0, _lastRequest.Length - 1).Trim(), _lastRequestValidThru); } } return(result); }
public static OperationResult Send(string applicationUser, string tokenID, string phoneNumber, string smsMessage) { long tokenEventID = -1L; int smsGatewayStatus = 0; string emailAddr = null; NotifyOperationResult notifyProcessorResult = NotifyOperationResult.Error; OperationResult result; if (phoneNumber == null) { SMSSender.getTokenUserEmailAndPhone(applicationUser, tokenID, out phoneNumber, out emailAddr); if (phoneNumber == null) { result = OperationResult.Error; return(result); } } string defaultSMSProcessor = SAFConfiguration.readParameterExternal("SAFSMSAssemblyProcessor"); if (defaultSMSProcessor == null || defaultSMSProcessor.Trim().Length < 1) { SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.ERROR, "SAFBUSINESS", new string[] { "http://sfexpand.SAFBusiness.SMSSender.softfinanca.com/", Assembly.GetExecutingAssembly().FullName.ToString(), "Invalid or inexistent SMS channel processor!" }); result = OperationResult.Error; } else { INotifyChannelProcessor notifyProcessor = NotifyChannelProcessorFactory.LoadSMSAssembly(defaultSMSProcessor); if (notifyProcessor == null) { SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.ERROR, "SAFBUSINESS", new string[] { "http://sfexpand.SAFBusiness.SMSSender.softfinanca.com/", Assembly.GetExecutingAssembly().FullName.ToString(), "[CHANNEL PROCESSOR] [" + defaultSMSProcessor + "]", "Invalid or inexistent SMS channel processor!" }); result = OperationResult.Error; } else { string defaultSMSGateway = SAFConfiguration.readParameterExternal("SAFSMSDefaultGateway"); if (defaultSMSGateway == null || defaultSMSGateway.Trim().Length < 1) { SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.ERROR, "SAFBUSINESS", new string[] { "http://sfexpand.SAFBusiness.SMSSender.softfinanca.com/", Assembly.GetExecutingAssembly().FullName.ToString(), "Sms default gateway invalid!" }); result = OperationResult.Error; } else { int defaultSMSGatewayTimeout = -1; int.TryParse(SAFConfiguration.readParameterExternal("SAFSMSDefaultGatewayTimeout"), out defaultSMSGatewayTimeout); try { NotificationEvent _event = NotificationEvent.loadNotificationEvent(0L, "SAFBUSINESS", "SAFBUSINESS", phoneNumber.Trim(), smsMessage, null, NotificationChannel.loadNotificationChannel(0, "", defaultSMSProcessor, defaultSMSGatewayTimeout, "SMS", 300L, true, defaultSMSGateway)); try { new TokensBusinessEventsDAO().insertTokenEvent(tokenID, 151, (int)notifyProcessorResult, applicationUser, out tokenEventID); notifyProcessorResult = notifyProcessor.SendNotification(_event, out smsGatewayStatus); if (tokenEventID > 0L) { new TokensBusinessEventsDAO().updateEventStatus(tokenEventID.ToString(), (byte)notifyProcessorResult); } result = ((notifyProcessorResult == NotifyOperationResult.Success) ? OperationResult.Success : OperationResult.Error); } catch (Exception ex) { SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFBUSINESS", new string[] { "http://sfexpand.SAFBusiness.SMSSender.softfinanca.com/", Assembly.GetExecutingAssembly().FullName.ToString(), ex.ToString() }); result = OperationResult.Error; } } catch (Exception ex) { SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFBUSINESS", new string[] { "http://sfexpand.SAFBusiness.SMSSender.softfinanca.com/", Assembly.GetExecutingAssembly().FullName.ToString(), ex.ToString() }); result = OperationResult.Error; } finally { } } } } return(result); }