Ejemplo n.º 1
0
            private EntryOTP EnsureEntry(PwEntry pe)
            {
                EntryOTP otp;

                if (m_dEntryOTPData.TryGetValue(pe, out otp) && !IgnoreBuffer)
                {
                    return(otp);
                }
                otp.db         = pe.GetDB();
                otp.Loaded     = true;
                otp.OTPDefined = OTPDefined(pe);
                if (otp.OTPDefined != OTPDefinition.Complete)
                {
                    otp.ReadableOTP = otp.OTPDefined == OTPDefinition.Partial ? "???" : string.Empty;
                    otp.ValidTo     = DateTime.MaxValue;
                    otp.kpotp       = new KPOTP();
                    InitIssuerLabel(otp.kpotp, pe);
                }
                else
                {
                    otp.kpotp   = GetSettings(pe);
                    otp.ValidTo = KPOTP.UnixStartUTC;
                }
                UpdateOTPBuffer(pe, otp);
                PluginDebug.AddInfo("Fill OTP buffer", 0,
                                    "Entry uuid: " + pe.Uuid.ToString(),
                                    "OTP defined: " + otp.OTPDefined.ToString(),
                                    "OTP setup valid: " + otp.kpotp.Valid.ToString());
                return(otp);
            }
Ejemplo n.º 2
0
            public override void SaveOTP(KPOTP myOTP, PwEntry pe)
            {
                KPOTP prev = GetOTP(pe);
                bool  OnlyCounterChanged = false;

                if (!SettingsChanged(pe, prev, myOTP, out OnlyCounterChanged))
                {
                    return;
                }

                PluginDebug.AddInfo("Update OTP data",
                                    "Entry uuid: " + pe.Uuid.ToString(),
                                    "Only change of HOTP counter: " + OnlyCounterChanged.ToString());
                if (!OnlyCounterChanged)
                {
                    //Create backup if something else than only the HOTP counter was changed
                    pe.CreateBackup(pe.GetDB());
                }
                if (myOTP.OTPSeed.IsEmpty)
                {
                    pe.Strings.Remove(Config.OTPFIELD);
                    pe.Strings.Remove(Config.TIMECORRECTION);
                }
                else
                {
                    //pe.Strings.Set(Config.SETTINGS, new ProtectedString(false, otpSettings));
                    //pe.Strings.Set(Config.SEED, myOTP.OTPSeed);
                    pe.Strings.Set(Config.OTPFIELD, myOTP.OTPAuthString);
                    if (myOTP.TimeCorrectionUrlOwn)
                    {
                        pe.Strings.Set(Config.TIMECORRECTION, new ProtectedString(false, "OWNURL"));
                    }
                    else if (string.IsNullOrEmpty(myOTP.TimeCorrectionUrl) || (myOTP.TimeCorrectionUrl == "OFF"))
                    {
                        pe.Strings.Remove(Config.TIMECORRECTION);
                    }
                    else
                    {
                        pe.Strings.Set(Config.TIMECORRECTION, new ProtectedString(false, myOTP.TimeCorrectionUrl));
                    }
                }
                pe.Touch(true);
            }
Ejemplo n.º 3
0
        public static OTPHandler_Base GetOTPHandler(PwEntry pe)
        {
            if (pe == null)
            {
                return(null);
            }
            PwDatabase      db = pe.GetDB();
            OTPHandler_Base h  = GetOTPHandler(db);

            if (h != null)
            {
                return(h);
            }
            if (!m_EntryOTPDAOHandler.ContainsKey(ENTRYHANDLER))
            {
                m_EntryOTPDAOHandler[ENTRYHANDLER] = new OTPHandler_Entry();
            }
            return(m_EntryOTPDAOHandler[ENTRYHANDLER]);
        }