public CommandHandlerBuilder WithShowExtendedPinPolicy() { _prerequisites.Enqueue(_validator.CanUseExtendedPinPolicies); _commands.Enqueue(() => { try { _logger.LogInformation(_logMessageBuilder.WithTokenId(Resources.GetExtendedPinPolicies)); PinPolicy pinPolicy = PinPolicyWorker.GetPinPolicy(_slot); byte MinPinLength = Math.Max(pinPolicy.MinPinLength.GetValueOrDefault(), Convert.ToByte(_runtimeTokenParams.MinUserPinLenFromToken)); Console.WriteLine(Resources.MinPinLengthDesc, MinPinLength); Console.WriteLine(Resources.PinHistoryDepthDesc, pinPolicy.PinHistoryDepth); Console.WriteLine(Resources.AllowDefaultPinUsageDesc, pinPolicy.AllowDefaultPinUsage); Console.WriteLine(Resources.PinContainsDigitDesc, pinPolicy.PinContainsDigit); Console.WriteLine(Resources.PinContainsUpperLetterDesc, pinPolicy.PinContainsUpperLetter); Console.WriteLine(Resources.PinContainsLowerLetterDesc, pinPolicy.PinContainsLowerLetter); Console.WriteLine(Resources.PinContainsSpecCharDesc, pinPolicy.PinContainsSpecChar); Console.WriteLine(Resources.RestrictOneCharPinDesc, pinPolicy.RestrictOneCharPin); Console.WriteLine(Resources.AllowChangePinPolicyDesc, pinPolicy.AllowChangePinPolicy); Console.WriteLine(Resources.RemovePinPolicyAfterFormatDesc, pinPolicy.RemovePinPolicyAfterFormat); } catch { _logger.LogError(_logMessageBuilder.WithTokenId(Resources.GetExtendedPinPoliciesFailed)); throw; } }); return(this); }
public CommandHandlerBuilder WithSetExtendedPinPolicy() { _prerequisites.Enqueue(_validator.CanUseExtendedPinPolicies); _prerequisites.Enqueue(_validator.ExtendedPinPolicySatisfyTokenPinPolicy); _commands.Enqueue(() => { try { _logger.LogInformation(_logMessageBuilder.WithTokenId(Resources.SetExtendedPinPolicies)); PinPolicyWorker.SetPinPolicy(_slot, _runtimeTokenParams.OldAdminPin.Value, _commandLineOptions.PinPolicy); } catch { _logger.LogError(_logMessageBuilder.WithTokenId(Resources.SetExtendedPinPoliciesFailed)); } }); return(this); }
public CommandHandlerBuilder ConfigureWith(IRutokenSlot slot, CommandLineOptions options) { _slot = slot; _commandLineOptions = options; // Todo: Resolve через DI _validator = new CommandLineOptionsValidator( _commandLineOptions, _runtimeTokenParams, _volumeOwnersStore); if (!string.IsNullOrWhiteSpace(_commandLineOptions.TokenLabelCp1251)) { _runtimeTokenParams.TokenLabel = _commandLineOptions.TokenLabelCp1251; } if (!string.IsNullOrWhiteSpace(_commandLineOptions.TokenLabelUtf8)) { _runtimeTokenParams.TokenLabel = _commandLineOptions.TokenLabelUtf8; } var tokenInfo = slot.GetTokenInfo(); _runtimeTokenParams.TokenSerial = tokenInfo.SerialNumber; _runtimeTokenParams.TokenSerialDecimal = Convert.ToInt64(_runtimeTokenParams.TokenSerial, 16).ToString(); var tokenExtendedInfo = slot.GetTokenInfoExtended(); _runtimeTokenParams.TokenType = tokenExtendedInfo.TokenType; // TODO: всегда ли тут разделитель точка? _runtimeTokenParams.HardwareMajorVersion = !string.IsNullOrWhiteSpace(tokenInfo.HardwareVersion) ? uint.Parse(tokenInfo.HardwareVersion.Substring(0, tokenInfo.HardwareVersion.IndexOf(".", StringComparison.OrdinalIgnoreCase))) : default; _runtimeTokenParams.OldUserPin = !string.IsNullOrWhiteSpace(_commandLineOptions.OldUserPin) ? new PinCode(PinCodeOwner.User, _commandLineOptions.OldUserPin) : new PinCode(PinCodeOwner.User); _runtimeTokenParams.OldAdminPin = !string.IsNullOrWhiteSpace(_commandLineOptions.OldAdminPin) ? new PinCode(PinCodeOwner.Admin, _commandLineOptions.OldAdminPin) : new PinCode(PinCodeOwner.Admin); _runtimeTokenParams.NewUserPin = !string.IsNullOrWhiteSpace(_commandLineOptions.UserPin) ? new PinCode(PinCodeOwner.User, _commandLineOptions.UserPin) : new PinCode(PinCodeOwner.User); _runtimeTokenParams.NewAdminPin = !string.IsNullOrWhiteSpace(_commandLineOptions.AdminPin) ? new PinCode(PinCodeOwner.Admin, _commandLineOptions.AdminPin) : new PinCode(PinCodeOwner.Admin); // TODO: сделать helper для битовых масок var adminCanChangeUserPin = (tokenExtendedInfo.Flags & (ulong)RutokenFlag.AdminChangeUserPin) == (ulong)RutokenFlag.AdminChangeUserPin; var userCanChangeUserPin = (tokenExtendedInfo.Flags & (ulong)RutokenFlag.UserChangeUserPin) == (ulong)RutokenFlag.UserChangeUserPin; _runtimeTokenParams.UserPinChangePolicy = UserPinChangePolicyFactory.Create(userCanChangeUserPin, adminCanChangeUserPin); _runtimeTokenParams.MinAdminPinLenFromToken = tokenExtendedInfo.MinAdminPinLen; _runtimeTokenParams.MaxAdminPinLenFromToken = tokenExtendedInfo.MaxAdminPinLen; _runtimeTokenParams.MinUserPinLenFromToken = tokenExtendedInfo.MinUserPinLen; _runtimeTokenParams.MaxUserPinLenFromToken = tokenExtendedInfo.MaxUserPinLen; _runtimeTokenParams.FlashMemoryAvailable = Convert.ToBoolean(tokenExtendedInfo.Flags & (uint)RutokenFlag.HasFlashDrive); try { _runtimeTokenParams.ExtendedPinPoliciesAvailable = PinPolicyWorker.PinPolicySupports(_slot); } catch (Exception) { _runtimeTokenParams.ExtendedPinPoliciesAvailable = false; } return(this); }