public static AutenticationStatus Validate(TokenCryptoData tokenCryptoData, byte[] entropy, string masterKey, string validatePwd, out long movingFactor)
		{
			long _initialMovingFactor = tokenCryptoData.CryptoData.MovingFactor;
			AutenticationStatus result;
			for (int i = 0; i < tokenCryptoData.TokenBaseParams.OTPValidationWindow; i++)
			{
				try
				{
					if (validatePwd.Equals(HOTPPwdGenerator.generate(tokenCryptoData, masterKey, entropy)))
					{
						AutenticationStatus authStatus = (tokenCryptoData.CryptoData.MovingFactor > _initialMovingFactor) ? AutenticationStatus.SuccessButSynchronized : AutenticationStatus.Success;
						movingFactor = tokenCryptoData.CryptoData.MovingFactor + tokenCryptoData.TokenBaseParams.HOTPMovingFactorDrift;
						result = authStatus;
						return result;
					}
					movingFactor = tokenCryptoData.CryptoData.MovingFactor + tokenCryptoData.TokenBaseParams.HOTPMovingFactorDrift;
					tokenCryptoData.ResetMovingFactor(movingFactor);
				}
				catch (Exception ex)
				{
					SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFCORE", new string[]
					{
						"http://sfexpand.SAFCore.HOTPPwdValidator.softfinanca.com/",
						ex.ToString()
					});
				}
			}
			tokenCryptoData.ResetMovingFactor(_initialMovingFactor);
			movingFactor = _initialMovingFactor;
			result = AutenticationStatus.TokenOrPasswordInvalid;
			return result;
		}
		public static OperationResult Import(TokenCryptoData tokenCryptoData, string tokenCreationLotID, DateTime tokenExpirationDate)
		{
			OperationResult result;
			try
			{
				if (tokenCryptoData.CryptoData.MovingFactor == 0L || tokenCryptoData.CryptoData.InternalSerialNumber == null || tokenCryptoData.CryptoData.CryptoKey == null)
				{
					result = OperationResult.Error;
				}
				else
				{
					string tkID;
					result = new TokensDAO().createToken(tokenCryptoData.TokenBaseParams.TokenTypeBaseParamsID, tokenCryptoData.CryptoData.MovingFactor, tokenExpirationDate, tokenCryptoData.CryptoData.CryptoKey, tokenCryptoData.SupplierSerialNumber, tokenCryptoData.CryptoData.InternalSerialNumber, tokenCreationLotID, tokenCryptoData.CryptoData.SupportCryptoData, out tkID);
				}
			}
			catch (Exception ex)
			{
				SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFCORE", new string[]
				{
					"http://sfexpand.SAFCore.PREProcessorTokens.softfinanca.com/",
					Assembly.GetExecutingAssembly().FullName.ToString(),
					ex.ToString()
				});
				result = OperationResult.Error;
			}
			return result;
		}
		public static AutenticationStatus Validate(TokenCryptoData tokenCryptoData, byte[] entropy, string masterKey, string validatePwd, out long movingFactor)
		{
			long num = tokenCryptoData.CryptoData.MovingFactor;
			for (int i = 0; i < tokenCryptoData.TokenBaseParams.OTPValidationWindow; i++)
			{
				try
				{
					if (validatePwd.Equals(HOTPPwdGenerator.generate(tokenCryptoData, masterKey, entropy)))
					{
						AutenticationStatus autenticationStatus = (num > tokenCryptoData.CryptoData.MovingFactor) ? AutenticationStatus.SuccessButSynchronized : AutenticationStatus.Success;
						if (autenticationStatus == AutenticationStatus.Success || autenticationStatus == AutenticationStatus.SuccessButSynchronized)
						{
							num = (movingFactor = num + tokenCryptoData.TokenBaseParams.HOTPMovingFactorDrift);
							return autenticationStatus;
						}
					}
					num += tokenCryptoData.TokenBaseParams.HOTPMovingFactorDrift;
				}
				catch (Exception)
				{
					LOGGER.Write(LOGGER.LogCategory.ERROR, "SF.Expand.SAF.Core.HOTPPwdValidator::validate[]", null);
				}
			}
			movingFactor = tokenCryptoData.CryptoData.MovingFactor;
			return AutenticationStatus.TokenOrPasswordInvalid;
		}
		public static string Export(TokenCryptoData tokenData, string loteID)
		{
			StringBuilder stringBuilder = new StringBuilder(900);
			string result;
			try
			{
				if (tokenData.SupplierSerialNumber == null || tokenData.CryptoData.CryptoKey == null || tokenData.CryptoData.InternalSerialNumber == null)
				{
					result = null;
				}
				else
				{
					stringBuilder.Append(loteID);
					stringBuilder.Append(BaseImportExportTokens.cFIELD_SEPARATOR_PARSER);
					stringBuilder.Append(tokenData.TokenBaseParams.TokenTypeBaseParamsID.ToString());
					stringBuilder.Append(BaseImportExportTokens.cFIELD_SEPARATOR_PARSER);
					stringBuilder.Append(tokenData.SupplierSerialNumber);
					stringBuilder.Append(BaseImportExportTokens.cFIELD_SEPARATOR_PARSER);
					stringBuilder.Append(tokenData.CryptoData.InternalSerialNumber);
					stringBuilder.Append(BaseImportExportTokens.cFIELD_SEPARATOR_PARSER);
					stringBuilder.Append(tokenData.CryptoData.MovingFactor.ToString().Trim());
					stringBuilder.Append(BaseImportExportTokens.cFIELD_SEPARATOR_PARSER);
					stringBuilder.Append(tokenData.CryptoData.CryptoKey);
					stringBuilder.Append(BaseImportExportTokens.cFIELD_SEPARATOR_PARSER);
					stringBuilder.Append((tokenData.CryptoData.SupportCryptoData.Length < 1) ? "NULL" : tokenData.CryptoData.SupportCryptoData);
					result = stringBuilder.ToString();
				}
			}
			catch
			{
				result = null;
			}
			return result;
		}
		public static OperationResult Synchronize(TokenCryptoData tokenCryptoData, byte[] entropy, string masterKey, string firstPwd, string secondPwd, out long movingFactor)
		{
			long num = tokenCryptoData.CryptoData.MovingFactor;
			int num2 = 0;
			while ((long)num2 < tokenCryptoData.TokenBaseParams.HOTPValidationWindow4Sync)
			{
				try
				{
					if (firstPwd.Equals(HOTPPwdGenerator.generate(tokenCryptoData, masterKey, entropy)))
					{
						AutenticationStatus autenticationStatus = (num > tokenCryptoData.CryptoData.MovingFactor) ? AutenticationStatus.SuccessButSynchronized : AutenticationStatus.Success;
						if (autenticationStatus == AutenticationStatus.Success || autenticationStatus == AutenticationStatus.SuccessButSynchronized)
						{
							num += tokenCryptoData.TokenBaseParams.HOTPMovingFactorDrift;
							if (firstPwd.Equals(HOTPPwdGenerator.generate(tokenCryptoData, masterKey, entropy)) && num <= tokenCryptoData.CryptoData.MovingFactor)
							{
								num = (movingFactor = num + tokenCryptoData.TokenBaseParams.HOTPMovingFactorDrift);
								return OperationResult.Success;
							}
						}
					}
					num += tokenCryptoData.TokenBaseParams.HOTPMovingFactorDrift;
				}
				catch (Exception)
				{
					LOGGER.Write(LOGGER.LogCategory.ERROR, "SF.Expand.SAF.Core.HOTPPwdValidator::Synchronize[]", null);
				}
				num2++;
			}
			movingFactor = tokenCryptoData.CryptoData.MovingFactor;
			return OperationResult.Error;
		}
		public static string generate(TokenCryptoData tokenCryptoData, byte[] tokenSeed, byte[] entropy)
		{
			int num = (entropy != null) ? (entropy.Length + 8) : 8;
			long _movingFactor = tokenCryptoData.CryptoData.MovingFactor;
			int[] DIGITS_POWER = new int[]
			{
				1,
				10,
				100,
				1000,
				10000,
				100000,
				1000000,
				10000000,
				100000000
			};
			byte[] buffer = new byte[num];
			byte[] buffer2 = new byte[20];
			string result;
			try
			{
				for (int i = num - 1; i >= 0; i--)
				{
					if (num - i <= 8)
					{
						buffer[i] = (byte)(_movingFactor & 255L);
						_movingFactor >>= 8;
					}
					else
					{
						buffer[i] = entropy[i];
					}
				}
				buffer2 = CryptoEngineHMACSHA1.process(tokenSeed, buffer, SHA1HashFunction.HashSize);
				int index = (int)(buffer2[buffer2.Length - 1] & 15);
				if (0 <= tokenCryptoData.TokenBaseParams.OTPOffSet && tokenCryptoData.TokenBaseParams.OTPOffSet < buffer2.Length - 4)
				{
					index = tokenCryptoData.TokenBaseParams.OTPOffSet;
				}
				int num2 = (int)(buffer2[index] & 127) << 24 | (int)(buffer2[index + 1] & 255) << 16 | (int)(buffer2[index + 2] & 255) << 8 | (int)(buffer2[index + 3] & 255);
				int num3 = num2 % DIGITS_POWER[tokenCryptoData.TokenBaseParams.OTPTotalDigits];
				result = Convert.ToString(num3, 10).PadLeft(tokenCryptoData.TokenBaseParams.OTPTotalDigits, '0');
			}
			catch (Exception ex)
			{
				SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFCORE", new string[]
				{
					"http://sfexpand.SAFCore.HOTPPwdGenerator.softfinanca.com/",
					Assembly.GetExecutingAssembly().FullName.ToString(),
					ex.ToString()
				});
				result = null;
			}
			finally
			{
			}
			return result;
		}
