// 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);
            }));
        }
Exemple #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)
        {
            Debug.Assert(chunk.Id == "ACCT");

            return(WithBytes(chunk.Payload, reader =>
            {
                var placeholder = "decryption failed";

                // Read all items
                var id = ReadItem(reader).ToUtf8();
                var name = DecryptAes256Plain(ReadItem(reader), encryptionKey, placeholder);
                var group = DecryptAes256Plain(ReadItem(reader), encryptionKey, placeholder);
                var url = ReadItem(reader).ToUtf8().DecodeHex().ToUtf8();
                var notes = DecryptAes256Plain(ReadItem(reader), encryptionKey, placeholder);
                2.Times(() => SkipItem(reader));
                var username = DecryptAes256Plain(ReadItem(reader), encryptionKey, placeholder);
                var password = DecryptAes256Plain(ReadItem(reader), encryptionKey, placeholder);
                2.Times(() => 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;
                    }
                }

                // Override the group name with the shared folder name if any.
                if (folder != null)
                {
                    group = folder.Name;
                }

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