Exemple #1
0
        public static Uri otpAuthDataToUri(PwEntry entry, OtpAuthData data)
        {
            UriBuilder uriBuilder = new UriBuilder();

            uriBuilder.Scheme = uriScheme;
            uriBuilder.Host   = data.Type.ToString().ToLower();
            uriBuilder.Path   = String.Format("{0}:{1}", entry.Strings.ReadSafe(PwDefs.TitleField), entry.Strings.ReadSafe(PwDefs.UserNameField));

            List <string> parameters = new List <string>();

            parameters.Add(String.Format("{0}={1}", uriSecretKey, data.GetPlainSecret()));
            parameters.Add(String.Format("{0}={1}", uriIssuerKey, Uri.EscapeDataString(entry.Strings.ReadSafe(PwDefs.TitleField))));
            if (data.Algorithm != OtpHashMode.Sha1)
            {
                parameters.Add(String.Format("{0}={1}", uriAlgorithmKey, data.Algorithm.ToString()));
            }
            if (data.Digits != 6)
            {
                parameters.Add(String.Format("{0}={1}", uriDigitsKey, data.Digits));
            }
            if (data.Type == OtpType.Hotp)
            {
                parameters.Add(String.Format("{0}={1}", uriCounterKey, data.Counter));
            }
            if (data.Period != 30)
            {
                parameters.Add(String.Format("{0}={1}", uriPeriodKey, data.Period));
            }

            uriBuilder.Query = String.Join("&", parameters.ToArray());

            return(uriBuilder.Uri);
        }
Exemple #2
0
        public static PwEntry migrateToKeeOtp1String(OtpAuthData data, PwEntry entry)
        {
            NameValueCollection collection = new NameValueCollection();

            collection.Add(KeeOtp1KeyParameter, data.GetPlainSecret());

            if (data.Type != OtpType.Totp)
            {
                collection.Add(KeeOtp1TypeParameter, data.Type.ToString());
            }

            if (data.Type == OtpType.Hotp)
            {
                collection.Add(KeeOtp1CounterParameter, data.Counter.ToString());
            }
            else if (data.Type == OtpType.Totp)
            {
                if (data.Period != 30)
                {
                    collection.Add(KeeOtp1StepParameter, data.Period.ToString());
                }
            }

            if (data.Digits != 6)
            {
                collection.Add(KeeOtp1SizeParameter, data.Digits.ToString());
            }

            if (data.Algorithm != OtpHashMode.Sha1)
            {
                collection.Add(KeeOtp1OtpHashModeParameter, data.Algorithm.ToString());
            }

            if (data.Encoding != OtpSecretEncoding.Base32)
            {
                collection.Add(KeeOtp1EncodingParameter, data.Encoding.ToString());
            }

            string output = string.Empty;

            foreach (var key in collection.AllKeys)
            {
                output += string.Format("{0}={1}&", key, collection[key]);
            }

            entry.Strings.Set(StringDictionaryKey, new ProtectedString(true, output.TrimEnd('&')));

            return(entry);
        }
Exemple #3
0
        public static PwEntry migrateToBuiltInOtp(OtpAuthData data, PwEntry entry)
        {
            string currentOtpPrefix = builtInTotpPrefix;

            if (data.Type == OtpType.Hotp)
            {
                currentOtpPrefix = builtInHotpPrefix;
            }

            if (data.Encoding == OtpSecretEncoding.Base32)
            {
                entry.Strings.Set(currentOtpPrefix + builtInBase32Suffix, new ProtectedString(true, data.GetPlainSecret()));
            }
            else if (data.Encoding == OtpSecretEncoding.Base64)
            {
                entry.Strings.Set(currentOtpPrefix + builtInBase64Suffix, new ProtectedString(true, data.GetPlainSecret()));
            }
            else if (data.Encoding == OtpSecretEncoding.Hex)
            {
                entry.Strings.Set(currentOtpPrefix + builtInHexSuffix, new ProtectedString(true, data.GetPlainSecret()));
            }
            else if (data.Encoding == OtpSecretEncoding.UTF8)
            {
                entry.Strings.Set(currentOtpPrefix + builtInUtf8Suffix, new ProtectedString(true, data.GetPlainSecret()));
            }

            if (data.Digits != 6)
            {
                entry.Strings.Set(currentOtpPrefix + builtInLengthSuffix, new ProtectedString(false, data.Digits.ToString()));
            }

            if (data.Algorithm != OtpHashMode.Sha1)
            {
                if (data.Algorithm == OtpHashMode.Sha1)
                {
                    entry.Strings.Set(currentOtpPrefix + builtInAlgorithmSuffix, new ProtectedString(false, builtInOtpHashModeSha1));
                }
                else if (data.Algorithm == OtpHashMode.Sha256)
                {
                    entry.Strings.Set(currentOtpPrefix + builtInAlgorithmSuffix, new ProtectedString(false, builtInOtpHashModeSha256));
                }
                else if (data.Algorithm == OtpHashMode.Sha512)
                {
                    entry.Strings.Set(currentOtpPrefix + builtInAlgorithmSuffix, new ProtectedString(false, builtInOtpHashModeSha512));
                }
            }

            if (data.Type == OtpType.Totp)
            {
                if (data.Period != 30)
                {
                    entry.Strings.Set(currentOtpPrefix + builtInPeriodSuffix, new ProtectedString(false, data.Period.ToString()));
                }
            }
            else if (data.Type == OtpType.Hotp)
            {
                entry.Strings.Set(currentOtpPrefix + builtInCounterSuffix, new ProtectedString(false, data.Counter.ToString()));
            }

            return(entry);
        }