Пример #7
0
		public bool Export(string pin, string deviceType, string masterKey, TokenCryptoData tokenCryptoData, out string tokenBlob)
		{
			SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFCORE", new string[]
			{
				"http://sfexpand.SAFCore.BLOBStrucSOFT01.softfinanca.com/",
				new NotImplementedException().ToString()
			});
			throw new NotImplementedException();
		}
Пример #8
0
		public bool Import(string tokenBlob, string blobCryptoPasswd, out TokenCryptoData tokenCryptoData)
		{
			SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFCORE", new string[]
			{
				"http://sfexpand.SAFCore.BLOBStrucSOFT01.softfinanca.com/",
				new NotImplementedException().ToString()
			});
			throw new NotImplementedException();
		}
		public static OperationResult Synchronize(TokenCryptoData tokenCryptoData, byte[] entropy, string masterKey, string firstPwd, string secondPwd, out long movingFactor)
		{
			long _movingFactor = tokenCryptoData.CryptoData.MovingFactor;
			int i = 0;
			OperationResult result;
			while ((long)i < tokenCryptoData.TokenBaseParams.HOTPValidationWindow4Sync)
			{
				try
				{
					if (firstPwd.Equals(HOTPPwdGenerator.generate(tokenCryptoData, masterKey, entropy)))
					{
						AutenticationStatus _authStatus = (_movingFactor > tokenCryptoData.CryptoData.MovingFactor) ? AutenticationStatus.SuccessButSynchronized : AutenticationStatus.Success;
						if (_authStatus == AutenticationStatus.Success || _authStatus == AutenticationStatus.SuccessButSynchronized)
						{
							_movingFactor += tokenCryptoData.TokenBaseParams.HOTPMovingFactorDrift;
							if (firstPwd.Equals(HOTPPwdGenerator.generate(tokenCryptoData, masterKey, entropy)))
							{
								_authStatus = ((_movingFactor > tokenCryptoData.CryptoData.MovingFactor) ? AutenticationStatus.SuccessButSynchronized : AutenticationStatus.Success);
								if (_authStatus == AutenticationStatus.Success)
								{
									_movingFactor = (movingFactor = _movingFactor + tokenCryptoData.TokenBaseParams.HOTPMovingFactorDrift);
									result = OperationResult.Success;
									return result;
								}
							}
						}
					}
					_movingFactor += tokenCryptoData.TokenBaseParams.HOTPMovingFactorDrift;
				}
				catch (Exception ex)
				{
					SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFCORE", new string[]
					{
						"http://sfexpand.SAFCore.HOTPPwdValidator.softfinanca.com/",
						Assembly.GetExecutingAssembly().FullName.ToString(),
						ex.ToString()
					});
				}
				i++;
			}
			movingFactor = tokenCryptoData.CryptoData.MovingFactor;
			result = OperationResult.Error;
			return result;
		}
		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;
		}
		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 Import(TokenCryptoData tokenCryptoData, string tokenCreationLotID, DateTime tokenExpirationDate)
		{
			OperationResult result;
			try
			{
				if (tokenCryptoData.CryptoData.MovingFactor == 0L || tokenCryptoData.CryptoData.InternalSerialNumber == null || tokenCryptoData.CryptoData.CryptoKey == null)
				{
					result = OperationResult.Error;
				}
				else
				{
					string text;
					result = new TokensDAO().createToken(tokenCryptoData.TokenBaseParams.TokenTypeBaseParamsID, tokenCryptoData.CryptoData.MovingFactor, tokenExpirationDate, tokenCryptoData.CryptoData.CryptoKey, tokenCryptoData.SupplierSerialNumber, tokenCryptoData.CryptoData.InternalSerialNumber, tokenCreationLotID, tokenCryptoData.CryptoData.SupportCryptoData, out text);
				}
			}
			catch
			{
				result = OperationResult.Error;
			}
			return result;
		}
