Beispiel #1
0
        public CommandHandlerBuilder PrintTokenInfo()
        {
            var tokenInfo = _slot.GetTokenInfoExtended();

            Console.WriteLine(_logMessageBuilder.WithTokenInfo(tokenInfo));

            return(this);
        }
Beispiel #2
0
        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);
        }