Ejemplo n.º 1
0
        private IEnumerable <AutotypeToken> GetProcessedTokens(Record record, IEnumerable <AutotypeToken> tokens, AutotypeToken suffixToken = null)
        {
            var tokenList = new List <AutotypeToken>(AutotypeToken.GetAutotypeTokens(tokens, this.Entry));

            if (suffixToken != null)
            {
                tokenList.Add(suffixToken);
            }

            var processedTokens = new List <AutotypeToken>();

            foreach (var token in tokenList)
            {
                if ((token.Kind == AutotypeTokenKind.Command) && token.Content.Equals("TwoFactorCode", StringComparison.Ordinal))
                {
                    var bytes = (record != null) ? record.GetBytes() : this.Entry.TwoFactorKey;
                    var key   = OneTimePassword.ToBase32(bytes, bytes.Length, SecretFormatFlags.Spacing | SecretFormatFlags.Padding);
                    processedTokens.AddRange(AutotypeToken.GetAutotypeTokensFromText(Helpers.GetTwoFactorCode(key)));
                }
                else
                {
                    processedTokens.Add(token);
                }
            }

            return(processedTokens.AsReadOnly());
        }
Ejemplo n.º 2
0
        public AutotypeForm(Entry entry)
        {
            InitializeComponent();

            this.Font = SystemFonts.MessageBoxFont;
            Medo.Windows.Forms.State.SetupOnLoadAndClose(this);
            this.Opacity = Settings.AutoTypeWindowOpacity / 100;

            var y = 0;

            foreach (var record in entry.Records)
            {
                if (record.RecordType == RecordType.Autotype)
                {
                    y = AddTokenButton(y, "Auto-type", AutotypeToken.GetUnexpandedAutotypeTokens(record.Text), isDefinedAutoType: true).Bottom;
                }
            }

            if (y == 0)   //no auto-type; use default
            {
                y = AddTokenButton(y, "Auto-type", AutotypeToken.GetUnexpandedAutotypeTokens(null), isDefinedAutoType: true).Bottom;
            }

            y += SystemInformation.DragSize.Height;

            //all textual fields
            foreach (var record in entry.Records)
            {
                var recordBytes = record.GetBytesSilently();
                try {
                    if (recordBytes.Length == 0)
                    {
                        continue;
                    }                                          //omit empty entries
                } finally {
                    Array.Clear(recordBytes, 0, recordBytes.Length);
                }

                switch (record.RecordType)
                {
                case RecordType.UserName:
                case RecordType.EmailAddress:
                case RecordType.CreditCardExpiration: {
                    var tokens = AutotypeToken.GetAutotypeTokensFromText(record.Text);
                    var btn    = AddTokenButton(y, Helpers.GetRecordCaption(record),
                                                tokens, record);
                    y = btn.Bottom;
                    AddSuffixButtons(btn, tokens, record);
                }
                break;

                case RecordType.Password:
                case RecordType.CreditCardPin:
                case RecordType.CreditCardVerificationValue: {
                    var tokens = AutotypeToken.GetAutotypeTokensFromText(record.Text);
                    var btn    = AddTokenButton(y, Helpers.GetRecordCaption(record),
                                                tokens, record, isTextHidden: true);
                    y = btn.Bottom;
                    AddSuffixButtons(btn, tokens, record);
                }
                break;

                case RecordType.TwoFactorKey: {
                    var tokens = AutotypeToken.GetUnexpandedAutotypeTokens(@"\2");
                    var btn    = AddTokenButton(y, Helpers.GetRecordCaption(record),
                                                tokens, record, isTextHidden: true);
                    y = btn.Bottom;
                    AddSuffixButtons(btn, tokens, record);
                }
                break;

                case RecordType.CreditCardNumber: {
                    var tokens = AutotypeToken.GetAutotypeTokensFromText(Helpers.FilterText(record.Text, Helpers.NumberCharacters));
                    var btn    = AddTokenButton(y, Helpers.GetRecordCaption(record),
                                                tokens, record);
                    y = btn.Bottom;
                    AddSuffixButtons(btn, tokens, record);
                }
                break;
                }
            }

            y += SystemInformation.DragSize.Height;

            var btnClose = AddGenericButton(y, "Close");

            btnClose.Click += delegate { this.Close(); };

            this.ClientSize  = new Size(SystemInformation.VerticalScrollBarWidth * 12, btnClose.Bottom);
            this.MinimumSize = new Size(SystemInformation.VerticalScrollBarWidth * 10, this.Height);
            this.MaximumSize = new Size(SystemInformation.VerticalScrollBarWidth * 30, this.Height);

            this.Entry = entry;
        }