Пример #13
0
		public static string generate(TokenCryptoData tokenCryptoData, byte[] tokenSeed, byte[] entropy)
		{
			int num = (entropy != null) ? (entropy.Length + 8) : 8;
			long num2 = tokenCryptoData.CryptoData.MovingFactor;
			byte[] array = new byte[num];
			byte[] array2 = new byte[20];
			int[] array3 = new int[]
			{
				1,
				10,
				100,
				1000,
				10000,
				100000,
				1000000,
				10000000,
				100000000
			};
			for (int i = num - 1; i >= 0; i--)
			{
				if (num - i <= 8)
				{
					array[i] = (byte)(num2 & 255L);
					num2 >>= 8;
				}
				else
				{
					array[i] = entropy[i];
				}
			}
			array2 = CryptoEngineHMACSHA1.process(tokenSeed, array, SHA1HashFunction.HashSize);
			int num3 = (int)(array2[array2.Length - 1] & 15);
			if (0 <= tokenCryptoData.TokenBaseParams.OTPOffSet && tokenCryptoData.TokenBaseParams.OTPOffSet < array2.Length - 4)
			{
				num3 = tokenCryptoData.TokenBaseParams.OTPOffSet;
			}
			int num4 = (int)(array2[num3] & 127) << 24 | (int)(array2[num3 + 1] & 255) << 16 | (int)(array2[num3 + 2] & 255) << 8 | (int)(array2[num3 + 3] & 255);
			int value = num4 % array3[tokenCryptoData.TokenBaseParams.OTPTotalDigits];
			return Convert.ToString(value, 10).PadLeft(tokenCryptoData.TokenBaseParams.OTPTotalDigits, '0');
		}
		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;
		}
		public static OperationResult tokenTANMatrixIntegrityCheck(TokenCryptoData tokenCryptoData, byte[] tkSeed, byte[] entropy, out string SupportCriptoData)
		{
			string _TanMatrixChallenge = string.Empty;
			OperationResult result;
			try
			{
				string[] _matriz = new string[tokenCryptoData.TokenBaseParams.OTPValidationWindow];
				for (int _idx = 0; _idx < tokenCryptoData.TokenBaseParams.OTPValidationWindow; _idx++)
				{
					bool _flag;
					do
					{
						_flag = false;
						tokenCryptoData.ResetMovingFactor(tokenCryptoData.CryptoData.MovingFactor + tokenCryptoData.TokenBaseParams.HOTPMovingFactorDrift);
						_matriz[_idx] = HOTPPwdGenerator.generate(tokenCryptoData, tkSeed, new byte[0]);
						for (int _idx2 = 0; _idx2 < _idx; _idx2++)
						{
							if (_matriz[_idx] == _matriz[_idx2])
							{
								_flag = true;
								break;
							}
						}
					}
					while (_flag);
					_TanMatrixChallenge = _TanMatrixChallenge + _matriz[_idx] + ";";
				}
				SupportCriptoData = BaseFunctions.EncodeTo64(_TanMatrixChallenge.Substring(0, _TanMatrixChallenge.Length - 1));
				result = OperationResult.Success;
			}
			catch (Exception ex)
			{
				SupportCriptoData = null;
				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;
		}
		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;
		}
		public static string Export(TokenCryptoData tokenData, string loteID)
		{
			StringBuilder strBuild = new StringBuilder(900);
			string result;
			try
			{
				if (tokenData.SupplierSerialNumber == null || tokenData.CryptoData.CryptoKey == null || tokenData.CryptoData.InternalSerialNumber == null)
				{
					result = null;
				}
				else
				{
					strBuild.Append(loteID);
					strBuild.Append(BaseImportExportTokens.cFIELD_SEPARATOR_PARSER);
					strBuild.Append(tokenData.TokenBaseParams.TokenTypeBaseParamsID.ToString());
					strBuild.Append(BaseImportExportTokens.cFIELD_SEPARATOR_PARSER);
					strBuild.Append(tokenData.SupplierSerialNumber);
					strBuild.Append(BaseImportExportTokens.cFIELD_SEPARATOR_PARSER);
					strBuild.Append(tokenData.CryptoData.InternalSerialNumber);
					strBuild.Append(BaseImportExportTokens.cFIELD_SEPARATOR_PARSER);
					strBuild.Append(tokenData.CryptoData.MovingFactor.ToString().Trim());
					strBuild.Append(BaseImportExportTokens.cFIELD_SEPARATOR_PARSER);
					strBuild.Append(tokenData.CryptoData.CryptoKey);
					strBuild.Append(BaseImportExportTokens.cFIELD_SEPARATOR_PARSER);
					strBuild.Append((tokenData.CryptoData.SupportCryptoData.Length < 1) ? "NULL" : tokenData.CryptoData.SupportCryptoData);
					result = strBuild.ToString();
				}
			}
			catch (Exception ex)
			{
				SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFCORE", new string[]
				{
					"http://sfexpand.SAFCore.PREProcessorTokens.softfinanca.com/",
					Assembly.GetExecutingAssembly().FullName.ToString(),
					ex.ToString()
				});
				result = null;
			}
			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;
		}
		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;
		}
