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 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 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; }
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; }
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 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[] 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; }
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; }