コード例 #1
0
        public static string MakeAccountPath(string group, SharedFolder folder)
        {
            if (folder == null)
            {
                return(string.IsNullOrEmpty(group) ? "(none)" : group);
            }

            return(string.IsNullOrEmpty(group) ? folder.Name : $"{folder.Name}\\{group}");
        }
コード例 #2
0
        // May return null when the chunk does not represent an account.
        // All secure notes are ACCTs but not all of them store account information.
        //
        // TODO: Add a test for the folder case!
        // TODO: Add a test case that covers secure note account!
        public static Account Parse_ACCT(Chunk chunk, byte[] encryptionKey, SharedFolder folder = null)
        {
            return(chunk.Payload.Open(reader =>
            {
                var placeholder = "decryption failed";

                // Read all items
                var id = ReadItem(reader).ToUtf8();
                var name = Util.DecryptAes256Plain(ReadItem(reader), encryptionKey, placeholder);
                var group = Util.DecryptAes256Plain(ReadItem(reader), encryptionKey, placeholder);
                var url = ReadItem(reader).ToUtf8().DecodeHex().ToUtf8();

                // Ignore "group" accounts. They have no credentials.
                if (url == "http://group")
                {
                    return null;
                }

                var notes = Util.DecryptAes256Plain(ReadItem(reader), encryptionKey, placeholder);
                SkipItem(reader);
                SkipItem(reader);
                var username = Util.DecryptAes256Plain(ReadItem(reader), encryptionKey, placeholder);
                var password = Util.DecryptAes256Plain(ReadItem(reader), encryptionKey, placeholder);
                SkipItem(reader);
                SkipItem(reader);
                var secureNoteMarker = ReadItem(reader).ToUtf8();

                // Parse secure note
                if (secureNoteMarker == "1")
                {
                    var type = "";
                    ParseSecureNoteServer(notes, ref type, ref url, ref username, ref password);

                    // Only the some secure notes contain account-like information
                    if (!AllowedSecureNoteTypes.Contains(type))
                    {
                        return null;
                    }
                }

                // Adjust the path to include the group and the shared folder, if any.
                var path = MakeAccountPath(group, folder);

                return new Account(id, name, username, password, url, path);
            }));
        }