Пример #20
0
		public TokenCryptoData loadTokenCryptoData(string tokenID)
		{
			IDataReader dataReader = null;
			IDbCommand dbCommand = null;
			TokenCryptoData result;
			try
			{
				base.ConnectionString = DBConnectionString.ExpandSAFCore();
				dbCommand = base.CreateCommand("GetTokenByID", CommandType.StoredProcedure);
				dbCommand.Parameters.Add(base.AddParameter("@tkID", tokenID));
				base.Connection.Open();
				dataReader = dbCommand.ExecuteReader(CommandBehavior.CloseConnection);
				dataReader.Read();
				result = new TokenCryptoData(dataReader[5].ToString(), dataReader[0].ToString(), new CryptoData((long)dataReader[1], dataReader[2].ToString().Trim(), dataReader[3].ToString().Trim(), (dataReader[6] != DBNull.Value) ? dataReader[6].ToString().Trim() : string.Empty), new TokenParamsDAO().loadTokenBaseParams(((byte)dataReader[4]).ToString()));
			}
			catch (Exception ex)
			{
				LOGGER.Write(LOGGER.LogCategory.ERROR, string.Concat(new string[]
				{
					"SF.Expand.SAF.Core.TokensDAO::loadTokenCryptoData[",
					tokenID,
					"]",
					Environment.NewLine,
					ex.ToString()
				}), null);
				result = new TokenCryptoData(null, null, default(CryptoData), default(TokenTypeBaseParams));
			}
			finally
			{
				if (dataReader != null)
				{
					dataReader.Dispose();
				}
				if (dbCommand != null)
				{
					dbCommand.Dispose();
				}
				base.CloseConnection();
			}
			return result;
		}
Пример #21
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;
		}
		public static OperationResult tokenTANMatrixIntegrityCheck(TokenCryptoData tokenCryptoData, byte[] tkSeed, byte[] entropy, out string SupportCriptoData)
		{
			OperationResult result;
			try
			{
				string text = string.Empty;
				string[] array = new string[tokenCryptoData.TokenBaseParams.OTPValidationWindow];
				for (int i = 0; i < tokenCryptoData.TokenBaseParams.OTPValidationWindow; i++)
				{
					bool flag;
					do
					{
						flag = false;
						tokenCryptoData.ResetMovingFactor(tokenCryptoData.CryptoData.MovingFactor + tokenCryptoData.TokenBaseParams.HOTPMovingFactorDrift);
						array[i] = HOTPPwdGenerator.generate(tokenCryptoData, tkSeed, new byte[0]);
						for (int j = 0; j < i; j++)
						{
							if (array[i] == array[j])
							{
								flag = true;
								break;
							}
						}
					}
					while (flag);
					text = text + array[i] + ";";
				}
				SupportCriptoData = BaseFunctions.EncodeTo64(text.Substring(0, text.Length - 1));
				result = OperationResult.Success;
			}
			catch
			{
				LOGGER.Write(LOGGER.LogCategory.ERROR, "SF.Expand.SAF.Core::TANMatrixIntegrityCheck[]", null);
				SupportCriptoData = null;
				result = OperationResult.Error;
			}
			return result;
		}
Пример #23
0
		public bool Import(string tokenBlob, string blobCryptoPasswd, out TokenCryptoData tokenCryptoData)
		{
			throw new NotImplementedException();
		}
		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 string[] tokenTANMatrixArrayFetch(TokenCryptoData tokenCryptoData, string masterKey, string dataEntropy)
		{
			string[] result;
			try
			{
				string[] array = BaseFunctions.DecodeFrom64(tokenCryptoData.CryptoData.SupportCryptoData).Split(new char[]
				{
					';'
				});
				if (tokenCryptoData.TokenBaseParams.OTPValidationWindow != array.Length)
				{
					result = null;
				}
				else
				{
					byte[] tokenSeed = tokenCryptoData.GetTokenSeed(masterKey);
					string[] array2 = new string[tokenCryptoData.TokenBaseParams.OTPValidationWindow];
					for (int i = 0; i < tokenCryptoData.TokenBaseParams.OTPValidationWindow; i++)
					{
						tokenCryptoData.ResetMovingFactor((long)int.Parse(array[i]));
						array2[i] = HOTPPwdGenerator.generate(tokenCryptoData, tokenSeed, (dataEntropy == null || dataEntropy.Length < 1) ? new byte[0] : BaseFunctions.convertStringToByteArray(dataEntropy));
					}
					result = array2;
				}
			}
			catch
			{
				LOGGER.Write(LOGGER.LogCategory.ERROR, "SF.Expand.SAF.Core::TANMatrixArrayFetch[]", null);
				result = null;
			}
			finally
			{
			}
			return result;
		}
Пример #26
0
		public TokenCryptoData loadTokenCryptoData(string tokenID)
		{
			IDataReader _rd = null;
			IDbCommand _cmd = null;
			TokenCryptoData result;
			try
			{
				base.ConnectionString = DBConnectionString.ExpandSAFCore();
				_cmd = base.CreateCommand("GetTokenByID", CommandType.StoredProcedure);
				_cmd.Parameters.Add(base.AddParameter("@tkID", tokenID));
				base.Connection.Open();
				_rd = _cmd.ExecuteReader(CommandBehavior.CloseConnection);
				_rd.Read();
				result = new TokenCryptoData(_rd[5].ToString(), _rd[0].ToString(), new CryptoData((long)_rd[1], _rd[2].ToString().Trim(), _rd[3].ToString().Trim(), (_rd[6] != DBNull.Value) ? _rd[6].ToString().Trim() : string.Empty), new TokenParamsDAO().loadTokenBaseParams(((byte)_rd[4]).ToString()));
			}
			catch (Exception ex)
			{
				SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFCORE", new string[]
				{
					"http://sfexpand.SAFCore.TokensDAO.softfinanca.com/",
					Assembly.GetExecutingAssembly().FullName.ToString(),
					ex.ToString()
				});
				result = new TokenCryptoData(null, null, default(CryptoData), default(TokenTypeBaseParams));
			}
			finally
			{
				if (_rd != null)
				{
					_rd.Dispose();
				}
				if (_cmd != null)
				{
					_cmd.Dispose();
				}
				base.CloseConnection();
			}
			return result;
		}
Пример #27
0
		public OperationResult updateMovingFactor(TokenCryptoData tkCryptoData)
		{
			return this._updateTable(tkCryptoData.ID, "PersistTokenMovingFactor", new object[]
			{
				tkCryptoData.CryptoData.MovingFactor
			});
		}
Пример #28
0
		public static string generate(TokenCryptoData tokenCryptoData, string masterKey, byte[] entropy)
		{
			return HOTPPwdGenerator.generate(tokenCryptoData, tokenCryptoData.GetTokenSeed(masterKey), entropy);
		}
		public static string[] tokenTANMatrixArrayFetch(TokenCryptoData tokenCryptoData, string masterKey, string dataEntropy)
		{
			string[] result;
			try
			{
				string[] _TanChallenge = BaseFunctions.DecodeFrom64(tokenCryptoData.CryptoData.SupportCryptoData).Split(new char[]
				{
					';'
				});
				if (tokenCryptoData.TokenBaseParams.OTPValidationWindow != _TanChallenge.Length)
				{
					result = null;
				}
				else
				{
					byte[] _seedOpen = tokenCryptoData.GetTokenSeed(masterKey);
					string[] _matriz = new string[tokenCryptoData.TokenBaseParams.OTPValidationWindow];
					for (int _index = 0; _index < tokenCryptoData.TokenBaseParams.OTPValidationWindow; _index++)
					{
						tokenCryptoData.ResetMovingFactor((long)int.Parse(_TanChallenge[_index]));
						_matriz[_index] = HOTPPwdGenerator.generate(tokenCryptoData, _seedOpen, (dataEntropy == null || dataEntropy.Length < 1) ? new byte[0] : BaseFunctions.convertStringToByteArray(dataEntropy));
					}
					result = _matriz;
				}
			}
			catch (Exception ex)
			{
				SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFCORE", new string[]
				{
					"http://sfexpand.SAFCore.TokensBaseFunctions.softfinanca.com/",
					Assembly.GetExecutingAssembly().FullName.ToString(),
					ex.ToString()
				});
				result = null;
			}
			finally
			{
			}
			return result;
		}